/* Brain Duel: a bright, quick arena on deep indigo. */
:root {
  --bg: #0f1630;
  --card: #18224a;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f2f5ff;
  --soft: #aab4dc;
  --teal: #2ee6c5;
  --gold: #ffd166;
  --red: #ff6b81;
  --me: #2ee6c5;
  --them: #ff9f5a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; background: radial-gradient(120% 60% at 50% 0%, #1f2d66 0%, var(--bg) 62%); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
.duel { max-width: 560px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 16px 48px; }

/* home */
.d-hero { padding: 4px 0 14px; text-align: center; }
.d-herorow { display: flex; justify-content: space-between; align-items: center; }
.d-back { color: var(--soft); text-decoration: none; font-weight: 600; min-height: 40px; display: inline-flex; align-items: center; border: 0; background: none; padding: 0; cursor: pointer; }
.d-chip { min-height: 34px; padding: 0 12px; display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; background: rgba(255, 255, 255, 0.06); font-weight: 700; }
.d-hero h1 { margin: 10px 0 4px; font-size: clamp(28px, 8vw, 40px); letter-spacing: 0.01em; }
.d-hero p { margin: 0; color: var(--soft); }
.d-card { margin: 0 0 12px; padding: 16px; border: 1px solid var(--line); border-radius: 20px; background: var(--card); }
.d-card h2 { margin: 2px 0 6px; font-size: 20px; }
.d-card p { margin: 0 0 12px; color: var(--soft); line-height: 1.45; }
.d-today { background: linear-gradient(135deg, #1d2c6b, #18224a 70%); border-color: rgba(46, 230, 197, 0.35); }
.d-challenge { background: linear-gradient(135deg, #3a2350, #18224a 75%); border-color: rgba(255, 159, 90, 0.45); }
.d-step { margin: 0; color: var(--teal); font-size: 12px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.d-btn { display: block; width: 100%; min-height: 52px; padding: 0 16px; border: 0; border-radius: 14px; background: var(--teal); color: #04221d; font-size: 17px; font-weight: 800; cursor: pointer; }
.d-btn:active { transform: scale(0.98); }
.d-btn.ghost { background: rgba(255, 255, 255, 0.07); color: var(--text); border: 1px solid var(--line); }
.d-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 6px; text-align: center; }
.d-stats div { padding: 12px 6px; border-radius: 16px; background: rgba(255, 255, 255, 0.04); }
.d-stats b { display: block; font-size: 20px; }
.d-stats small { color: var(--soft); font-size: 12px; }

/* round intro */
.d-intro { padding: 32px 4px; text-align: center; }
.d-intro h2 { margin: 4px 0 8px; font-size: 26px; }
.d-intro p { color: var(--soft); line-height: 1.5; margin: 0 0 18px; }
.d-big { font-size: 64px; margin: 14px 0 0 !important; }
.d-vs { color: var(--them) !important; font-weight: 700; }

/* playing */
.d-play { padding-top: 6px; }
.d-top { display: flex; justify-content: space-between; align-items: center; min-height: 40px; }
.d-tag { font-weight: 800; color: var(--soft); }
.d-top b { font-size: 22px; font-variant-numeric: tabular-nums; }
.d-bar { position: relative; height: 10px; margin: 6px 0 10px; border-radius: 99px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.d-bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--teal), var(--gold)); transition: width 0.2s linear; }
.d-bar i.low { background: linear-gradient(90deg, var(--red), var(--gold)); }
.d-time { margin-left: auto; margin-right: 12px; color: var(--soft); font-weight: 800; font-variant-numeric: tabular-nums; }
.d-ghost { margin: 0 0 6px; padding: 8px 12px; border-radius: 12px; background: rgba(255, 159, 90, 0.12); color: var(--them); font-size: 14px; }
.d-ghost small { color: var(--me); }
.d-q { margin: 18px 0 6px; text-align: center; font-size: clamp(38px, 12vw, 56px); font-weight: 800; font-variant-numeric: tabular-nums; }
.d-in { margin: 0 auto 16px; max-width: 240px; min-height: 56px; padding: 6px; border-bottom: 3px solid var(--line); text-align: center; font-size: 36px; font-weight: 800; font-variant-numeric: tabular-nums; }
.d-in.ok { color: var(--teal); border-color: var(--teal); }
.d-in.bad { color: var(--red); border-color: var(--red); animation: d-shake 0.25s; }
@keyframes d-shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.d-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.d-pad button { min-height: 62px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255, 255, 255, 0.07); font-size: 26px; font-weight: 700; cursor: pointer; touch-action: manipulation; user-select: none; }
.d-pad button:active { background: rgba(46, 230, 197, 0.25); }
.d-pad .d-skip { font-size: 16px; color: var(--soft); }
.d-prompt { margin: 18px 0 8px; text-align: center; color: var(--soft); font-size: 17px; line-height: 1.4; }
.d-seq { margin: 6px 0 18px; text-align: center; font-size: clamp(26px, 8vw, 36px); font-weight: 800; font-variant-numeric: tabular-nums; }
.d-seq b { color: var(--gold); }
.d-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.d-opts button { min-height: 68px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255, 255, 255, 0.07); font-size: 26px; font-weight: 800; cursor: pointer; touch-action: manipulation; }
.d-opts button.ok, .d-grid button.ok { background: var(--teal); color: #04221d; border-color: var(--teal); }
.d-opts button.bad, .d-grid button.bad { background: var(--red); color: #2a0610; border-color: var(--red); }
.d-grid { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 8px; max-width: 420px; margin: 14px auto 0; }
.d-grid button { aspect-ratio: 1; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, 0.07); cursor: pointer; touch-action: manipulation; transition: background 0.15s; }
.d-grid button:disabled { cursor: default; }
.d-grid button.lit { background: var(--gold); border-color: var(--gold); box-shadow: 0 0 18px rgba(255, 209, 102, 0.5); }
.d-grid button.miss { background: rgba(255, 209, 102, 0.35); }

/* results */
.d-res { padding-top: 14px; text-align: center; }
.d-total { margin: 6px 0 2px; font-size: 64px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.d-total small { display: block; margin-top: 4px; font-size: 14px; font-weight: 600; color: var(--soft); }
.d-streak { margin: 10px 0 0; font-weight: 800; color: var(--gold); }
.d-break { list-style: none; margin: 18px 0; padding: 0; text-align: left; }
.d-break li { display: grid; grid-template-columns: 1fr auto; gap: 0 10px; padding: 12px 14px; margin-bottom: 8px; border-radius: 14px; background: var(--card); }
.d-break b { font-size: 18px; font-variant-numeric: tabular-nums; }
.d-break small { grid-column: 1 / -1; color: var(--soft); font-size: 13px; }
.d-note { color: var(--soft); font-size: 13px; margin: 8px 0 14px; line-height: 1.4; }
.d-res .d-btn + .d-btn, .d-res .d-note + .d-btn { margin-top: 8px; }

/* head to head */
.d-cmp { margin: 0 0 16px; padding: 14px; border-radius: 16px; background: rgba(255, 255, 255, 0.04); text-align: left; }
.d-verdict { margin: 0 0 10px; font-size: 20px; font-weight: 800; text-align: center; color: var(--text) !important; }
.d-row { display: grid; grid-template-columns: 112px 1fr; gap: 8px; align-items: center; margin: 8px 0; font-size: 13px; color: var(--soft); }
.d-bars { display: grid; gap: 4px; }
.d-bars i { display: block; min-width: 34px; height: 20px; border-radius: 6px; font-style: normal; position: relative; }
.d-bars i b { position: absolute; right: 6px; top: 1px; font-size: 12px; color: #0b1028; }
.d-bars .me, .d-legend .me { background: var(--me); }
.d-bars .them, .d-legend .them { background: var(--them); }
.d-legend { margin: 10px 0 0 !important; font-size: 13px; color: var(--soft); text-align: center; }
.d-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin: 0 4px 0 10px; }

/* levels, chips and the home cards */
.d-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.d-chips button { min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255, 255, 255, 0.05); font-weight: 700; cursor: pointer; }
.d-chips button[aria-pressed="true"] { border-color: var(--teal); background: rgba(46, 230, 197, 0.18); color: #c9fff4; }
.d-chips button:disabled { opacity: 0.55; cursor: default; }
.d-levels { display: grid; grid-template-columns: repeat(4, 1fr); }
.d-levels button { padding: 0 6px; }
.d-hint { margin: 6px 0 0; color: var(--soft); font-size: 13px; line-height: 1.4; text-align: center; }
.d-card .d-hint { text-align: left; margin: 0; }
.d-row2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 8px; }
.d-live { background: linear-gradient(135deg, #12345a, #18224a 70%); border-color: rgba(91, 124, 250, 0.45); }
.d-join { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 10px; }
.d-join input, .d-form input { min-height: 50px; padding: 0 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(0, 0, 0, 0.25); color: var(--text); font: inherit; font-size: 18px; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; }
.d-form input { letter-spacing: normal; text-transform: none; width: 100%; margin-bottom: 10px; }
.d-join input { min-width: 0; width: 100%; }
.d-join .d-btn { width: auto; padding: 0 22px; }
.d-row2 .d-btn { font-size: 15px; padding: 0 10px; }
.d-face-card { background: linear-gradient(135deg, #3a2a1a, #18224a 70%); border-color: rgba(255, 159, 90, 0.4); }
.d-practice { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 8px; }
.d-practice button { display: grid; gap: 2px; justify-items: center; padding: 12px 6px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255, 255, 255, 0.05); cursor: pointer; }
.d-practice span { font-size: 26px; }
.d-practice b { font-size: 13px; }
.d-practice small { font-size: 11px; color: var(--soft); }
.d-lvl { display: inline-block; padding: 4px 12px; border-radius: 999px; background: rgba(46, 230, 197, 0.15); color: #c9fff4 !important; font-weight: 800; }
.linklike { border: 0; background: none; color: var(--teal); font-weight: 700; text-decoration: underline; cursor: pointer; padding: 8px; }

/* rounds */
.d-tag small { color: var(--teal); font-weight: 700; }
.d-tier { margin: 8px 0 0; text-align: center; font-size: 12px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--soft); }
.d-tier[data-t="4"], .d-tier[data-t="5"] { color: var(--gold); }
.d-tier[data-t="6"], .d-tier[data-t="7"] { color: var(--red); }
.d-q { overflow-wrap: anywhere; }
.d-snapq { font-size: clamp(30px, 10vw, 46px); padding: 18px 8px; border-radius: 18px; transition: background 0.15s; }
.d-snapq.ok { background: rgba(46, 230, 197, 0.15); }
.d-snapq.bad { background: rgba(255, 107, 129, 0.18); }
.d-streak-live { margin: 6px 0 0; text-align: center; color: var(--gold); font-weight: 800; min-height: 22px; }
.d-snap { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.d-snap button { display: grid; justify-items: center; min-height: 120px; border: 0; border-radius: 22px; font-size: 48px; font-weight: 900; cursor: pointer; touch-action: manipulation; user-select: none; }
.d-snap button small { font-size: 15px; font-weight: 800; }
.d-snap .no { background: rgba(255, 107, 129, 0.2); color: #ffc2cc; }
.d-snap .yes { background: rgba(46, 230, 197, 0.2); color: #c9fff4; }
.d-snap button:active { transform: scale(0.97); }
.d-count { margin: 6px 0 0; text-align: center; color: var(--soft); font-size: 13px; font-weight: 700; }
.d-rows { margin: 10px auto 4px; border-collapse: separate; border-spacing: 8px; }
.d-rows td { min-width: 58px; padding: 10px; border-radius: 12px; background: rgba(255, 255, 255, 0.07); text-align: center; font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.d-rows td.q { color: var(--gold); }
.d-opts button { font-size: clamp(20px, 6vw, 26px); }
.d-lives { margin-left: 6px; }
.d-flash { margin: 22px 0 8px; min-height: 96px; text-align: center; font-size: 84px; font-weight: 900; line-height: 96px; font-variant-numeric: tabular-nums; }
.d-flash.ready, .d-flash.ask { font-size: 32px; color: var(--soft); }
.d-flash.ok { color: var(--teal); }
.d-flash.bad { color: var(--red); }
.d-pad .d-enter { background: var(--teal); color: #04221d; }

/* live rooms */
.d-race { list-style: none; margin: 0 0 6px; padding: 8px 10px; border-radius: 14px; background: rgba(255, 255, 255, 0.04); display: grid; gap: 4px; }
.d-race li { display: grid; grid-template-columns: 74px 1fr 56px; gap: 8px; align-items: center; font-size: 13px; }
.d-race li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--soft); }
.d-race li i { height: 10px; border-radius: 99px; background: var(--them); transition: width 0.6s ease; }
.d-race li.me i { background: var(--me); }
.d-race li.me span { color: var(--text); font-weight: 800; }
.d-race li.away { opacity: 0.5; }
.d-race li b { text-align: right; font-variant-numeric: tabular-nums; }
.d-lobby { padding-top: 4px; }
.d-code { margin: 4px 0 12px; text-align: center; font-size: 52px; font-weight: 900; letter-spacing: 0.18em; color: var(--gold); }
.d-share2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 8px; margin-bottom: 14px; }
.d-share2 a { display: flex; align-items: center; justify-content: center; text-decoration: none; }
.d-players { list-style: none; margin: 8px 0 14px; padding: 0; display: grid; gap: 6px; }
.d-players li { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-radius: 14px; background: var(--card); }
.d-players li.me { border: 1px solid rgba(46, 230, 197, 0.5); }
.d-players li.away { opacity: 0.55; }
.d-players small { color: var(--soft); }
.d-wait { text-align: center; color: var(--soft); padding: 14px; border-radius: 14px; background: rgba(255, 255, 255, 0.04); }
.d-count-big { margin: 30px 0 !important; font-size: 120px; font-weight: 900; color: var(--gold) !important; line-height: 1; }
.d-count-mid { margin: 14px 0 0 !important; font-size: 40px; font-weight: 900; color: var(--gold) !important; }
.d-winner { margin: 6px 0 12px; font-size: 28px; }
.d-standings { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 6px; text-align: left; }
.d-standings li { display: grid; grid-template-columns: 28px 1fr auto; gap: 2px 10px; align-items: center; padding: 12px 14px; border-radius: 14px; background: var(--card); }
.d-standings li:first-child { background: linear-gradient(135deg, #4a3a10, #18224a); border: 1px solid rgba(255, 209, 102, 0.5); }
.d-standings li.me b { color: var(--teal); }
.d-standings span { font-weight: 900; color: var(--soft); }
.d-standings em { font-style: normal; font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }
.d-standings small { grid-column: 2 / -1; color: var(--soft); font-size: 12px; }
.d-rating { color: var(--gold); font-weight: 700; }

/* leaderboard */
.d-board { margin: 0 0 16px; padding: 14px; border-radius: 16px; background: rgba(255, 255, 255, 0.04); text-align: left; }
.d-board-h { margin: 0 0 8px; font-weight: 700; }
.d-lb { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.d-lb li { display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.04); }
.d-lb li.me { background: rgba(46, 230, 197, 0.15); }
.d-lb span { color: var(--soft); font-weight: 800; }
.d-lb em { font-style: normal; font-weight: 800; font-variant-numeric: tabular-nums; }
.d-board .d-hint { text-align: left; }

/* face to face: the top half is turned round for the player opposite */
body.d-face { overflow: hidden; }
body.d-face .duel { max-width: none; padding: 0; }
.f-wrap { position: fixed; inset: 0; display: grid; grid-template-rows: 1fr auto 1fr; background: var(--bg); }
.f-half { display: flex; flex-direction: column; justify-content: center; gap: 10px; padding: 14px 16px; transition: background 0.2s; }
.f-p1 { transform: rotate(180deg); background: linear-gradient(180deg, rgba(255, 159, 90, 0.16), transparent); }
.f-p0 { background: linear-gradient(0deg, rgba(46, 230, 197, 0.16), transparent); }
.f-head { display: flex; align-items: center; gap: 10px; }
.f-score { font-size: 32px; font-weight: 900; }
.f-p0 .f-score { color: var(--me); }
.f-p1 .f-score { color: var(--them); }
.f-name { font-weight: 800; color: var(--soft); }
.f-dots { margin-left: auto; letter-spacing: 2px; font-size: 11px; color: var(--soft); }
.f-q { margin: 0; text-align: center; font-size: clamp(30px, 9vw, 48px); font-weight: 900; font-variant-numeric: tabular-nums; }
.f-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.f-opts button { min-height: 64px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255, 255, 255, 0.08); font-size: 26px; font-weight: 800; cursor: pointer; touch-action: manipulation; user-select: none; }
.f-opts button.ok { background: var(--teal); color: #04221d; }
.f-opts button.bad { background: var(--red); color: #2a0610; }
.f-fb { margin: 0; text-align: center; min-height: 22px; color: var(--soft); font-weight: 700; }
.f-half.locked { opacity: 0.55; }
.f-half.won { background: rgba(46, 230, 197, 0.22); }
.f-half.lost { background: rgba(255, 107, 129, 0.12); }
.f-mid { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 8px; border-block: 1px solid var(--line); background: #0b1126; font-size: 13px; font-weight: 700; color: var(--soft); }
.f-x { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 50%; background: rgba(255, 255, 255, 0.06); cursor: pointer; }

.d-toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 40px); max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px; background: #263266; color: var(--text); font-weight: 700; opacity: 0; transition: 0.25s; pointer-events: none; z-index: 20; }
.d-toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .d-race li i, .d-snapq, .f-half { transition: none; }
  .d-in.bad { animation: none; }
  .d-bar i, .d-grid button { transition: none; }
}
