:root {
  --ground: #10131C;      /* lifted near-black, never #000 */
  --panel: #1A1F2E;
  --panel-2: #262D42;
  --ink: #FFFFFF;
  --ink-soft: #CFD6E6;
  --pink: #FF3B3B;        /* hero red (kept the old variable name so shared rules carry over) */
  --pink-deep: #C40024;
  --gold: #FFD400;
  --dark-on-pink: #10131C;
  --sky: #25B5FF;
  --display: 'Bangers', 'Impact', system-ui, sans-serif;
  --radius: 22px;
  --font: 'Fredoka', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 500;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible { outline: 4px solid var(--gold); outline-offset: 3px; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; display: none; }
body[data-screen="start"] #start { display: flex; }
body[data-screen="studio"] #studio { display: flex; }

/* ───────────── start ───────────── */
.start {
  flex-direction: column; justify-content: safe center; align-items: flex-start;
  padding: max(32px, env(safe-area-inset-top)) 8vw 40px;
  overflow-y: auto;
  background:
    radial-gradient(120% 70% at 100% 0%, rgba(255, 59, 59, .35), transparent 60%),
    radial-gradient(90% 60% at 0% 100%, rgba(37, 181, 255, .25), transparent 60%),
    var(--ground);
  overflow: hidden;
}
.start-body { position: relative; z-index: 1; width: 100%; max-width: 640px; }
.kicker { margin: 0; font-family: var(--display); font-size: clamp(34px, 7vw, 60px); color: var(--gold); letter-spacing: .02em; transform: rotate(-4deg); transform-origin: left; }
.title {
  margin: 0 0 28px; font-family: var(--display); font-weight: 400; line-height: .86; letter-spacing: .01em;
  font-size: clamp(80px, min(26vw, 24vh), 240px); text-transform: uppercase; color: var(--ink);
  text-shadow: 6px 6px 0 var(--pink), 12px 12px 0 var(--pink-deep);
  transform: rotate(-3deg); transform-origin: left;
}
.ask { margin: 18px 0 22px; font-size: clamp(22px, 4vw, 32px); color: var(--ink); }
.start-actions { display: flex; flex-direction: column; gap: 16px; max-width: 460px; }
.big {
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  min-height: 72px; padding: 0 28px; border-radius: 999px;
  font-size: 26px; font-weight: 700; transition: transform .12s ease;
}
.big:active { transform: scale(.95); }
.big .ico { font-size: 32px; }
.primary { background: var(--pink); color: var(--dark-on-pink); box-shadow: 0 6px 0 var(--pink-deep); }
.secondary { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 3px var(--ink); }
.text-btn { display: flex; align-items: center; gap: 8px; margin-top: 22px; min-height: 48px; font-size: 20px; color: var(--ink-soft); text-decoration: underline; text-underline-offset: 5px; }

.go { min-height: 104px; padding: 0 44px; font-family: var(--display); font-weight: 400; font-size: clamp(44px, 9vw, 64px); letter-spacing: .03em; }
.go .ico { font-size: 1.1em; }
.go { animation: ready 1.8s ease-in-out infinite; }
@keyframes ready { 50% { scale: 1.04; } }
.burst {
  position: absolute; right: -20vmax; top: -20vmax; width: 80vmax; height: 80vmax; pointer-events: none;
  background: repeating-conic-gradient(from 0deg, rgba(255, 212, 0, .10) 0 6deg, transparent 6deg 18deg);
  border-radius: 50%; animation: spinSlow 60s linear infinite;
}
@keyframes spinSlow { to { rotate: 1turn; } }

/* ───────────── studio ───────────── */
.studio { flex-direction: column; }
.stage { position: relative; flex: 1; min-height: 0; background: #0f0b13; overflow: hidden; }
#video { display: none; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }

.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 6;   /* above loading/error so Home always works */
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 14px 12px;
  background: linear-gradient(rgba(23, 18, 29, .75), transparent);
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 52px; min-width: 52px; padding: 0 18px; border-radius: 999px;
  background: rgba(23, 18, 29, .8); color: var(--ink); font-size: 20px; font-weight: 700;
  backdrop-filter: blur(6px);
}
.chip:active { transform: scale(.94); }
.brand { font-family: var(--display); font-size: 24px; letter-spacing: .08em; color: var(--ink); text-shadow: 0 2px 8px rgba(0,0,0,.6); }

.hint {
  position: absolute; left: 50%; top: 50%; translate: -50% -50%; z-index: 2;
  max-width: min(86%, 460px); padding: 18px 24px; border-radius: var(--radius);
  background: rgba(23, 18, 29, .88); font-size: 24px; line-height: 1.3; text-align: center;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { scale: 1.04; } }

.power-hint {
  position: absolute; left: 50%; top: 84px; translate: -50% 0; z-index: 3;
  padding: 10px 24px; border-radius: 999px; background: rgba(16, 19, 28, .85);
  font-size: 44px; line-height: 1.1; white-space: nowrap; pointer-events: none;
  box-shadow: 0 0 0 3px var(--gold);
  animation: pulse 1.4s ease-in-out infinite;
}
.count {
  position: absolute; inset: 0; z-index: 3; display: grid; place-items: center;
  font-family: var(--display); font-size: min(46vw, 320px); font-weight: 400; color: var(--ink);
  text-shadow: 0 8px 0 var(--pink-deep), 0 0 40px rgba(0,0,0,.6);
  pointer-events: none;
}
.count.tick { animation: countPop .7s ease-out; }
@keyframes countPop { from { scale: 1.6; opacity: 0; } 25% { scale: 1; opacity: 1; } to { scale: .9; opacity: .9; } }
.flash { position: absolute; inset: 0; z-index: 4; background: #fff; animation: flash .5s ease-out forwards; pointer-events: none; }
@keyframes flash { from { opacity: .45; } to { opacity: 0; } }   /* soft, never a full white-out */

.overlay {
  position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; padding: 24px; text-align: center;
  background: rgba(23, 18, 29, .94); font-size: 24px;
}
.spinner { width: 72px; height: 72px; border-radius: 50%; border: 8px solid rgba(255,255,255,.18); border-top-color: var(--pink); animation: spin 1s linear infinite; }
@keyframes spin { to { rotate: 1turn; } }
.err-ico { font-size: 72px; }
.err-title { margin: 0; font-size: 34px; font-weight: 700; color: var(--pink); }
.err-text { margin: 0 0 8px; max-width: 480px; line-height: 1.35; color: var(--ink); }

/* ───────────── hero 1 / hero 2 (shows up once two heroes are on camera) ───────────── */
:root { --p1: #25B5FF; --p2: #FF5FA8; }
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.player {
  display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 60px; border-radius: 999px;
  font-size: 30px; background: var(--panel-2); box-shadow: inset 0 0 0 3px rgba(255,255,255,.18);
  transition: transform .12s ease;
}
.player:active { transform: scale(.94); }
.pnum { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; font-family: var(--display); font-size: 28px; color: var(--dark-on-pink); }
.p1 .pnum { background: var(--p1); }
.p2 .pnum { background: var(--p2); }
.player { position: relative; }
.player[aria-checked="false"] { opacity: .75; }
.player[aria-checked="true"]::after {                     /* same ✓ badge the tiles use: "this one is on" without colour */
  content: '✓'; position: absolute; right: 12px; top: 50%; translate: 0 -50%; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; background: var(--gold); color: var(--dark-on-pink); font-size: 18px; font-weight: 700;
}
.player.pop { animation: tilePop .35s ease-out; }
.p1[aria-checked="true"] { background: #173A55; box-shadow: inset 0 0 0 5px var(--p1); }
.p2[aria-checked="true"] { background: #55193A; box-shadow: inset 0 0 0 5px var(--p2); }
body.two[data-player="0"] .tile.on { box-shadow: inset 0 0 0 5px var(--p1); }
body.two[data-player="1"] .tile.on { box-shadow: inset 0 0 0 5px var(--p2); }
body.two[data-player="0"] .tile-check { background: var(--p1); }
body.two[data-player="1"] .tile-check { background: var(--p2); }

/* ───────────── dock ───────────── */
.dock {
  flex: none; display: flex; flex-direction: column; gap: 14px;
  padding: 16px 16px max(16px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 3px solid var(--pink);
}
body.overlay-up .dock { opacity: .4; }
body.overlay-up .dock .tray, body.overlay-up .dock .tabs { pointer-events: none; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tab-ico { font-size: 1.3em; }
.tab.pop { animation: tilePop .5s ease-out 2; box-shadow: inset 0 0 0 4px var(--gold); }
.tab {
  display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; padding: 0 6px;
  min-height: 64px; border-radius: 999px; font-size: 20px; font-weight: 700;
  background: var(--panel-2); color: var(--ink);
}
.tab[aria-selected="true"] { background: #3A2447; color: var(--ink); box-shadow: inset 0 0 0 4px var(--pink); }

.tray {
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(2, auto); gap: 10px;
  grid-auto-columns: calc((100% - 30px) / 4.4);          /* a sliver of the next column says "swipe for more" */
  overflow-x: auto; overflow-y: hidden; scroll-snap-type: x proximity; overscroll-behavior-x: contain;
  scrollbar-width: none; padding-bottom: 2px;
}
.tray::-webkit-scrollbar { display: none; }
.tray .tile { scroll-snap-align: start; }
.tile {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 118px; padding: 6px 4px; border-radius: var(--radius);
  background: var(--panel-2); color: var(--ink);
  box-shadow: inset 0 0 0 3px transparent;
  transition: transform .12s ease, box-shadow .12s ease;
}
.tile:active { transform: scale(.93); }
.tile-ico { font-size: 46px; line-height: 1; }
.tile canvas { width: 80px; height: 80px; display: block; pointer-events: none; }
.tile-name { font-size: 18px; font-weight: 700; }
.tile-dot { position: absolute; left: 10px; top: 10px; width: 20px; height: 20px; border-radius: 50%; box-shadow: 0 0 0 2px var(--ink); }
.tile-check {
  position: absolute; right: 8px; top: 8px; width: 28px; height: 28px; border-radius: 50%;
  display: none; place-items: center; background: var(--gold); color: var(--dark-on-pink); font-size: 18px; font-weight: 700;
}
.tile { border: 2px solid rgba(255, 255, 255, 0.16); }
.tile.on { box-shadow: inset 0 0 0 5px var(--gold); background: #33304A; }
.tile.on .tile-check { display: grid; }
.tray .tile:focus-visible { outline-offset: -6px; }     /* the tray clips anything outside it */
.tile.pop { animation: tilePop .35s ease-out; }
@keyframes tilePop { 40% { scale: 1.1; } }


.shutter-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; }
.side-btn { justify-self: center; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 80px; min-height: 80px; }
.side-btn .thumb {
  width: 60px; height: 60px; border-radius: 16px; display: grid; place-items: center; overflow: hidden;
  background: var(--panel-2); font-size: 30px; box-shadow: inset 0 0 0 2px rgba(255,255,255,.2);
}
.side-btn .thumb img { width: 100%; height: 100%; object-fit: cover; }
.side-btn .thumb.bump { animation: tilePop .4s ease-out; }
.side-label { font-size: 16px; color: var(--ink-soft); }
.shutter {
  width: 104px; height: 104px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ink); box-shadow: 0 0 0 6px var(--pink), 0 8px 24px rgba(255, 79, 163, .45);
  transition: transform .1s ease;
}
.shutter:active { transform: scale(.9); }
.shutter-core { width: 80px; height: 80px; border-radius: 50%; display: grid; place-items: center; background: var(--pink); font-size: 38px; }
.shutter:disabled { opacity: .5; }

.fly { position: fixed; z-index: 20; border-radius: 16px; object-fit: cover; box-shadow: 0 10px 30px rgba(0,0,0,.5); transition: all .55s cubic-bezier(.5, 0, .3, 1); pointer-events: none; }

/* ───────────── gallery + viewer ───────────── */
.sheet { position: fixed; inset: 0; z-index: 10; background: var(--ground); display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: max(16px, env(safe-area-inset-top)) 18px 12px; border-bottom: 3px solid var(--pink); }
.sheet-head h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 40px; letter-spacing: .03em; }
.grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; padding: 16px; align-content: start; }
.grid button { aspect-ratio: 3 / 4; border-radius: 18px; overflow: hidden; background: var(--panel-2); }
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.empty { margin: auto; padding: 24px; text-align: center; font-size: 26px; line-height: 1.4; color: var(--ink-soft); }
.viewer { justify-content: center; align-items: center; gap: 18px; padding: 18px; }
.viewer img { max-width: 100%; max-height: calc(100% - 110px); border-radius: 18px; object-fit: contain; }
.viewer-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px; background: rgba(10, 6, 14, .75); }
.modal-card { width: min(100%, 460px); padding: 26px; border-radius: 28px; background: var(--panel); text-align: center; }
.modal-card p { margin: 0 0 20px; font-size: 28px; font-weight: 700; }
.modal-actions { display: flex; flex-direction: column; gap: 12px; }

.toast {
  position: fixed; left: 50%; top: 22%; translate: -50% 0; z-index: 25;
  padding: 16px 28px; border-radius: 999px; background: var(--gold); color: var(--dark-on-pink);
  font-size: 26px; font-weight: 700; box-shadow: 0 10px 30px rgba(0,0,0,.4);
  animation: toastIn .3s ease-out;
}
@keyframes toastIn { from { translate: -50% -20px; opacity: 0; } }

/* ───────────── landscape tablet: dock becomes a side panel ───────────── */
@media (orientation: landscape) and (min-width: 600px) {
  .studio { flex-direction: row; }
  .dock { overflow-x: hidden; }
  .tabs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tab { flex-direction: column; gap: 0; font-size: 15px; line-height: 1.1; }
  .dock { width: 400px; border-top: 0; border-left: 3px solid var(--pink); overflow-y: auto; justify-content: flex-start; padding-top: max(16px, env(safe-area-inset-top)); }
  .tray {
    grid-auto-flow: row; grid-template-rows: none; grid-auto-columns: auto; grid-template-columns: repeat(3, 1fr);
    overflow-x: hidden; overflow-y: auto; flex: 1; min-height: 0; align-content: start; scroll-snap-type: y proximity;
  }
  .shutter-row { margin-top: auto; }
  .power-hint { top: 76px; }
  .start-actions .big { flex: 1; }
  .start-actions { flex-direction: row; max-width: none; }
}

/* short landscape (8" tablets sideways, phones sideways): compact side panel */
@media (orientation: landscape) and (min-width: 600px) and (max-height: 640px) {
  .dock { width: 340px; gap: 8px; padding: 10px 12px; }
  .tab { min-height: 64px; font-size: 14px; gap: 0; padding: 2px; flex-direction: column; line-height: 1.1; }
  .go { font-size: 40px; min-height: 76px; }
  .tray { gap: 8px; }
  .tile { min-height: 96px; padding: 6px; }
  .tile canvas { width: 62px; height: 62px; }
  .tile-ico { font-size: 32px; }
  .tile-name { font-size: 15px; }
  .side-btn { min-width: 64px; min-height: 64px; }
  .side-btn .thumb { width: 48px; height: 48px; font-size: 24px; }
  .side-label { font-size: 14px; }
  .shutter { width: 80px; height: 80px; }
  .shutter-core { width: 62px; height: 62px; font-size: 28px; }
  .chip { min-height: 48px; font-size: 17px; padding: 0 14px; }
  .player { min-height: 48px; font-size: 22px; }
  .pnum { width: 32px; height: 32px; font-size: 22px; }
  .ask { margin: 8px 0 12px; }
  .big:not(.go) { min-height: 60px; font-size: 21px; }
  .text-btn { margin-top: 10px; }
}

/* ───────────── phone ───────────── */
@media (max-width: 540px) {
  .dock { gap: 10px; padding: 12px 12px max(12px, env(safe-area-inset-bottom)); }
  .player { min-height: 52px; font-size: 24px; }
  .pnum { width: 34px; height: 34px; font-size: 24px; }
  .brand { display: none; }
  .tab { font-size: 14px; min-height: 64px; gap: 2px; padding: 0 3px; }
  .tile-name { font-size: 12px; white-space: nowrap; }
  .tray { gap: 6px; grid-auto-columns: calc((100% - 18px) / 4.3); }
  .tile { min-height: 100px; }
  .tile canvas { width: 64px; height: 64px; }
  .power-hint { font-size: 34px; top: 72px; }
  .go { font-size: 40px; min-height: 88px; padding: 0 28px; }
  .tile-ico { font-size: 36px; }
  .tile-name { font-size: 15px; }
  .shutter { width: 88px; height: 88px; }
  .shutter-core { width: 68px; height: 68px; font-size: 32px; }
  .big:not(.go) { font-size: 22px; min-height: 64px; }
  .grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 380px) {
  .tile-name { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .float, .hint, .go, .burst, .power-hint { animation: none; }
}
