/* Cranial Combat: Trivia Showdown
   Electric cyan against fire orange, on a near-black arena. Cyan is "you / go", orange is "the rival / the lead". */
:root {
  --ink: #060a18; --navy: #0b1432; --navy-2: #121f47;
  --cyan: #28d4ff; --ember: #ff7a1a;
  --chrome: #eaf2fc; --muted: #a3b5d6;
  --good: #3be08a; --bad: #ff5a6e;
  --line: #2a3b6b;
  --display: "Russo One", "Arial Black", Impact, system-ui, sans-serif;
  --ui: "Rajdhani", "Segoe UI", system-ui, -apple-system, sans-serif;
  --notch: 14px;
}
* { box-sizing: border-box; }
html { background: var(--ink); }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh; background: transparent; color: var(--chrome);
  font-family: var(--ui); font-weight: 500; font-size: 1.1rem; line-height: 1.4;
}

/* the blurred, darkened artwork behind every screen */
.backdrop {
  position: fixed; inset: 0; z-index: -1; background-color: var(--ink);
  background-image: linear-gradient(rgba(6,10,24,.55), rgba(6,10,24,.9)), var(--art, none);
  background-size: cover; background-position: center top;
}
.backdrop::after {   /* blur without bleeding past the screen edge */
  content: ""; position: absolute; inset: -30px; z-index: -1;
  background: var(--art, none) center top / cover; filter: blur(16px) brightness(.5) saturate(1.3);
}

.stage {
  min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 16px;
  filter: drop-shadow(-5px 0 12px rgba(40,212,255,.28)) drop-shadow(5px 0 12px rgba(255,122,26,.28));
}
.stage.splash-stage { filter: none; padding: 0; }

/* ---------- panel: glass, cyan-to-orange edge, notched corners ---------- */
.panel {
  width: 100%; max-width: 620px; padding: 28px;
  background:
    linear-gradient(rgba(8,14,34,.9), rgba(8,14,34,.93)) padding-box,
    linear-gradient(120deg, var(--cyan), #3b4f8c 45%, #8a4a2a 60%, var(--ember)) border-box;
  border: 2px solid transparent;
  clip-path: polygon(var(--notch) 0, 100% 0, 100% calc(100% - var(--notch)), calc(100% - var(--notch)) 100%, 0 100%, 0 var(--notch));
  backdrop-filter: blur(6px);
}

/* ---------- type ---------- */
h1, h2, .headline, .winner, .code-big, .score, .timer-text, .topbar b {
  font-family: var(--display); font-weight: 400;
}
h1 {
  margin: 0 0 10px; font-size: 1.9rem; line-height: 1.1; font-style: italic; text-transform: uppercase; letter-spacing: .02em;
  background: linear-gradient(180deg, #fff 0%, #d5e0ee 42%, #7f90ab 52%, #e4ecf6 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 8px rgba(40,212,255,.45));
}
h1 small { display: block; margin-top: 4px; font-size: .55em; letter-spacing: .14em; }
h2 { margin: 22px 0 6px; font-size: 1.05rem; color: var(--cyan); letter-spacing: .06em; font-style: italic; }
label { display: block; margin: 16px 0 6px; font-size: 1rem; font-weight: 600; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .95rem; }
.mono { font-family: ui-monospace, Consolas, monospace; word-break: break-all; }
.center { text-align: center; }
.build { margin: 18px 0 0; text-align: center; font-size: .85rem; color: #7f90b4; }

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 1rem; font-weight: 600; color: var(--muted); margin-bottom: 14px; }

.badge {
  display: inline-block; padding: 2px 12px; font-size: .9rem; font-weight: 700; letter-spacing: .04em;
  background: var(--cyan); color: #04111f; margin: 0 6px 6px 0;
  clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%);
}
.badge.medium { background: #ffd23f; }
.badge.hard { background: var(--ember); }
.badge.category { background: #26376a; color: var(--chrome); font-weight: 600; }

.question { font-size: 1.45rem; font-weight: 600; line-height: 1.3; margin: 12px 0 20px; }
.question.small-q { font-size: 1.15rem; margin: 10px 0 14px; }
.answers { display: grid; gap: 10px; }

/* ---------- buttons ---------- */
button, input, select { font: inherit; }
button {
  cursor: pointer; min-height: 46px; padding: 10px 16px; text-align: left; color: var(--chrome);
  background: linear-gradient(180deg, #14224d, #0a1330);
  border: 2px solid var(--cyan); border-radius: 4px;
  box-shadow: 0 0 10px rgba(40,212,255,.35), inset 0 0 12px rgba(40,212,255,.12);
  transition: box-shadow .15s, transform .1s;
}
button:hover:not(:disabled) { box-shadow: 0 0 18px rgba(40,212,255,.7), inset 0 0 14px rgba(40,212,255,.2); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.primary, .secondary {
  width: 100%; margin-top: 18px; text-align: center; font-family: var(--display); font-size: 1.1rem;
  text-transform: uppercase; letter-spacing: .06em; min-height: 52px;
}
.secondary { margin-top: 12px; border-color: var(--ember); box-shadow: 0 0 10px rgba(255,122,26,.4), inset 0 0 12px rgba(255,122,26,.12); }
.secondary:hover:not(:disabled) { box-shadow: 0 0 18px rgba(255,122,26,.75), inset 0 0 14px rgba(255,122,26,.22); }

/* answers: alternate cyan and orange, lettered A to D */
.answers button { display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 1.15rem; }
.answers button::before {
  content: attr(data-k); flex: none; width: 30px; height: 30px; display: grid; place-items: center;
  font-family: var(--display); font-size: .95rem; background: var(--cyan); color: #04111f;
  clip-path: polygon(6px 0, 100% 0, calc(100% - 6px) 100%, 0 100%);
}
.answers button:nth-child(even) { border-color: var(--ember); box-shadow: 0 0 10px rgba(255,122,26,.4), inset 0 0 12px rgba(255,122,26,.12); }
.answers button:nth-child(even):hover:not(:disabled) { box-shadow: 0 0 18px rgba(255,122,26,.75), inset 0 0 14px rgba(255,122,26,.22); }
.answers button:nth-child(even)::before { background: var(--ember); }
.answers button.picked { background: linear-gradient(180deg, #1d3f78, #10265a); box-shadow: 0 0 20px rgba(255,255,255,.55); border-color: #fff; }
.answers button:disabled:not(.correct):not(.wrong):not(.picked) { opacity: .55; }
.answers button.correct { border-color: var(--good); background: rgba(59,224,138,.18); box-shadow: 0 0 18px rgba(59,224,138,.7); }
.answers button.correct::after { content: "✓"; margin-left: auto; color: var(--good); font-weight: 700; font-size: 1.4rem; }
.answers button.wrong { border-color: var(--bad); background: rgba(255,90,110,.18); box-shadow: 0 0 18px rgba(255,90,110,.6); }
.answers button.wrong::after { content: "✕"; margin-left: auto; color: var(--bad); font-weight: 700; font-size: 1.3rem; }
.answers button.correct::before { background: var(--good); }
.answers button.wrong::before { background: var(--bad); }

/* ---------- inputs ---------- */
input, select {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 4px; border: 2px solid var(--line);
  background: #070d24; color: var(--chrome);
}
input::placeholder { color: #7486ab; }
input:focus, select:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 14px rgba(40,212,255,.55); }
.code-input { text-transform: uppercase; letter-spacing: .4em; font-family: var(--display); font-size: 1.5rem; text-align: center; }

/* ---------- timer: runs from orange (out of time) to cyan (full) ---------- */
.timer { height: 10px; background: #070d24; border: 1px solid var(--line); overflow: hidden; }
.timer-bar { height: 100%; width: 100%; background: linear-gradient(90deg, var(--ember), var(--cyan)); box-shadow: 0 0 12px rgba(40,212,255,.7); clip-path: inset(0 0 0 0); }
.timer.urgent { animation: pulse .7s ease-in-out infinite; }
.timer-text { text-align: right; font-size: 1.1rem; margin: 4px 0 8px; color: var(--chrome); }
.status { margin-top: 16px; min-height: 26px; font-weight: 600; color: var(--muted); }
@keyframes pulse { 50% { box-shadow: 0 0 14px 2px rgba(255,122,26,.9); border-color: var(--ember); } }

/* ---------- reveal ---------- */
.headline { font-size: 1.6rem; font-style: italic; }
.headline.good { color: var(--good); text-shadow: 0 0 14px rgba(59,224,138,.6); }
.headline.bad { color: var(--bad); text-shadow: 0 0 14px rgba(255,90,110,.6); }

/* ---------- standings: you in cyan, the leader in orange ---------- */
.standings { width: 100%; border-collapse: collapse; margin: 8px 0; }
.standings td, .standings th { padding: 8px 8px; border-bottom: 1px solid var(--line); }
.standings th { text-align: right; font-size: .9rem; color: var(--muted); font-weight: 600; }
.standings th:nth-child(2) { text-align: left; }
.standings .rank { width: 2.4em; text-align: center; }
.standings .name { text-align: left; font-weight: 600; }
.standings .gain { color: var(--good); font-weight: 700; text-align: right; width: 3.5em; }
.standings .score { text-align: right; font-family: var(--display); font-size: 1.25rem; width: 3.5em; }
.standings.final td { text-align: right; }
.standings.final td.name, .standings.final td.rank { text-align: left; }
.standings.final td.rank { text-align: center; }
.standings tr.lead td { color: #ffb066; }
.standings tr.lead .score { text-shadow: 0 0 10px rgba(255,122,26,.8); }
.standings tr.lead td:first-child { box-shadow: inset 4px 0 0 var(--ember); }
.standings tr.me { background: rgba(40,212,255,.14); box-shadow: inset 0 0 14px rgba(40,212,255,.3); }
.standings tr.me .score { text-shadow: 0 0 10px rgba(40,212,255,.9); }
.standings tr.me:not(.lead) td { color: var(--chrome); }
.standings tr.gone, .players li.gone { opacity: .55; }
.you, .tag {
  font-size: .8rem; font-weight: 700; padding: 0 8px; vertical-align: middle; margin-left: 6px;
  clip-path: polygon(5px 0, 100% 0, calc(100% - 5px) 100%, 0 100%); display: inline-block;
}
.you { background: var(--cyan); color: #04111f; }
.tag { background: var(--ember); color: #1a0a00; }

/* ---------- lobby ---------- */
.code-label { font-size: 1rem; font-weight: 600; color: var(--muted); }
.code-big {
  font-size: 3.4rem; letter-spacing: .22em; margin: 4px 0 8px; line-height: 1.1; color: var(--chrome);
  text-shadow: 0 0 14px rgba(40,212,255,.8), 0 0 30px rgba(255,122,26,.4);
}
.cat-name { font-size: 1.25rem; font-weight: 700; margin-top: 2px; }
.players { list-style: none; padding: 0; margin: 18px 0 6px; display: flex; flex-wrap: wrap; gap: 8px; }
.players li { background: #0a1330; border: 2px solid var(--line); padding: 4px 14px; font-weight: 600; }
.players li:nth-child(odd) { border-color: rgba(40,212,255,.6); }
.players li:nth-child(even) { border-color: rgba(255,122,26,.6); }
.note { color: #ffcf70; min-height: 1.2em; margin: 10px 0 0; }

.winner {
  font-size: 1.6rem; font-style: italic; margin: 10px 0 14px; padding: 14px 12px; text-align: center; color: #fff;
  background: linear-gradient(90deg, rgba(40,212,255,.25), rgba(255,122,26,.25));
  border: 2px solid transparent; border-image: linear-gradient(90deg, var(--cyan), var(--ember)) 1;
  text-shadow: 0 0 14px rgba(255,255,255,.7); box-shadow: 0 0 24px rgba(40,212,255,.35), 0 0 24px rgba(255,122,26,.35);
}
.spinner {
  width: 44px; height: 44px; border-radius: 50%; margin: 18px 0;
  border: 4px solid rgba(255,122,26,.35); border-top-color: var(--cyan); animation: spin 1s linear infinite;
  box-shadow: 0 0 14px rgba(40,212,255,.5);
}
@keyframes spin { to { transform: rotate(360deg); } }
.form-error { color: var(--bad); min-height: 1.3em; margin: 10px 0 0; font-size: 1rem; font-weight: 700; }

/* ---------- lobby chat ---------- */
.chat h2 { margin-top: 18px; }
.chat-log {
  height: 180px; overflow-y: auto; background: #070d24; border: 2px solid var(--line);
  padding: 8px 12px; font-size: 1.02rem; line-height: 1.35;
}
.msg { margin: 4px 0; overflow-wrap: anywhere; }
.msg .who { font-weight: 700; color: var(--cyan); margin-right: 8px; }
.msg.mine .who { color: #ffb066; }
.msg.sys { color: var(--muted); font-style: italic; font-size: .95rem; }
.chat-form { display: flex; gap: 8px; margin-top: 8px; }
.chat-form input { flex: 1; min-width: 0; }
.chat-form button { text-align: center; padding: 8px 18px; font-weight: 700; }

/* ---------- sound button ---------- */
.sound-btn {
  position: fixed; top: 10px; right: 10px; z-index: 60; width: 46px; height: 46px; min-height: 0; padding: 0;
  display: grid; place-items: center; font-size: 1.3rem; text-align: center; border-radius: 50%;
  background: rgba(8,14,34,.85);
}

.sound-panel {
  position: fixed; top: 64px; right: 10px; z-index: 60; width: min(260px, calc(100vw - 20px)); padding: 14px 16px 16px;
  background: rgba(8,14,34,.95); border: 1px solid var(--cyan, #28d4ff); border-radius: 12px;
  box-shadow: 0 0 24px rgba(40,212,255,.25); display: grid; gap: 12px;
}
.sound-panel[hidden] { display: none; }
.sound-panel label { font-weight: 600; color: var(--muted); }
.sound-panel label b { color: var(--chrome); font-weight: 700; }
.sound-panel input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 34px; background: transparent; border: 0; border-radius: 0; box-shadow: none; margin: 0; padding: 0; touch-action: none; cursor: pointer;
  --fill: 100%;
}
.sound-panel input[type=range]::-webkit-slider-runnable-track {
  height: 8px; border-radius: 4px; background: linear-gradient(90deg, #28d4ff var(--fill), rgba(255,255,255,.18) var(--fill));
}
.sound-panel input[type=range]::-moz-range-track { height: 8px; border-radius: 4px; background: rgba(255,255,255,.18); }
.sound-panel input[type=range]::-moz-range-progress { height: 8px; border-radius: 4px; background: #28d4ff; }
.sound-panel input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 28px; height: 28px; margin-top: -10px; border-radius: 50%;
  background: #ff7a1a; border: 2px solid #fff; box-shadow: 0 0 12px rgba(255,122,26,.8);
}
.sound-panel input[type=range]::-moz-range-thumb { width: 24px; height: 24px; border-radius: 50%; background: #ff7a1a; border: 2px solid #fff; box-shadow: 0 0 12px rgba(255,122,26,.8); }
.sound-panel input[type=range]:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ---------- Solo, Top 10 ---------- */
.link { display: block; margin: 14px auto 0; min-height: 44px; padding: 8px 14px; background: none; border: 0; box-shadow: none;
  color: var(--muted); font-weight: 600; text-decoration: underline; text-underline-offset: 4px; cursor: pointer; }
.link:hover:not(:disabled) { color: var(--chrome); box-shadow: none; }
.lock-in { margin-top: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 4px 0 12px; }
.chip { min-height: 40px; padding: 6px 14px; border-radius: 20px; border: 1px solid var(--cyan); background: rgba(8,14,34,.7); color: var(--chrome); font-weight: 600; cursor: pointer; }
.chip.on { background: var(--cyan); color: #04121f; }
.top10 { margin: 14px 0 4px; }
.top10 h2 { margin: 0 0 8px; text-align: center; font-size: 1.15rem; color: var(--chrome); text-shadow: 0 0 12px rgba(255,122,26,.7); }
.top10-table { width: 100%; font-size: .92rem; }
.top10-table td, .top10-table th { padding: 6px 6px; }
.top10-table td.name { max-width: 10em; }
.top10-table .mode { display: block; font-size: .78rem; font-weight: 400; color: var(--muted); }
.top10-table td:last-child, .top10-table th:last-child { white-space: nowrap; }

/* ---------- Ready ---------- */
.score-line { margin: 14px 0 0; font-weight: 600; color: var(--muted); text-align: center; }
.score-line b { font-family: var(--display); font-weight: 400; font-size: 2rem; color: var(--chrome); margin-left: 8px; text-shadow: 0 0 12px rgba(40,212,255,.7); }
.ready.pending, .end-buttons.pending, .winner.pending, .top10-area.pending { visibility: hidden; }   /* keeps their space so nothing jumps */
.ready .status { margin-top: 12px; min-height: 26px; }
.ready .primary:disabled { opacity: 1; border-color: var(--good); box-shadow: 0 0 16px rgba(59,224,138,.6); color: var(--good); }

/* ---------- scoreboard reveal: one row at a time, last place first ---------- */
.board { cursor: pointer; }
.standings .row.pending { visibility: hidden; }
.standings .row.shown { animation: rowin .6s ease-out; }
.standings .row.shown.lead { animation: rowin .6s ease-out, champ 1.4s ease-out; }
@keyframes rowin { from { opacity: 0; transform: translateX(-28px); } to { opacity: 1; transform: none; } }
@keyframes champ { 0% { filter: brightness(2.2); } 100% { filter: none; } }
.winner.shown { animation: pop .8s cubic-bezier(.2,1.5,.4,1); }
@keyframes pop { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: none; } }
.end-buttons .center { margin: 8px 0 0; }
.fx-canvas { position: fixed; inset: 0; z-index: 40; pointer-events: none; }

/* ---------- reconnecting strip ---------- */
.conn-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50; padding: 10px 16px; text-align: center; font-weight: 700;
  background: #2a1500; color: #ffd9a8; border-bottom: 2px solid var(--ember); box-shadow: 0 0 18px rgba(255,122,26,.6);
}

/* ---------- splash ---------- */
.splash { width: 100%; max-width: 1100px; margin: 0 auto; }
.splash-art { position: relative; line-height: 0; }
.splash-art img {
  width: 100%; height: auto; display: block;
  -webkit-mask-image: linear-gradient(#000 90%, transparent);
  mask-image: linear-gradient(#000 90%, transparent);
}
.clash {   /* a slow glow where the two brains collide */
  position: absolute; left: 48.5%; top: 62%; width: 14%; aspect-ratio: 1; margin: -7% 0 0 -7%;
  border-radius: 50%; pointer-events: none; mix-blend-mode: screen;
  background: radial-gradient(circle, rgba(255,255,255,.9), rgba(255,190,110,.45) 35%, rgba(40,212,255,.25) 60%, transparent 72%);
  animation: clash 3.2s ease-in-out infinite;
}
@keyframes clash { 0%, 100% { opacity: .15; transform: scale(.85); } 50% { opacity: .6; transform: scale(1.1); } }
.splash .start {
  display: block; width: min(360px, calc(100% - 48px)); margin: 4px auto 28px; padding: 14px 24px;
  font-size: 1.5rem; min-height: 60px; background: linear-gradient(180deg, #16295c, #0a1535);
  box-shadow: 0 0 22px rgba(40,212,255,.6), inset 0 0 16px rgba(40,212,255,.2);
}
.fallback-title { padding: 15vh 16px 8vh; text-align: center; font-size: 2.6rem; line-height: 1; }
@media (max-width: 640px) {
  .panel { padding: 20px 16px; }
  .code-big { font-size: 2.6rem; }
  h1 { font-size: 1.6rem; }
  .question { font-size: 1.3rem; }
  .standings.final th, .standings.final td { padding: 8px 3px; font-size: .95rem; }
}

@media (prefers-reduced-motion: reduce) {
  .clash, .timer.urgent, .spinner, .standings .row.shown, .standings .row.shown.lead, .winner.shown { animation: none; }
  .clash { opacity: .35; }
  .spinner { border-top-color: var(--cyan); }
  button { transition: none; }
}

/* Challenge a friend */
.invite { margin: 12px 0; padding: 10px 12px; border: 1px solid var(--cyan); border-radius: 10px; background: rgba(8,14,34,.6); text-align: left; }
.invite summary { cursor: pointer; font-weight: 700; color: var(--chrome); min-height: 32px; display: flex; align-items: center; }
.invite-row { display: flex; gap: 8px; margin-top: 8px; }
.invite-row input { flex: 1; min-width: 0; }
.invite .secondary { width: 100%; }
