:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eceef4;
  --text: #1a1c20;
  --text-2: #5b5f69;
  --line: #d9dce4;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --accent-soft: #dfe6fb;
  --good: #1e7d3c;
  --warn: #9a5b00;
  --danger: #b3261e;
  --scrim: rgba(10, 12, 16, 0.45);
  --radius: 18px;
  --nav-h: 64px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316;
    --surface: #1d1f24;
    --surface-2: #2a2d33;
    --text: #e6e7ea;
    --text-2: #a3a7b1;
    --line: #353841;
    --accent: #a9c0ff;
    --accent-text: #0e2257;
    --accent-soft: #263457;
    --good: #7fd69a;
    --warn: #f2c06b;
    --danger: #ffb4ab;
    --scrim: rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; font-size: 16px; line-height: 1.4; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app { max-width: 680px; margin: 0 auto; min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top) + 14px) 20px 10px;
  background: var(--bg);
}
.topbar h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.01em; }

main { padding: 4px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); outline: none; }

.section-title { margin: 22px 4px 8px; font-size: 14px; font-weight: 600; color: var(--text-2); text-transform: none; }
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card.flush { padding: 0; overflow: hidden; }
.muted { color: var(--text-2); font-size: 14px; }
.small { font-size: 13px; }
.good { color: var(--good); }
.warn { color: var(--warn); }
.row { display: flex; align-items: center; gap: 12px; }
.row.top { align-items: flex-start; }
.grow { flex: 1; min-width: 0; }
.name { font-weight: 600; font-size: 17px; overflow-wrap: anywhere; }
.stack > * + * { margin-top: 4px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px; border-radius: 22px; border: 0;
  background: var(--surface-2); color: var(--text); font-weight: 600; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.text { background: transparent; color: var(--accent); padding: 0 12px; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn:focus-visible, select:focus-visible, input:focus-visible, .tile:focus-visible, .list-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

/* Form */
label.field { display: block; margin-top: 12px; }
label.field > span { display: block; font-size: 14px; color: var(--text-2); margin-bottom: 6px; }
input[type=text], input[type=password], select {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg);
}
select { -webkit-appearance: none; appearance: none; padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.pair-qr { width: 132px; height: 132px; border-radius: 8px; background: #fff; flex: none; }
.pair-code { font-size: 34px; font-weight: 700; letter-spacing: 0.08em; font-variant-numeric: tabular-nums; margin: 14px 0 4px; }
.error { color: var(--danger); font-size: 14px; margin-top: 8px; }

/* Settings list */
.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; min-height: 56px; }
.list-item + .list-item { border-top: 1px solid var(--line); }
.list-btn { width: 100%; text-align: left; background: none; border: 0; cursor: pointer; }
.list-item .value { color: var(--text-2); font-size: 15px; text-align: right; overflow-wrap: anywhere; }

/* Switch */
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch .track { position: absolute; inset: 0; border-radius: 16px; background: var(--surface-2); border: 2px solid var(--line); transition: background .15s; }
.switch .thumb { position: absolute; top: 8px; left: 8px; width: 16px; height: 16px; border-radius: 50%; background: var(--text-2); transition: all .15s; }
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track + .thumb { left: 24px; top: 4px; width: 24px; height: 24px; background: var(--accent-text); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Wallpaper tab */
.current-img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--surface-2); }
.current-info { padding: 12px 16px 16px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { position: relative; padding: 0; border: 0; border-radius: 12px; overflow: hidden; background: var(--surface-2); aspect-ratio: 4 / 3; cursor: pointer; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .badge { position: absolute; left: 6px; bottom: 6px; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: var(--accent); color: var(--accent-text); }
.empty { text-align: center; padding: 28px 16px; }

/* Devices */
.device { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.device .art { display: flex; justify-content: center; align-items: center; min-height: 80px; }
.device canvas { display: block; max-width: 100%; touch-action: none; }
.mode-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.mode-row > span { color: var(--text-2); font-size: 14px; flex: none; }
.explain { margin-top: 8px; font-size: 14px; color: var(--text-2); }
.explain b { color: var(--text); font-weight: 600; }
.phones { display: flex; gap: 16px; overflow-x: auto; padding: 4px 2px 2px; }
.phones figure { margin: 0; text-align: center; flex: none; }
.phones figcaption { font-size: 12px; color: var(--text-2); margin-top: 6px; max-width: 90px; overflow-wrap: anywhere; }
.crop-area { display: flex; gap: 16px; align-items: flex-start; justify-content: center; flex-wrap: wrap; }
.crop-side { flex: 1; min-width: 150px; }
.crop-side canvas { cursor: pointer; border-radius: 6px; }

/* Bottom navigation */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs button {
  flex: 1; max-width: 200px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 0; background: none; padding: 4px 0; cursor: pointer; color: var(--text-2); font-size: 12px; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.tabs svg { width: 56px; height: 30px; padding: 4px 16px; border-radius: 15px; fill: currentColor; }
.tabs button[aria-current=page] { color: var(--text); }
.tabs button[aria-current=page] svg { background: var(--accent-soft); }
.tabs button:focus-visible svg { outline: 2px solid var(--accent); }

/* Full-screen sheet */
.sheet { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-inner { max-width: 680px; margin: 0 auto; padding: 0 16px calc(env(safe-area-inset-bottom) + 96px); }
.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 8px) 0 8px; background: var(--bg); }
.sheet-head h2 { margin: 0; font-size: 20px; flex: 1; }
.sheet-foot { position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px); background: var(--bg); border-top: 1px solid var(--line); }
.sheet-foot .inner { max-width: 648px; margin: 0 auto; }

/* Small action sheet */
.scrim { position: fixed; inset: 0; z-index: 30; background: var(--scrim); display: flex; align-items: flex-end; justify-content: center; }
.actions { width: 100%; max-width: 520px; background: var(--surface); border-radius: 24px 24px 0 0; padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px); }
.actions img { width: 100%; max-height: 40vh; object-fit: contain; border-radius: 12px; background: var(--surface-2); }
.actions .btn { margin-top: 8px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 40;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  width: calc(100% - 32px); max-width: 520px; padding: 12px 16px; border-radius: 12px;
  background: #2b2e35; color: #f1f2f4; box-shadow: 0 4px 16px rgba(0,0,0,.25); font-size: 15px;
  display: flex; align-items: center; gap: 12px;
}
.toast .btn.text { color: #a9c0ff; margin-left: auto; min-height: 36px; }

.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } * { transition: none !important; } }

@media (min-width: 560px) {
  .device { grid-template-columns: 240px minmax(0, 1fr); align-items: start; }
  .grid { grid-template-columns: repeat(4, 1fr); }
}

.copy-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.copy-value { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; overflow-wrap: anywhere; }

a.btn { text-decoration: none; }
