:root {
  --bg: #050505;
  --panel: #111010;
  --line: #2a2725;
  --text: #e9e4dc;
  --muted: #8b847b;
  --orange: #ff6a1f;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--text); font: 13px/1.4 "JetBrains Mono", Consolas, monospace; }
body { min-height: 100vh; }
#app { max-width: 1600px; margin: 0 auto; padding: 16px; }

#stage-wrap { display: flex; gap: 12px; align-items: flex-start; }
#stage { position: relative; flex: 1 1 0; aspect-ratio: 16 / 9; background: #000; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
#screen { display: block; width: 100%; height: 100%; }
#loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); letter-spacing: .1em; }
#err { display: none; position: absolute; left: 12px; right: 12px; bottom: 12px; padding: 8px 10px; background: #3a0d05; color: #ffb59a; border-radius: 6px; }

/* compare panel */
#ref { display: none; position: relative; flex: 1 1 0; }
.ref-crop { position: relative; width: 100%; aspect-ratio: 664 / 376; overflow: hidden; border-radius: 10px; border: 1px solid var(--line); background: #000; }
.ref-crop img { position: absolute; width: 108.434%; left: -4.819%; top: -134.04%; }
.ref-label { position: absolute; top: 8px; left: 10px; font-size: 11px; color: #fff; background: rgba(0,0,0,.6); padding: 2px 6px; border-radius: 4px; }
body[data-ref="side"] #ref { display: block; }
body[data-ref="overlay"] #stage-wrap { position: relative; }
body[data-ref="overlay"] #ref { display: block; position: absolute; inset: 0; pointer-events: none; opacity: .5; }
body[data-ref="overlay"] .ref-crop { height: 100%; aspect-ratio: auto; }

/* controls */
#controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 12px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
#controls button, #controls select, #controls .btn {
  background: #1b1918; color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 10px; font: inherit; cursor: pointer;
}
#controls button:hover, #controls .btn:hover, #controls select:hover { border-color: var(--orange); }
#btn-play { width: 44px; font-size: 15px; }
#scrub { flex: 1 1 320px; accent-color: var(--orange); }
.readout { display: flex; gap: 12px; font-variant-numeric: tabular-nums; }
#frame { color: var(--orange); }
#scene-name { color: var(--muted); flex: 1 1 220px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chk { display: flex; gap: 6px; align-items: center; color: var(--muted); }
.keys { margin-top: 8px; color: var(--muted); font-size: 11px; }

body.no-ui #app { max-width: none; padding: 0; }
body.no-ui #controls, body.no-ui .keys { display: none; }
body.no-ui #stage { border: 0; border-radius: 0; }

@media (max-width: 720px) {
  #app { padding: 8px; }
  #stage-wrap { flex-direction: column; }
  #stage { flex: none; width: 100%; }
  html, body { overflow-x: hidden; }
  #app, #stage-wrap, #stage, #controls, .group, .name-form { min-width: 0; max-width: 100%; }
  .group > * { flex: 0 1 auto; min-width: 0; }
  #controls select { max-width: 46%; }
  #controls { gap: 8px; padding: 8px; }
  #scrub { flex: 1 1 100%; order: 3; }
  .readout { order: 2; }
  #scene-name { display: none; }
  .group { width: 100%; }
  #controls select, #controls button, #controls .btn { padding: 5px 7px; font-size: 12px; }
  .name-form input { width: 100%; }
  .keys { display: none; }
  #ref { width: 100%; }
}

.name-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 10px; color: var(--muted); }
.name-form input { background: #1b1918; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; font: inherit; width: 200px; }
.name-form input:focus { outline: none; border-color: var(--orange); }
.name-form button { background: var(--orange); color: #1a0a04; border: 0; border-radius: 6px; padding: 7px 12px; font: inherit; font-weight: 700; cursor: pointer; }
.name-form .share { font-size: 11px; color: var(--muted); word-break: break-all; }
#btn-debug.on { border-color: var(--orange); color: var(--orange); }
body.no-ui .name-form { display: none; }

#start { display: none; position: absolute; inset: 0; z-index: 5; flex-direction: column; align-items: center; justify-content: center; gap: 1.2vw;
  background: radial-gradient(circle at 50% 45%, rgba(60,24,8,0.55), rgba(5,5,5,0.92) 70%); border: 0; color: var(--text); cursor: pointer; font: inherit; padding: 16px; text-align: center; }
#start.show { display: flex; }
#start .start-play { width: clamp(56px, 8vw, 110px); height: clamp(56px, 8vw, 110px); border-radius: 50%; background: var(--orange); color: #1a0a04;
  display: grid; place-items: center; font-size: clamp(22px, 3.2vw, 44px); padding-left: 0.2em; box-shadow: 0 0 40px rgba(255,106,31,0.6); transition: transform .2s; }
#start:hover .start-play { transform: scale(1.08); }
#start .start-title { font: 800 clamp(18px, 3.4vw, 52px)/1.1 "Inter", sans-serif; letter-spacing: -0.01em; }
#start .start-sub { color: var(--muted); font-size: clamp(11px, 1.1vw, 16px); }
#start .start-by { color: var(--orange); font-size: clamp(10px, 0.9vw, 13px); letter-spacing: .12em; text-transform: uppercase; }

/* ---------- phones: immersive full-screen player ---------- */
#tap-ui { display: none; }
body.immersive { overflow: hidden; }
body.immersive #stage-wrap { position: fixed; inset: 0; z-index: 100; background: #000; display: block; }
body.immersive #ref, body.immersive #controls, body.immersive .name-form, body.immersive .keys { display: none; }
body.immersive #stage { position: absolute; left: 50%; top: 50%; border: 0; border-radius: 0; flex: none;
  width: min(100vw, calc(100vh * 16 / 9)); width: min(100vw, calc(100dvh * 16 / 9)); max-width: none; height: auto; aspect-ratio: 16 / 9; transform: translate(-50%, -50%); }
/* phone held upright: turn the picture sideways so it fills the screen */
@media (orientation: portrait) {
  body.immersive #stage { width: min(100vh, calc(100vw * 16 / 9)); width: min(100dvh, calc(100vw * 16 / 9)); transform: translate(-50%, -50%) rotate(90deg); }
}
body.immersive #tap-ui { display: block; position: absolute; inset: 0; pointer-events: none; transition: opacity .3s; }
body.immersive.ui-hidden #tap-ui { opacity: 0; }
#tap-ui button { pointer-events: auto; position: absolute; width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(243,238,230,0.35);
  background: rgba(10,9,8,0.65); color: #f2eee8; font: 600 16px "JetBrains Mono", monospace; display: grid; place-items: center; cursor: pointer; }
#tap-exit { top: 12px; right: 12px; }
#tap-play { bottom: 12px; left: 12px; }
#tap-debug { bottom: 12px; right: 12px; color: var(--orange) !important; }
body.immersive.ui-hidden #tap-ui button { pointer-events: none; }
