/* =========================================================
   Hearth — design system
   Warm graphite surfaces, one ember accent, tactile keys.
   ========================================================= */
:root {
  color-scheme: dark light;
  --bg: #0f0e0d;
  --bg-raise: #171513;
  --sheet: #1a1816;
  --key: #23201d;
  --key-top: #2a2723;
  --key-press: #312d29;
  --hairline: rgba(255, 244, 230, .075);
  --hairline-2: rgba(255, 244, 230, .12);
  --text: #f6f1ea;
  --text-2: rgba(246, 241, 234, .62);
  --text-3: rgba(246, 241, 234, .38);
  --accent: #ff8a3d;
  --accent-hi: #ffb27a;
  --accent-deep: #d2501a;
  --accent-ink: #1b0f08;
  --ok: #5bd58e;
  --warn: #ffc247;
  --danger: #ff6159;
  --key-shadow: inset 0 1px 0 rgba(255,255,255,.065), inset 0 -1px 0 rgba(0,0,0,.25), 0 1px 1px rgba(0,0,0,.4), 0 10px 22px -12px rgba(0,0,0,.75);
  --glass: rgba(30, 27, 24, .72);
  --scrim: rgba(5, 4, 3, .55);
  --icon-accent: var(--accent);

  --r-key: 22px;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-sheet: cubic-bezier(.32, .72, 0, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif;
  --font-round: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f0eb;
    --bg-raise: #faf8f5;
    --sheet: #fbfaf7;
    --key: #ffffff;
    --key-top: #ffffff;
    --key-press: #ece7e0;
    --hairline: rgba(40, 28, 18, .08);
    --hairline-2: rgba(40, 28, 18, .13);
    --text: #1d1a17;
    --text-2: rgba(29, 26, 23, .6);
    --text-3: rgba(29, 26, 23, .36);
    --accent: #f2701f;
    --accent-hi: #ff9a5a;
    --accent-deep: #c2410c;
    --key-shadow: inset 0 1px 0 rgba(255,255,255,.9), 0 1px 1px rgba(60,40,20,.10), 0 8px 20px -12px rgba(60,40,20,.35);
    --glass: rgba(251, 250, 247, .78);
    --scrim: rgba(30, 22, 14, .28);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body {
  position: fixed; inset: 0; overflow: hidden;
  font: 17px/1.35 var(--font); color: var(--text);
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none; touch-action: manipulation;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; touch-action: manipulation; }
input { font: inherit; color: inherit; -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }
.ico { width: 24px; height: 24px; flex: none; display: block; }
img { -webkit-user-drag: none; }

/* ---------- Haptic switches (see tactile() in app.js) ----------
   A real iOS switch, practically invisible, covering the control so the user's tap toggles it. */
.hx-host { position: relative; }
.hx { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; opacity: .011; z-index: 2; cursor: pointer; border-radius: inherit; -webkit-tap-highlight-color: transparent; outline: none; }
.hx-round { clip-path: circle(50%); }
.dpad > .hx { z-index: 1; }
.dpad-ok { z-index: 3; }
body.no-hx .hx { display: none; }

/* ---------- App container (scales back when a sheet opens, like iOS) ---------- */
.app {
  position: absolute; inset: 0; background: var(--bg);
  transition: transform .5s var(--ease-sheet), border-radius .5s var(--ease-sheet), filter .5s var(--ease-sheet);
  transform-origin: 50% 100%;
}
body.sheet-open .app { transform: translateY(calc(var(--sat) * .35)) scale(.935); border-radius: 26px; overflow: hidden; filter: brightness(.72); }
@media (prefers-color-scheme: light) { body.sheet-open .app { filter: brightness(.9); } }
.view { position: absolute; inset: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 52px; padding: 0 24px; border-radius: 999px;
  font-weight: 600; font-size: 17px; letter-spacing: -.01em; text-decoration: none;
  transition: transform .25s var(--ease-spring), background .2s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 10px 30px -12px color-mix(in srgb, var(--accent) 75%, transparent), inset 0 1px 0 rgba(255,255,255,.28); }
.btn-ghost { background: var(--key); color: var(--text); box-shadow: var(--key-shadow); }
.btn-xl { height: 58px; width: 100%; font-size: 18px; }
.btn .ico { width: 22px; height: 22px; --icon-accent: var(--accent-ink); }
.text-btn { color: var(--accent); font-weight: 500; font-size: 17px; padding: 8px 4px; }
.pill-btn { height: 34px; padding: 0 16px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 15px; }
.icon-close { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--hairline-2); color: var(--text-2); }
.icon-close .ico { width: 18px; height: 18px; }
.fine { font-size: 13px; line-height: 1.45; color: var(--text-3); margin: 0; text-wrap: pretty; }

/* ---------- Guard / Welcome ---------- */
.guard { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: calc(var(--sat) + 24px) 32px calc(var(--sab) + 24px); gap: 14px; }
.guard-icon { border-radius: 22%; box-shadow: 0 18px 40px -16px rgba(0,0,0,.6); }
.guard h1 { font: 700 26px/1.15 var(--font-display); letter-spacing: -.02em; margin: 8px 0 0; }
.guard p { color: var(--text-2); margin: 0 0 12px; max-width: 32ch; }

.view-welcome { display: flex; flex-direction: column; padding-bottom: calc(var(--sab) + 20px); }
.welcome-art { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.welcome-art img {
  position: absolute; left: 50%; bottom: -2%; width: 138%; max-width: 760px; height: auto; transform: translateX(-52%);
  -webkit-mask-image: radial-gradient(72% 66% at 50% 50%, #000 58%, transparent 100%); mask-image: radial-gradient(72% 66% at 50% 50%, #000 58%, transparent 100%);
  animation: heroIn 1.4s var(--ease-out) both;
}
@media (prefers-color-scheme: light) { .welcome-art { background: radial-gradient(80% 60% at 50% 45%, #1a1512 0%, #1a1512 40%, var(--bg) 78%); } }
@keyframes heroIn { from { opacity: 0; transform: translateX(-52%) translateY(18px) scale(.97); } }
.welcome-copy { padding: 0 28px; animation: rise .9s .15s var(--ease-out) both; }
.eyebrow { margin: 0 0 10px; font: 600 13px/1 var(--font-round); letter-spacing: .16em; text-transform: uppercase; color: var(--accent); }
.display { margin: 0; font: 700 40px/1.04 var(--font-display); letter-spacing: -.035em; }
.lede { margin: 14px 0 0; color: var(--text-2); font-size: 17px; max-width: 30ch; text-wrap: pretty; }
.welcome-actions { padding: 28px 24px 0; display: grid; gap: 14px; text-align: center; animation: rise .9s .28s var(--ease-out) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* =========================================================
   REMOTE
   ========================================================= */
.view-remote {
  display: flex; flex-direction: column; align-items: center;
  padding: calc(var(--sat) + 4px) 20px calc(var(--sab) + 8px);
  --dpad: clamp(208px, min(76vw, calc(100svh - 496px)), 300px);
}

/* Top bar */
.topbar { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 60px; }
.device-switch { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 6px 10px 6px 6px; margin-left: -6px; border-radius: 18px; transition: background .2s, transform .25s var(--ease-spring); }
.device-switch:active { background: var(--hairline); transform: scale(.98); }
.dev-glyph { position: relative; width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: var(--key); box-shadow: var(--key-shadow); color: var(--text); }
.dev-glyph .ico { width: 24px; height: 24px; }
.status-dot { position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%; background: var(--text-3); border: 2.5px solid var(--bg); transition: background .3s; }
.status-dot[data-state="connected"] { background: var(--ok); }
.status-dot[data-state="connecting"], .status-dot[data-state="pairing"] { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.status-dot[data-state="offline"], .status-dot[data-state="declined"] { background: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }
.dev-text { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; text-align: left; }
.dev-name { font: 600 19px/1.2 var(--font-display); letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }
.dev-sub { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }
.chev { width: 18px; height: 18px; color: var(--text-3); }

.round-btn {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: var(--key); box-shadow: var(--key-shadow); color: var(--text);
  transition: transform .32s var(--ease-spring), background .2s, color .2s;
}
.power-btn { width: 44px; height: 44px; color: var(--accent); --icon-accent: var(--accent); }
.power-btn .ico { width: 22px; height: 22px; }

/* Mode segmented control */
.mode-bar { height: 48px; display: grid; place-items: center; }
.segmented {
  position: relative; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 3px; border-radius: 12px;
  background: var(--hairline); min-width: 264px;
}
.segmented button { position: relative; z-index: 1; height: 32px; padding: 0 12px; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); transition: color .25s; white-space: nowrap; }
.segmented button .ico { width: 16px; height: 16px; --icon-accent: currentColor; }
.segmented button[aria-selected="true"] { color: var(--text); }
.segmented button[aria-selected="true"] .ico { --icon-accent: var(--accent); }
.seg-thumb { position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 3px; border-radius: 9px; background: var(--key-top); box-shadow: 0 1px 2px rgba(0,0,0,.25), 0 3px 10px -4px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.06); transition: transform .42s var(--ease-sheet), width .42s var(--ease-sheet); }

/* Stage */
.stage { position: relative; flex: 1 1 auto; width: 100%; display: grid; place-items: center; min-height: calc(var(--dpad) + 8px); }

/* D-pad */
.dpad { position: relative; width: var(--dpad); height: var(--dpad); touch-action: none; border-radius: 50%; }
.dpad::before { /* soft floor shadow */
  content: ""; position: absolute; inset: 6% 6% -4% 6%; border-radius: 50%; background: radial-gradient(closest-side, rgba(0,0,0,.55), transparent); filter: blur(14px); z-index: -1;
}
@media (prefers-color-scheme: light) { .dpad::before { background: radial-gradient(closest-side, rgba(80,50,20,.22), transparent); } }
.dpad-svg { width: 100%; height: 100%; display: block; overflow: visible; }
.wedge path.w { fill: var(--key); stroke: var(--hairline-2); stroke-width: 1; transition: fill .22s var(--ease-out); }
.wedge path.hl { fill: none; stroke: rgba(255,255,255,.07); stroke-width: 1.5; }
@media (prefers-color-scheme: light) { .wedge path.hl { stroke: rgba(255,255,255,1); } }
.wedge path.glow { fill: url(#g-ember); opacity: 0; transition: opacity .35s var(--ease-out); }
.wedge path.chev { fill: none; stroke: var(--text-2); stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; transition: stroke .2s, transform .25s var(--ease-spring); transform-box: fill-box; transform-origin: center; }
.wedge.is-pressed path.glow { opacity: 1; transition-duration: .05s; }
.wedge.is-pressed path.chev { stroke: var(--accent-ink); transform: scale(.86); }
.dpad.is-pressed-any .dpad-svg { filter: drop-shadow(0 0 22px color-mix(in srgb, var(--accent) 35%, transparent)); }

.dpad-ok {
  position: absolute; left: 50%; top: 50%; width: 40%; height: 40%; transform: translate(-50%, -50%);
  border-radius: 50%; background: var(--key-top); color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 0 0 1px var(--hairline-2), 0 2px 3px rgba(0,0,0,.4), 0 18px 34px -16px rgba(0,0,0,.85);
  font: 600 19px/1 var(--font-round); letter-spacing: .04em;
  transition: transform .3s var(--ease-spring), background .2s, color .2s, box-shadow .2s;
}
@media (prefers-color-scheme: light) { .dpad-ok { box-shadow: inset 0 1px 0 #fff, 0 0 0 1px var(--hairline-2), 0 10px 24px -12px rgba(60,40,20,.4); } }
.dpad-ok.is-pressed { transform: translate(-50%, -50%) scale(.93); background: var(--accent); color: var(--accent-ink); box-shadow: 0 0 0 1px transparent, 0 0 36px -4px color-mix(in srgb, var(--accent) 70%, transparent); transition-duration: .06s; }

/* Touchpad */
.touchpad {
  position: relative; width: min(calc(var(--dpad) * 1.12), 100%); height: var(--dpad); border-radius: 34px; touch-action: none; overflow: hidden;
  background: var(--bg-raise); box-shadow: inset 0 0 0 1px var(--hairline), inset 0 1px 0 rgba(255,255,255,.04);
}
.tp-grain { position: absolute; inset: 0; opacity: .5;
  background-image: radial-gradient(var(--hairline-2) 1px, transparent 1.2px); background-size: 18px 18px; background-position: 9px 9px;
  -webkit-mask-image: radial-gradient(closest-side, #000, transparent); mask-image: radial-gradient(closest-side, #000 40%, transparent 100%); }
.tp-hint { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 0 28px; text-align: center; font-size: 13px; line-height: 1.4; color: var(--text-3); transition: opacity .4s; pointer-events: none; }
.tp-hint .ico { width: 34px; height: 34px; color: var(--text-2); --icon-accent: var(--accent); opacity: .8; }
.tp-dot { position: absolute; left: 0; top: 0; width: 64px; height: 64px; margin: -32px 0 0 -32px; border-radius: 50%; pointer-events: none; opacity: 0;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 55%, transparent) 0, color-mix(in srgb, var(--accent) 18%, transparent) 45%, transparent 70%);
  transition: opacity .3s, transform .12s; }
.tp-dot.on { opacity: 1; }
.tp-ripple { position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; border: 2px solid var(--accent); pointer-events: none; animation: ripple .55s var(--ease-out) forwards; }
@keyframes ripple { to { transform: scale(5.5); opacity: 0; } }
.tp-arrow { position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; color: var(--accent); pointer-events: none; animation: arrowFlash .42s var(--ease-out) forwards; }
@keyframes arrowFlash { from { opacity: .95; } to { opacity: 0; transform: translate(var(--tx), var(--ty)); } }

/* Stage status overlay */
.stage-status { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 16px; border-radius: 999px;
  background: var(--glass); -webkit-backdrop-filter: blur(20px) saturate(1.4); backdrop-filter: blur(20px) saturate(1.4); box-shadow: 0 0 0 1px var(--hairline-2), 0 20px 40px -20px rgba(0,0,0,.7);
  font-size: 15px; font-weight: 500; white-space: nowrap; z-index: 5; animation: rise .35s var(--ease-out); }
.view-remote.is-offline .dpad, .view-remote.is-offline .touchpad, .view-remote.is-offline .nav-row, .view-remote.is-offline .rockers, .view-remote.is-offline .dock { opacity: .38; filter: saturate(.4); transition: opacity .4s, filter .4s; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--hairline-2); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Nav row */
.nav-row { display: flex; justify-content: center; gap: clamp(28px, 10vw, 44px); padding: 10px 0 14px; }
.nav-row .round-btn { width: 58px; height: 58px; }

/* Rockers */
.rockers { display: grid; grid-template-columns: 64px auto 64px; align-items: center; justify-content: center; column-gap: clamp(30px, 11vw, 48px); padding-bottom: 14px; }
.rocker { display: grid; grid-template-rows: 1fr auto 1fr; width: 64px; height: clamp(124px, 17svh, 148px); border-radius: 32px; background: var(--key); box-shadow: var(--key-shadow); overflow: hidden; position: relative; }
.rocker button { display: grid; place-items: center; color: var(--text); transition: background .18s, color .18s; position: relative; }
.rocker button .ico { width: 22px; height: 22px; transition: transform .28s var(--ease-spring); }
.rocker button.is-pressed { background: color-mix(in srgb, var(--accent) 16%, var(--key)); color: var(--accent); transition-duration: .04s; }
.rocker button.is-pressed .ico { transform: scale(.86); }
.rocker-label { font: 600 11px/1 var(--font-round); letter-spacing: .14em; color: var(--text-3); text-align: center; padding: 2px 0; }
.rocker-mid { display: grid; gap: 14px; }

.round-btn .ico { transition: transform .3s var(--ease-spring); }
.round-btn.is-pressed { transform: scale(.92); background: var(--key-press); transition-duration: .05s; }
.round-btn.is-pressed .ico { transform: scale(.9); }
#muteBtn.is-on { background: color-mix(in srgb, var(--accent) 22%, var(--key)); color: var(--accent); }

/* Dock */
.dock { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; max-width: 380px; padding: 6px; border-radius: 24px; background: var(--bg-raise); box-shadow: inset 0 0 0 1px var(--hairline); }
.dock button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 9px 0 8px; border-radius: 18px; font-size: 11px; font-weight: 600; color: var(--text-2); transition: background .2s, transform .3s var(--ease-spring), color .2s; }
.dock button .ico { width: 24px; height: 24px; color: var(--text); }
.dock button.is-pressed { background: var(--hairline-2); transform: scale(.95); transition-duration: .05s; }

/* Volume HUD */
.hud { position: absolute; left: 50%; top: calc(var(--sat) + 66px); transform: translate(-50%, -12px) scale(.96); opacity: 0; pointer-events: none; z-index: 20;
  display: flex; align-items: center; gap: 10px; padding: 11px 18px 11px 14px; border-radius: 999px; width: min(300px, calc(100vw - 48px));
  background: var(--glass); -webkit-backdrop-filter: blur(24px) saturate(1.5); backdrop-filter: blur(24px) saturate(1.5); box-shadow: 0 0 0 1px var(--hairline-2), 0 18px 40px -18px rgba(0,0,0,.7);
  transition: opacity .3s var(--ease-out), transform .45s var(--ease-spring); }
.hud.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.hud .ico { width: 20px; height: 20px; color: var(--text); }
.hud-bar { flex: 1; height: 6px; border-radius: 3px; background: var(--hairline-2); overflow: hidden; }
.hud-bar i { display: block; height: 100%; width: 0; border-radius: 3px; background: linear-gradient(90deg, var(--accent-deep), var(--accent)); transition: width .25s var(--ease-out); }
.hud-num { font: 600 15px/1 var(--font-round); font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }

/* Toast */
.toast { position: fixed; left: 50%; top: calc(var(--sat) + 10px); z-index: 90; transform: translate(-50%, -140%); width: max-content; max-width: calc(100vw - 32px);
  padding: 11px 18px; border-radius: 999px; font-size: 15px; font-weight: 500; color: var(--text);
  background: var(--glass); -webkit-backdrop-filter: blur(24px) saturate(1.5); backdrop-filter: blur(24px) saturate(1.5); box-shadow: 0 0 0 1px var(--hairline-2), 0 18px 40px -18px rgba(0,0,0,.7);
  transition: transform .5s var(--ease-spring); pointer-events: none; text-align: center; }
.toast.show { transform: translate(-50%, 0); }

/* =========================================================
   SHEETS
   ========================================================= */
.scrim { position: fixed; inset: 0; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity .45s var(--ease-sheet); z-index: 40; }
body.sheet-open .scrim { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; max-height: calc(100svh - var(--sat) - 10px);
  display: flex; flex-direction: column; background: var(--sheet); border-radius: 30px 30px 0 0;
  box-shadow: 0 -1px 0 var(--hairline-2), 0 -30px 60px -30px rgba(0,0,0,.6);
  transform: translateY(105%); transition: transform .5s var(--ease-sheet); visibility: hidden;
  padding-bottom: calc(var(--sab) + 12px); will-change: transform;
}
.sheet.open { transform: translateY(0); visibility: visible; }
body.kb-open .sheet { bottom: var(--kb, 0px); padding-bottom: 12px; max-height: calc(100svh - var(--kb, 0px) - var(--sat) - 10px); transition: transform .5s var(--ease-sheet), bottom .25s var(--ease-out); }
body.kb-open .sheet-tall { height: auto; }
.sheet.dragging { transition: none; }
.sheet-tall { height: calc(100svh - var(--sat) - 10px); }
.sheet-grab { height: 22px; display: grid; place-items: center; flex: none; touch-action: none; }
.sheet-grab i { width: 38px; height: 5px; border-radius: 3px; background: var(--hairline-2); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 0 20px 10px; flex: none; touch-action: none; }
.sheet-head h2 { margin: 0; font: 700 24px/1.2 var(--font-display); letter-spacing: -.025em; }
.sheet-body { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 4px 16px 8px; touch-action: pan-y; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; border-radius: 18px; background: var(--bg-raise); box-shadow: inset 0 0 0 1px var(--hairline); overflow: hidden; }
.list:empty { display: none; }
.list li { position: relative; }
.list li + li::before { content: ""; position: absolute; top: 0; left: 70px; right: 0; height: 1px; background: var(--hairline); }
.row { width: 100%; display: flex; align-items: center; gap: 14px; padding: 12px 14px; min-height: 66px; text-align: left; transition: background .15s; }
.row:active, .row.is-pressed { background: var(--hairline); }
.row-ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--key); box-shadow: var(--key-shadow); flex: none; color: var(--text); position: relative; }
.row-ico img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { font-weight: 600; font-size: 17px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-end { color: var(--text-3); display: flex; align-items: center; gap: 8px; }
.row-end .ico { width: 20px; height: 20px; }
.row-check { color: var(--accent); }
.row input.rename { font-weight: 600; font-size: 17px; background: var(--key); border: 0; border-radius: 10px; padding: 8px 10px; width: 100%; outline: none; box-shadow: inset 0 0 0 1px var(--hairline-2); }
.row-del { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }
.row-del .ico { width: 18px; height: 18px; }

.badge { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px 0 5px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: .01em; }
.badge .ico { width: 13px; height: 13px; }
.badge-verified { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); --icon-accent: var(--ok); }
.badge-exp { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }

.list-add { width: 100%; display: flex; align-items: center; gap: 14px; margin-top: 12px; padding: 12px 14px; border-radius: 18px; color: var(--accent); font-weight: 600; font-size: 17px; background: var(--bg-raise); box-shadow: inset 0 0 0 1px var(--hairline); transition: transform .3s var(--ease-spring); }
.list-add:active { transform: scale(.98); }
.list-add.subtle { background: transparent; box-shadow: none; color: var(--text-2); font-weight: 500; }
.add-ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.list-add.subtle .add-ico { background: var(--hairline); color: var(--text-2); }
.add-ico .ico { width: 20px; height: 20px; }

.settings { margin-top: 22px; display: grid; gap: 12px; }
.setting { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-radius: 16px; background: var(--bg-raise); box-shadow: inset 0 0 0 1px var(--hairline); font-weight: 500; }
.setting input[type=checkbox] { accent-color: var(--accent); transform: scale(1.1); }
.settings .fine { padding: 0 4px; }

/* Add TV */
.add-body { display: flex; flex-direction: column; }
.add-step { display: flex; flex-direction: column; animation: rise .45s var(--ease-out); }
.radar { position: relative; width: 132px; height: 132px; margin: 18px auto 8px; display: grid; place-items: center; }
.radar span { position: absolute; inset: 0; border-radius: 50%; border: 1.5px solid color-mix(in srgb, var(--accent) 60%, transparent); animation: radar 2.4s var(--ease-out) infinite; opacity: 0; }
.radar span:nth-child(2) { animation-delay: .8s; } .radar span:nth-child(3) { animation-delay: 1.6s; }
.radar.done span { animation: none; }
@keyframes radar { 0% { transform: scale(.35); opacity: .9; } 100% { transform: scale(1); opacity: 0; } }
.radar .ico { width: 46px; height: 46px; padding: 14px; box-sizing: content-box; border-radius: 22px; background: var(--key); box-shadow: var(--key-shadow); color: var(--text); }
.scan-status { text-align: center; color: var(--text-2); font-size: 15px; margin: 6px 0 12px; min-height: 20px; }
.scan-progress { height: 3px; border-radius: 2px; background: var(--hairline); margin: 0 auto 18px; width: 140px; overflow: hidden; transition: opacity .4s; }
.scan-progress i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 2px; transition: width .3s var(--ease-out); }
.found li { animation: rise .4s var(--ease-out); }
.manual { display: grid; gap: 14px; margin-top: 10px; animation: rise .35s var(--ease-out); }
.field { display: grid; gap: 6px; }
.field span { font-size: 13px; font-weight: 600; color: var(--text-2); padding-left: 4px; }
.field input { height: 52px; border-radius: 14px; border: 0; outline: none; padding: 0 16px; font-size: 17px; background: var(--bg-raise); box-shadow: inset 0 0 0 1px var(--hairline-2); transition: box-shadow .2s; }
.field input:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.platform-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.platform-pick button { height: 64px; border-radius: 14px; background: var(--bg-raise); box-shadow: inset 0 0 0 1px var(--hairline-2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-weight: 600; font-size: 15px; transition: box-shadow .2s, transform .3s var(--ease-spring); }
.platform-pick button small { font-size: 11px; font-weight: 600; color: var(--warn); }
.platform-pick button small.v { color: var(--ok); }
.platform-pick button[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--accent); }
.platform-pick button:active { transform: scale(.97); }

.pair-art { position: relative; width: min(78%, 300px); margin: 6px auto 0; aspect-ratio: 1; }
.pair-art::before { content: ""; position: absolute; inset: 18%; border-radius: 50%; background: radial-gradient(closest-side, color-mix(in srgb, var(--accent) 38%, transparent), transparent); filter: blur(24px); animation: breathe 2.6s ease-in-out infinite; }
.pair-art img { position: relative; width: 100%; height: 100%; object-fit: contain; }
@keyframes breathe { 50% { transform: scale(1.12); opacity: .6; } }
.pair-title { text-align: center; margin: 6px 0 6px; font: 700 26px/1.15 var(--font-display); letter-spacing: -.025em; }
.pair-text { text-align: center; color: var(--text-2); margin: 0 auto; max-width: 30ch; text-wrap: pretty; }
.pair-text b { color: var(--accent); font-weight: 600; }
.pair-state { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 18px 0 22px; color: var(--text-2); font-size: 15px; min-height: 22px; text-align: center; }
.pair-state.err { color: var(--danger); }
.pair-state.err .spinner { display: none; }
.pair-actions { display: flex; gap: 10px; justify-content: center; }
.pair-actions .btn { flex: 1; max-width: 200px; }

.done-mark { width: 92px; height: 92px; margin: 34px auto 6px; }
.done-mark svg { width: 100%; height: 100%; }
.done-mark circle { fill: color-mix(in srgb, var(--ok) 15%, transparent); stroke: var(--ok); stroke-width: 2.5; stroke-dasharray: 151; stroke-dashoffset: 151; animation: draw .6s var(--ease-out) forwards; }
.done-mark path { fill: none; stroke: var(--ok); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 40; stroke-dashoffset: 40; animation: draw .45s .4s var(--ease-out) forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
[data-step="done"] .field { margin: 18px 0 20px; }

/* Apps */
.app-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px 10px; padding: 8px 4px 20px; }
.app-tile { display: flex; flex-direction: column; align-items: center; gap: 7px; transition: transform .3s var(--ease-spring); }
.app-tile.is-pressed { transform: scale(.92); transition-duration: .06s; }
.app-tile .app-ico { position: relative; width: 64px; height: 64px; border-radius: 16px; background: var(--key); box-shadow: var(--key-shadow); overflow: hidden; display: grid; place-items: center; font: 700 26px/1 var(--font-round); color: var(--text-2); }
.app-tile .app-ico::before { content: attr(data-l); }
.app-tile .app-ico img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.app-tile span { font-size: 12px; line-height: 1.2; text-align: center; color: var(--text-2); max-width: 76px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.skeleton { background: linear-gradient(100deg, var(--key) 30%, var(--key-press) 50%, var(--key) 70%); background-size: 300% 100%; animation: shimmer 1.3s linear infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -50% 0; } }
.empty { text-align: center; padding: 30px 20px; color: var(--text-2); font-size: 15px; }

/* Keyboard */
.kb-form { margin: 6px 0 12px; }
.kb-input { width: 100%; height: 56px; border-radius: 16px; border: 0; outline: none; padding: 0 18px; font-size: 19px; background: var(--bg-raise); box-shadow: inset 0 0 0 2px var(--accent); caret-color: var(--accent); }
.sheet-kb .fine { padding: 0 4px; }

/* Short screens (iPhone SE, mini) */
@media (max-height: 740px) {
  .view-remote { --dpad: clamp(190px, min(70vw, calc(100svh - 430px)), 260px); }
  .topbar { height: 52px; }
  .mode-bar { height: 42px; }
  .nav-row { padding: 6px 0 10px; }
  .nav-row .round-btn, .round-btn { width: 50px; height: 50px; }
  .rocker { height: 112px; width: 58px; }
  .rockers { grid-template-columns: 58px auto 58px; padding-bottom: 10px; }
  .rocker-mid { gap: 10px; }
  .dock button { padding: 7px 0 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important; }
}
