:root {
  --bg: #000;
  --bg-2: #0b0b0c;
  --s1: #121214;
  --s2: #1a1a1d;
  --s3: #242428;
  --line: #2a2a2f;
  --line-2: #38383e;
  --text: #ededf0;
  --text-2: #a4a4ad;
  --muted: #8c8c96;            /* ≥4.5:1 on --s1/--s2 for small text */
  --z-bar: 20; --z-modal: 50; --z-toast: 60;
  --hi: #f4f4f6;          /* active fill (light grey on black) */
  --hi-text: #0a0a0b;
  --ok: #7dd3a0;
  --bad: #f08a8a;
  --warn: #e8c37a;
  --r: 14px;
  --r-sm: 10px;
  --gap: 12px;
  --tab-h: 64px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --remote-w: 360px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.35; overscroll-behavior: none; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
svg.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.app { display: flex; height: 100dvh; padding: var(--safe-t) var(--safe-r) 0 var(--safe-l); }
.pane { overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; scrollbar-width: thin; scrollbar-color: var(--s3) transparent; }
.remote { flex: none; }
.detail { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.views { flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--s3) transparent; }
.view { display: none; padding: 16px; padding-bottom: 32px; }
.view.on { display: block; }

/* Phone (iPhone Duo folded, regular iPhones): one pane at a time + bottom bar */
@media (max-width: 739px) {
  .app { flex-direction: column; padding-bottom: calc(var(--tab-h) + var(--safe-b)); }
  .remote { flex: 1; padding: 12px 16px 24px; display: none; }
  .remote.on { display: block; }
  .detail { display: none; }
  .detail.on { display: flex; }
  .toptabs { display: none; }
  .bottombar { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tab-h) + var(--safe-b)); padding: 6px max(8px, var(--safe-l)) var(--safe-b);
    display: grid; grid-template-columns: repeat(7, 1fr); background: rgba(10,10,11,.92); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid var(--line); z-index: var(--z-bar); }
}
/* Two-pane: iPhone Duo unfolded, tablets, laptops */
@media (min-width: 740px) {
  .remote { width: var(--remote-w); border-right: 1px solid var(--line); padding: 14px 16px 24px; background: var(--bg-2); }
  .bottombar { display: none; }
  .toptabs { display: flex; gap: 4px; padding: 10px 16px; border-bottom: 1px solid var(--line); overflow-x: auto; flex: none; scrollbar-width: none; }
  .toptabs::-webkit-scrollbar { display: none; }
  [data-only="phone"] { display: none !important; }
  .view.grid { columns: 360px auto; column-gap: var(--gap); }
  .view.grid > .card { break-inside: avoid; display: inline-block; width: 100%; }
}

/* Duo unfolded is short & wide: compact the remote column */
@media (min-width: 740px) and (max-height: 720px) {
  :root { --remote-w: 330px; }
  .dial-wrap { --dial: 170px !important; }
  .remote .hero { padding: 10px 12px; }
}
/* Foldables that report two viewport segments: split at the hinge */
@media (horizontal-viewport-segments: 2) {
  :root { --remote-w: env(viewport-segment-width 0 0, 50vw); }
}
@media (min-width: 1240px) {
  :root { --remote-w: 380px; }
  .view { padding: 20px 24px 40px; }
}

/* ---------- nav ---------- */
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 10.5px; font-weight: 500; border-radius: 12px; }
.tab.on { color: var(--text); }
.tab svg.i { width: 22px; height: 22px; }
.toptabs .tab { flex-direction: row; gap: 8px; padding: 9px 14px; font-size: 14px; color: var(--text-2); border-radius: 999px; white-space: nowrap; }
.toptabs .tab svg.i { width: 18px; height: 18px; }
.toptabs .tab:hover { background: var(--s1); }
.toptabs .tab.on { background: var(--s2); color: var(--text); }
.toptabs .spacer { flex: 1; }

/* ---------- cards & controls ---------- */
.card { background: var(--s1); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: var(--gap); }
.card h3 { margin: 0 0 12px; font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.card h3 .right { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; }
.row { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.row + .row { border-top: 1px solid var(--line); }
.row .lbl { flex: 1; min-width: 0; }
.row .lbl small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.stack > * + * { margin-top: 10px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 14px; border-radius: var(--r-sm);
  background: var(--s2); border: 1px solid var(--line); color: var(--text); font-weight: 500; transition: background .12s, transform .08s; user-select: none; -webkit-user-select: none; }
.btn:hover { background: var(--s3); }
.btn:active { transform: scale(.97); }
.btn.on { background: var(--hi); color: var(--hi-text); border-color: var(--hi); }
.btn.ghost { background: transparent; }
.btn.round { width: 44px; min-width: 44px; height: 44px; padding: 0; border-radius: 50%; }
.btn.big { min-height: 52px; font-size: 16px; }
.btn.danger { color: var(--bad); }
.btn[disabled] { opacity: .4; pointer-events: none; }

.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { flex: 1 0 auto; min-height: 34px; padding: 0 10px; border-radius: 8px; color: var(--text-2); font-size: 13.5px; font-weight: 500; white-space: nowrap; }
.seg button.on { background: var(--s3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }

.switch { position: relative; width: 50px; height: 30px; flex: none; border-radius: 99px; background: var(--s3); transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #8a8a92; transition: transform .18s, background .15s; }
.switch.on { background: var(--hi); }
.switch.on::after { transform: translateX(20px); background: #0b0b0c; }

.grid-btns { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.tile { display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 10px; min-height: 72px; padding: 11px 12px;
  border-radius: 12px; background: var(--s2); border: 1px solid var(--line); text-align: left; font-size: 13.5px; font-weight: 500; transition: background .12s, transform .08s; overflow: hidden; }
.tile small { color: var(--muted); font-size: 11.5px; font-weight: 400; display: block; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tile span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tile:hover { background: var(--s3); }
.tile:active { transform: scale(.97); }
.tile.on { background: var(--hi); color: var(--hi-text); border-color: var(--hi); }
.tile.on small { color: #555; }

/* sliders */
.slider { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 10px; padding: 8px 0; }
.slider + .slider { border-top: 1px solid var(--line); }
.slider .name { font-size: 14px; }
.slider .val { font-size: 14px; color: var(--text-2); min-width: 64px; text-align: right; }
.slider .ctl { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; }
.slider .ctl .btn { width: 36px; min-width: 36px; height: 36px; min-height: 36px; padding: 0; border-radius: 9px; }
input[type=range] { -webkit-appearance: none; appearance: none; flex: 1; height: 36px; background: transparent; margin: 0; touch-action: pan-y; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 6px; background: linear-gradient(to right, #d9d9de var(--p, 50%), var(--s3) var(--p, 50%)); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 6px; background: var(--s3); }
input[type=range]::-moz-range-progress { height: 6px; border-radius: 6px; background: #d9d9de; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -9px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 6px rgba(0,0,0,.6); }
input[type=range]::-moz-range-thumb { width: 24px; height: 24px; border-radius: 50%; background: #fff; border: 0; }
input[type=range].center::-webkit-slider-runnable-track { background: var(--s3); }

input.text, select.text { width: 100%; min-height: 42px; padding: 0 12px; border-radius: var(--r-sm); background: var(--bg); border: 1px solid var(--line); color: var(--text); outline: none; }
input.text:focus, select.text:focus { border-color: var(--line-2); background: #050506; }
label.field { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 10px; }
label.field > input, label.field > select { margin-top: 5px; }

/* ---------- remote pane ---------- */
.remote .head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.remote .head .title { flex: 1; min-width: 0; }
.remote .head .title b { display: block; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.remote .head .title small { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--bad); flex: none; }
.dot.ok { background: var(--ok); }
.power { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: var(--s2); border: 1px solid var(--line); color: var(--muted); transition: background-color .15s, color .15s, border-color .15s; }
.power.on { background: var(--hi); color: var(--hi-text); border-color: var(--hi); }
.power svg.i { width: 22px; height: 22px; stroke-width: 2.2; }

.hero { background: var(--s1); border: 1px solid var(--line); border-radius: 18px; padding: 14px; margin-bottom: 12px; }
.hero .now { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; color: var(--text-2); }
.hero .now b { color: var(--text); font-weight: 600; font-size: 14px; display: block; }
.hero .now .r { text-align: right; min-width: 0; }
.hero .now .r b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.dial-wrap { --dial: 210px; display: flex; align-items: center; justify-content: center; gap: 14px; margin: 10px 0 4px; }
.dial { position: relative; width: var(--dial); height: var(--dial); touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
.dial svg { width: 100%; height: 100%; display: block; }
.dial .read { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.dial .read .v { font-size: calc(var(--dial) * .2); font-weight: 300; letter-spacing: -.03em; line-height: 1; }
.dial .read .u { font-size: 12px; color: var(--muted); margin-top: 4px; letter-spacing: .08em; }
.dial.muted .read .v { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 2px; }
.dial-side { display: flex; flex-direction: column; gap: 10px; }
.vol-row { display: flex; justify-content: center; gap: 10px; margin-top: 6px; }
.offline-veil { opacity: .45; pointer-events: none; filter: grayscale(1); }

.section-label { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 16px 2px 8px; display: flex; align-items: center; }
.section-label .right { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; }
.inputs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 560px) and (max-width: 739px) { .inputs { grid-template-columns: repeat(4, 1fr); } }
.inputs .tile { min-height: 64px; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 13px; border-radius: 99px; background: var(--s2); border: 1px solid var(--line); font-size: 13.5px; font-weight: 500; white-space: nowrap; }
.chip.on { background: var(--hi); color: var(--hi-text); border-color: var(--hi); }
.chip svg.i { width: 16px; height: 16px; }
.slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.slots .btn { min-height: 44px; }

/* ---------- media ---------- */
.np { display: grid; grid-template-columns: 112px 1fr; gap: 14px; align-items: center; }
.art { width: 112px; height: 112px; border-radius: 12px; background: var(--s3); display: grid; place-items: center; overflow: hidden; color: var(--muted); }
.art img { width: 100%; height: 100%; object-fit: cover; }
.art svg.i { width: 40px; height: 40px; stroke-width: 1.3; }
.np .meta b { display: block; font-size: 17px; font-weight: 650; line-height: 1.2; }
.np .meta div { color: var(--text-2); margin-top: 3px; font-size: 14px; }
.np .meta small { color: var(--muted); }
.progress { height: 4px; border-radius: 4px; background: var(--s3); margin: 14px 0 4px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: #d9d9de; width: 100%; transform: scaleX(0); transform-origin: left; transition: transform .5s linear; }
.times { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.transport { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 10px; }
.transport .play { width: 60px; height: 60px; border-radius: 50%; background: var(--hi); color: var(--hi-text); display: grid; place-items: center; }
.transport .play svg.i { width: 26px; height: 26px; fill: currentColor; stroke-width: 0; }
.transport .btn.round { background: transparent; border: 0; color: var(--text-2); }
.transport .btn.round.on { color: var(--text); background: var(--s3); }
.favs { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 8px; }
.fav { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; background: var(--s2); border: 1px solid var(--line); text-align: left; font-size: 13px; font-weight: 500; min-height: 56px; }
.fav .art { width: 40px; height: 40px; border-radius: 8px; flex: none; }
.fav .art svg.i { width: 18px; height: 18px; }
.fav > span:last-child { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.freq { font-size: 40px; font-weight: 300; letter-spacing: -.02em; text-align: center; }
.freq small { font-size: 15px; color: var(--muted); margin-left: 4px; }
.station { text-align: center; color: var(--text-2); margin-bottom: 8px; min-height: 20px; }

/* d-pad */
.dpad { display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(3, 64px); gap: 6px; justify-content: center; margin: 8px auto; }
.dpad .btn { width: 64px; height: 64px; border-radius: 16px; padding: 0; }
.dpad .ok { border-radius: 50%; background: var(--s3); font-weight: 650; }

/* channel levels */
.chan-grid { display: grid; grid-template-columns: 1fr; }

/* scenes */
.scene-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.scene { position: relative; display: flex; flex-direction: column; justify-content: space-between; gap: 18px; min-height: 104px; padding: 14px; border-radius: 16px;
  background: var(--s2); border: 1px solid var(--line); text-align: left; }
.scene b { font-size: 15px; font-weight: 600; }
.scene small { color: var(--muted); font-size: 12px; }
.scene .edit { position: absolute; top: 8px; right: 8px; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.scene .edit:hover { background: var(--s3); color: var(--text); }
.scene.running { border-color: var(--hi); }
.step { display: grid; grid-template-columns: 74px 1fr auto; gap: 6px; align-items: center; margin-bottom: 6px; }
.step select, .step input { min-height: 38px; }
.step .acts { display: flex; gap: 2px; }
.step .acts .btn { width: 32px; min-width: 32px; height: 38px; min-height: 38px; padding: 0; }

/* console */
.console { font: 12px/1.5 ui-monospace, "SF Mono", Menlo, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px; height: 180px; overflow-y: auto; color: var(--text-2); white-space: pre-wrap; word-break: break-all; }

/* modal + toast */
.modal { position: fixed; inset: 0; z-index: var(--z-modal); background: rgba(0,0,0,.7); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); display: flex; align-items: flex-end; justify-content: center; }
.modal .sheet { width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; background: var(--s1); border: 1px solid var(--line); border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); }
@media (min-width: 740px) { .modal { align-items: center; } .modal .sheet { border-radius: 20px; } }
.sheet h2 { margin: 0 0 14px; font-size: 18px; display: flex; align-items: center; gap: 10px; }
.sheet h2 .x { margin-left: auto; }
.sheet .foot { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.sheet .foot .grow { flex: 1; }
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 14px); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: var(--z-toast);
  background: var(--s3); border: 1px solid var(--line-2); color: var(--text); padding: 10px 16px; border-radius: 99px; font-size: 14px; transition: transform .2s ease-out, opacity .2s ease-out; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 740px) { .toast { bottom: 24px; } }

.banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 12px; background: #1a1712; border: 1px solid #3a3222; color: #e9d8b0; font-size: 13.5px; margin-bottom: 12px; }
.empty { color: var(--muted); text-align: center; padding: 22px 8px; font-size: 14px; }

/* compact top tabs on Duo unfolded / small tablets (kept last so it wins) */
@media (min-width: 740px) and (max-width: 1100px) {
  .toptabs .tab { padding: 8px 10px; gap: 6px; font-size: 13.5px; }
  .toptabs .tab span { display: none; }
  .toptabs .tab.on span { display: inline; }
}

/* TV apps — logo-only tiles (icons come from the TV) */
.tvapps { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 8px; }
.tvapp { position: relative; aspect-ratio: 1; border-radius: 16px; overflow: hidden; background: var(--s2); border: 1px solid var(--line);
  display: grid; place-items: center; transition: transform .08s, box-shadow .12s; padding: 0; }
.tvapp img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tvapp .t { display: none; }
.tvapp.noimg .t { display: block; padding: 6px; font-size: 12.5px; font-weight: 600; text-align: center; line-height: 1.15; color: var(--text); }
.tvapp:hover { transform: translateY(-1px); }
.tvapp:active { transform: scale(.95); }
.tvapp.on { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--hi); }
@media (max-width: 739px) { .tab span { font-size: 10px; } }

/* ---------- accessibility & polish (v1.3) ---------- */
/* visible keyboard focus everywhere (mouse/touch clicks don't show it) */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--hi); outline-offset: 2px; }
.seg button:focus-visible, .tab:focus-visible { outline-offset: -2px; }
input.text:focus-visible, select.text:focus-visible { outline: 2px solid var(--hi); outline-offset: 0; }
.dial:focus-visible { outline: none; }
.dial:focus-visible svg { outline: 2px solid var(--hi); outline-offset: 4px; border-radius: 50%; }
/* disabled sliders say so with more than opacity */
.slider.is-off .name::after { content: " · off"; color: var(--muted); }
.slider.is-off { opacity: .55; }
/* readable wrapping */
h2, h3, .card h3, .np .meta b { text-wrap: balance; }
.hint, .banner, .empty, p { text-wrap: pretty; }
/* respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
/* version label */
.version { margin-top: 18px; text-align: center; font-size: 12px; color: var(--muted); }
.version button { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.update-bar { position: fixed; left: 50%; top: calc(var(--safe-t) + 10px); transform: translateX(-50%); z-index: var(--z-toast);
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 16px; border-radius: 99px; background: var(--s3); border: 1px solid var(--line-2); font-size: 14px; }
.changes { margin: 0; padding-left: 18px; color: var(--text-2); font-size: 13.5px; }
.changes li + li { margin-top: 4px; }
