/* Oda — mobile-first remote. No external fonts or assets; tokens switch with the system theme. */
:root {
  color-scheme: light dark;
  --bg: #f1f1ec;
  --surface: #ffffff;
  --surface-sunk: #e5e5de;
  --press: #d9d9d1;
  --ink: #1b1e1c;
  --muted: #5b605a;
  --line: rgba(27, 30, 28, .1);
  --shadow: 0 1px 2px rgba(27, 30, 28, .08), 0 4px 14px rgba(27, 30, 28, .06);
  --ok-bg: #1b1e1c;
  --ok-ink: #ffffff;
  --ok-press: #3a3f3c;
  --power: #c0472f;
  --danger: #b3261e;
  --danger-tint: rgba(179, 38, 30, .1);
  --success: #23855a;
  --warn: #9a6700;
  --focus: #2563d9;
  --focus-tint: rgba(37, 99, 217, .14);
  --chip: rgba(27, 30, 28, .07);
  --sheet: #f7f7f3;
  --backdrop: rgba(10, 12, 11, .42);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111312;
    --surface: #252a27;
    --surface-sunk: #191c1a;
    --press: #353a37;
    --ink: #f1f1ec;
    --muted: #a9aea7;
    --line: rgba(241, 241, 236, .09);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --ok-bg: #f1f1ec;
    --ok-ink: #111312;
    --ok-press: #c9c9c2;
    --power: #ff8a70;
    --danger: #ff8a80;
    --danger-tint: rgba(255, 138, 128, .14);
    --success: #5fd39b;
    --warn: #f0c04a;
    --focus: #8db4ff;
    --focus-tint: rgba(141, 180, 255, .18);
    --chip: rgba(241, 241, 236, .09);
    --sheet: #1a1d1b;
    --backdrop: rgba(0, 0, 0, .6);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--bg); color: var(--ink); }
body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
html:has(dialog[open]) { overflow: hidden; }
button, input { font: inherit; color: inherit; }
button {
  margin: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
button:disabled { cursor: not-allowed; opacity: .3; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
svg {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Remote ---------- */
.shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 440px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 12px)
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 10px)
    calc(env(safe-area-inset-left) + 16px);
}
.remote {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-evenly;
  gap: 14px;
}

/* Shared key surface */
.key, .dpad, .rocker {
  background: var(--surface);
  box-shadow: var(--shadow);
}
.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 48px;
  min-height: 48px;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.01em;
  transition: transform .08s ease, background-color .08s ease;
}
.key-round { width: 56px; height: 56px; border-radius: 50%; }
.key-power { color: var(--power); }

.key:active:not(:disabled), .key.pressed { background: var(--press); transform: scale(.95); }

.top-row {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 56px;
  align-items: center;
  gap: 8px;
}

/* Status: a quiet dot that only speaks up when something is wrong. */
.status {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  min-width: 44px;
  max-width: 100%;
  padding: 0 14px;
  border-radius: 22px;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.status-dot {
  position: relative;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.status-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status[data-state="online"] .status-dot { background: var(--success); }
.status[data-state="online"] .status-text,
.status[data-state="checking"] .status-text {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.status[data-state="demo"] { color: var(--warn); }
.status[data-state="demo"] .status-dot { background: var(--warn); }
.status[data-state="offline"],
.status[data-state="unreachable"] {
  color: var(--danger);
  background: var(--danger-tint);
}
.status[data-state="offline"] .status-dot,
.status[data-state="unreachable"] .status-dot { background: var(--danger); }
.status.sending .status-dot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid currentColor;
  opacity: .5;
  animation: ping .7s ease-out infinite;
}
.status[data-state="online"].sending .status-dot::after { border-color: var(--success); }
@keyframes ping { from { transform: scale(.6); opacity: .7; } to { transform: scale(1.5); opacity: 0; } }

/* D-pad */
/* Each arrow owns a full quarter of the ring (clip-path also limits its hit area), so no tap lands in a dead corner. */
.dpad {
  position: relative;
  align-self: center;
  width: clamp(216px, 38vh, 272px);
  width: clamp(216px, 38dvh, 272px);
  aspect-ratio: 1;
  border-radius: 50%;
  overflow: hidden;
}
.dpad-key {
  position: absolute;
  inset: 0;
  display: flex;
  color: var(--ink);
  transition: background-color .08s ease;
}
.dpad-key svg { width: 28px; height: 28px; stroke-width: 2.2; }
.dpad-up { clip-path: polygon(0 0, 100% 0, 50% 50%); justify-content: center; align-items: flex-start; padding-top: 12%; }
.dpad-right { clip-path: polygon(100% 0, 100% 100%, 50% 50%); justify-content: flex-end; align-items: center; padding-right: 12%; }
.dpad-down { clip-path: polygon(0 100%, 100% 100%, 50% 50%); justify-content: center; align-items: flex-end; padding-bottom: 12%; }
.dpad-left { clip-path: polygon(0 0, 0 100%, 50% 50%); justify-content: flex-start; align-items: center; padding-left: 12%; }
.dpad-key:not(.dpad-ok):active:not(:disabled),
.dpad-key:not(.dpad-ok).pressed { background: var(--press); }
/* An outline would be clipped away with the wedge, so keyboard focus tints it instead. */
.dpad-key:not(.dpad-ok):focus-visible { outline: none; background: var(--focus-tint); color: var(--focus); }
.dpad-ok {
  inset: 32%;
  z-index: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  box-shadow: 0 0 0 6px var(--surface);
  background: var(--ok-bg);
  color: var(--ok-ink);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .02em;
  transition: transform .08s ease, background-color .08s ease;
}
.dpad-ok:active:not(:disabled), .dpad-ok.pressed { background: var(--ok-press); transform: scale(.95); }

.nav-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.key-pill { min-height: 52px; border-radius: 26px; padding: 0 8px; font-size: 15px; }
.key-pill svg { width: 20px; height: 20px; }
.key-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Volume / channel rockers */
.rockers {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 56px minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
}
.rocker {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  border-radius: 28px;
  overflow: hidden;
  min-height: 152px;
}
.rocker-key {
  /* Fires on pointerdown (app.js); it must never start a scroll or a double-tap zoom. */
  touch-action: none;
  flex: 1;
  min-height: 60px;
  display: grid;
  place-items: center;
  color: var(--ink);
  transition: background-color .08s ease;
}
.rocker-key svg { width: 26px; height: 26px; stroke-width: 2.2; }
.rocker-key:active:not(:disabled), .rocker-key.pressed { background: var(--press); }
.rocker-label {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--muted);
  line-height: 1;
  pointer-events: none;
}
.rocker-middle {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.key-stack {
  flex-direction: column;
  gap: 3px;
  width: 56px;
  height: 64px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
}
.key-stack svg { width: 22px; height: 22px; }
.key-stack span { color: var(--muted); }

/* Settings button at the very bottom */
.bottom-bar { padding-top: 14px; }
.settings-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border-radius: 26px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  border: 1px solid var(--line);
  transition: background-color .08s ease;
}
.settings-button svg { width: 20px; height: 20px; }
.settings-button:active { background: var(--press); }
.settings-tv {
  margin-left: auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

/* Toast: only for errors, never in the way of a tap. */
.toast {
  position: fixed;
  z-index: 10;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 12px);
  width: max-content;
  max-width: min(400px, calc(100% - 32px));
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--bg);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Sheets ---------- */
.sheet {
  width: 100%;
  max-width: 440px;
  max-height: calc(100vh - env(safe-area-inset-top) - 24px);
  max-height: calc(100dvh - env(safe-area-inset-top) - 24px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 24px 24px 0 0;
  background: var(--sheet);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: contain;
}
.sheet[open] { display: flex; flex-direction: column; animation: sheet-in .24s cubic-bezier(.2, .8, .2, 1); }
.sheet::backdrop { background: var(--backdrop); animation: fade-in .2s ease; }
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.sheet-body {
  overflow-y: auto;
  padding:
    6px
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 20px)
    calc(env(safe-area-inset-left) + 16px);
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  margin-bottom: 4px;
}
.sheet-head h2 { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-right: -6px;
  border-radius: 50%;
  background: var(--chip);
  color: var(--ink);
}
.icon-button svg { width: 20px; height: 20px; }
.icon-button:active { background: var(--press); }

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  margin-bottom: 16px;
  border-radius: 14px;
  background: var(--chip);
}
.tabs [role="tab"] {
  min-height: 44px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}
.tabs [aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.panel { display: grid; gap: 10px; align-content: start; }
/* Keep the sheet the same height on every tab so the header and tabs do not jump. */
@media (min-height: 641px) { .panel { min-height: 312px; } }
.numpad, .grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.grid-4, .color-keys { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.numpad .key { min-height: 56px; font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.numpad .key-text, .grid-3 .key { font-size: 15px; }
.grid-3 .key { min-height: 52px; padding: 0 6px; }
.key-media {
  flex-direction: column;
  gap: 4px;
  min-height: 68px;
  padding: 6px 2px;
  font-size: 12px;
  font-weight: 600;
}
.key-media svg { width: 22px; height: 22px; }
.key-media span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-dot { fill: var(--power); stroke: var(--power); }
.color-key { min-height: 48px; border-radius: 14px; }
.color-key.red { background: #d93a2b; }
.color-key.green { background: #1f9d55; }
.color-key.yellow { background: #e8b500; }
.color-key.blue { background: #2463d6; }
.color-key:active:not(:disabled), .color-key.pressed { filter: brightness(.82); }

/* Settings list: groups of rows, ready for more rows later. */
.settings-group + .settings-group { margin-top: 22px; }
.group-title {
  padding: 0 4px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.list {
  border-radius: 16px;
  background: var(--surface);
  overflow: hidden;
}
.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 56px;
  padding: 8px 16px;
  text-align: left;
  font-size: 16px;
}
.row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 54px;
  right: 0;
  border-top: 1px solid var(--line);
}
.row-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: var(--muted);
}
.row-icon svg { width: 22px; height: 22px; }
.row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-sub { font-size: 14px; color: var(--muted); }
.row-check { color: var(--focus); visibility: hidden; }
.row-button, .tv-row { cursor: pointer; transition: background-color .08s ease; }
.row-button:active, .tv-row:active { background: var(--press); }
.row-danger { color: var(--danger); }
.row-danger .row-icon { color: var(--danger); }
.tv-row input { position: absolute; opacity: 0; pointer-events: none; }
.tv-row:has(input:checked) .row-check { visibility: visible; }
.tv-row:has(input:checked) .row-icon { color: var(--ink); }
.tv-row:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: -3px; }
.status-icon::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}
.status-icon[data-state="online"]::before { background: var(--success); }
.status-icon[data-state="demo"]::before { background: var(--warn); }
.status-icon[data-state="offline"]::before,
.status-icon[data-state="unreachable"]::before { background: var(--danger); }

/* ---------- Login ---------- */
.auth {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding:
    calc(env(safe-area-inset-top) + 24px)
    calc(env(safe-area-inset-right) + 20px)
    calc(env(safe-area-inset-bottom) + 24px)
    calc(env(safe-area-inset-left) + 20px);
}
.auth-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 16px; }
.app-mark {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  width: 52px;
  height: 52px;
  padding: 13px 12px;
  border-radius: 14px;
  background: var(--ok-bg);
}
.app-mark b { width: 6px; height: 26px; border-radius: 1px; background: var(--ok-ink); }
.app-mark b:nth-child(2) { height: 20px; }
.app-mark b:nth-child(3) { height: 14px; background: var(--power); }
.auth-title { font-size: 30px; font-weight: 800; letter-spacing: -.02em; margin-top: 8px; }
.auth-sub { color: var(--muted); font-size: 16px; margin-top: -8px; margin-bottom: 8px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.field input {
  min-height: 52px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 17px;
  font-weight: 500;
}
.field input:focus-visible { outline-offset: 0; }
.form-error { color: var(--danger); font-size: 15px; font-weight: 600; }
.primary-button {
  min-height: 52px;
  margin-top: 4px;
  border-radius: 26px;
  background: var(--ok-bg);
  color: var(--ok-ink);
  font-size: 17px;
  font-weight: 700;
}
.primary-button:active:not(:disabled) { background: var(--ok-press); }

/* Short screens (iPhone SE, Safari with toolbars): tighten spacing before anything scrolls. */
@media (max-height: 640px) {
  .shell { padding-top: calc(env(safe-area-inset-top) + 8px); padding-bottom: calc(env(safe-area-inset-bottom) + 8px); }
  .remote { gap: 10px; }
  .dpad { width: clamp(196px, 36vh, 272px); width: clamp(196px, 36dvh, 272px); }
  .rocker { min-height: 136px; }
  .rocker-key { min-height: 54px; }
  .rocker-middle { gap: 6px; }
  .key-stack { height: 62px; }
  .bottom-bar { padding-top: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .key:active:not(:disabled), .key.pressed, .dpad-ok:active:not(:disabled), .dpad-ok.pressed { transform: none; }
  .status.sending .status-dot::after { opacity: .6; transform: scale(1.3); }
  .toast { transform: translate(-50%, 0); }
}
@media (forced-colors: active) {
  .key, .dpad, .rocker, .list, .status { border: 1px solid ButtonText; }
}
