@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/shared/ibm-plex-sans-upright.woff2') format('woff2');
  font-weight: 100 700;
  font-style: normal;
  font-display: swap;
}

/* Brand values match BRAND in /shared/theme.js (app.js re-applies them at runtime). */
:root {
  --blue: #0D27F5;
  --blue-deep: #091AAB;
  --ink: #1A1B2D;
  --mint: #70FAD8;
  --lime: #DCF36C;
  --light: #F2F5FE;
  --mid: #D5E0FD;
  --white: #FFFFFF;
  --caution: #D89A2E;
  --danger: #C8364A;
  /* Right and wrong (BRAND.right, BRAND.wrong): true green and red, never mint. Tints for answer cards. */
  --right: #16A34A;
  --wrong: #DC2626;
  --right-tint: #DCFCE7;
  --wrong-tint: #FEE2E2;
  --muted: #5B5E78;
  --font: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--light);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
body { touch-action: manipulation; }
button, input, a { font: inherit; }
button { cursor: pointer; }

.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Tick and cross marks (/shared/icons.js): plain strokes in text, or white on a rounded-square tile. */
.mark { flex: none; display: inline-grid; place-items: center; width: 1em; height: 1em; }
.mark svg { display: block; width: 100%; height: 100%; overflow: visible; }
.mark-tile { width: 28px; height: 28px; border-radius: 7px; color: var(--white); }
.mark-tile svg { width: 66%; height: 66%; }
.mark-tile.mark-right { background: var(--right); }
.mark-tile.mark-wrong { background: var(--wrong); }
.small { font-size: 13px; }
.center { text-align: center; }

/* ---------- screens ---------- */

.screen { display: none; min-height: 100dvh; }
body[data-screen="boot"] [data-for="boot"],
body[data-screen="signup"] [data-for="signup"],
body[data-screen="home"] [data-for="home"],
body[data-screen="host"] [data-for="host"],
body[data-screen="join"] [data-for="join"],
body[data-screen="countdown"] [data-for="countdown"],
body[data-screen="game"] [data-for="game"],
body[data-screen="submitting"] [data-for="submitting"],
body[data-screen="results"] [data-for="results"],
body[data-screen="versus"] [data-for="versus"] { display: flex; }

.screen-center {
  flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: calc(24px + var(--safe-t)) 16px calc(24px + var(--safe-b)); gap: 10px;
}
.screen-page {
  flex-direction: column; gap: 14px;
  padding: calc(16px + var(--safe-t)) 16px calc(24px + var(--safe-b));
  max-width: 520px; margin: 0 auto;
}
.screen-blue { background: var(--blue); color: var(--white); }

.boot-mark { width: 52px; height: 58px; animation: pulse 1.4s ease-in-out infinite; }
.boot-title { font-weight: 700; font-size: 22px; margin: 6px 0 0; }
@keyframes pulse { 50% { transform: scale(0.92); opacity: 0.7; } }
.pulse { animation: fade 1.6s ease-in-out infinite; }
@keyframes fade { 50% { opacity: 0.45; } }

/* ---------- sign-up ---------- */

.brand-head { display: flex; align-items: center; justify-content: space-between; }
.logo { height: 28px; width: auto; display: block; }
.event-chip {
  background: var(--ink); color: var(--lime); font-weight: 600; font-size: 12px;
  padding: 4px 10px; border-radius: 999px; letter-spacing: 0.02em;
}
.title { font-size: 32px; line-height: 1.1; margin: 8px 0 0; letter-spacing: -0.01em; }
.lede { margin: 0; color: #3C3F5A; line-height: 1.45; }

form { display: flex; flex-direction: column; gap: 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 14px; min-width: 0; }
.field small { font-weight: 400; color: var(--muted); }
.field input {
  appearance: none; border: 2px solid var(--mid); background: var(--white); border-radius: 12px;
  padding: 12px; font-size: 16px; color: var(--ink); width: 100%; min-width: 0;
}
.field input:focus { outline: none; border-color: var(--blue); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.err { color: var(--danger); font-style: normal; font-size: 13px; font-weight: 500; }
.err:empty { display: none; }

.sectors-field { border: 0; padding: 0; margin: 0; }
.sectors-field legend { padding: 0; margin-bottom: 6px; }
.sector-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.sector-chip {
  border: 2px solid var(--mid); background: var(--white); color: var(--ink); border-radius: 999px;
  padding: 8px 12px; font-size: 14px; font-weight: 600; min-height: 44px;
}
.sector-chip[aria-checked="true"] { background: var(--blue); border-color: var(--blue); color: var(--white); }

.notice {
  background: var(--white); border-radius: 12px; padding: 10px 12px; font-size: 13px; line-height: 1.45;
  color: #3C3F5A; border: 1px solid var(--mid);
}
.notice p { margin: 0; }
.notice a { color: var(--blue); font-weight: 600; }

.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 1.35; padding: 6px 0; }
.check input {
  appearance: none; flex: 0 0 26px; width: 26px; height: 26px; margin: 0; border-radius: 7px;
  border: 2px solid var(--blue); background: var(--white); display: grid; place-items: center;
}
.check input:checked { background: var(--blue); }
.check input:checked::after {
  content: ''; width: 6px; height: 12px; border: solid var(--white); border-width: 0 3px 3px 0;
  transform: translateY(-1px) rotate(45deg);
}
.check-quiet { font-size: 13px; color: var(--muted); }
.check-quiet input { border-color: #8A8DA6; }
.form-error { color: var(--danger); margin: 0; font-weight: 600; font-size: 14px; }
.form-error:empty { display: none; }

/* Company logo preview at sign-up, and the small logo tile used next to names. */
.company-pick {
  background: var(--white); border: 2px solid var(--blue); border-radius: 14px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.company-head { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 15px; flex-wrap: wrap; }
.company-pick .check { padding: 2px 0; }
.company-note { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.company-pick.is-off .co-tile, .company-pick.is-off #company-name { opacity: 0.35; filter: grayscale(1); }
.co-tile {
  display: inline-flex; align-items: center; justify-content: center; flex: none; height: 30px; min-width: 30px; max-width: 110px;
  padding: 4px 8px; border-radius: 8px; background: var(--white); border: 1px solid var(--mid); vertical-align: middle; overflow: hidden;
}
.co-tile img { display: block; height: 100%; width: auto; max-width: 94px; min-width: 0; object-fit: contain; }
.co-tile-sm { height: 24px; padding: 3px 6px; margin-right: 8px; }

/* ---------- buttons ---------- */

.btn {
  appearance: none; border: 0; border-radius: 14px; padding: 15px 18px; font-weight: 700; font-size: 17px;
  text-align: center; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  min-height: 56px; user-select: none; -webkit-user-select: none; transition: transform 0.08s ease;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.55; }
.btn-block { width: 100%; }
.btn-xl { min-height: 64px; font-size: 19px; }
.btn-primary { background: var(--blue); color: var(--white); }
.btn-secondary { background: var(--white); color: var(--blue); border: 2px solid var(--blue); }
.btn-ghost { background: transparent; color: var(--ink); text-decoration: underline; min-height: 48px; }
.link { background: none; border: 0; color: var(--blue); font-weight: 600; padding: 10px; min-height: 44px; }
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.stack.narrow { width: min(100%, 360px); }

/* ---------- start ---------- */

.home-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.home-head > div { min-width: 0; }
.home-head .link { flex: none; }
.me-name { margin: 0; font-weight: 700; font-size: 20px; display: flex; align-items: center; min-width: 0; }
#me-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-head .small { margin: 0; }
.hero-tile {
  background: linear-gradient(155deg, var(--blue), var(--blue-deep)); color: var(--white);
  border-radius: 22px; padding: 20px; position: relative; overflow: hidden;
}
.hero-tile::after {
  content: ''; position: absolute; right: 14px; top: -10%; height: 120%; width: 10px;
  background: var(--lime); transform: skewX(-8deg); box-shadow: 12px 0 0 -2px var(--mint);
}
.logo-light { filter: brightness(0) invert(1); height: 24px; }
.hero-title { font-size: 34px; margin: 14px 0 0; letter-spacing: -0.015em; }
.best { margin: 6px 0 0; color: var(--mint); font-weight: 600; }
.best b { color: var(--white); font-variant-numeric: tabular-nums; }
/* Mode picker: two big cards, Easy and Hard. */
.levels { display: flex; flex-direction: column; gap: 6px; }
.levels-label { margin: 0; font-weight: 700; font-size: 15px; }
.levels-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.level-card {
  appearance: none; text-align: left; border: 3px solid var(--mid); background: var(--white); color: var(--ink);
  border-radius: 18px; padding: 14px 12px; display: flex; flex-direction: column; gap: 6px; min-height: 150px;
  transition: transform 0.08s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.level-card:active { transform: scale(0.98); }
.level-name { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.level-body { font-size: 13.5px; line-height: 1.35; color: #3C3F5A; }
.level-best { margin-top: auto; font-size: 13px; font-weight: 700; color: var(--blue); font-variant-numeric: tabular-nums; }
.level-card[aria-checked="true"] { border-color: var(--blue); box-shadow: 0 0 0 3px var(--mint); }
.level-hard { background: var(--ink); color: var(--white); border-color: #3C3F5A; }
.level-hard .level-body { color: var(--mid); }
.level-hard .level-best { color: var(--mint); }
.level-hard[aria-checked="true"] { border-color: var(--mint); box-shadow: 0 0 0 3px var(--lime); }
.level-chip {
  display: inline-block; background: var(--ink); color: var(--lime); font-weight: 700; font-size: 13px;
  padding: 4px 12px; border-radius: 999px; letter-spacing: 0.04em; text-transform: uppercase;
}
.level-chip:empty { display: none; }
.how { background: var(--white); border: 1px solid var(--mid); border-radius: 16px; padding: 14px 16px; }
.how p { margin: 0; line-height: 1.5; color: #3C3F5A; }
.h2 { font-size: 20px; margin: 0 0 6px; }
.banner {
  margin: 0; background: var(--white); border-left: 4px solid var(--caution); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; line-height: 1.4;
}
.banner:empty { display: none; }

/* ---------- challenge ---------- */

.code {
  font-size: clamp(64px, 24vw, 104px); font-weight: 700; letter-spacing: 0.12em; text-align: center;
  margin: 8px 0; color: var(--blue); font-variant-numeric: tabular-nums;
}
.code-input {
  appearance: none; width: 100%; text-align: center; font-size: 48px; font-weight: 700; letter-spacing: 0.3em;
  text-transform: uppercase; padding: 14px 0 14px 0.3em; border-radius: 16px; border: 3px solid var(--mid);
  background: var(--white); color: var(--ink);
}
.code-input:focus { outline: none; border-color: var(--blue); }

/* ---------- countdown ---------- */

.cd-label { font-size: 20px; font-weight: 600; margin: 0; color: var(--mint); }
.cd-big { font-size: clamp(110px, 40vw, 180px); font-weight: 700; line-height: 1; margin: 0; font-variant-numeric: tabular-nums; }
.cd-vs { font-size: 18px; font-weight: 600; margin: 0; }
.cd-mode { margin: 0; font-size: 14px; font-weight: 700; color: var(--lime); text-transform: uppercase; letter-spacing: 0.1em; }
.cd-mode:empty { display: none; }

/* ---------- game ---------- */

.screen-game {
  flex-direction: column; gap: 12px; max-width: 560px; margin: 0 auto;
  padding: calc(10px + var(--safe-t)) 14px calc(16px + var(--safe-b));
  user-select: none; -webkit-user-select: none; position: relative;
}
.game-bar { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.g-round { color: var(--muted); font-size: 15px; }
.g-round b { color: var(--ink); font-variant-numeric: tabular-nums; }
.g-clock {
  margin-left: auto; font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}
.g-pen {
  background: var(--wrong); color: var(--white); border-radius: 999px; padding: 3px 9px; font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.g-streak {
  background: var(--lime); color: var(--ink); border-radius: 999px; padding: 3px 9px; font-size: 13px; font-weight: 700;
  white-space: nowrap;
}
.g-streak.pop { animation: pop 0.35s ease; }
@keyframes pop { 40% { transform: scale(1.18); } }
.progress { height: 6px; border-radius: 3px; background: var(--mid); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--blue); transition: width 0.25s ease; }

.statement {
  background: var(--ink); color: var(--white); border-radius: 16px; padding: 12px 14px 16px;
  box-shadow: 0 8px 20px rgba(26, 27, 45, 0.18);
}
.statement-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.statement-label { font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--mint); }
.statement-date { font-size: 13px; font-weight: 600; color: #B9BCD3; font-variant-numeric: tabular-nums; }
.statement-line { display: flex; align-items: flex-start; gap: 12px; }
.raw {
  margin: 0; flex: 1; min-width: 0; font-family: var(--mono); font-size: clamp(16px, 4.6vw, 20px); line-height: 1.35;
  letter-spacing: 0.01em; word-break: break-word; min-height: 2.7em;
}
/* Statement-style signed amount: debits in white, credits in mint so a refund reads at a glance. */
.amount {
  margin: 0; flex: none; font-family: var(--mono); font-size: clamp(17px, 4.9vw, 21px); line-height: 1.35;
  font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.amount.is-debit { color: var(--white); }
.amount.is-credit { color: var(--mint); }
.prompt { margin: 2px 0 0; font-weight: 700; font-size: 16px; }

/* Hard mode history: replaces the options while open, so peeking is a real trade-off. */
.history-btn {
  appearance: none; border: 2px dashed var(--blue); background: var(--white); color: var(--blue); font-weight: 700;
  font-size: 16px; border-radius: 14px; min-height: 48px; padding: 10px 14px;
}
.history-btn:active { transform: scale(0.985); }
.history {
  background: var(--white); border: 2px solid var(--blue); border-radius: 16px; padding: 10px 12px 12px;
  animation: slide 0.2s ease both;
}
@keyframes slide { from { opacity: 0; transform: translateY(12px); } }
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.history-title { font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--blue); }
.history-close {
  appearance: none; border: 0; background: var(--blue); color: var(--white); font-weight: 700; font-size: 14px;
  border-radius: 999px; padding: 8px 14px; min-height: 40px;
}
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.history-list li {
  display: grid; grid-template-columns: 74px 1fr auto; gap: 8px; align-items: baseline; padding: 7px 0;
  border-top: 1px solid var(--mid); font-variant-numeric: tabular-nums;
}
.history-list li:first-child { border-top: 0; }
.h-date { font-size: 12.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.h-raw { font-family: var(--mono); font-size: 12.5px; line-height: 1.3; word-break: break-word; min-width: 0; }
.h-amt { font-family: var(--mono); font-size: 13px; font-weight: 700; white-space: nowrap; }
.h-amt.is-credit { color: #12896C; }
body.history-open #g-prompt, body.history-open #g-options { display: none; }

.options { display: flex; flex-direction: column; gap: 10px; }
.opt {
  appearance: none; text-align: left; border: 2px solid var(--mid); background: var(--white); color: var(--ink);
  border-radius: 14px; padding: 10px 12px; min-height: 68px; display: flex; align-items: center;
  gap: 12px; position: relative; transition: transform 0.06s ease, border-color 0.1s ease;
}
.opt-body { flex: 1 1 auto; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.opt-logo {
  flex: none; width: 44px; height: 44px; border-radius: 11px; background: var(--white);
  border: 1px solid var(--mid); display: grid; place-items: center; overflow: hidden;
}
.opt-logo img { width: 100%; height: 100%; padding: 3px; object-fit: contain; display: block; }
.opt-mono { border: 0; color: var(--ink); font-weight: 700; font-size: 16px; letter-spacing: 0.02em; }
.opt:active { transform: scale(0.985); }
.opt-merchant { font-weight: 700; font-size: 17px; line-height: 1.2; overflow-wrap: anywhere; }
/* Pills wrap onto new lines inside the option, and a single long pill wraps its own text. */
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; min-width: 0; }
.tag { font-size: 13px; font-weight: 600; line-height: 1.15; padding: 4px 8px; border-radius: 999px; max-width: 100%; overflow-wrap: anywhere; }
.tag-cat { background: #E3E8FF; color: var(--blue-deep); }
.tag-debit { background: #FFE9D6; color: #8A4B12; }
.tag-credit { background: #D2F9EE; color: #0B6B52; }
.tag-place { background: #ECEEF5; color: #3C3F5A; }
.opt.is-correct { background: var(--right-tint); border-color: var(--right); }
.opt.is-wrong { background: var(--wrong-tint); border-color: var(--wrong); }
.opt-mark { align-self: center; }
.opt.is-dim { opacity: 0.45; }
.opt.is-reveal { animation: reveal 0.5s ease 2; }
@keyframes reveal { 50% { transform: scale(1.03); box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.4); } }
@media (prefers-reduced-motion: reduce) { .opt.is-reveal { animation: none; } }
.opt-tag {
  position: absolute; right: 10px; top: -10px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; background: var(--ink); color: var(--mint); padding: 2px 8px; border-radius: 999px;
}
.opts-enter .opt { animation: rise 0.22s ease both; }
.opts-enter .opt:nth-child(2) { animation-delay: 0.03s; }
.opts-enter .opt:nth-child(3) { animation-delay: 0.06s; }
.opts-enter .opt:nth-child(4) { animation-delay: 0.09s; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.g-flash {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(0.9); pointer-events: none;
  font-size: 22px; font-weight: 700; padding: 10px 18px; border-radius: 14px; opacity: 0;
  transition: opacity 0.12s ease, transform 0.12s ease; white-space: nowrap; max-width: calc(100% - 28px);
  display: flex; align-items: center; gap: 10px; color: var(--white);
}
.g-flash.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.g-flash.good { background: var(--right); }
.g-flash.bad { background: var(--wrong); }

/* ---------- results ---------- */

.res-label { margin: 18px 0 0; text-align: center; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; font-size: 13px; }
.res-time {
  margin: 0; text-align: center; font-size: clamp(64px, 22vw, 96px); font-weight: 700; line-height: 1;
  letter-spacing: -0.03em; color: var(--blue); font-variant-numeric: tabular-nums;
}
.res-sub { margin: 0; text-align: center; font-weight: 600; }
.res-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.res-grid > div {
  background: var(--white); border: 1px solid var(--mid); border-radius: 14px; padding: 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.res-k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.res-v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 8px; min-width: 0; }
.res-mark { width: 24px; height: 24px; border-radius: 6px; }

.vs-head { text-align: center; font-size: 34px; font-weight: 700; margin: 24px 0 4px; color: var(--blue); }
.vs-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: stretch; }
.vs-side {
  background: var(--white); border: 2px solid var(--mid); border-radius: 16px; padding: 14px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; min-width: 0;
}
.vs-side.winner { border-color: var(--blue); box-shadow: 0 0 0 3px var(--mint); }
.vs-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.vs-time { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.vs-sub { font-size: 13px; color: var(--muted); }
.vs-mid { align-self: center; font-weight: 700; color: var(--muted); }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translate(-50%, 160%);
  background: var(--ink); color: var(--white); font-weight: 600; font-size: 14px; padding: 12px 16px; border-radius: 12px;
  max-width: calc(100% - 32px); text-align: center; z-index: 10;
  opacity: 0; visibility: hidden; transition: transform 0.25s ease, opacity 0.25s ease, visibility 0s 0.25s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; transition: transform 0.25s ease, opacity 0.25s ease; }

@media (prefers-reduced-motion: reduce) {
  .boot-mark, .pulse, .opts-enter .opt { animation: none; }
}
