/* Sized for a 1920x1200 touch screen read at arm's length.
   Touch only: no :hover styling, :active gives press feedback, every control
   has a >= 64px hit target. */

:root {
  --bg: #0b0c0f;
  --surface: #16181d;
  --surface-2: #20232a;
  --line: #2b2f37;
  --text: #f3f4f6;
  --muted: #9ba1ac;
  --accent: #ff3b30;
  --ok: #30d158;
  --bad: #ff453a;
  --radius: 22px;
  --hit: 72px;
  --gutter: clamp(16px, 2.2vw, 40px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 500 22px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }

.view { min-height: 100%; padding: var(--gutter); padding-bottom: 48px; }

/* ---------- Hub ---------- */
.hub-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 8px 0 32px; }
.hub-head h1 { margin: 0; font-size: 48px; letter-spacing: -0.02em; }
.pill { font-size: 18px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 10px 18px; }
.pill b { color: var(--text); }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.tile {
  min-height: 260px; padding: 32px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-end; gap: 6px;
  text-align: left; transition: transform .12s ease, background .12s ease;
}
.tile:active:not(:disabled) { transform: scale(.98); background: var(--surface-2); }
.tile-icon { width: 84px; height: 84px; border-radius: 22px; display: grid; place-items: center; background: var(--tile); color: #fff; margin-bottom: auto; }
.tile-name { font-size: 34px; font-weight: 700; }
.tile-blurb { color: var(--muted); font-size: 20px; }
.tile.soon { opacity: .45; }

.pills { display: flex; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
button.pill { min-height: 64px; }
.pill.ok b { color: var(--ok); }
.pill.warn b { color: #ffd60a; }

/* ---------- Search ---------- */
.bar { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.bar h2 { margin: 0; font-size: 34px; }
.icon-btn { min-width: var(--hit); height: var(--hit); border-radius: 20px; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line); flex: none; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn.ghost { background: none; border: 0; min-width: 64px; height: 64px; color: var(--muted); }

.search { flex: 1; display: flex; align-items: center; gap: 8px; height: var(--hit); padding: 4px 4px 4px 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; }
.search input { flex: 1; min-width: 0; height: 100%; background: none; border: 0; outline: 0; color: var(--text); font: inherit; font-size: 24px; }
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { display: none; }
.go-btn { height: 64px; padding: 0 32px; border-radius: 16px; background: var(--accent); color: #fff; font-weight: 700; flex: none; }
.go-btn:active { filter: brightness(.85); }

.status-line { color: var(--muted); margin: 8px 4px 24px; }
.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 400px), 1fr)); gap: 28px 24px; }
.card { display: flex; flex-direction: column; gap: 10px; text-align: left; border-radius: var(--radius); padding: 0 0 8px; }
.card:active .thumb { transform: scale(.98); }
.thumb { position: relative; display: block; aspect-ratio: 16 / 9; border-radius: 18px; overflow: hidden; background: var(--surface); transition: transform .12s ease; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dur { position: absolute; right: 10px; bottom: 10px; background: rgba(0,0,0,.8); padding: 3px 10px; border-radius: 8px; font-size: 18px; font-variant-numeric: tabular-nums; }
.card-title { font-size: 23px; font-weight: 650; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { color: var(--muted); font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.system-table { width: 100%; border-collapse: collapse; font-size: 18px; }
.system-table th, .system-table td { text-align: left; vertical-align: top; padding: 12px 16px; border-bottom: 1px solid var(--line); word-break: break-word; }
.system-table th { color: var(--muted); font-weight: 500; width: 28%; }

.tabs { display: flex; gap: 12px; margin: 0 0 24px; overflow-x: auto; }
.tabs button { min-height: 64px; padding: 0 28px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-weight: 650; white-space: nowrap; }
.tabs button.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.host-banner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 20px 16px 24px; margin: 0 0 24px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.host-banner button { min-height: 64px; padding: 0 24px; border-radius: 14px; background: var(--surface-2); color: var(--text); font-weight: 650; flex: none; }
.pair-card { max-width: 900px; }
.pair-card p { color: var(--muted); }
.pair-card code { color: var(--text); }
.pair-form { margin: 24px 0 8px; }
.pair-form input { letter-spacing: .2em; text-transform: uppercase; font-size: 32px; }
.unpair { margin-top: 24px; }

/* ---------- Player ---------- */
.player { position: fixed; inset: 0; z-index: 10; background: #000; }
.stage { position: absolute; inset: 0; overflow: hidden; }
#screen { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }

/* The decode-only <video> of rungs 2/3. Never a visible surface. */
.offscreen-video { position: fixed; left: 0; bottom: 0; width: 1px; height: 1px; opacity: .01; pointer-events: none; }

.controls { position: absolute; inset: 0; display: grid; grid-template-rows: auto 1fr auto; transition: opacity .25s ease; pointer-events: none; }
.controls > * { pointer-events: auto; }
.player.controls-hidden .controls { opacity: 0; }
.player.controls-hidden .controls > * { pointer-events: none; }

.ctl-top { display: flex; align-items: center; gap: 20px; padding: var(--gutter); background: linear-gradient(rgba(0,0,0,.75), transparent); }
.ctl-top .icon-btn { background: rgba(255,255,255,.12); border: 0; }
.title { font-size: 26px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 3px #000; }

.ctl-mid { display: flex; align-items: center; justify-content: center; gap: clamp(32px, 8vw, 120px); pointer-events: none !important; }
.ctl-mid > * { pointer-events: auto; }
.player.controls-hidden .ctl-mid > * { pointer-events: none; }
.round-btn { position: relative; width: 112px; height: 112px; border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(0,0,0,.45); backdrop-filter: blur(6px); }
.round-btn span { font-size: 16px; font-weight: 700; margin-top: -4px; }
.round-btn.big { width: 160px; height: 160px; background: rgba(0,0,0,.55); }
.round-btn:active { background: rgba(255,255,255,.2); }
.round-btn .i-pause { display: none; }
.round-btn.is-playing .i-pause { display: block; }
.round-btn.is-playing .i-play { display: none; }

.ctl-bottom { display: flex; align-items: center; gap: 20px; padding: 24px var(--gutter) calc(var(--gutter) + env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(0,0,0,.8)); }
.time { font-variant-numeric: tabular-nums; font-size: 22px; min-width: 76px; text-align: center; text-shadow: 0 1px 3px #000; }
.seek { flex: 1; height: var(--hit); display: flex; align-items: center; touch-action: none; }
.seek-track { position: relative; width: 100%; height: 8px; border-radius: 4px; background: rgba(255,255,255,.28); }
.seek-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--accent); }
.seek-thumb { position: absolute; right: -16px; top: 50%; width: 32px; height: 32px; margin-top: -16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 6px rgba(0,0,0,.6); }
.chip-btn { min-width: 96px; height: 64px; padding: 0 20px; border-radius: 16px; background: rgba(255,255,255,.14); font-weight: 700; font-size: 20px; }
.chip-btn:active { background: rgba(255,255,255,.26); }

.menu { position: absolute; right: var(--gutter); bottom: 128px; min-width: 380px; max-height: 60vh; overflow: auto; background: rgba(22,24,29,.96); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; z-index: 3; }
.menu-title { color: var(--muted); font-size: 18px; padding: 10px 16px 6px; }
.menu-item { position: relative; width: 100%; min-height: var(--hit); display: flex; flex-direction: column; justify-content: center; align-items: flex-start; padding: 8px 16px; border-radius: 14px; text-align: left; }
.menu-item small { color: var(--muted); font-size: 16px; }
.menu-item.active { background: rgba(255,255,255,.1); }
.menu-item.active::after { content: "✓"; position: absolute; right: 28px; }
.menu-item:disabled { opacity: .45; }
.menu-item:active:not(:disabled) { background: rgba(255,255,255,.18); }

.cue { position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%); max-width: 80%; text-align: center; font-size: 34px; font-weight: 600; line-height: 1.3; padding: 4px 14px; border-radius: 8px; background: rgba(0,0,0,.65); white-space: pre-line; pointer-events: none; }
.cue:empty { display: none; }
.player.controls-hidden .cue { bottom: 48px; }

.spinner { position: absolute; left: 50%; top: 50%; width: 88px; height: 88px; margin: -44px; border-radius: 50%; border: 6px solid rgba(255,255,255,.2); border-top-color: #fff; animation: spin 0.9s linear infinite; display: none; pointer-events: none; }
.player.buffering .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.status-msg { position: absolute; left: 50%; top: 50%; transform: translate(-50%, 90px); max-width: 80%; min-height: var(--hit); padding: 16px 28px; border-radius: 18px; background: rgba(0,0,0,.75); font-size: 24px; z-index: 4; }
.status-msg.error { color: #ffb4ae; }

.toast { position: absolute; left: 50%; top: calc(var(--gutter) + 96px); transform: translateX(-50%); display: flex; align-items: center; gap: 16px; padding: 10px 10px 10px 24px; border-radius: 18px; background: rgba(0,0,0,.8); font-size: 22px; z-index: 4; white-space: nowrap; }
.toast button { min-height: 64px; padding: 0 22px; border-radius: 14px; background: rgba(255,255,255,.16); font-weight: 700; }

/* ---------- ?debug=1 ---------- */
.debug-hud {
  position: fixed; top: 112px; right: 12px; z-index: 100; max-width: min(820px, calc(100vw - 24px));
  font: 15px/1.45 ui-monospace, "DejaVu Sans Mono", Menlo, monospace; color: #e6e6e6;
  background: rgba(0,0,0,.78); border: 1px solid rgba(255,255,255,.15); border-radius: 12px; padding: 10px 14px;
  pointer-events: none; white-space: nowrap; overflow: hidden;
}
.debug-hud .k { color: #8ab4ff; display: inline-block; min-width: 210px; }
.debug-hud .ok { color: var(--ok); font-weight: 700; }
.debug-hud .bad { color: var(--bad); font-weight: 700; }
.debug-hud .tree { margin-top: 6px; border-top: 1px solid rgba(255,255,255,.15); padding-top: 6px; }
.debug-hud .tree div { padding-left: 210px; }

/* ---------- Portrait fallback ---------- */
@media (orientation: portrait) {
  .tiles { grid-template-columns: repeat(2, 1fr); gap: 16px; }
  .tile { min-height: 200px; padding: 24px; }
  .round-btn { width: 96px; height: 96px; }
  .round-btn.big { width: 128px; height: 128px; }
  .ctl-bottom { flex-wrap: wrap; row-gap: 4px; }
  .seek { order: -1; flex-basis: 100%; }
  .ctl-bottom .time:last-of-type { margin-right: auto; }
  .menu { left: var(--gutter); right: var(--gutter); min-width: 0; bottom: 180px; }
  .debug-hud { font-size: 12px; white-space: normal; }
  .debug-hud .k { min-width: 0; margin-right: 6px; }
  .debug-hud .tree div { padding-left: 0; }
}
@media (max-width: 720px) {
  body { font-size: 19px; }
  .tiles { grid-template-columns: 1fr; }
  .go-btn { padding: 0 18px; }
  .search input { font-size: 20px; }
}
