* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* brand */
  --red: #e10600;
  --red-soft: #ff3b30;
  --gold: #ffd24a;
  --green: #3ddc84;

  /* surfaces — each step is a real elevation, not just a shade */
  --bg: #08080c;
  --panel: #121219;
  --panel-2: #1a1a23;
  --line: #26262f;
  --line-soft: #1f1f28;

  /* text */
  --text: #f4f4f6;
  --muted: #9797a6;
  --dim: #6c6c7a;

  /* scale */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --pad: clamp(1rem, 4vw, 1.75rem);
  --gap: clamp(0.75rem, 3vw, 1.25rem);

  --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.35);
  --shadow-lg: 0 2px 4px rgba(0,0,0,0.4), 0 18px 48px rgba(0,0,0,0.5);
  --ring: 0 0 0 3px rgba(225,6,0,0.28);
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100svh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* long clue text and pasted codes must never widen the page */
p, li, h1, h2, h3, span { overflow-wrap: break-word; }

.hidden { display: none !important; }

/* ================= cinematic text intro ================= */
#intro {
  position: fixed; inset: 0; z-index: 50; background: #000;
  transition: opacity 0.8s ease;
  overflow: hidden;
}
#intro.fade-out { opacity: 0; }

/* ---- start gate (also unlocks browser audio) ---- */
#start-gate {
  position: absolute; inset: 0; z-index: 6;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(225,6,0,0.16), transparent 60%),
    #000;
  transition: opacity 0.45s ease, transform 0.45s ease;
}
#start-gate.gate-gone { opacity: 0; transform: scale(1.06); pointer-events: none; }
.gate-inner { text-align: center; padding: 2rem; animation: gate-in 1s ease both; }
@keyframes gate-in { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.gate-inner h1 {
  font-size: clamp(1.3rem, 4.4vw, 2.6rem); letter-spacing: 0.24em;
  color: #fff; font-weight: 800;
}
.gate-sub {
  color: var(--gold); letter-spacing: 0.32em; margin-top: 0.7rem;
  font-size: clamp(0.65rem, 1.9vw, 0.9rem);
}
.gate-lights { display: flex; gap: 0.7rem; justify-content: center; margin-bottom: 2rem; }
.gate-lights i {
  width: 14px; height: 14px; border-radius: 50%;
  background: #2a0d0d; box-shadow: inset 0 0 6px #000;
  animation: gate-pulse 2.4s ease-in-out infinite;
}
.gate-lights i:nth-child(2) { animation-delay: 0.15s; }
.gate-lights i:nth-child(3) { animation-delay: 0.3s; }
.gate-lights i:nth-child(4) { animation-delay: 0.45s; }
.gate-lights i:nth-child(5) { animation-delay: 0.6s; }
@keyframes gate-pulse {
  0%, 70%, 100% { background: #2a0d0d; box-shadow: inset 0 0 6px #000; }
  35% { background: #ff1a10; box-shadow: 0 0 16px #ff1a10, 0 0 34px rgba(255,26,16,0.55); }
}
#begin-btn {
  margin-top: 2.4rem; background: var(--red); color: #fff; border: none;
  padding: 1rem 3rem; border-radius: 999px; font-size: 1.05rem; font-weight: 800;
  letter-spacing: 0.22em; cursor: pointer;
  box-shadow: 0 0 0 rgba(225,6,0,0.7); animation: begin-pulse 2.2s ease-out infinite;
}
@keyframes begin-pulse {
  0% { box-shadow: 0 0 0 0 rgba(225,6,0,0.55); }
  70% { box-shadow: 0 0 0 22px rgba(225,6,0,0); }
  100% { box-shadow: 0 0 0 0 rgba(225,6,0,0); }
}
#begin-btn:hover { transform: translateY(-2px); }
.gate-hint { color: var(--muted); font-size: 0.8rem; letter-spacing: 0.14em; margin-top: 1.3rem; }
#mute-start-btn {
  margin-top: 0.9rem; background: none; border: none; color: #6a6a78;
  font-size: 0.78rem; letter-spacing: 0.1em; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
}
#mute-start-btn:hover { color: #b0b0c0; }

/* ---- the sequence ---- */
#cinema { position: absolute; inset: 0; z-index: 5; background: #000; }

.cine-bar {
  position: absolute; left: 0; right: 0; height: 0; background: #000; z-index: 4;
  transition: height 1.1s cubic-bezier(0.22, 1, 0.36, 1);
}
.cine-bar-top { top: 0; }
.cine-bar-bottom { bottom: 0; }
body.cine-active .cine-bar { height: 9vh; }

#stage {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 0 6vw;
}

.cine-line { opacity: 0; color: #fff; will-change: transform, opacity, filter; }
.cine-line.play { animation: line-in 2.6s cubic-bezier(0.16, 1, 0.3, 1) both; }
.cine-line-sub.play { animation-delay: 0.28s; }

@keyframes line-in {
  0%   { opacity: 0; letter-spacing: 0.05em; filter: blur(14px); transform: scale(1.06); }
  22%  { opacity: 1; filter: blur(0); }
  78%  { opacity: 1; filter: blur(0); }
  100% { opacity: 0; letter-spacing: 0.4em; filter: blur(6px); transform: scale(1.01); }
}

.style-wide#card-line1, .cine-line.style-wide:not(.cine-line-sub) {
  font-size: clamp(1.5rem, 6vw, 3.6rem); font-weight: 800; letter-spacing: 0.22em;
  text-shadow: 0 0 40px rgba(255,255,255,0.28);
}
.cine-line-sub.style-wide {
  font-size: clamp(0.7rem, 2.2vw, 1rem); letter-spacing: 0.42em;
  color: var(--gold); margin-top: 1.2rem; font-weight: 600;
}
.cine-line.style-title:not(.cine-line-sub) {
  font-size: clamp(1.9rem, 8.5vw, 5.6rem); font-weight: 900; letter-spacing: 0.1em;
  background: linear-gradient(180deg, #fff 0%, #ffd9d7 45%, var(--red) 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  filter: drop-shadow(0 0 34px rgba(225,6,0,0.75));
}
.cine-line-sub.style-title {
  font-size: clamp(0.7rem, 2.3vw, 1.05rem); letter-spacing: 0.36em;
  color: #d8d8e2; margin-top: 1.4rem; font-weight: 500;
}

/* start-light rig */
#light-rig { display: flex; gap: clamp(0.6rem, 2.4vw, 1.5rem); margin-top: 3rem; }
#light-rig i {
  width: clamp(20px, 5.2vw, 40px); height: clamp(20px, 5.2vw, 40px);
  border-radius: 50%; background: #1a0808;
  border: 2px solid #2e2e38; box-shadow: inset 0 3px 10px rgba(0,0,0,0.9);
  transition: background 0.1s linear, box-shadow 0.1s linear;
}
#light-rig i.on {
  background: #ff1608; border-color: #ff5a4a;
  box-shadow: 0 0 22px #ff1608, 0 0 60px rgba(255,22,8,0.6), inset 0 0 10px #ffdad6;
}

/* atmosphere */
#flash {
  position: absolute; inset: 0; z-index: 3; background: #fff;
  opacity: 0; pointer-events: none;
}
#vignette {
  position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background: radial-gradient(ellipse at 50% 50%, transparent 42%, rgba(0,0,0,0.82) 100%);
}
#grain {
  position: absolute; inset: -60px; z-index: 3; pointer-events: none; opacity: 0.05;
  background-image:
    repeating-radial-gradient(circle at 17% 33%, #fff 0 1px, transparent 1px 3px),
    repeating-radial-gradient(circle at 71% 62%, #fff 0 1px, transparent 1px 4px);
  animation: grain-shift 0.5s steps(3) infinite;
}
@keyframes grain-shift {
  0%   { transform: translate(0, 0); }
  33%  { transform: translate(-14px, 9px); }
  66%  { transform: translate(11px, -12px); }
  100% { transform: translate(0, 0); }
}

#skip-btn {
  position: absolute; bottom: max(3vh, 12vh); left: 50%; transform: translateX(-50%);
  z-index: 7; background: rgba(255,255,255,0.06); color: #cfcfda;
  border: 1px solid rgba(255,255,255,0.22); padding: 0.55rem 1.5rem;
  border-radius: 999px; cursor: pointer; font-size: 0.82rem; letter-spacing: 0.16em;
  transition: background 0.2s, color 0.2s;
}
#skip-btn:hover { background: var(--red); border-color: var(--red); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  .cine-line.play { animation-duration: 0.01s; opacity: 1; }
  #grain, .gate-lights i, #begin-btn { animation: none; }
}

/* ---------------- shared layout ---------------- */
/* Restrained backdrop: a cool base with one soft warm accent and a fine
   grid, rather than large saturated glows. Reads as product, not poster. */
.race-bg {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(225,6,0,0.10), transparent 60%),
    radial-gradient(90% 60% at 85% 105%, rgba(70,90,140,0.10), transparent 65%),
    var(--bg);
}
.race-bg::after {
  content: ''; position: absolute; inset: 0; opacity: 0.5;
  background-image:
    linear-gradient(rgba(255,255,255,0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.022) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(circle at 50% 0%, #000 0%, transparent 75%);
  -webkit-mask-image: radial-gradient(circle at 50% 0%, #000 0%, transparent 75%);
}

/* ============================ top bar ============================ */
.topbar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.7rem clamp(0.85rem, 4vw, 1.5rem);
  padding-top: calc(0.7rem + env(safe-area-inset-top));
  background: rgba(14,14,20,0.82);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(225,6,0,0.55);
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
}
.logo {
  font-weight: 800; letter-spacing: 0.1em; color: var(--gold);
  font-size: clamp(0.82rem, 3.4vw, 1rem); white-space: nowrap; flex-shrink: 0;
}
/* the middle chip is the only part allowed to shrink and ellipsize */
#user-chip, #vs-chip {
  color: var(--muted); font-size: clamp(0.75rem, 3vw, 0.9rem);
  flex: 1; min-width: 0; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .btn-ghost {
  flex-shrink: 0; white-space: nowrap;
  padding: 0.5rem 0.8rem; font-size: 0.78rem; letter-spacing: 0.06em;
}
/* on narrow phones the logo sheds its wordmark so the team names get the room */
@media (max-width: 430px) {
  .logo .logo-text { display: none; }
  .topbar { gap: 0.5rem; }
}

/* ============================ layout ============================ */
.container {
  max-width: 1000px; margin: 0 auto;
  padding: var(--gap) clamp(0.85rem, 4vw, 1.5rem);
  padding-bottom: calc(2.5rem + env(safe-area-inset-bottom));
}
.section-title {
  text-align: center; letter-spacing: 0.18em; margin-bottom: var(--gap);
  font-size: clamp(1rem, 4.4vw, 1.3rem);
}

/* single column on phones, two up from 760px */
.split { display: grid; grid-template-columns: 1fr; gap: var(--gap); }
@media (min-width: 760px) { .split { grid-template-columns: 1fr 1fr; } }

/* ============================ cards ============================ */
.card {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.035), transparent 120px),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--pad);
  padding-top: calc(var(--pad) + 0.4rem);
  position: relative; overflow: hidden;
  box-shadow: var(--shadow);
}
.card + .card, .card.wide { margin-top: var(--gap); }
.card h1 {
  letter-spacing: 0.02em; margin-bottom: 0.3rem; line-height: 1.2;
  font-size: clamp(1.15rem, 5vw, 1.6rem);
}
.card h2 { margin-bottom: 0.3rem; font-size: clamp(1.05rem, 4.6vw, 1.35rem); line-height: 1.25; }
.card h3 {
  margin: 1.4rem 0 0.6rem; color: var(--gold);
  letter-spacing: 0.16em; font-size: 0.74rem; text-transform: uppercase;
}
.sub { color: var(--muted); margin-bottom: 1.1rem; font-size: 0.95rem; }

/* slim chequered signature along the card top */
.checker-strip {
  position: absolute; top: 0; left: 0; right: 0; height: 5px;
  background: repeating-conic-gradient(#fff 0% 25%, #14141c 0% 50%) 0 0/12px 6px;
  opacity: 0.9;
}

/* ============================ form controls ============================ */
input, textarea {
  width: 100%;
  padding: 0.85rem 1rem;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  /* 16px keeps iOS Safari from zooming in when a field is focused */
  font-size: 16px; font-family: inherit; line-height: 1.4;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
input::placeholder, textarea::placeholder { color: var(--dim); }
textarea { min-height: 84px; resize: vertical; }
input:focus, textarea:focus {
  outline: none; border-color: var(--red);
  background: #1e1e28; box-shadow: var(--ring);
}
label {
  display: block; margin-bottom: 0.4rem; color: var(--muted);
  font-size: 0.75rem; letter-spacing: 0.14em; text-transform: uppercase;
}
.field { margin-bottom: 1rem; }
form input, form textarea { margin-bottom: 0.9rem; }

button { font-family: inherit; }
.btn-red, .btn-gold, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 50px;                    /* comfortable thumb target */
  padding: 0.85rem 1.5rem; border: 1px solid transparent;
  border-radius: var(--r-sm);
  font-weight: 700; letter-spacing: 0.09em; cursor: pointer;
  font-size: 0.92rem; text-align: center;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.btn-red { background: var(--red); color: #fff; box-shadow: 0 2px 10px rgba(225,6,0,0.18); }
.btn-gold { background: var(--gold); color: #14141c; box-shadow: 0 2px 10px rgba(255,210,74,0.14); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--line); min-height: 44px; padding: 0.6rem 1rem; }
@media (hover: hover) {
  .btn-red:hover { background: #ff1409; box-shadow: 0 6px 22px rgba(225,6,0,0.5); transform: translateY(-1px); }
  .btn-gold:hover { background: #ffdc6e; box-shadow: 0 6px 22px rgba(255,210,74,0.4); transform: translateY(-1px); }
  .btn-ghost:hover { color: #fff; border-color: #4a4a58; background: rgba(255,255,255,0.04); }
}
.btn-red:active, .btn-gold:active, .btn-ghost:active { transform: translateY(1px) scale(0.99); }
.btn-link { text-decoration: none; }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* full-width primary actions on phones — easier to hit while walking */
.btn-red, .btn-gold { width: 100%; }
@media (min-width: 620px) { .btn-red, .btn-gold { width: auto; } .btn-block { width: 100%; } }

.error { color: #ff7a72; margin-top: 0.5rem; min-height: 1.2em; font-size: 0.9rem; }
.success { color: var(--green); margin-top: 0.5rem; font-size: 0.9rem; }
.hint { color: var(--dim); font-size: 0.82rem; }

/* input + button pairs: stacked on phone, inline once there is room */
.row { display: flex; flex-direction: column; gap: 0.7rem; }
.row input { flex: 1; min-width: 0; margin-bottom: 0; }
@media (min-width: 620px) {
  .row { flex-direction: row; align-items: stretch; }
  .row .btn-red, .row .btn-gold { width: auto; flex-shrink: 0; }
}

/* ============================ registration ============================ */
#register {
  min-height: 100svh; display: flex; align-items: center; justify-content: center;
  padding: clamp(1rem, 5vw, 2rem);
}
.reg-card {
  width: 100%; max-width: 430px; text-align: center;
  animation: card-in 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.reg-card form { text-align: left; margin-top: 1.4rem; }
.reg-card .btn-red { width: 100%; margin-top: 0.5rem; }
@keyframes card-in {
  from { opacity: 0; transform: translateY(22px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* ============================ codes & stat tiles ============================ */
/* auto-fit means these reflow instead of overflowing on any width */
.codes, .setup-status {
  display: grid; gap: var(--gap); margin: 1.1rem 0;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.code-box, .timer-box, .score-box {
  min-width: 0;                        /* lets grid items shrink properly */
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 1rem 0.75rem;
  display: flex; flex-direction: column; gap: 0.3rem;
  text-align: center;
}
.label {
  font-size: 0.66rem; letter-spacing: 0.16em; color: var(--muted);
  text-transform: uppercase;
}
.big-code {
  font-size: clamp(1.4rem, 7vw, 2rem); font-weight: 800; letter-spacing: 0.12em;
  color: #fff; font-variant-numeric: tabular-nums; line-height: 1.1;
}
.big-code.gold { color: var(--gold); }

.members { list-style: none; }
.members li {
  padding: 0.6rem 0; border-bottom: 1px solid var(--line-soft);
  color: #d0d0d8; font-size: 0.95rem;
}
.members li:last-child { border-bottom: none; }
/* empty lists read as a deliberate state rather than a blank gap */
#solve-list:empty::after,
#cp-list:empty::after {
  content: attr(data-empty);
  display: block; padding: 0.9rem 0; color: var(--dim);
  font-size: 0.9rem; font-style: italic;
}

.battle-live {
  color: var(--green); font-size: 1rem; margin-bottom: 1rem;
  display: flex; align-items: center; gap: 0.5rem;
}
.battle-live::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 10px var(--green);
  animation: live-pulse 1.8s ease-in-out infinite; flex-shrink: 0;
}
@keyframes live-pulse { 50% { opacity: 0.35; transform: scale(0.8); } }

/* ============================ scoreboard ============================ */
/* grid with min-width:0 — this is what stops the sideways scroll on phones */
.scoreboard {
  display: grid; grid-template-columns: 1fr auto 1fr;
  gap: 0.6rem; align-items: stretch; margin-bottom: var(--gap);
}
.score-box.mine { border-color: var(--gold); background: rgba(255,210,74,0.06); }
.vs {
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; color: var(--red);
  font-size: clamp(0.85rem, 3.6vw, 1.2rem); letter-spacing: 0.06em;
}

/* ============================ clues ============================ */
.clue {
  background: var(--panel-2); border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: var(--r-sm); padding: 1rem 1.1rem; margin-bottom: 0.8rem;
  animation: card-in 0.45s ease both;
}
.clue-1 { border-left-color: var(--red); }
.clue-2 { border-left-color: #ff9f1c; }
.clue-3 { border-left-color: var(--gold); }
.clue-label {
  font-size: 0.68rem; letter-spacing: 0.16em; color: var(--muted);
  display: block; margin-bottom: 0.45rem; text-transform: uppercase;
}
.clue p { line-height: 1.6; font-size: 1rem; }

/* ============================ results ============================ */
.result-card { text-align: center; padding: clamp(1.75rem, 7vw, 3rem) var(--pad); }
.result-card h1 { font-size: clamp(1.6rem, 8vw, 2.4rem); }
.winner-img {
  width: 100%; height: auto; border-radius: var(--r-md); margin-top: 1.4rem;
  border: 2px solid var(--gold); box-shadow: var(--shadow-lg);
}

/* wide content must scroll inside its own box, never widen the page */
pre, table { max-width: 100%; overflow-x: auto; }
