:root {
  --bg: #0b0d14;
  --ink: #e9e6dc;
  --quiet: #8c93a6;
  --accent: #ffcf5c;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font: 16px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
body { background: #141623; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#labels { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
.lbl { position: absolute; left: 0; top: 0; display: none; padding: 1px 7px; border-radius: 999px; white-space: nowrap; transform-origin: 50% 100%;
  font: 600 13px/1.35 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-variant-numeric: tabular-nums;
  color: #f1eee3; background: #0b0d14b8; will-change: transform, opacity; }
.lbl.you { background: var(--accent); color: #14110a; }

/* speech bubbles: pinned above heads like the place numbers, a few at a time */
#bubbles { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 1; }
.bub { position: absolute; left: 0; top: 0; display: none; max-width: 150px; padding: 5px 10px; border-radius: 12px; transform-origin: 50% 100%;
  font: 600 12px/1.3 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; text-align: center;
  color: #14110a; background: #f4f1e8; box-shadow: 0 2px 10px #0008; will-change: transform, opacity; }
.bub::after { content: ""; position: absolute; left: 50%; bottom: -6px; margin-left: -6px; border: 6px solid transparent; border-bottom: 0; border-top-color: #f4f1e8; }
.bub.you { background: var(--accent); }
.bub.you::after { border-top-color: var(--accent); }
.bub.staff { background: #1c1c26; color: #f1eee3; border: 1px solid #ffffff33; }
.bub.staff::after { border-top-color: #1c1c26; }

/* Portrait phone first; desktop gets the same layout, centred */
#hud { position: fixed; top: calc(12px + var(--safe-t)); left: 0; right: 0; text-align: center; pointer-events: none; text-shadow: 0 1px 12px #000a; }
#pos { font-size: clamp(40px, 12vw, 64px); font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.05; }
#tally { color: var(--quiet); font-size: 15px; margin-top: 2px; font-variant-numeric: tabular-nums; }
#who { color: var(--accent); font-size: 13px; margin-top: 2px; opacity: 0.9; }

#hint { position: fixed; top: calc(192px + var(--safe-t)); left: 24px; right: 24px; text-align: center; font-size: 13px; color: var(--quiet); opacity: 0; transition: opacity 1.2s ease; pointer-events: none; }
#hint.on { opacity: 0.85; }

#whisper { position: fixed; left: 24px; right: 24px; bottom: calc(84px + var(--safe-b)); text-align: center; font-style: italic;
  color: #cfd3e0; opacity: 0; transition: opacity 1.2s ease; pointer-events: none; text-shadow: 0 1px 10px #000c; }
#whisper.on { opacity: 0.92; }

#bar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px calc(12px + var(--safe-b)); background: linear-gradient(to top, #0b0d14ee, #0b0d1400); }
#status { color: var(--quiet); font-size: 14px; margin-right: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#bar button { padding: 10px 16px; }
#bar #sound { padding: 10px 13px; }
#sound[aria-pressed="false"] { color: var(--quiet); }
button { font: inherit; color: #14110a; background: var(--accent); border: 0; border-radius: 999px; padding: 12px 20px; min-height: 44px; font-weight: 600; }
button.quiet { background: transparent; color: var(--ink); border: 1px solid #ffffff33; }
button:active { transform: scale(0.97); }

#front { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; background: #000; animation: fadein 1.6s ease forwards; }
#front[hidden], #after[hidden], #elsewhere[hidden] { display: none; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
#glow { position: absolute; inset: 0; animation: pulse 4s ease-in-out infinite; }
#front.v0 #glow { background: radial-gradient(60% 45% at 50% 40%, #fff6d8 0%, #f3d98a55 45%, #0000 75%); }
#front.v1 #glow { background: linear-gradient(to bottom, #0000 0%, #1b1710 60%, #0a0805 100%), radial-gradient(30% 12% at 50% 62%, #8a6a3a66 0%, #0000 100%); }
#front.v2 #glow { background: linear-gradient(90deg, #000 0%, #000 44%, #e9e1c4 49%, #e9e1c4 51%, #000 56%, #000 100%); opacity: 0.5; }
@keyframes pulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
#after { position: relative; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; text-align: center; animation: fadein 2s ease; background: #000d; border-radius: 20px; padding: 20px; }
#finished { color: var(--quiet); margin: 0 0 12px; font-variant-numeric: tabular-nums; }
#after label { color: var(--ink); }
#wtext { width: 100%; font: inherit; color: var(--ink); background: #ffffff10; border: 1px solid #ffffff2a; border-radius: 12px; padding: 12px 14px; min-height: 44px; }
.row { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }

#elsewhere { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; background: #0b0d14f2; color: var(--quiet); }

#clock { color: var(--quiet); font-size: 13px; margin-top: 2px; font-variant-numeric: tabular-nums; opacity: 0.9; }
#tally, #clock { color: #dfe3f2; text-shadow: 0 1px 4px #000c, 0 0 14px #0008; }
#clock { opacity: 0.8; }
/* the focus chip: who the camera is on */
#focus { position: fixed; top: calc(150px + var(--safe-t)); left: 50%; transform: translateX(-50%); max-width: calc(100% - 140px); padding: 3px 12px; border-radius: 999px;
  background: #0b0d14b8; border: 1px solid #ffffff22; color: var(--ink); font-size: 13px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums;
  opacity: 0; transition: opacity 0.3s ease; pointer-events: none; z-index: 2; }
#focus.on { opacity: 1; }
#focus.you { background: var(--accent); color: #14110a; border-color: transparent; }

/* rails: the scrubber along the line (right) and zoom + tilt (left), sitting in thumb reach at each edge */
#scroll, #view { position: fixed; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 3; user-select: none; -webkit-user-select: none; }
#scroll { right: 8px; }
#view { left: 8px; }
.rbtn { width: 46px; height: 46px; min-height: 0; padding: 0; font-size: 18px; line-height: 1; background: #0b0d14aa; color: var(--ink); border: 1px solid #ffffff33; touch-action: none; }
.rbtn:active { background: #ffffff22; }
#view .lab { margin-top: 4px; font: 700 9px/1 ui-sans-serif, system-ui, sans-serif; letter-spacing: 0.12em; text-transform: uppercase; color: var(--quiet); }
.rail { position: relative; width: 46px; height: min(38vh, 320px); touch-action: none; cursor: grab; }
.rail.short { height: min(20vh, 140px); }
.rail::before { content: ""; position: absolute; left: 50%; top: 14px; bottom: 14px; width: 6px; margin-left: -3px; border-radius: 3px; background: #0b0d14aa; border: 1px solid #ffffff33; }
.rail .end { position: absolute; left: -4px; right: -4px; text-align: center; font: 600 9px/14px ui-sans-serif, system-ui, sans-serif; color: var(--quiet); pointer-events: none; white-space: nowrap; overflow: hidden; }
.rail .end.top { top: 0; } .rail .end.bottom { bottom: 0; }
.thumb { position: absolute; left: 50%; top: 14px; width: 40px; height: 26px; margin-left: -20px; transform: translateY(-50%); border-radius: 999px;
  background: var(--ink); box-shadow: 0 2px 10px #000a; pointer-events: none; }
.thumb::after { content: ""; position: absolute; left: 12px; right: 12px; top: 50%; height: 6px; margin-top: -3px; border-top: 2px solid #14110a55; border-bottom: 2px solid #14110a55; }
.rail.drag .thumb { background: var(--accent); }
.you-mark { position: absolute; left: 50%; top: 14px; width: 26px; height: 4px; margin-left: -13px; border-radius: 2px; background: var(--accent); transform: translateY(-50%); pointer-events: none; box-shadow: 0 0 0 2px #0b0d14aa; }
.tip { position: absolute; right: 46px; top: 50%; transform: translateY(-50%); padding: 2px 9px; border-radius: 999px; background: var(--accent); color: #14110a; font: 700 13px/1.4 ui-sans-serif, system-ui, sans-serif; font-variant-numeric: tabular-nums; white-space: nowrap; opacity: 0; transition: opacity 0.15s ease; }
.rail.drag .tip { opacity: 1; }
#scroll.flat .rail, #scroll.flat .rbtn { opacity: 0.35; pointer-events: none; }

/* share: the button sits top right, clear of the rails; the panel mirrors the rules panel */
#sharebtn { position: fixed; top: calc(12px + var(--safe-t)); right: 12px; z-index: 3; padding: 8px 16px; background: #0b0d14aa; }
#sharebtn[hidden] { display: none; }
#share { position: fixed; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 24px; background: #0b0d14f2; }
#share[hidden] { display: none; }
#share .card { width: 100%; max-width: 380px; max-height: 100%; overflow-y: auto; padding: 24px 20px 20px; border-radius: 20px; background: #1a1d2b; border: 1px solid #ffffff22; }
#share h2 { margin: 0 0 16px; font-size: 28px; font-weight: 800; line-height: 1.05; letter-spacing: -0.01em; color: var(--ink); }
#shot { display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; min-height: 120px; }
#shotimg { display: block; width: auto; height: auto; max-width: 100%; max-height: 40vh; border-radius: 12px; }
#shotimg[hidden] { display: none; }
#shotwait { color: var(--quiet); font-size: 14px; }
#shotwait[hidden] { display: none; }
#sharetext { margin: 0 0 16px; color: var(--quiet); font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
#shares { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.sbtn { display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 14px; border-radius: 999px; border: 1px solid #ffffff33; background: transparent;
  color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; text-align: center; cursor: pointer; }
.sbtn.primary { background: var(--accent); color: #14110a; border-color: transparent; }
.sbtn.off { opacity: 0.4; pointer-events: none; }
.sbtn[hidden] { display: none; }
.sbtn:active { transform: scale(0.97); }
#share .wide, .sbtn.wide { grid-column: 1 / -1; width: 100%; }

/* rules panel */
#rules { position: fixed; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 24px; background: #0b0d14f2; }
#rules[hidden] { display: none; }
#rules .card { width: 100%; max-width: 380px; max-height: 100%; overflow-y: auto; padding: 24px 20px 20px; border-radius: 20px; background: #1a1d2b; border: 1px solid #ffffff22; }
#rules h2 { margin: 0 0 16px; font-size: 28px; font-weight: 800; line-height: 1.05; letter-spacing: -0.01em; color: var(--ink); }
#rules ol { margin: 0 0 20px; padding: 0; list-style: none; counter-reset: rule; }
#rules li { counter-increment: rule; display: flex; gap: 12px; padding: 8px 0; font-weight: 500; color: var(--ink); }
#rules li::before { content: counter(rule); flex: none; min-width: 1.4em; color: var(--quiet); font-weight: 700; font-variant-numeric: tabular-nums; }
#rules button { width: 100%; }
