:root {
  --bg: #0b0d12; --card: #161a22; --line: #252b36; --fg: #eef0f4; --mute: #8c93a1;
  --acc: #4f8cff; --danger: #ff5a5f; --pad: rgba(255,255,255,.14); --pad-on: rgba(79,140,255,.55);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 16px -apple-system, system-ui, sans-serif; }
body { padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left)); }
[hidden] { display: none !important; }

header { display: flex; align-items: center; gap: 8px; padding: 12px 0; }
header h1 { flex: 1; margin: 0; font-size: 26px; }
.btn { background: var(--acc); color: #fff; border: 0; border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; }
.btn.ghost { background: var(--card); color: var(--fg); }
.btn.danger, .danger { background: var(--danger) !important; color: #fff; }
.card { background: var(--card); border-radius: 14px; padding: 14px; margin: 12px 0; }
.card label { display: block; margin-bottom: 12px; color: var(--mute); font-size: 14px; }
input, select { display: block; width: 100%; margin-top: 6px; background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: inherit; font-size: 16px; }
.row { display: flex; gap: 8px; align-items: center; }
.row input { margin: 0; }
.hint { color: var(--mute); font-size: 14px; }
.err { color: var(--danger); font-size: 14px; }
summary { font-weight: 600; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { background: var(--card); border-radius: 14px; padding: 14px 16px; margin: 10px 0; display: flex; justify-content: space-between; align-items: center; }
.list li small { color: var(--mute); display: block; margin-top: 2px; }

.grid { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.grid li { aspect-ratio: 3/4; border-radius: 14px; padding: 12px; display: flex; flex-direction: column; justify-content: flex-end; font-weight: 700; position: relative; overflow: hidden; }
.grid li::before { content: attr(data-initial); position: absolute; top: 8px; left: 12px; font-size: 56px; opacity: .25; }
.grid li small { font-weight: 400; opacity: .7; margin-top: 4px; }
.grid li:active { transform: scale(.97); }

/* ---- stream ---- */
#v-stream { position: fixed; inset: 0; background: #000; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#status { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--mute); pointer-events: none; padding: 20px; }
#status button { pointer-events: auto; margin-top: 12px; }
#stats { position: absolute; top: max(6px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); margin: 0; font: 11px ui-monospace, monospace; background: rgba(0,0,0,.55); padding: 6px 8px; border-radius: 6px; pointer-events: none; z-index: 3; }
#menu-btn { position: absolute; top: max(4px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.35); color: #fff; border: 0; border-radius: 12px; padding: 4px 14px; font-size: 14px; z-index: 4; }
#menu { position: absolute; top: 44px; left: 50%; transform: translateX(-50%); background: rgba(22,26,34,.95); border-radius: 14px; padding: 8px; display: grid; gap: 6px; z-index: 4; min-width: 200px; }
#menu button { background: var(--line); color: #fff; border: 0; border-radius: 10px; padding: 12px; font: inherit; text-align: left; }
#menu button.on::after { content: " ✓"; color: var(--acc); }
#rotate { display: none; position: absolute; inset: 0; align-items: center; justify-content: center; background: #000; color: var(--mute); z-index: 5; }
@media (orientation: portrait) { #rotate { display: flex; } }

/* controller overlay (landscape) */
#pad { position: absolute; inset: 0; z-index: 2; --u: 1vmin; }
#pad > div, #pad .mid > div, #pad .abxy > div { position: absolute; display: flex; align-items: center; justify-content: center; color: rgba(255,255,255,.75); font-weight: 700; font-size: calc(3.6 * var(--u)); }
#pad .on { background: var(--pad-on) !important; }
.trig, .bump { width: calc(15 * var(--u)); height: calc(9 * var(--u)); background: var(--pad); border-radius: calc(3 * var(--u)); }
.trig.l { left: max(3vw, env(safe-area-inset-left)); top: 3vh; }
.bump.l { left: calc(max(3vw, env(safe-area-inset-left)) + 17 * var(--u)); top: 3vh; }
.trig.r { right: max(3vw, env(safe-area-inset-right)); top: 3vh; }
.bump.r { right: calc(max(3vw, env(safe-area-inset-right)) + 17 * var(--u)); top: 3vh; }
#pad .mid { left: 50%; top: 14vh; transform: translateX(-50%); width: calc(34 * var(--u)); height: calc(8 * var(--u)); position: absolute; }
#pad .mid > div { top: 0; width: calc(9 * var(--u)); height: calc(8 * var(--u)); background: var(--pad); border-radius: 50%; }
#pad .mid > div:nth-child(1) { left: 0; } #pad .mid > div:nth-child(2) { left: calc(12.5 * var(--u)); } #pad .mid > div:nth-child(3) { right: 0; }

/* sticks: large invisible zones, floating base follows the thumb */
.stick { width: 34vw; height: 52vh; bottom: 0; }
.stick.l { left: 0; } .stick.r { right: 28vw; width: 22vw; height: 40vh; }
.stick .base { position: absolute; width: calc(26 * var(--u)); height: calc(26 * var(--u)); margin: calc(-13 * var(--u)) 0 0 calc(-13 * var(--u)); border-radius: 50%; background: var(--pad); }
.stick.l .base { left: calc(max(3vw, env(safe-area-inset-left)) + 15 * var(--u)); top: 48%; }
.stick.r .base { left: 40%; top: 55%; }
.stick .knob { position: absolute; left: 50%; top: 50%; width: calc(12 * var(--u)); height: calc(12 * var(--u)); margin: calc(-6 * var(--u)); border-radius: 50%; background: rgba(255,255,255,.35); }
.thumb { width: calc(9 * var(--u)); height: calc(7 * var(--u)); background: var(--pad); border-radius: calc(2 * var(--u)); font-size: calc(2.8 * var(--u)) !important; bottom: 4vh; }
.thumb.l { left: max(3vw, env(safe-area-inset-left)); } .thumb.r { right: calc(max(3vw, env(safe-area-inset-right)) + 36 * var(--u)); }

.dpad { width: calc(27 * var(--u)); height: calc(27 * var(--u)); left: calc(max(3vw, env(safe-area-inset-left)) + 36 * var(--u)); bottom: 3vh; border-radius: 50%; background: var(--pad); }
.dpad span { position: absolute; font-size: calc(3.4 * var(--u)); opacity: .8; }
.dpad span:nth-child(1) { top: 6%; } .dpad span:nth-child(2) { right: 8%; } .dpad span:nth-child(3) { bottom: 6%; } .dpad span:nth-child(4) { left: 8%; }
.dpad.u span:nth-child(1), .dpad.r span:nth-child(2), .dpad.d span:nth-child(3), .dpad.l span:nth-child(4) { color: var(--acc); opacity: 1; }

#pad .abxy { right: max(3vw, env(safe-area-inset-right)); bottom: 14vh; width: calc(33 * var(--u)); height: calc(33 * var(--u)); position: absolute; }
#pad .abxy > div { width: calc(12 * var(--u)); height: calc(12 * var(--u)); border-radius: 50%; background: var(--pad); font-size: calc(4.5 * var(--u)); }
.abxy .y { left: 50%; top: 0; transform: translateX(-50%); color: #f6c744 !important; }
.abxy .a { left: 50%; bottom: 0; transform: translateX(-50%); color: #5bd36a !important; }
.abxy .x { left: 0; top: 50%; transform: translateY(-50%); color: #4f9dff !important; }
.abxy .b { right: 0; top: 50%; transform: translateY(-50%); color: #ff5a5f !important; }
