:root {
  --bg: #f4f3ec;
  --surface: rgba(255, 255, 255, 0.92);
  --text: #1c1917;
  --muted: #656058;
  --line: #d4cfbe;
  --soft: #e8e4d7;
  --card-lip: #c0b9a3;
  --accent: #38b277;
  --accent-lip: #248556;
  --accent-text: #ffffff;
  --gold: #d97706;
  --you-color: #38b277;
  --opp-color: #e05252;
  --ok: #299c64;
  --ok-soft: #def7ea;
  --bad: #c2410c;
  --bad-soft: #ffedd5;
  --heat-1: #ccebd9;
  --heat-2: #8cd4ad;
  --heat-3: #4ebc84;
  --heat-4: #248556;
  --radius: 14px;
  --math: 'Cambria Math', 'STIX Two Math', 'Latin Modern Math', Cambria, Georgia, 'Times New Roman', serif;
  --sans: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111614;
    --surface: rgba(24, 33, 29, 0.90);
    --text: #f2f6f4;
    --muted: #96b0a3;
    --line: #2d4037;
    --soft: #202d27;
    --card-lip: #090d0b;
    --accent: #65d99e;
    --accent-lip: #389e6a;
    --accent-text: #062314;
    --gold: #facc15;
    --you-color: #65d99e;
    --opp-color: #f87171;
    --ok: #65d99e;
    --ok-soft: #133322;
    --bad: #fb923c;
    --bad-soft: #3a1f0e;
    --heat-1: #1c3629;
    --heat-2: #295941;
    --heat-3: #43996d;
    --heat-4: #65d99e;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111614;
  --surface: rgba(24, 33, 29, 0.90);
  --text: #f2f6f4;
  --muted: #96b0a3;
  --line: #2d4037;
  --soft: #202d27;
  --card-lip: #090d0b;
  --accent: #65d99e;
  --accent-lip: #389e6a;
  --accent-text: #062314;
  --gold: #facc15;
  --you-color: #65d99e;
  --opp-color: #f87171;
  --ok: #65d99e;
  --ok-soft: #133322;
  --bad: #fb923c;
  --bad-soft: #3a1f0e;
  --heat-1: #1c3629;
  --heat-2: #295941;
  --heat-3: #43996d;
  --heat-4: #65d99e;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  position: relative;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; font-weight: 600; margin: 0; }
button, input { font: inherit; color: inherit; }
::selection { background: var(--accent); color: var(--accent-text); }

/* ── Top bar ── */
.topbar {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  max-width: 980px; margin: 0 auto; padding: 1.1rem 1.25rem;
}
.brand { font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: .55rem; white-space: nowrap; }
.brand-mark {
  font-family: var(--math); font-size: 1rem; font-weight: 700; display: inline-grid; place-items: center;
  width: 2rem; height: 2rem; border-radius: 9px; background: var(--accent); color: var(--accent-text);
  border-bottom: 3px solid var(--accent-lip);
}
.brand-sigma {
  font-family: var(--math);
  font-weight: 700;
  color: var(--accent);
  font-size: 1.12em;
  margin-right: 1px;
}
#nav { display: flex; align-items: center; gap: .25rem; }
#nav a { padding: .4rem .75rem; border-radius: 10px; color: var(--muted); font-size: .94rem; font-weight: 500; transition: color .15s, background .15s; }
#nav a:hover { color: var(--text); }
#nav a.active { color: var(--text); background: var(--soft); border-bottom: 2px solid var(--card-lip); font-weight: 600; }
.lang {
  margin-left: .35rem; border: 1px solid var(--line); border-bottom: 2px solid var(--card-lip); background: var(--surface); border-radius: 999px;
  font-size: .75rem; font-weight: 600; letter-spacing: .05em; padding: .3rem .65rem; cursor: pointer; color: var(--muted);
}
.lang:hover:not(:disabled) { color: var(--text); border-color: var(--accent); }
.lang:disabled { opacity: .35; cursor: default; }

main { position: relative; z-index: 1; max-width: 980px; margin: 0 auto; padding: 1rem 1.25rem 4rem; }
.narrow { max-width: 560px; margin: 2rem auto 0; }
.wide { max-width: 900px; margin: 1.5rem auto 0; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.sep { margin: 0 .6rem; color: var(--line); }

/* ── Buttons (Tactile 3D Game Feel) ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .7rem 1.2rem; border-radius: 10px; border: 1px solid transparent;
  border-bottom: 3px solid var(--card-lip);
  font-weight: 600; cursor: pointer;
  transition: transform .07s cubic-bezier(.34,1.56,.64,1), filter .15s, background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { filter: brightness(1.05); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(2px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  border-bottom: 4px solid var(--accent-lip);
}
.btn.ghost {
  background: var(--surface);
  border-color: var(--line);
  border-bottom: 3px solid var(--card-lip);
}
.btn.ghost:hover:not(:disabled) { border-color: var(--accent); border-bottom-color: var(--accent-lip); }
.btn.danger { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); border-bottom: 3px solid var(--bad); }
.btn.block { width: 100%; }
.btn.lg { padding: .95rem 1.2rem; font-size: 1.05rem; }
.btn.sm { padding: .38rem .8rem; font-size: .84rem; border-radius: 8px; border-bottom-width: 2px; }
.btn-row { display: flex; gap: .75rem; justify-content: center; margin-top: 2rem; flex-wrap: wrap; }
.link { background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; color: var(--accent); font-weight: 600; }

/* ── Forms & Cards ── */
.card {
  background: var(--surface);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-bottom: 4px solid var(--card-lip);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.auth-wrap { min-height: 70vh; display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 390px; padding: 2rem; display: grid; gap: 1rem; }
.auth-card .muted { margin: -.5rem 0 .5rem; }
.auth-title { font-family: var(--math); font-weight: 600; font-size: 2rem; margin: 0; }
label { display: grid; gap: .35rem; font-size: .85rem; color: var(--muted); font-weight: 500; }
input[type=text], input[type=password] {
  width: 100%; padding: .75rem .9rem; border-radius: 10px; border: 1px solid var(--line);
  border-bottom: 2px solid var(--card-lip);
  background: var(--surface); color: var(--text); font-size: 1rem; outline: none; transition: border-color .15s;
}
input:focus { border-color: var(--accent); }
.form-error { color: var(--bad); font-size: .9rem; margin: 0; min-height: 1.2em; }

.field { margin: 1.5rem 0; }
.field-label { font-size: .78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: .5rem; }

.segmented { display: flex; gap: .45rem; flex-wrap: wrap; }
.segmented button {
  flex: 1; min-width: 4.5rem; padding: .65rem .8rem; border-radius: 10px;
  border: 1px solid var(--line); border-bottom: 3px solid var(--card-lip);
  background: var(--surface); cursor: pointer;
  display: grid; gap: .1rem; text-align: center; transition: border-color .15s, background .15s, transform .08s;
}
.segmented button:hover { border-color: var(--accent); transform: translateY(-1px); }
.segmented button.active {
  border-color: var(--accent);
  border-bottom-color: var(--accent-lip);
  background: var(--soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.seg-label { font-weight: 600; font-size: .95rem; }
.seg-sub { font-family: var(--math); color: var(--muted); font-size: .85rem; }
.segmented.levels button { padding: .85rem .8rem; }

/* ── Home (Arena Hub) ── */
.home { margin-top: 1.5rem; }
.home-hero-card {
  display: flex; align-items: center; justify-content: space-between; gap: 1.5rem;
  flex-wrap: wrap; margin-bottom: 1.25rem;
}
.home-hero-left { display: grid; gap: .35rem; }
.home-title { font-size: 1.9rem; margin: 0; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.home-streak-pills { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: .2rem; }
.streak-pill {
  display: inline-flex; align-items: center; gap: .3rem; font-size: .8rem; font-weight: 700;
  padding: .22rem .65rem; border-radius: 999px; background: var(--soft);
  border: 1px solid var(--line); color: var(--gold);
}
.home-hero-right { min-width: 230px; text-align: right; }
.home-elo-num { font-size: 1.55rem; font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; }
.big-num { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }

.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
.mode-card {
  position: relative; overflow: hidden;
  background: var(--surface); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-bottom: 4px solid var(--card-lip);
  border-radius: var(--radius);
  padding: 1.75rem 1.6rem; transition: border-color .2s, transform .2s; display: grid; gap: .35rem;
}
.mode-card:hover { border-color: var(--accent); border-bottom-color: var(--accent-lip); transform: translateY(-3px); }
.mode-card p { margin: 0; }
.mode-eq { font-family: var(--math); font-size: 1.85rem; font-weight: 600; color: var(--accent); margin-bottom: .75rem; letter-spacing: .01em; }
.mode-card.battle-card .mode-eq { color: var(--gold); }
.mode-watermark {
  position: absolute; right: .75rem; top: .4rem;
  font-family: var(--math); font-size: 4rem; font-weight: 700;
  opacity: .07; pointer-events: none; user-select: none;
}

.quick-play-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: .65rem; margin-top: 1rem;
}
.quick-tile {
  background: var(--surface); border: 1px solid var(--line); border-bottom: 3px solid var(--card-lip);
  border-radius: 12px; padding: .75rem .65rem; text-align: center; cursor: pointer;
  transition: transform .1s, border-color .15s;
}
.quick-tile:hover { border-color: var(--accent); border-bottom-color: var(--accent-lip); transform: translateY(-2px); }
.quick-tile:active { transform: translateY(2px); }
.quick-tile-math { font-family: var(--math); font-size: .92rem; font-weight: 700; color: var(--accent); }
.quick-tile-label { font-size: .82rem; font-weight: 600; margin-top: .15rem; }

.home-bottom-grid {
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 1rem; margin-top: 1.25rem;
}

/* ── Play (training & battle — 100% distraction-free focus stage) ── */
.play { max-width: 640px; margin: 1.5rem auto 0; }
.session-bar, .duel-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
.bar-stats { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 600; }
.clock {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.1rem; min-width: 3.5rem;
  padding: .2rem .65rem; border-radius: 8px; background: var(--soft); border: 1px solid var(--line);
}
.clock.big { font-size: 1.55rem; text-align: center; color: var(--gold); }
.clock.urgent { color: var(--bad); border-color: var(--bad); }

.tug-bar {
  height: 8px; background: var(--soft); border-radius: 999px; overflow: hidden;
  display: flex; margin-bottom: .65rem; border: 1px solid var(--line);
}
.tug-you { height: 100%; background: var(--you-color); transition: width .25s ease; }
.tug-opp { height: 100%; background: var(--opp-color); transition: width .25s ease; }

.stage { position: relative; }
.problem-card {
  background: var(--surface); border: 1px solid var(--line); border-bottom: 4px solid var(--card-lip);
  border-radius: var(--radius);
  padding: 2.25rem 1.5rem 2.5rem; text-align: center; transition: border-color .2s, background .25s;
}
.problem-card.enter { animation: enter .18s ease-out; }
.problem-card.correct { border-color: var(--ok); background: var(--ok-soft); }
.problem-card.wrong { border-color: var(--bad); background: var(--bad-soft); }
.problem-tag {
  display: inline-block; font-size: .74rem; font-weight: 700; color: var(--accent);
  background: var(--soft); padding: .2rem .65rem; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .08em; margin-bottom: 1.1rem;
}
.equation { font-family: var(--math); font-size: clamp(1.7rem, 6vw, 2.65rem); font-weight: 600; line-height: 1.25; word-spacing: .05em; }

.answer-box { margin-top: 1rem; }
.answer-row { display: flex; gap: .5rem; }
.answer-input { font-family: var(--math); font-size: 1.3rem !important; font-weight: 600; padding: .85rem 1rem !important; text-align: center; }
.keys { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; margin-top: .65rem; }
.key {
  min-width: 2.45rem; height: 2.3rem; padding: 0 .6rem; border-radius: 8px;
  border: 1px solid var(--line); border-bottom: 3px solid var(--card-lip);
  background: var(--surface); cursor: pointer; font-family: var(--math); font-size: 1.05rem; font-weight: 600; color: var(--text);
  transition: transform .06s, border-color .15s;
}
.key:hover:not(:disabled) { border-color: var(--accent); border-bottom-color: var(--accent-lip); }
.key:active:not(:disabled) { transform: translateY(2px); }
.key:disabled { opacity: .4; }
.hint { text-align: center; font-size: .8rem; color: var(--muted); margin-top: .5rem; }
.feedback { min-height: 3.25rem; margin-top: 1rem; display: flex; flex-direction: column; align-items: center; gap: .75rem; text-align: center; }
.reveal { font-size: 1rem; }
.solution { font-family: var(--math); font-size: 1.15rem; font-weight: 600; color: var(--text); }
.prev-feedback {
  display: inline-grid; gap: .2rem; padding: .55rem 1rem; border-radius: 10px;
  background: var(--soft); border: 1px solid var(--line); animation: enter .18s ease-out;
}
.prev-label { font-size: .78rem; }
.prev-math { font-family: var(--math); font-size: 1.05rem; }
.prev-eq { font-family: var(--math); }
.play-actions { display: flex; justify-content: center; margin-top: .5rem; }

.shake { animation: shake .35s; border-color: var(--bad) !important; }

/* ── Battle ── */
.duel-player { min-width: 7rem; }
.duel-player.right { text-align: right; }
.duel-name { font-size: .85rem; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 11rem; }
.duel-score { font-size: 2.2rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; color: var(--you-color); }
.duel-player.right .duel-score { color: var(--opp-color); }
.bump { animation: bump .3s; }
.progress { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; margin-bottom: 1rem; }
.progress-fill { height: 100%; background: var(--accent); transform-origin: left; transition: transform .1s linear; }
.countdown {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: .25rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.countdown-num { font-size: 3.5rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }

.divider { display: flex; align-items: center; gap: 1rem; color: var(--muted); font-size: .85rem; margin: 1.25rem 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.room-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.room-row > .btn { flex: 1; }
.join-form { display: flex; gap: .5rem; flex: 1; }
.code-input { text-transform: uppercase; letter-spacing: .25em; text-align: center; font-weight: 600; min-width: 0; }
.waiting { display: grid; gap: 1rem; justify-items: center; margin-top: 5rem; }
.room-code { font-size: 3rem; font-weight: 600; letter-spacing: .3em; padding-left: .3em; cursor: copy; font-variant-numeric: tabular-nums; }
.room-config { margin-top: 1rem; }
.group-live-strip {
  display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .75rem;
}
.group-chip {
  font-size: .8rem; padding: .2rem .55rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-variant-numeric: tabular-nums;
}
.group-chip.me { border-color: var(--text); font-weight: 500; }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
.spinner { width: 28px; height: 28px; border: 2px solid var(--line); border-top-color: var(--text); border-radius: 50%; animation: spin .8s linear infinite; margin: 2rem auto; }

.result { margin-top: 4rem; }
.result-title { font-size: 3rem; font-weight: 600; letter-spacing: -0.03em; }
.result-title.win { color: var(--ok); }
.result-title.loss { color: var(--bad); }
.result-score { display: flex; align-items: center; justify-content: center; gap: 2rem; margin: 2rem 0 1rem; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin: 2.5rem 0 .85rem; }
.section-head .section-title { margin: 0; }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 500; margin: 2.5rem 0 .85rem; }
.sub-title { font-size: .95rem; font-weight: 500; margin: 1.5rem 0 .5rem; }
.link-subtle:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.back-row { margin-bottom: .75rem; }
.leaderboard ol { list-style: none; padding: 0; margin: 0; counter-reset: lb; }
.leaderboard li {
  counter-increment: lb; display: flex; align-items: center; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--line);
}
.leaderboard li::before { content: counter(lb); color: var(--muted); width: 1.5rem; font-variant-numeric: tabular-nums; }
.leaderboard li.me .lb-name { font-weight: 600; }
.lb-name { flex: 1; }
.lb-name:hover { text-decoration: underline; text-underline-offset: 3px; }
.lb-rating { font-variant-numeric: tabular-nums; font-weight: 500; }

/* ── Leaderboard & Friends pages ── */
.lb-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.lb-header p { margin: 0; }
.lb-controls { display: flex; gap: .6rem; flex-wrap: wrap; }
.lb-scope button, .lb-sort button { padding: .5rem .75rem; min-width: 3.5rem; }
.lb-sort { min-width: 260px; }
.lb-table-wrap { overflow-x: auto; }
.lb-table td { padding: .75rem .6rem .75rem 0; vertical-align: middle; }
.lb-table th { padding: .5rem .6rem .5rem 0; vertical-align: middle; }
.lb-col-rank { width: 2.2rem; font-variant-numeric: tabular-nums; }
.lb-row { cursor: pointer; transition: background .12s; }
.lb-row:hover { background: var(--soft); }
.lb-row td:first-child { padding-left: .5rem; border-top-left-radius: 8px; border-bottom-left-radius: 8px; }
.lb-row td:last-child { padding-right: .5rem; border-top-right-radius: 8px; border-bottom-right-radius: 8px; }
.lb-table th:first-child { padding-left: .5rem; }
.lb-table th:last-child { padding-right: .5rem; }
.lb-player-cell { display: flex; align-items: center; gap: .5rem; }
.lb-row.me .lb-player-name, .lb-strong { font-weight: 600; }
.me-pill { min-width: 0; padding: .1rem .45rem; font-size: .7rem; color: var(--muted); }

.friend-add-form { display: flex; gap: .5rem; min-width: 260px; }
.req-list, .lobby-friend-list { list-style: none; padding: 0; margin: 0; }
.req-item, .lobby-friend-list li {
  display: flex; align-items: center; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--line);
}
.req-item .lb-player-name { flex: 1; font-weight: 500; }
.req-actions, .friend-row-actions { display: inline-flex; align-items: center; gap: .4rem; justify-content: flex-end; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; background: var(--line); }
.status-dot.online { background: var(--ok); }
.status-dot.busy { background: var(--bad); }
.profile-name-row { display: flex; align-items: center; gap: .6rem; }

.invite-banner {
  position: fixed; right: 1.5rem; bottom: 1.5rem; z-index: 20;
  display: flex; align-items: center; gap: 1.25rem; max-width: 440px;
  box-shadow: 0 12px 32px rgba(0,0,0,.15); animation: enter .2s ease-out;
}
.invite-title { font-weight: 600; }
.invite-actions { display: flex; gap: .4rem; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 30;
  display: grid; place-items: center; padding: 1rem; animation: enter .15s ease-out;
}
.modal-card { width: 100%; max-width: 460px; padding: 1.75rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.5rem; }
.check-row { display: flex; align-items: center; gap: .5rem; cursor: pointer; font-size: .9rem; color: var(--text); }
.mod-search { max-width: 200px; padding: .45rem .75rem !important; font-size: .9rem !important; }
.row-banned { opacity: .65; }

/* ── Stats ── */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; margin-top: 1.5rem; }
.stat-grid.six { grid-template-columns: repeat(6, 1fr); margin-top: 0; }
.stat-grid.five { grid-template-columns: repeat(5, 1fr); margin-top: 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-bottom: 3px solid var(--card-lip); border-radius: var(--radius); padding: 1rem; text-align: center; }
.profile .stat { text-align: left; }
.stat-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1.2; }
.stat-label { font-size: .8rem; color: var(--muted); }

/* ── Profile ── */
.profile-head { display: flex; align-items: center; gap: 1.5rem; }
.profile-head > div:first-child { flex: 1; }
.profile-head h1 { margin: 0; }
.profile-head p { margin: .15rem 0 0; }
.profile-rating { text-align: right; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 2rem; }
.streak-card { display: grid; gap: .2rem; }
.streak-main { display: flex; align-items: baseline; gap: .35rem; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { font-weight: 500; color: var(--muted); font-size: .75rem; text-align: left; padding: .4rem .5rem .4rem 0; border-bottom: 1px solid var(--line); }
.table td { padding: .6rem .5rem .6rem 0; border-bottom: 1px solid var(--line); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.acc { display: flex; align-items: center; gap: .5rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.acc-bar { flex: 1; min-width: 3rem; height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
.acc-fill { height: 100%; background: var(--accent); }

.heatmap-wrap { overflow-x: auto; }
.heatmap { display: flex; gap: 4px; }
.week { display: grid; grid-template-rows: repeat(7, 1fr); gap: 4px; }
.cell { width: 14px; height: 14px; border-radius: 3px; background: var(--soft); }
.cell.l1 { background: var(--heat-1); }
.cell.l2 { background: var(--heat-2); }
.cell.l3 { background: var(--heat-3); }
.cell.l4 { background: var(--heat-4); }
.cell.future { background: transparent; }
.heatmap-legend { display: flex; align-items: center; gap: 4px; margin-top: .6rem; justify-content: flex-end; }
.heatmap-legend .cell { width: 11px; height: 11px; }

.recent { list-style: none; padding: 0; margin: 0; }
.recent li { display: flex; align-items: center; gap: 1rem; padding: .65rem 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.recent-opp { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-score { font-variant-numeric: tabular-nums; font-weight: 500; }
.recent-date { min-width: 3.5rem; text-align: right; }
.pill { font-size: .72rem; padding: .15rem .55rem; border-radius: 999px; border: 1px solid var(--line); min-width: 4.8rem; text-align: center; }
.pill.win { color: var(--ok); border-color: currentColor; }
.pill.loss { color: var(--bad); border-color: currentColor; }

/* ── Rank Tiers ── */
.tier-badge {
  display: inline-flex; align-items: center; font-size: .68rem; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase; padding: .12rem .5rem;
  border-radius: 999px; border: 1px solid currentColor; white-space: nowrap;
  transition: opacity .15s, transform .1s;
}
.tier-badge:hover { opacity: .8; transform: translateY(-1px); }
.tier-bronze { color: #b45309; }
.tier-silver { color: #64748b; }
.tier-gold { color: #ca8a04; }
.tier-diamond { color: #0284c7; }
.tier-grandmaster { color: #e11d48; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tier-bronze { color: #f59e0b; }
  :root:not([data-theme="light"]) .tier-silver { color: #94a3b8; }
  :root:not([data-theme="light"]) .tier-gold { color: #facc15; }
  :root:not([data-theme="light"]) .tier-diamond { color: #38bdf8; }
  :root:not([data-theme="light"]) .tier-grandmaster { color: #fb7185; }
}
:root[data-theme="dark"] .tier-bronze { color: #f59e0b; }
:root[data-theme="dark"] .tier-silver { color: #94a3b8; }
:root[data-theme="dark"] .tier-gold { color: #facc15; }
:root[data-theme="dark"] .tier-diamond { color: #38bdf8; }
:root[data-theme="dark"] .tier-grandmaster { color: #fb7185; }
.tier-progress-wrap { margin-top: .45rem; min-width: 8.5rem; }
.tier-bar { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
.tier-bar-fill { height: 100%; background: currentColor; }
.tier-sub { font-size: .72rem; margin-top: .2rem; }
.tier-promo {
  display: inline-block; margin-top: .5rem; padding: .35rem .85rem;
  border-radius: 999px; background: var(--ok-soft); color: var(--ok);
  font-weight: 600; font-size: .9rem; animation: bump .35s;
}
.ranks-me-card {
  display: flex; align-items: center; justify-content: space-between; gap: 1.5rem;
  flex-wrap: wrap; margin-top: 1.25rem;
}
.ranks-me-main { display: flex; align-items: center; gap: .75rem; }
.ranks-me-progress { flex: 1; min-width: 220px; max-width: 340px; }
.tiers-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .75rem; }
.tier-card.current { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.tier-card-head { display: flex; align-items: center; gap: .5rem; }
.tier-range { margin-left: auto; font-weight: 600; font-size: .88rem; font-variant-numeric: tabular-nums; }

/* ── Supporter Badges ── */
.supporter-badge {
  display: inline-flex; align-items: center; gap: .25rem; font-size: .68rem; font-weight: 600;
  letter-spacing: .03em; padding: .12rem .55rem; border-radius: 999px;
  border: 1px solid currentColor; white-space: nowrap;
  transition: opacity .15s, transform .1s;
}
.supporter-badge:hover { opacity: .82; transform: translateY(-1px); }
.sup-supporter { color: #db2777; background: rgba(219, 39, 119, .08); }
.sup-bronze_patron { color: #b45309; background: rgba(180, 83, 9, .1); }
.sup-silver_patron { color: #475569; background: rgba(100, 116, 139, .12); }
.sup-gold_patron { color: #b45309; background: rgba(234, 179, 8, .18); border-color: #ca8a04; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .sup-supporter { color: #f472b6; background: rgba(244, 114, 182, .12); }
  :root:not([data-theme="light"]) .sup-bronze_patron { color: #f59e0b; background: rgba(245, 158, 11, .12); }
  :root:not([data-theme="light"]) .sup-silver_patron { color: #cbd5e1; background: rgba(148, 163, 184, .14); }
  :root:not([data-theme="light"]) .sup-gold_patron { color: #fde047; background: rgba(250, 204, 21, .16); border-color: #facc15; }
}
:root[data-theme="dark"] .sup-supporter { color: #f472b6; background: rgba(244, 114, 182, .12); }
:root[data-theme="dark"] .sup-bronze_patron { color: #f59e0b; background: rgba(245, 158, 11, .12); }
:root[data-theme="dark"] .sup-silver_patron { color: #cbd5e1; background: rgba(148, 163, 184, .14); }
:root[data-theme="dark"] .sup-gold_patron { color: #fde047; background: rgba(250, 204, 21, .16); border-color: #facc15; }
.support-steps p { margin: 0 0 .65rem; line-height: 1.5; }

.toast {
  position: fixed; left: 50%; bottom: 2rem; transform: translate(-50%, 1rem); opacity: 0;
  background: var(--accent); color: var(--accent-text); padding: .65rem 1.1rem; border-radius: 10px;
  font-size: .9rem; transition: opacity .25s, transform .25s; z-index: 10; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Animations ── */
@keyframes enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes shake { 0%, 100% { transform: none; } 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes bump { 50% { transform: scale(1.2); } }
@keyframes pulse { 50% { opacity: .45; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile ── */
@media (max-width: 720px) {
  .topbar { padding: .75rem 1rem; flex-wrap: wrap; gap: .5rem; }
  .brand { font-size: 1.05rem; gap: .45rem; }
  .brand-mark { font-size: .95rem; width: 2rem; height: 2rem; flex-shrink: 0; }
  .brand-text { font-size: 1.05rem; white-space: nowrap; }
  #nav { flex-wrap: wrap; justify-content: flex-end; gap: .25rem; }
  #nav a { padding: .3rem .55rem; font-size: .84rem; }
  .btn-upgrade-pill { font-size: .75rem; padding: .25rem .55rem; }
  .auth-wrap { min-height: 60vh; padding: 1rem 0; }
  .auth-card { padding: 1.5rem 1.25rem; border-radius: 12px; }
  .auth-title { font-size: 1.75rem; }
  main { padding: .5rem .75rem 3rem; }
  .mode-grid, .grid-2, .grid-3, .home-bottom-grid { grid-template-columns: 1fr; }
  .quick-play-grid { grid-template-columns: repeat(2, 1fr); gap: .5rem; }
  .quick-tile { padding: .75rem .5rem; }
  .home-hero-right { text-align: left; width: 100%; margin-top: .5rem; }
  .stat-grid, .stat-grid.six { grid-template-columns: repeat(2, 1fr); }
  .stat-grid.five { grid-template-columns: repeat(3, 1fr); }
  .profile-head { flex-wrap: wrap; }
  .recent li { gap: .6rem; }
  .recent li > .small:not(.recent-date) { display: none; }
  .duel-score { font-size: 1.8rem; }
  .clock.big { font-size: 1.5rem; }
  .segmented.levels { flex-direction: column; }
  .room-row { flex-direction: column; }
  .keys .key { min-width: 2.2rem; height: 2.35rem; font-size: 1.05rem; padding: 0 .4rem; }
  .equation { font-size: clamp(1.4rem, 6.5vw, 2.3rem); }
  .hide-sm { display: none; }
}

@media (max-width: 440px) {
  .topbar { padding: .6rem .75rem; }
  .brand-text { font-size: .95rem; }
  #nav a { padding: .25rem .45rem; font-size: .78rem; }
  .lang { padding: .25rem .5rem; font-size: .7rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── Site Analytics Dashboard ── */
.analytics-hero-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .85rem;
  margin-bottom: 1.25rem;
}
@media (max-width: 860px) {
  .analytics-hero-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .analytics-hero-grid { grid-template-columns: 1fr; }
}

.analytics-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: 3px solid var(--card-lip);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: .5rem;
  transition: transform .12s, border-color .15s;
}
.analytics-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.analytics-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
.analytics-card-title {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.analytics-card-value {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  color: var(--text);
}
.analytics-card-sub {
  font-size: .82rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
}
.analytics-badge {
  display: inline-flex;
  align-items: center;
  font-size: .75rem;
  font-weight: 600;
  padding: .15rem .5rem;
  border-radius: 999px;
  background: var(--soft);
  color: var(--text);
  border: 1px solid var(--line);
}
.analytics-badge.ok {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: currentColor;
}

/* Distribution Bars */
.dist-card {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .85rem;
}
.dist-row {
  display: grid;
  grid-template-columns: 110px 1fr 65px;
  align-items: center;
  gap: .75rem;
  font-size: .85rem;
}
.dist-label {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dist-track {
  height: 8px;
  background: var(--soft);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.dist-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width .3s ease-out;
}
.dist-fill.gold { background: var(--gold); }
.dist-fill.bronze { background: #b45309; }
.dist-fill.silver { background: #64748b; }
.dist-fill.diamond { background: #0284c7; }
.dist-count {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* 14-Day Activity Trend Bar Chart */
.trend-card {
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}
.trend-chart-wrap {
  display: flex;
  align-items: flex-end;
  gap: .45rem;
  height: 140px;
  padding: 1.5rem 0 .5rem;
  border-bottom: 1px solid var(--line);
}
.trend-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  position: relative;
  cursor: pointer;
}
.trend-bar-stack {
  width: 100%;
  max-width: 28px;
  border-radius: 4px 4px 0 0;
  background: var(--accent);
  min-height: 4px;
  transition: background .12s, transform .12s;
}
.trend-col:hover .trend-bar-stack {
  background: var(--accent-lip);
  transform: scaleY(1.04);
}
.trend-date-label {
  font-size: .7rem;
  color: var(--muted);
  margin-top: .4rem;
  font-variant-numeric: tabular-nums;
}
.trend-tooltip {
  display: none;
  position: absolute;
  bottom: 105%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 6px 18px rgba(0,0,0,.15);
  padding: .45rem .65rem;
  border-radius: 8px;
  font-size: .75rem;
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
}
.trend-col:hover .trend-tooltip {
  display: block;
}

/* Telegram Bot Info Box */
.telegram-card {
  padding: 1.5rem;
  display: grid;
  gap: 1.2rem;
}
.telegram-status-pill {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  font-weight: 600;
  font-size: .85rem;
  padding: .3rem .75rem;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.telegram-status-pill.active {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: currentColor;
}
.telegram-status-pill.inactive {
  background: var(--soft);
  color: var(--muted);
}
.telegram-step-list {
  display: grid;
  gap: .65rem;
  margin: 0;
  padding-left: 1.2rem;
  font-size: .92rem;
}
.telegram-code-box {
  background: var(--soft);
  border: 1px solid var(--line);
  padding: .65rem .85rem;
  border-radius: 8px;
  font-family: monospace;
  font-size: .85rem;
  overflow-x: auto;
  user-select: all;
}

/* ── Guest Mode ── */
.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 1.25rem 0 1rem 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--line);
}
.auth-divider span {
  padding: 0 0.75rem;
  text-transform: lowercase;
}
.btn-guest {
  font-weight: 600;
  font-size: 1rem;
  padding: 0.8rem 1rem;
  background: var(--surface);
  border: 2px solid var(--accent);
  color: var(--accent);
  border-radius: var(--radius);
  transition: all 0.15s ease;
  margin-top: 0.75rem;
}
.btn-guest:hover {
  background: var(--accent);
  color: var(--accent-text);
  transform: translateY(-1px);
}
.btn-upgrade-pill {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  border: none;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  box-shadow: 0 2px 8px rgba(217, 119, 6, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn-upgrade-pill:hover {
  transform: scale(1.04);
  box-shadow: 0 4px 12px rgba(217, 119, 6, 0.5);
}
.guest-banner {
  background: var(--surface);
  border: 1px solid var(--gold);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius);
  padding: 0.85rem 1.25rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  animation: enter .2s ease-out;
}
.guest-banner-text {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.4;
}
.guest-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--soft);
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  margin-left: 0.4rem;
  vertical-align: middle;
}
