:root {
  --bg: #0b0d12;
  --surface: #151922;
  --surface-2: #1c212c;
  --line: rgba(255, 255, 255, .07);
  --text: #eef1f6;
  --muted: #8a93a6;
  --accent: #6d8bff;
  --accent-2: #9b6dff;
  --danger: #ff4d5e;
  --ok: #34d399;
  --warn: #fbbf24;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .05);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(900px 500px at 50% -200px, rgba(109, 139, 255, .16), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }
h1, h2 { margin: 0; }

.screen {
  max-width: 440px; margin: 0 auto; min-height: 100vh; min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 14px) 18px calc(env(safe-area-inset-bottom) + 28px);
  animation: fade .25s ease;
}
.screen[hidden] { display: none; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line); flex: none; }
.icon-btn:active { transform: scale(.94); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 21px; font-weight: 700; letter-spacing: -.01em; }
.sub { margin: 0; color: var(--muted); font-size: 13px; }
#scanBtn.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* dashboard */
.devices { display: flex; flex-direction: column; gap: 12px; }
.device {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 14px; border-radius: 22px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line); box-shadow: var(--shadow);
  transition: transform .08s ease;
  animation: fade .3s ease both;
}
.device:active { transform: scale(.98); }
.device .ico {
  width: 56px; height: 56px; border-radius: 16px; flex: none; display: grid; place-items: center;
  background: linear-gradient(145deg, rgba(109, 139, 255, .25), rgba(155, 109, 255, .18));
  color: #c7d2ff;
}
.device .ico svg { width: 28px; height: 28px; }
.device.dim .ico { background: rgba(255, 255, 255, .05); color: var(--muted); }
.device .info { flex: 1; min-width: 0; }
.device .name { font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device .meta { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.device .chev { color: var(--muted); flex: none; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; display: inline-block; transition: background .3s, box-shadow .3s; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 211, 153, .18); }
.dot.wait { background: var(--warn); box-shadow: 0 0 0 3px rgba(251, 191, 36, .18); animation: pulse 1.4s infinite; }
.dot.off { background: #5b6375; }
.dot.bad { background: var(--danger); }
@keyframes pulse { 50% { opacity: .45; } }

.empty { text-align: center; padding: 48px 16px 24px; }
.empty h2 { font-size: 18px; margin-top: 22px; }
.empty p { color: var(--muted); margin: 8px 0 0; }
.radar { position: relative; width: 92px; height: 92px; margin: 0 auto; display: grid; place-items: center; color: #c7d2ff; }
.radar svg { width: 34px; height: 34px; position: relative; }
.radar span { position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(109, 139, 255, .5); animation: ring 2s ease-out infinite; }
.radar span + span { animation-delay: 1s; }
.empty.idle .radar span { animation: none; opacity: .25; }
@keyframes ring { from { transform: scale(.45); opacity: 1; } to { transform: scale(1.15); opacity: 0; } }
.foot { color: #5b6375; font-size: 12.5px; text-align: center; margin: 28px 12px 0; }

/* remote header */
.title { flex: 1; min-width: 0; text-align: center; }
.dev-name { font-weight: 650; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dev-state { color: var(--muted); font-size: 13px; display: flex; align-items: center; justify-content: center; gap: 6px; }

.banner {
  margin: -4px 0 16px; padding: 12px 14px; border-radius: 16px; font-size: 14px;
  background: rgba(251, 191, 36, .1); border: 1px solid rgba(251, 191, 36, .25); color: #fde68a;
}
.banner.error { background: rgba(255, 77, 94, .1); border-color: rgba(255, 77, 94, .3); color: #fecdd3; }

/* shared button look */
.round, .pill, .sq, .rocker, .numpad button {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transition: transform .08s ease, background .2s;
}
.round:active, .pill:active, .sq:active, .numpad button:active, .rocker button:active { transform: scale(.94); }
.pressed { background: linear-gradient(180deg, #262c3a, #1d2230) !important; }

.row { display: flex; gap: 12px; justify-content: space-between; }
.quick .round { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; }
.round.power { color: var(--danger); }
.round.power:active { background: rgba(255, 77, 94, .18) !important; }

/* d-pad */
.dpad-wrap { display: grid; place-items: center; margin: 26px 0; }
.dpad {
  position: relative; width: min(78vw, 290px); aspect-ratio: 1; border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, transparent 37%, rgba(255, 255, 255, .03) 37.5%, transparent 70%),
    linear-gradient(160deg, #1f2431, #12151c);
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .06);
  touch-action: none;
}
.dpad::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%; opacity: 0; transition: opacity .12s;
  background: conic-gradient(from var(--a, 0deg), rgba(109, 139, 255, .28) 0 90deg, transparent 90deg);
  -webkit-mask: radial-gradient(circle, transparent 36%, #000 36.5%);
          mask: radial-gradient(circle, transparent 36%, #000 36.5%);
}
.dpad[data-hit="up"]::before { --a: -45deg; opacity: 1; }
.dpad[data-hit="right"]::before { --a: 45deg; opacity: 1; }
.dpad[data-hit="down"]::before { --a: 135deg; opacity: 1; }
.dpad[data-hit="left"]::before { --a: 225deg; opacity: 1; }
.arrow { position: absolute; color: var(--muted); pointer-events: none; }
.arrow svg { width: 28px; height: 28px; }
.arrow.up { top: 7%; left: 50%; translate: -50% 0; }
.arrow.down { bottom: 7%; left: 50%; translate: -50% 0; }
.arrow.left { left: 7%; top: 50%; translate: 0 -50%; }
.arrow.right { right: 7%; top: 50%; translate: 0 -50%; }
.ok {
  position: absolute; inset: 31%; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; letter-spacing: .08em; pointer-events: none;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 26px rgba(109, 139, 255, .45), inset 0 1px 0 rgba(255, 255, 255, .25);
  transition: transform .1s;
}
.dpad[data-hit="ok"] .ok { transform: scale(.93); filter: brightness(1.1); }

.nav .pill { flex: 1; }
.pill { height: 50px; border-radius: 16px; display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 550; font-size: 14px; }
.pill svg { width: 18px; height: 18px; }

.rockers { display: grid; grid-template-columns: 68px 1fr 68px; gap: 14px; margin-top: 16px; align-items: stretch; }
.rocker { border-radius: 34px; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 4px 0; }
.rocker button { width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; }
.rocker span { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .1em; }
.media { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sq { border-radius: 18px; display: grid; place-items: center; min-height: 64px; }
.sq svg { width: 20px; height: 20px; }

.more { margin-top: 16px; width: 100%; color: #d7dbe4; }
.num-ico { font-size: 11px; font-weight: 800; letter-spacing: .04em; padding: 3px 7px; border-radius: 8px; background: rgba(109, 139, 255, .18); color: #c7d2ff; }

/* numbers sheet */
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 10px; }
.numpad button { height: 60px; border-radius: 18px; font-size: 24px; font-weight: 600; }
.numpad button.small { font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--muted); }
.colors { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 16px 0; }
.colors button { height: 34px; border-radius: 12px; background: var(--c); opacity: .85; }
.colors button:active { opacity: 1; transform: scale(.95); }
.extra .pill { flex: 1; font-size: 13px; padding: 0 4px; }

/* sheets */
.sheet { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; justify-content: center; z-index: 10; animation: fadebg .2s; }
.sheet[hidden] { display: none; }
@keyframes fadebg { from { background: rgba(0, 0, 0, 0); } }
.sheet-card {
  width: 100%; max-width: 440px; max-height: 88vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 26px 26px 0 0; padding: 18px 18px calc(env(safe-area-inset-bottom) + 20px);
  animation: up .25s cubic-bezier(.2, .9, .3, 1); user-select: text; -webkit-user-select: text;
}
@keyframes up { from { transform: translateY(40%); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sheet-head h2 { font-size: 19px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 14px; }
form { display: flex; flex-direction: column; gap: 12px; }
input {
  width: 100%; height: 50px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg);
  color: var(--text); padding: 0 14px; font: inherit; font-size: 16px; outline: none; margin-top: 6px;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(109, 139, 255, .2); }
label { font-size: 13px; color: var(--muted); font-weight: 600; }
.primary, .ghost { height: 50px; border-radius: 14px; font-weight: 650; padding: 0 18px; flex: none; }
.primary { background: linear-gradient(145deg, var(--accent), var(--accent-2)); color: #fff; }
.ghost { color: var(--muted); }
.wide { width: 100%; }
.primary:active { transform: scale(.98); }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 28px); translate: -50% 0;
  background: #262c3a; border: 1px solid var(--line); padding: 10px 16px; border-radius: 14px;
  font-size: 14px; z-index: 20; box-shadow: var(--shadow); max-width: 90vw; animation: up .2s;
}

@media (min-width: 700px) {
  .screen { padding-top: 32px; }
}

/* ---------- no zooming: double-tap, pinch, long-press callouts ---------- */
* { touch-action: manipulation; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-touch-callout: none; }

/* ---------- remote: one fixed screen, scaled to the phone ----------
   --u is one "design pixel": the layout is drawn for 400x800 and shrinks
   or grows (up to 12%) to fit the device, so nothing scrolls or overflows. */
#remote {
  --u: min(calc(100vw / 400), calc(100vh / 800), 1.12px);
  --u: min(calc(100vw / 400), calc(100dvh / 800), 1.12px);
  position: fixed; inset: 0; margin: 0 auto; max-width: 440px;
  height: 100vh; height: 100dvh; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12 * var(--u)) 18px calc(env(safe-area-inset-bottom) + 18 * var(--u));
}
#remote[hidden] { display: none; }
#remote .top { margin: 0; }
#remote .icon-btn { width: calc(44 * var(--u)); height: calc(44 * var(--u)); border-radius: calc(14 * var(--u)); }
#remote .dev-name { font-size: calc(17 * var(--u)); }
#remote .dev-state { font-size: calc(13 * var(--u)); }

#remote .banner {
  position: absolute; z-index: 4; left: 18px; right: 18px; margin: 0;
  top: calc(env(safe-area-inset-top) + 64 * var(--u));
  background: rgba(40, 33, 12, .94); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
#remote .banner.error { background: rgba(48, 16, 22, .94); }

#remote .quick { justify-content: center; gap: calc(30 * var(--u)); }
#remote .quick .round { width: calc(64 * var(--u)); height: calc(64 * var(--u)); }
#remote .round svg { width: calc(22 * var(--u)); height: calc(22 * var(--u)); }

#remote .dpad-wrap { margin: 0; }
#remote .dpad { width: calc(290 * var(--u)); }
#remote .arrow svg { width: calc(28 * var(--u)); height: calc(28 * var(--u)); }
#remote .ok { font-size: calc(15 * var(--u)); }

#remote .row { gap: calc(12 * var(--u)); }
#remote .pill { height: calc(50 * var(--u)); border-radius: calc(16 * var(--u)); font-size: calc(14 * var(--u)); }
#remote .pill svg { width: calc(18 * var(--u)); height: calc(18 * var(--u)); }

#remote .rockers { margin: 0; gap: calc(14 * var(--u)); grid-template-columns: calc(68 * var(--u)) 1fr calc(68 * var(--u)); }
#remote .rocker { border-radius: calc(34 * var(--u)); padding: calc(4 * var(--u)) 0; }
#remote .rocker button { width: calc(60 * var(--u)); height: calc(60 * var(--u)); }
#remote .rocker span { font-size: calc(11 * var(--u)); }
#remote .media { gap: calc(10 * var(--u)); }
#remote .sq { min-height: calc(64 * var(--u)); border-radius: calc(18 * var(--u)); }
#remote .sq svg { width: calc(20 * var(--u)); height: calc(20 * var(--u)); }

#remote .more { margin: 0; }

/* direct mode: add-TV sheet */
.empty .primary { margin-top: 18px; }
.steps { margin: 2px 0 4px; padding-left: 20px; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.steps li + li { margin-top: 6px; }
.steps a, .banner a { color: var(--accent); font-weight: 650; }
.steps a.disabled { opacity: .5; }
.ghost.danger { color: #ff7a88; }
.foot a, .hint a { color: var(--muted); }
