:root {
  --paper: #FBFAF7;
  --surface: #FFFFFF;
  --surface-2: #F3F2EE;
  --ink: #16171B;
  --ink-2: #40424A;
  --muted: #7A7C85;
  --hairline: #E9E7DF;
  --hairline-2: #DFDCD2;
  --signal: #3D34F2;
  --signal-ink: #2C24D0;
  --signal-soft: #ECEAFF;
  --coral: #FF5A45;
  --gold: #F5A524;
  --good: #12A150;
  --bad: #E5484D;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(20,20,40,.06), 0 1px 3px rgba(20,20,40,.05);
  --shadow-lg: 0 24px 60px rgba(20,20,40,.12), 0 2px 8px rgba(20,20,40,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .brand-name, .serif { font-family: 'Fraunces', Georgia, serif; letter-spacing: -0.02em; }
.mono, .display-num, .val, .rank, .result .value, .number-input,
.stat-row b, .hero .stats b, .score-item .v { font-family: 'JetBrains Mono', ui-monospace, monospace; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 26px;
  padding: 15px 30px;
  border-bottom: 1px solid var(--hairline);
  background: rgba(251,250,247,.85);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 11px; font-weight: 600; font-size: 20px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--ink); color: #fff; box-shadow: 0 4px 12px rgba(20,20,40,.18);
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-name { font-weight: 600; }
.brand-name span { color: var(--signal); }
.nav { display: flex; gap: 2px; margin-left: 10px; }
.nav a {
  padding: 8px 14px; border-radius: 9px; color: var(--muted);
  font-weight: 500; font-size: 14.5px; transition: .15s;
}
.nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav a.active { color: var(--ink); background: var(--surface-2); }
.auth-area { margin-left: auto; display: flex; align-items: center; gap: 8px; }

main { flex: 1; width: min(1100px, 92vw); margin: 0 auto; padding: 40px 0 70px; }

/* ---- Buttons ---- */
.btn {
  border: 1px solid var(--hairline-2); background: var(--surface);
  color: var(--ink); padding: 10px 18px; border-radius: var(--radius-sm);
  font-weight: 550; font-size: 14.5px; transition: .15s; display: inline-flex;
  align-items: center; gap: 8px; box-shadow: 0 1px 2px rgba(20,20,40,.04);
}
.btn:hover { background: var(--surface-2); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn.primary {
  background: var(--signal); border-color: transparent; color: #fff;
  box-shadow: 0 6px 18px rgba(61,52,242,.28);
}
.btn.primary:hover { background: var(--signal-ink); }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); box-shadow: none; }
.btn.small { padding: 7px 13px; font-size: 13px; border-radius: 10px; }
.btn.danger { color: var(--bad); border-color: rgba(229,72,77,.35); background: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.pill { padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--hairline); }

/* ---- Hero ---- */
.hero { text-align: center; margin: 24px 0 52px; }
.hero .eyebrow { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600;
  color: var(--signal); background: var(--signal-soft); padding: 6px 13px; border-radius: 999px;
  letter-spacing: .02em; margin-bottom: 20px; }
.hero .eyebrow .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--signal); }
.hero h1 { font-size: 60px; margin: 0 0 16px; line-height: 1.02; font-weight: 550; }
.hero h1 .mark { color: var(--signal); position: relative; white-space: nowrap; }
.hero h1 .mark::after { content: ''; position: absolute; left: 0; right: 0; bottom: 6px; height: 10px;
  background: var(--signal-soft); z-index: -1; border-radius: 4px; }
.hero p { color: var(--muted); font-size: 18px; max-width: 560px; margin: 0 auto; line-height: 1.6; }
.hero .stats { display: inline-flex; gap: 0; margin-top: 30px; border: 1px solid var(--hairline);
  border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.hero .stats > div { padding: 16px 30px; }
.hero .stats > div + div { border-left: 1px solid var(--hairline); }
.hero .stats b { font-size: 26px; display: block; font-weight: 600; }
.hero .stats span { color: var(--muted); font-size: 12.5px; letter-spacing: .02em; }

/* ---- Section title ---- */
.section-title { display: flex; align-items: center; gap: 12px; margin: 0 0 24px; }
.section-title h2 { margin: 0; font-size: 32px; font-weight: 550; }
.section-title .sub { color: var(--muted); font-size: 15px; margin-left: 2px; }

/* ---- Test grid ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; }
.test-card {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 24px 22px; cursor: pointer;
  transition: .18s; position: relative; overflow: hidden; box-shadow: var(--shadow);
}
.test-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--hue, var(--signal)); opacity: 0; transition: .18s; }
.test-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--hairline-2); }
.test-card:hover::before { opacity: 1; }
.test-card .tile { width: 48px; height: 48px; border-radius: 13px; display: grid; place-items: center;
  font-size: 25px; margin-bottom: 16px; background: color-mix(in srgb, var(--hue, var(--signal)) 14%, #fff);
  border: 1px solid color-mix(in srgb, var(--hue, var(--signal)) 22%, #fff); }
.test-card h3 { margin: 0 0 7px; font-size: 20px; font-weight: 600; font-family: 'Inter', sans-serif; letter-spacing: -0.01em; }
.test-card p { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.test-card .best { margin-top: 16px; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.test-card .best .mono { color: var(--ink); }
.test-card .best.none { color: var(--muted); font-weight: 500; }
.test-card .arrow { position: absolute; bottom: 22px; right: 22px; color: var(--muted); opacity: 0; transform: translateX(-4px); transition: .18s; }
.test-card:hover .arrow { opacity: 1; transform: translateX(0); color: var(--hue, var(--signal)); }

/* ---- Panels ---- */
.panel {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 26px; box-shadow: var(--shadow);
}

/* ---- Game stage ---- */
.stage {
  min-height: 460px; border-radius: var(--radius-sm); position: relative;
  display: flex; align-items: center; justify-content: center; text-align: center;
  user-select: none; overflow: hidden; color: var(--ink); background: var(--surface-2);
  transition: background .12s;
}
.stage.clickable { cursor: pointer; }
.stage-inner { padding: 34px; z-index: 2; }
.stage h2 { font-size: 30px; margin: 0 0 8px; font-weight: 550; }
.stage p { font-size: 17px; margin: 6px auto; max-width: 460px; line-height: 1.5; color: var(--ink-2); }
.stage .big-emoji { font-size: 60px; margin-bottom: 10px; display: block; }
.stage .hint { display: inline-block; margin-top: 14px; font-size: 13px; font-weight: 600;
  color: var(--signal); background: var(--signal-soft); padding: 8px 16px; border-radius: 999px; }
.display-num { font-size: 66px; font-weight: 600; letter-spacing: 1px; }

/* vivid, functional in-test states */
.stage-blue, .stage-green, .stage-red, .stage-purple { color: #fff; }
.stage-blue, .stage-green, .stage-red, .stage-purple { --pt: rgba(255,255,255,.9); }
.stage-blue p, .stage-green p, .stage-red p, .stage-purple p { color: rgba(255,255,255,.9); }
.stage-blue .hint, .stage-green .hint, .stage-red .hint, .stage-purple .hint { background: rgba(255,255,255,.22); color: #fff; }
.stage-blue { background: #2E7BFF; }
.stage-green { background: var(--good); }
.stage-red { background: var(--coral); }
.stage-purple { background: linear-gradient(150deg, #4B3BFF, #7A5CFF); }
.stage-dark { background: var(--surface-2); color: var(--ink); }
.stage-dark p { color: var(--ink-2); }

.back-link { color: var(--muted); font-size: 14px; margin-bottom: 16px; display: inline-flex; gap: 6px; font-weight: 500; }
.back-link:hover { color: var(--ink); }

/* benchmark / percentile block on the result screen */
.bench { margin: 20px 0 6px; width: min(440px, 88vw); }
.bench-head { display: flex; align-items: center; gap: 16px; justify-content: center; text-align: left; margin-bottom: 10px; }
.bench-pct { font-family: 'JetBrains Mono', monospace; font-size: 46px; font-weight: 700; line-height: 1; }
.bench-pct small { font-size: 20px; opacity: .7; }
.bench-cap { font-size: 13.5px; color: var(--muted); line-height: 1.45; }
.bench-cap b { color: var(--ink); font-weight: 600; }
.bench-graph { background: var(--surface); border: 1px solid var(--hairline); border-radius: 14px; padding: 10px 12px 4px; }

/* result */
.result { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.result .value { font-size: 62px; font-weight: 600; }
.result .label { color: var(--muted); font-size: 15px; }
.result .row { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; justify-content: center; }
.badge-best { color: #6b4a00; background: color-mix(in srgb, var(--gold) 26%, #fff); border: 1px solid color-mix(in srgb, var(--gold) 45%, #fff);
  padding: 5px 13px; border-radius: 999px; font-weight: 700; font-size: 13px; }

/* ---- Aim / grid targets ---- */
.aim-target { position: absolute; width: 58px; height: 58px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0 6%, #FF7A5C 12% 55%, #E5484D 100%);
  cursor: crosshair; box-shadow: 0 6px 16px rgba(229,72,77,.4); }

.mem-grid { display: grid; gap: 12px; }
.mem-cell {
  aspect-ratio: 1; border-radius: 12px; background: #fff;
  border: 1px solid var(--hairline-2); cursor: pointer; transition: .12s;
  box-shadow: 0 1px 2px rgba(20,20,40,.04);
}
.mem-cell:hover { background: var(--surface-2); border-color: var(--muted); }
.mem-cell.lit { background: var(--signal); border-color: var(--signal); box-shadow: 0 0 0 4px var(--signal-soft), 0 8px 20px rgba(61,52,242,.35); transform: scale(1.04); }
.mem-cell.active { background: var(--signal); border-color: var(--signal);
  box-shadow: 0 0 0 4px var(--signal-soft); transform: scale(1.05); }
.mem-cell.correct { background: var(--good); border-color: var(--good); box-shadow: 0 6px 16px rgba(18,161,80,.3); }
.mem-cell.wrong { background: var(--bad); border-color: var(--bad); box-shadow: 0 6px 16px rgba(229,72,77,.3); }
.chimp-cell { display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 600; font-family: 'JetBrains Mono', monospace; color: #fff;
  background: var(--ink) !important; border-color: var(--ink) !important; }
.chimp-cell.hidden-num { color: transparent; background: var(--signal) !important; border-color: var(--signal) !important; }
.chimp-cell.correct { background: var(--good) !important; border-color: var(--good) !important; color: #fff; }
.chimp-cell.wrong { background: var(--bad) !important; border-color: var(--bad) !important; }

/* ---- Inputs & forms ---- */
input[type=text], input[type=password], input[type=search] {
  width: 100%; padding: 13px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--hairline-2); background: var(--surface); color: var(--ink);
  font-size: 16px; outline: none; transition: .15s;
}
input::placeholder { color: #b3b2ad; }
input:focus { border-color: var(--signal); box-shadow: 0 0 0 3px var(--signal-soft); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.number-input { font-size: 30px; text-align: center; letter-spacing: 6px; }

/* ---- Tabs / leaderboard ---- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 20px; }
.tab { padding: 8px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--hairline-2);
  color: var(--muted); font-weight: 550; font-size: 14px; }
.tab:hover { color: var(--ink); }
.tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.scope-toggle { display: inline-flex; background: var(--surface-2); border: 1px solid var(--hairline);
  border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 18px; padding: 3px; gap: 3px; }
.scope-toggle button { padding: 8px 18px; border: none; background: transparent; color: var(--muted); font-weight: 600; border-radius: 9px; }
.scope-toggle button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .06em; padding: 10px 14px; border-bottom: 1px solid var(--hairline); font-weight: 600; }
td { padding: 14px; border-bottom: 1px solid var(--hairline); font-size: 15px; }
tbody tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }
.rank { font-weight: 600; width: 62px; color: var(--muted); }
.rank-1, .rank-2, .rank-3 { font-size: 18px; }
.uname { font-weight: 600; cursor: pointer; }
.uname:hover { color: var(--signal); }
.me-row td { background: var(--signal-soft) !important; }
.val { font-weight: 600; }

.muted { color: var(--muted); }
.center { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 56px 20px; font-size: 15px; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--hairline); border-top-color: var(--signal);
  border-radius: 50%; animation: spin 1s linear infinite; margin: 44px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Profile ---- */
.profile-head { display: flex; align-items: center; gap: 20px; margin-bottom: 28px; flex-wrap: wrap; }
.avatar { width: 74px; height: 74px; border-radius: 20px; display: grid; place-items: center;
  font-size: 30px; font-weight: 600; font-family: 'JetBrains Mono', monospace;
  background: var(--ink); color: #fff; }
.stat-row { display: flex; gap: 26px; margin-top: 10px; }
.stat-row b { font-size: 22px; display: block; font-weight: 600; }
.stat-row span { color: var(--muted); font-size: 12px; }
.score-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px,1fr)); gap: 14px; }
.score-item { background: var(--surface); border: 1px solid var(--hairline); border-radius: 14px; padding: 16px;
  position: relative; overflow: hidden; }
.score-item::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--hue, var(--signal)); }
.score-item .t { color: var(--muted); font-size: 13px; margin-bottom: 8px; display: flex; gap: 7px; align-items: center; font-weight: 500; }
.score-item .v { font-size: 26px; font-weight: 600; }
.score-item.empty-score { background: var(--surface-2); }
.score-item.empty-score::before { background: var(--hairline-2); }
.score-item.empty-score .v { color: var(--muted); }

/* ---- Toast / modal ---- */
.toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; border: none; padding: 13px 22px; border-radius: 12px;
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: .25s; z-index: 200; font-weight: 500; font-size: 14.5px; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.good { background: var(--good); } .toast.bad { background: var(--bad); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(22,23,27,.4); backdrop-filter: blur(4px);
  display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--hairline);
  border-radius: 22px; padding: 30px; box-shadow: var(--shadow-lg); }
.modal h2 { margin: 0 0 4px; font-size: 26px; font-weight: 550; }
.modal .sub { color: var(--muted); margin: 0 0 22px; font-size: 14.5px; line-height: 1.5; }
.modal .switch { text-align: center; margin-top: 18px; font-size: 14px; color: var(--muted); }
.modal .switch a { color: var(--signal); font-weight: 600; cursor: pointer; }
.modal .err { color: var(--bad); font-size: 13px; margin-bottom: 10px; min-height: 18px; }

.footer { text-align: center; padding: 26px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--hairline); }

@media (max-width: 640px) {
  .nav { display: none; }
  .topbar { padding: 14px 18px; }
  .hero h1 { font-size: 40px; }
  .hero .stats { flex-direction: column; }
  .hero .stats > div + div { border-left: none; border-top: 1px solid var(--hairline); }
  main { padding-top: 26px; }
}
