/* ============================================
   RankedSTEM  Competitive Ladder UI
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* === TOKENS === */
:root {
    --bg: #000000;
    --surface: #0a0a0a;
    --card: #0f0f0f;
    --card-light: #161616;
    --card-hover: #1a1a1a;
    --text: #ffffff;
    --text-secondary: #a0a0a0;
    --muted: #4a4a4a;
    --border: #1e1e1e;
    --border-hover: #2e2e2e;
    --accent: #22c55e;
    --accent-2: #16a34a;
    --accent-glow: rgba(34, 197, 94, 0.15);
    --accent-glow-strong: rgba(34, 197, 94, 0.3);
    --accent-edge: rgba(74, 222, 128, 0.75);
    --accent-edge-soft: rgba(34, 197, 94, 0.24);
    --glass-card: transparent;
    --glass-card-hover: rgba(255, 255, 255, 0.04);
    --glass-border: rgba(255, 255, 255, 0.10);
    --glass-shadow: 0 4px 24px rgba(0, 0, 0, 0.22);
    --glass-shadow-hover: 0 10px 40px rgba(0, 0, 0, 0.32);
    --bg-depth-1: rgba(34, 197, 94, 0.14);
    --bg-depth-2: rgba(34, 197, 94, 0.08);
    --bg-depth-3: rgba(255, 255, 255, 0.035);
    --rank-bronze: #b87444;
    --rank-silver: #b9c2d0;
    --rank-gold: #e6c15a;
    --rank-platinum: #6ad6c3;
    --rank-diamond: #67b7ff;
    --rank-master: #b18cff;
    --wrong: #ef4444;
    --warning: #f97316;
    --glass: rgba(255,255,255,0.03);
    --mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

html.light-mode {
    --bg: #fafafa;
    --surface: #f0f0f0;
    --card: #ffffff;
    --card-light: #f5f5f5;
    --card-hover: #eeeeee;
    --text: #0a0a0a;
    --text-secondary: #555555;
    --muted: #888888;
    --border: #e0e0e0;
    --border-hover: #cccccc;
    --accent: #16a34a;
    --accent-2: #22c55e;
    --accent-glow: rgba(22, 163, 74, 0.1);
    --accent-glow-strong: rgba(22, 163, 74, 0.2);
    --accent-edge: rgba(34, 197, 94, 0.45);
    --accent-edge-soft: rgba(22, 163, 74, 0.14);
    --glass-card: transparent;
    --glass-card-hover: rgba(255, 255, 255, 0.22);
    --glass-border: rgba(0, 0, 0, 0.07);
    --glass-shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
    --glass-shadow-hover: 0 10px 40px rgba(15, 23, 42, 0.10);
    --bg-depth-1: rgba(22, 163, 74, 0.1);
    --bg-depth-2: rgba(22, 163, 74, 0.05);
    --bg-depth-3: rgba(255, 255, 255, 0.4);
    --rank-bronze: #b97a56;
    --rank-silver: #9ca8ba;
    --rank-gold: #d4a83d;
    --rank-platinum: #2eb6a4;
    --rank-diamond: #3185d6;
    --rank-master: #8a67dc;
    --wrong: #dc2626;
    --warning: #ea580c;
    --glass: rgba(0,0,0,0.03);
}

/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    min-height: 100vh;
    margin: 0;
    padding: 0;
    background: var(--bg);
    font-family: var(--sans);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    display: flex;
    flex-direction: column;
    scrollbar-width: none;
    -ms-overflow-style: none;
    max-width: 100%;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* overflow-x must only be on html, not body.
   Setting it on body implicitly sets overflow-y:auto on body,
   making body (not the viewport) the scroll container — which
   breaks native scroll momentum, window.scroll events, and
   IntersectionObserver on the home page stats sections. */
html {
    position: relative;
    overflow-x: hidden;
}

html::-webkit-scrollbar, body::-webkit-scrollbar { display: none; }

p { margin: 0 0 20px 0; color: var(--text-secondary); }

/* Universal cursor hide — only active after the user has moved the mouse once.
   Deferring this prevents Chromium/Windows from swallowing the very first click:
   cursor:none causes Chromium to defer hit-test initialisation to the first
   native pointer event, which consumes that event. By not applying cursor:none
   until after the first pointermove (which is not a click), the first click
   always reaches the page normally. */
html.cursor-active, html.cursor-active body,
html.cursor-active *, html.cursor-active *::before, html.cursor-active *::after {
    cursor: none !important;
}

/* Mobile phones (html.is-mobile, set by UA detection in <head>) get the
   default cursor restored so the browser's touch→click event pipeline works
   correctly; cursor:none on touchscreens can silently drop early taps.
   Scoped to .is-mobile (phone UA only) rather than a pointer/hover media
   query so Windows tablets / Surface Pro are never accidentally matched. */
html.is-mobile, html.is-mobile body,
html.is-mobile *, html.is-mobile *::before, html.is-mobile *::after {
    cursor: auto !important;
}

/* Eliminate the 300ms double-tap-to-zoom delay on interactive elements.
   touch-action:manipulation keeps single-tap/click instant on all browsers. */
button, input, select, textarea, a, label,
[tabindex], [onclick], .difficulty-btn, .action-card, .action-card-stats,
.stats-tab-btn, .gear-btn, .gear-dropdown-item, .upgrade-top-btn,
.calc-toggle-btn, .math-btn, .mode-btn, .canvas-ctrl-btn {
    touch-action: manipulation;
}

/* === CUSTOM CURSOR === */
/* All #customCursor styling is done via inline JS — no CSS rules here */

/* === DEPTH LAYERS === */
html::before,
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
}

html::before {
    z-index: 0;
    background:
        radial-gradient(circle at 18% 18%, var(--bg-depth-1) 0%, transparent 34%),
        radial-gradient(circle at 82% 14%, var(--bg-depth-2) 0%, transparent 28%),
        radial-gradient(circle at 50% 80%, var(--bg-depth-3) 0%, transparent 40%);
    opacity: 0.9;
}

body::before {
    z-index: 1;
    background:
        radial-gradient(circle at 24% 24%, rgba(34, 197, 94, 0.08) 0%, transparent 20%),
        radial-gradient(circle at 76% 20%, rgba(255, 255, 255, 0.035) 0%, transparent 18%),
        radial-gradient(circle at 50% 100%, rgba(34, 197, 94, 0.05) 0%, transparent 28%);
    mix-blend-mode: screen;
    opacity: 0.9;
}

/* === BACKGROUND CANVAS === */
#cubeBackground {
    position: fixed;
    top: -300px; left: 0;
    width: 100%; height: calc(100% + 600px);
    z-index: 2;
    pointer-events: none;
    opacity: 0.92;
    filter: saturate(1.05) brightness(0.92);
}

/* === BOTTOM ACCENT LINE (#33) === */
body::after {
    content: '';
    position: fixed;
    bottom: 0; left: 0;
    width: 100%; height: 2px;
    background: linear-gradient(90deg, transparent 0%, var(--accent) 30%, var(--accent) 70%, transparent 100%);
    z-index: 999;
    opacity: 0.5;
}

/* === PAGE TRANSITION (#32) === */
.page-transition-out {
    animation: pageOut 0.2s ease-in forwards;
}
.page-transition-in {
    animation: pageIn 0.25s ease-out forwards;
}
@keyframes pageOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-20px); }
}
@keyframes pageIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === MAIN CARD WRAPPER === */
.card {
    width: 100%;
    max-width: 100%;
    background: transparent;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    border: none;
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 20px 40px 20px;
    position: relative;
    z-index: 10;
}

/* === HEADER === */
.header {
    text-align: center;
    margin-bottom: 24px;
    padding: 24px 0 20px 0;
    background: linear-gradient(180deg, var(--accent-glow) 0%, transparent 100%);
    margin-left: -20px;
    margin-right: -20px;
    padding-left: 20px;
    padding-right: 20px;
    transition: border-color 0.3s ease;
    position: relative;
}

html.light-mode .header {
    background: linear-gradient(180deg, rgba(22, 163, 74, 0.12) 0%, transparent 100%);
}

h1 {
    margin: 0;
    font-weight: 800;
    font-size: 42px;
    letter-spacing: -1.5px;
    color: var(--text);
    font-family: var(--sans);
}

.subtitle {
    margin: 8px 0 0 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
    display: none;
}

/* ── Aetas badge (under disciplina. heading) ── */
.aetas-tagline {
    display: inline-block;
    margin-top: 6px;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--accent);
    opacity: 0.75;
    cursor: default;
    position: relative;
}

/* ── Tooltip for [data-aetas-tooltip] ── */
[data-aetas-tooltip] {
    position: relative;
    cursor: default;
}

[data-aetas-tooltip]::after {
    content: attr(data-aetas-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--card-bg, #1a1a1a);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--muted);
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.3px;
    text-transform: none;
    white-space: nowrap;
    padding: 6px 10px;
    border-radius: 6px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 100;
}

[data-aetas-tooltip]:hover::after {
    opacity: 1;
}

/* === PLAYER IDENTITY BAR (#5, #6) === */
/* Home screen: centered competitive rating module */
.player-bar {
    display: none;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: 12px;
    padding: 10px 18px 24px;
    max-width: 560px;
    margin: 0 auto;
    background: rgba(9, 14, 12, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: relative;
    z-index: 11;
    --rank-tier-color: var(--accent);
    --rank-tier-rgb: 34, 197, 94;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}
html.light-mode .player-bar {
    background: rgba(255, 255, 255, 0.84);
    border-color: rgba(0, 0, 0, 0.08);
}
.player-bar.visible { display: none; }

/* In-game: compact single-line strip just below the header */
.player-bar.visible.in-game {
    position: static;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 0 0 16px;
    max-width: none;
    width: 100%;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    min-width: 0;
    transform: none;
    top: auto;
    right: auto;
    z-index: auto;
}
/* hide heavy sections in the strip */
.player-bar.visible.in-game .rank-progression,
.player-bar.visible.in-game .rank-ladder-compact {
    display: none;
}
/* Compact strip: username left-aligned */
.player-bar.visible.in-game .player-bar-left {
    justify-content: flex-start;
    flex-shrink: 0;
}
/* Compact strip: rank badge + elo side-by-side */
.player-bar.visible.in-game .player-rating-stack {
    flex-direction: row;
    align-items: center;
    padding: 0;
    gap: 8px;
}
.player-bar.visible.in-game .player-bar-rating {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -0.2px;
    text-shadow: none;
    line-height: 1;
}
.player-bar.visible.in-game .player-bar-rating-label {
    font-size: 9px;
    letter-spacing: 1.5px;
}
.player-bar.visible.in-game .player-bar-rank {
    font-size: 9px;
    padding: 3px 8px;
    letter-spacing: 0.8px;
}
.player-bar.visible.in-game .rank-badge-shell {
    animation: none;
    background: rgba(var(--rank-tier-rgb, 34, 197, 94), 0.18);
}

.player-bar-separator {
    display: none;
}
.player-bar.in-game .player-bar-separator { display: none; }

.player-bar-left {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.player-bar.in-game .player-bar-left {
    align-items: center;
}
.player-bar-username {
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 1.2px;
    text-transform: uppercase;
}

.player-rating-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 0 2px;
}

.rank-badge-shell {
    position: relative;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    padding: 1px;
    border-radius: 999px;
    background: linear-gradient(120deg, rgba(var(--rank-tier-rgb), 0) 0%, rgba(var(--rank-tier-rgb), 0.85) 50%, rgba(var(--rank-tier-rgb), 0) 100%);
    background-size: 200% 100%;
    animation: badgeShimmer 3.2s linear infinite;
}
.player-bar-rank {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 700;
    color: var(--rank-tier-color);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    padding: 5px 12px;
    border: 1px solid rgba(var(--rank-tier-rgb), 0.78);
    border-radius: 20px;
    background: rgba(var(--rank-tier-rgb), 0.16);
    box-shadow: 0 0 0 1px rgba(var(--rank-tier-rgb), 0.16), 0 0 20px rgba(var(--rank-tier-rgb), 0.34);
}
.player-bar-right {
    display: none;
}
.player-bar-rating {
    font-family: var(--mono);
    font-size: 56px;
    line-height: 1;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -1.8px;
    text-shadow: 0 0 22px rgba(var(--rank-tier-rgb), 0.35);
}
.player-bar-rating-label {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 2px;
}
.player-bar-delta {
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 600;
    margin-left: 0;
    text-align: center;
}
.player-bar-delta.positive { color: var(--accent); }
.player-bar-delta.negative { color: var(--wrong); }

/* Animated rating delta badge (post-match) */
.rating-delta-badge {
    position: absolute;
    right: -8px;
    top: -2px;
    font-family: var(--mono);
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.5px;
    pointer-events: none;
    animation: deltaSlideUp 2.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    white-space: nowrap;
    z-index: 12;
}
.rating-delta-badge.positive { color: var(--accent); }
.rating-delta-badge.negative { color: var(--wrong); }

@keyframes deltaSlideUp {
    0%   { opacity: 0; transform: translateY(8px); }
    12%  { opacity: 1; transform: translateY(0); }
    70%  { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-14px); }
}

.rank-progression {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rank-progression-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.6px;
    text-transform: uppercase;
}

.rank-current {
    color: var(--text-secondary);
}

.rank-next {
    color: var(--rank-tier-color);
    font-weight: 700;
}

.rank-progress-track {
    height: 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.rank-progress-fill {
    height: 100%;
    width: 0%;
    border-radius: inherit;
    background: linear-gradient(90deg, rgba(var(--rank-tier-rgb), 0.86) 0%, var(--rank-tier-color) 100%);
    box-shadow: 0 0 18px rgba(var(--rank-tier-rgb), 0.48);
    transition: width 1.2s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.5s ease;
}

.rank-progress-meta {
    display: flex;
    justify-content: flex-end;
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-secondary);
}

.rank-ladder-compact {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.rank-ladder-chip {
    font-family: var(--mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 3px 7px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--muted);
    background: rgba(255, 255, 255, 0.03);
}

.rank-ladder-chip.current {
    color: var(--text);
    border-color: rgba(var(--rank-tier-rgb), 0.78);
    background: rgba(var(--rank-tier-rgb), 0.16);
}

.rank-ladder-chip.next {
    color: var(--rank-tier-color);
    border-color: rgba(var(--rank-tier-rgb), 0.56);
}

.player-bar[data-tier='bronze'] { --rank-tier-color: #d97706; --rank-tier-rgb: 217, 119, 6; }
.player-bar[data-tier='silver'] { --rank-tier-color: #90a4ae; --rank-tier-rgb: 144, 164, 174; }
.player-bar[data-tier='gold'] { --rank-tier-color: #ffd740; --rank-tier-rgb: 255, 215, 64; }
.player-bar[data-tier='platinum'] { --rank-tier-color: #26c6da; --rank-tier-rgb: 38, 198, 218; }
.player-bar[data-tier='diamond'] { --rank-tier-color: #40c4ff; --rank-tier-rgb: 64, 196, 255; }
.player-bar[data-tier='master'] { --rank-tier-color: #e040fb; --rank-tier-rgb: 224, 64, 251; }
.player-bar[data-tier='grandmaster'] { --rank-tier-color: #ff4444; --rank-tier-rgb: 255, 68, 68; }
.player-bar[data-tier='unranked'] { --rank-tier-color: #4a4a4a; --rank-tier-rgb: 74, 74, 74; }

@keyframes badgeShimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

/* === GEAR MENU (#11) === */
.gear-btn {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1001;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: top 0.28s ease, opacity 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    padding: 0;
}
/* Tier badge — sits to the left of upgrade/gear */
.tier-badge {
    position: fixed;
    top: 20px;
    right: 108px;
    z-index: 1001;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.06em;
    color: #22c55e;
    transition: opacity 0.25s;
}
.tier-badge--free { right: 108px; }
.tier-badge--base { right: 60px; }
body.sticky-nav-visible .tier-badge {
    opacity: 0;
    pointer-events: none;
}
/* Hero upgrade button — sits to the left of the gear icon */
.hero-upgrade-btn {
    position: fixed;
    top: 16px;
    right: 60px;
    z-index: 1001;
    height: 36px;
    padding: 0 14px;
    border-radius: 8px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.03em;
    transition: opacity 0.25s, transform 0.15s;
}
.hero-upgrade-btn:hover {
    transform: scale(1.04);
    box-shadow: 0 0 12px var(--accent-glow);
}
/* Hide when sticky nav scrolls in (sticky nav has its own upgrade button) */
body.sticky-nav-visible .hero-upgrade-btn {
    opacity: 0;
    pointer-events: none;
}
/* Push gear below sticky nav when it's visible so they don't overlap */
body.sticky-nav-visible .gear-btn {
    top: 64px;
}
.gear-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: rotate(45deg);
    box-shadow: 0 0 12px var(--accent-glow);
}
.gear-dropdown {
    position: fixed;
    top: 56px;
    right: 16px;
    z-index: 1001;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px;
    display: none;
    min-width: 160px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
.gear-dropdown.open { display: block; }
.gear-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.15s ease;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: var(--sans);
}
.gear-dropdown-item:hover {
    background: var(--card-hover);
    color: var(--text);
    transform: none;
}

/* Hide the old theme toggle */
.theme-toggle-container { display: none; }
.theme-checkbox { display: none; }
.theme-switch { display: none; }

/* === CONTAINER SECTIONS === */
#loginContainer,
#difficultyContainer,
#matchmakingContainer,
#gameContainer,
#statsContainer,
#competitiveStatsContainer,
#leaderboardContainer {
    width: 100%;
    max-width: 960px;
    margin-left: auto;
    margin-right: auto;
    padding: 0 20px;
}

/* === LOGIN SCREEN (#1) === */
#loginContainer {
    max-width: 380px;
}

#loginForm, #registerForm {
    animation: pageIn 0.3s ease-out;
}

#loginForm input, #registerForm input {
    display: block;
    margin: 0 auto 14px;
    width: 100%;
    max-width: 100%;
    padding: 14px 16px;
    font-size: 14px;
    font-family: var(--sans);
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    text-align: left;
}

#loginForm input:hover, #registerForm input:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}
#loginForm input:focus, #registerForm input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* === HOME DASHBOARD LAYOUT === */
#difficultyContainer {
    max-width: 1260px;
}

.home-dashboard {
    display: grid;
    grid-template-columns: 260px 1fr 260px;
    gap: 18px;
    align-items: stretch;
}

/* Centre column: competitive card tall + practice card below */
.dashboard-actions-column {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.dashboard-actions-column .action-card--competitive {
    flex: 1;
    min-height: 200px;
    order: unset;
    grid-column: unset;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 28px;
}

.dashboard-actions-column .action-card:not(.action-card--competitive) {
    padding: 22px 28px;
    text-align: center;
}

.action-card-row {
    display: flex;
    gap: 14px;
}
.action-card-row .action-card {
    flex: 1;
}

.dashboard-panel {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 18px;
    box-shadow: var(--glass-shadow), inset 0 1px 0 rgba(255,255,255,0.06);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.dashboard-kicker {
    margin: 0 0 14px 0;
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--muted);
}

.dashboard-panel-identity {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    justify-content: center;
    text-align: center;
}

.dashboard-panel-identity .dashboard-kicker,
.dashboard-panel-progression .dashboard-kicker {
    color: var(--accent);
}

.dashboard-identity-name {
    font-family: var(--mono);
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
}

.dashboard-identity-rank {
    display: inline-flex;
    align-self: center;
    border-radius: 999px;
    padding: 6px 12px;
    border: 1px solid rgba(var(--rank-tier-rgb, 34, 197, 94), 0.6);
    background: rgba(var(--rank-tier-rgb, 34, 197, 94), 0.16);
    color: var(--rank-tier-color, var(--accent));
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.dashboard-identity-rating {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.dashboard-identity-value {
    font-family: var(--mono);
    font-size: 46px;
    line-height: 1;
    font-weight: 800;
    color: var(--text);
    text-shadow: none;
}

.dashboard-identity-label {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--muted);
    letter-spacing: 1.8px;
}

@keyframes competitivePulse {
    0%, 100% {
        box-shadow:
            0 20px 46px rgba(0, 0, 0, 0.42),
            0 12px 30px rgba(34, 197, 94, 0.24),
            0 0 0 1px rgba(74, 222, 128, 0.22),
            0 0 40px rgba(34, 197, 94, 0.08);
        border-color: rgba(34, 197, 94, 0.4);
    }
    50% {
        box-shadow:
            0 20px 46px rgba(0, 0, 0, 0.42),
            0 12px 30px rgba(34, 197, 94, 0.38),
            0 0 0 1px rgba(74, 222, 128, 0.5),
            0 0 60px rgba(34, 197, 94, 0.18);
        border-color: rgba(74, 222, 128, 0.65);
    }
}

.action-card--competitive {
    order: unset;
    grid-column: unset;
    min-height: 0;
    border-color: rgba(34, 197, 94, 0.4);
    background: rgba(34, 197, 94, 0.06);
    box-shadow:
        0 20px 46px rgba(0, 0, 0, 0.42),
        0 12px 30px rgba(34, 197, 94, 0.24),
        0 0 0 1px rgba(74, 222, 128, 0.22);
    animation: competitivePulse 3s ease-in-out infinite;
}

.action-card--competitive .action-card-title {
    font-size: 20px;
}

.action-card--competitive .action-card-subtitle {
    font-size: 13px;
}

.action-card--competitive:hover {
    animation: none;
    transform:
        translateY(-8px)
        translateX(var(--mag-shift-x))
        translateY(var(--mag-shift-y))
        rotateX(var(--mag-rotate-x))
        rotateY(var(--mag-rotate-y))
        scale(1.03);
    box-shadow:
        0 26px 56px rgba(0, 0, 0, 0.48),
        0 16px 38px rgba(34, 197, 94, 0.44),
        0 30px 64px rgba(34, 197, 94, 0.28),
        0 0 0 1px rgba(74, 222, 128, 0.6),
        0 0 80px rgba(34, 197, 94, 0.2);
    border-color: rgba(74, 222, 128, 0.7);
}

.dashboard-panel-progression {
    display: flex;
    flex-direction: column;
    gap: 10px;
    justify-content: space-between;
}

.dashboard-progress-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text-secondary);
}

.dashboard-progress-row strong {
    color: var(--text);
    letter-spacing: 0.4px;
}

.dashboard-progress-track {
    height: 12px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.05);
    overflow: hidden;
}

.dashboard-progress-fill {
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, rgba(var(--rank-tier-rgb, 34, 197, 94), 0.8) 0%, var(--rank-tier-color, var(--accent)) 100%);
    box-shadow: 0 0 18px rgba(var(--rank-tier-rgb, 34, 197, 94), 0.4);
    transition: width 1.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.dashboard-progress-percent {
    font-family: var(--mono);
    font-size: 12px;
    text-align: right;
    color: var(--text-secondary);
}

.dashboard-rank-ladder {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.dashboard-rank-chip {
    font-family: var(--mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 8px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--muted);
    background: rgba(255, 255, 255, 0.02);
}

.dashboard-rank-chip.current {
    color: var(--text);
    border-color: rgba(var(--rank-tier-rgb, 34, 197, 94), 0.8);
    background: rgba(var(--rank-tier-rgb, 34, 197, 94), 0.16);
}

.dashboard-rank-chip.next {
    color: var(--rank-tier-color, var(--accent));
    border-color: rgba(var(--rank-tier-rgb, 34, 197, 94), 0.58);
}

/* === DASHBOARD ACTION CARDS (#7) === */
.action-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin: 0 0 16px;
    max-width: none;
}

.action-card {
    --mag-rotate-x: 0deg;
    --mag-rotate-y: 0deg;
    --mag-shift-x: 0px;
    --mag-shift-y: 0px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    padding: 40px 20px 32px;
    transition:
        transform 0.28s cubic-bezier(0.22, 1, 0.36, 1),
        box-shadow 0.28s cubic-bezier(0.22, 1, 0.36, 1),
        border-color 0.22s ease,
        background 0.22s ease;
    position: relative;
    overflow: hidden;
    text-align: center;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    box-shadow: var(--glass-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
    transform:
        translateY(0)
        translateX(var(--mag-shift-x))
        translateY(var(--mag-shift-y))
        rotateX(var(--mag-rotate-x))
        rotateY(var(--mag-rotate-y))
        scale(1);
    transform-style: preserve-3d;
    will-change: transform;
}

.action-card::before {
    content: '';
    position: absolute;
    bottom: 0; left: 0;
    width: 100%; height: 2px;
    background: var(--accent);
    opacity: 0;
    transition: opacity 0.25s;
}

.action-card::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(130% 90% at 50% 118%, rgba(34, 197, 94, 0.24), transparent 64%);
    opacity: 0;
    transition: opacity 0.28s ease, filter 0.28s ease;
    pointer-events: none;
}

.action-card:hover {
    background: var(--glass-card-hover);
    border-color: var(--accent-edge);
    transform:
        translateY(-6px)
        translateX(var(--mag-shift-x))
        translateY(var(--mag-shift-y))
        rotateX(var(--mag-rotate-x))
        rotateY(var(--mag-rotate-y))
        scale(1.025);
    box-shadow:
        var(--glass-shadow-hover),
        0 0 0 1px rgba(74, 222, 128, 0.12),
        0 14px 30px rgba(34, 197, 94, 0.18),
        0 26px 52px rgba(34, 197, 94, 0.14);
}

.action-card:hover::before { opacity: 0.65; }

.action-card:hover::after {
    opacity: 1;
    filter: brightness(1.2);
}

.action-card-icon {
    font-size: 28px;
    margin-bottom: 12px;
    display: block;
}

.action-card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
    letter-spacing: -0.3px;
}

.action-card-subtitle {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    font-family: var(--mono);
    transition: color 0.2s;
    min-height: 16px;
}

.action-card:hover .action-card-subtitle { color: var(--text-secondary); }

/* Live pulse dot on competitive card (#8) */
.pulse-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    margin-right: 6px;
    animation: pulseDot 2s ease-in-out infinite;
    vertical-align: middle;
}
@keyframes pulseDot {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 var(--accent-glow-strong); }
    50% { opacity: 0.6; box-shadow: 0 0 0 6px transparent; }
}

/* Stats sub-row under action cards */
.action-cards-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin: 0 0 20px;
    max-width: none;
}

.action-card-stats {
    --mag-rotate-x: 0deg;
    --mag-rotate-y: 0deg;
    --mag-shift-x: 0px;
    --mag-shift-y: 0px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    padding: 24px 20px;
    transition:
        transform 0.28s cubic-bezier(0.22, 1, 0.36, 1),
        box-shadow 0.28s cubic-bezier(0.22, 1, 0.36, 1),
        border-color 0.22s ease,
        background 0.22s ease;
    text-align: center;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    box-shadow: var(--glass-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
    transform:
        translateY(0)
        translateX(var(--mag-shift-x))
        translateY(var(--mag-shift-y))
        rotateX(var(--mag-rotate-x))
        rotateY(var(--mag-rotate-y))
        scale(1);
    transform-style: preserve-3d;
    will-change: transform;
}

.action-card-stats::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(circle at 100% 0%, var(--accent-edge-soft), transparent 42%);
    opacity: 0;
    transition: opacity 0.28s ease;
    pointer-events: none;
}

.action-card-stats:hover {
    background: var(--glass-card-hover);
    border-color: var(--accent-edge);
    transform:
        translateY(-5px)
        translateX(var(--mag-shift-x))
        translateY(var(--mag-shift-y))
        rotateX(var(--mag-rotate-x))
        rotateY(var(--mag-rotate-y))
        scale(1.018);
    box-shadow:
        0 22px 44px rgba(0, 0, 0, 0.34),
        0 0 0 1px rgba(74, 222, 128, 0.1),
        0 0 20px var(--accent-glow);
}

.action-card-stats:hover::after {
    opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
    .action-card,
    .action-card:hover,
    .action-card-stats,
    .action-card-stats:hover {
        transform: none;
    }
}

/* === BUTTONS === */
button {
    padding: 12px 24px;
    font-size: 14px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    color: var(--text);
    transition:
        transform 0.2s cubic-bezier(0.22, 1, 0.36, 1),
        box-shadow 0.22s ease,
        border-color 0.2s ease,
        background 0.2s ease,
        color 0.2s ease;
    font-family: var(--sans);
}
button:hover {
    transform: translateY(-2px) scale(1.035);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22);
}
button:active { transform: translateY(0) scale(0.99); }
button:disabled { opacity: 0.4; }

.difficulty-btn {
    padding: 14px 24px;
    font-size: 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.04) 0%, rgba(255, 255, 255, 0.01) 100%),
        var(--card);
    color: var(--text);
    font-weight: 600;
    transition:
        transform 0.2s cubic-bezier(0.22, 1, 0.36, 1),
        box-shadow 0.24s ease,
        border-color 0.2s ease,
        background 0.2s ease,
        color 0.2s ease;
    text-align: center;
    font-family: var(--sans);
}
.difficulty-btn:hover {
    background: var(--accent);
    color: #000000;
    border-color: var(--accent);
    transform: translateY(-2px) scale(1.03);
    box-shadow:
        0 14px 28px rgba(0, 0, 0, 0.24),
        0 0 18px var(--accent-glow-strong),
        0 0 32px rgba(34, 197, 94, 0.2);
}
.difficulty-btn:active { transform: translateY(0) scale(0.99); }

/* === INPUT FIELDS === */
input[type="text"],
input[type="password"],
input[type="number"] {
    width: 100%;
    max-width: 280px;
    padding: 14px 16px;
    font-size: 15px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.1s;
    text-align: center;
    font-family: var(--sans);
}
input[type="text"]::placeholder,
input[type="password"]::placeholder,
input[type="number"]::placeholder {
    color: var(--muted);
}
input[type="text"]:hover,
input[type="password"]:hover,
input[type="number"]:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}
input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
    transform: translateY(-1px);
}

/* === GAME AREA (#14) === */
#gameContainer { display: none; }

/* When JS sets display:grid the three-column layout activates */
#gameContainer[style*="grid"] {
    /* layout is set inline by JS; these rules apply when visible */
    grid-template-columns: 150px 1fr 150px;
    grid-template-rows: 1fr auto;
    flex: 1;
    min-height: 0;
    width: calc(100% + 40px);
    max-width: none;
    margin-left: -20px;
    margin-right: -20px;
    padding: 0;
}

/* ── Left sidebar ── */
#gameSidebar {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
    padding: 24px 12px;
}

.sidebar-stat {
    text-align: center;
    padding: 0;
}

.sidebar-sublabel {
    margin-top: 6px;
    font-size: 10px;
}

/* Keep streak accent on sidebar */
#streak-card .stat-value { color: var(--warning); }

/* ── Center: question ── */
#gameCenter {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 40px;
    overflow: hidden;
    min-height: 0;
}

/* ── Right sidebar ── */
#gameRightBar {
    grid-column: 3;
    grid-row: 1;
}

/* ── Bottom bar ── */
#gameBottomBar {
    grid-column: 1 / 4;
    grid-row: 2;
    padding: 16px 24px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

/* ── Old game-section — no longer needed but keep for safety ── */
.game-section {
    background: transparent;
    border-radius: 0;
    padding: 0;
    border: none;
    width: 100%;
}

/* Answer input redesign (#14) */
.controls {
    margin-top: 0;
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

.controls #answer {
    flex: 1;
    max-width: 480px;
    font-family: var(--mono);
    font-size: 16px;
    padding: 14px 20px;
    text-align: left;
    letter-spacing: -0.3px;
    border-radius: 10px;
}

/* MathLive math-field overrides */
math-field#answer {
    display: block;
    min-height: 52px;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
    /* MathLive accent colours */
    --caret-color: var(--accent);
    --selection-background-color: rgba(34, 197, 94, 0.25);
    --selection-color: var(--text);
    --primary-color: var(--accent);
    --text-font-family: var(--mono);
    /* Fix: fraction/structure highlight defaults to near-white — use subtle dark tint instead */
    --contains-highlight-background-color: rgba(34, 197, 94, 0.07);
}

math-field#answer:focus,
math-field#answer.has-value {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

/* === MATHLIVE VIRTUAL KEYBOARD DARK THEME === */
/* CSS custom properties pierce the shadow DOM, so these reliably override MathLive defaults */
math-virtual-keyboard {
    /* Panel */
    --keyboard-background:              var(--surface);
    --keyboard-border:                  1px solid var(--border);
    /* Toolbar strip (layer tabs at the top) */
    --keyboard-toolbar-background:      var(--bg);
    --keyboard-toolbar-text:            var(--text-secondary);
    --keyboard-toolbar-text-active:     var(--accent);
    --keyboard-toolbar-rule:            var(--border);
    /* Key caps */
    --keycap-height:                    44px;
    --keycap-font-size:                 15px;
    --keycap-background:                var(--card);
    --keycap-border:                    var(--border);
    --keycap-text:                      var(--text);
    --keycap-secondary-text:            var(--muted);
    /* Pressed state */
    --keycap-background-active:         var(--accent);
    --keycap-text-active:               #000000;
    /* Modifier / special keys (shift, backspace, arrows) */
    --keycap-modifier-background:       var(--card-light);
    --keycap-modifier-border:           var(--border);
    --keycap-modifier-text:             var(--text-secondary);
    z-index: 2000;
}

#submitBtn,
#submitBtnDraw {
    background: var(--accent);
    color: #000000;
    padding: 14px 28px;
    font-size: 14px;
    font-weight: 700;
    border-radius: 10px;
    border: none;
    letter-spacing: 0.3px;
    box-shadow: 0 4px 16px var(--accent-glow-strong);
}
#submitBtn:hover,
#submitBtnDraw:hover {
    box-shadow: 0 8px 24px var(--accent-glow-strong);
    transform: translateY(-2px);
}

#nextBtn {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    box-shadow: none;
    padding: 14px 20px;
    font-size: 13px;
    border-radius: 10px;
}
#nextBtn:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-1px);
}

#result {
    margin-top: 20px;
    font-size: 16px;
    font-weight: 600;
    min-height: 24px;
    font-family: var(--mono);
    letter-spacing: -0.3px;
}

/* === INPUT MODE TOGGLE === */
.input-mode-toggle {
    display: flex;
    gap: 4px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 3px;
    flex-shrink: 0;
}

.mode-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 16px;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    cursor: none !important;
    padding: 0;
}

.mode-btn.active {
    background: var(--accent);
    color: #000;
}

.mode-btn:hover:not(.active) {
    color: var(--text);
    background: var(--card-hover);
}

/* === HANDWRITING CANVAS === */
#typeInputWrapper {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* === MATH INPUT TOOLBAR === */
.math-toolbar {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    align-items: center;
}

.math-btn {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-family: var(--mono);
    font-size: 12px;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: none !important;
    transition: background 0.12s, color 0.12s, border-color 0.12s, transform 0.1s;
    line-height: 1.2;
    white-space: nowrap;
    font-weight: 500;
    min-width: 34px;
    text-align: center;
}

.math-btn sup, .math-btn sub {
    font-size: 9px;
}

.math-btn:hover {
    background: var(--card-hover);
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-1px);
}

.math-btn:active {
    transform: translateY(0);
}

.math-toolbar-sep {
    width: 1px;
    height: 22px;
    background: var(--border);
    flex-shrink: 0;
    margin: 0 2px;
}

#drawInputWrapper {
    flex: 1;
    min-width: 0;
}

.controls--draw {
    max-width: 1100px;
}

.canvas-section-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 4px;
}

.handwriting-canvas-container {
    position: relative;
    width: 100%;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    transition: height 0.3s ease;
}

.working-canvas-container {
    height: 260px;
}

.answer-canvas-container {
    height: 110px;
}

.handwriting-canvas-container canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    cursor: crosshair !important;
}

/* Suppress text selection everywhere while in draw mode.
   Prevents Safari/iPadOS from selecting adjacent text during canvas strokes. */
body.draw-mode,
body.draw-mode * {
    -webkit-user-select: none !important;
    user-select: none !important;
}

.canvas-controls {
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    gap: 4px;
    align-items: center;
    z-index: 2;
}

.canvas-expand-btn {
    display: block;
    width: 100%;
    margin-top: 4px;
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--muted);
    font-size: 12px;
    padding: 5px 8px;
    border-radius: 6px;
    cursor: none !important;
    transition: color 0.15s, border-color 0.15s;
    font-family: var(--sans);
    letter-spacing: 0.3px;
}

.canvas-expand-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Diagram drawing overlay ─────────────────────── */
.diagram-wrapper {
    position: relative;
    display: inline-block;
    max-width: 100%;
    margin: 0 auto 15px;
    border-radius: 8px;
    overflow: hidden;
}

.diagram-img {
    display: block;
    max-width: 100%;
    max-height: 420px;
    height: auto;
    width: auto;
    border-radius: 8px;
}

.diagram-overlay-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: crosshair;
    touch-action: none;
}

.diagram-toolbar {
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    gap: 4px;
    background: rgba(0,0,0,0.55);
    border-radius: 8px;
    padding: 4px;
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
}

.diagram-wrapper:hover .diagram-toolbar,
.diagram-wrapper:focus-within .diagram-toolbar {
    opacity: 1;
    pointer-events: auto;
}

.diagram-tool-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 5px;
    color: #fff;
    font-size: 14px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background 0.1s, border-color 0.1s;
}

.diagram-tool-btn:hover,
.diagram-tool-btn.active {
    background: rgba(255,255,255,0.15);
    border-color: rgba(255,255,255,0.4);
}

/* ── Answer-input canvas controls ────────────────── */
.canvas-ctrl-btn {
    background: var(--card-hover);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    cursor: none !important;
    padding: 0;
}

.canvas-ctrl-btn:hover {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
}

.stroke-width-slider {
    display: flex;
    align-items: center;
}

.stroke-width-slider input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 60px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: none !important;
}

.stroke-width-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 50%;
    cursor: none !important;
}

/* === QUESTION DISPLAY === */
.question-area {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    overflow: hidden;
    margin: 12px 0;
}
#question {
    font-size: 17px !important;
    font-weight: 400 !important;
    line-height: 1.7;
    margin: 0;
    color: var(--text);
    letter-spacing: normal;
    width: 100%;
    visibility: visible !important;
    display: block !important;
    opacity: 1 !important;
    z-index: 10;
    overflow-wrap: break-word;
    word-wrap: break-word;
    text-align: center;
}

/* Question slide animation (#20) */
.question-slide-in {
    animation: questionSlideIn 0.2s ease-out;
}
@keyframes questionSlideIn {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}
.question-shake {
    animation: questionShake 0.3s ease-out;
}
@keyframes questionShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* KaTeX */
#question .katex { font-size: 1.4em !important; color: inherit; max-width: 100%; }
#question .katex-html { display: inline-block; max-width: 100%; overflow: visible; vertical-align: middle; }
#question .katex-display { margin: 0.7em auto; overflow: visible; max-width: 100%; text-align: center; padding: 0.3em 0; }
#question .katex-display > .katex { font-size: 2em !important; }

html.light-mode #question { color: #0a0a0a; }

/* === PRACTICE HUD STRIP (#18) === */
.stats-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 32px;
    margin: 16px auto;
    padding: 12px 24px;
    max-width: 720px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.stat-card {
    text-align: center;
    transition: all 0.2s ease;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
}

.stat-label {
    color: var(--muted);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 2px;
    font-family: var(--sans);
}

.stat-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    font-family: var(--mono);
    letter-spacing: -0.5px;
}

/* Streak card accent */
#streak-card .stat-value { color: var(--warning); }

/* Level indicator bars (#21) */
.level-bars {
    display: flex;
    gap: 3px;
    justify-content: center;
    margin-top: 4px;
}
.level-bar {
    width: 12px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    transition: background 0.3s, box-shadow 0.3s;
}
.level-bar.filled {
    background: var(--accent);
    box-shadow: 0 0 6px var(--accent-glow);
}

/* === COMPETITIVE SCORE - PROGRESS RAIL (#13) === */
#competitiveScore {
    margin: 0 auto 16px;
    max-width: 600px;
}

.progress-rail {
    display: flex;
    align-items: center;
    gap: 0;
    height: 32px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
}

.progress-rail-segment {
    flex: 1;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    transition: all 0.3s ease;
    border-right: 1px solid var(--border);
    position: relative;
}
.progress-rail-segment:last-child { border-right: none; }

.progress-rail-segment.won {
    background: var(--accent);
    color: #000000;
}
.progress-rail-segment.lost {
    background: var(--wrong);
    color: #ffffff;
}
.progress-rail-segment.tie {
    background: var(--muted);
    color: #ffffff;
}

.progress-rail-names {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    padding: 0 4px;
}
.progress-rail-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.progress-rail-name .win-count {
    font-family: var(--mono);
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
}

/* Competitive round win circles */
.comp-score-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px 0 4px;
    width: 100%;
}
.comp-score-name {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 60px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 110px;
}
.comp-score-circles {
    display: flex;
    gap: 7px;
    align-items: center;
}
.comp-score-vs {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 0 4px;
}
.progress-circle {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--border);
    display: inline-block;
    transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}
.progress-circle.won {
    background: #22c55e;
    border-color: #22c55e;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.45);
}
.progress-circle.lost {
    background: #ef4444;
    border-color: #ef4444;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}
.progress-circle.empty { background: transparent; }
.progress-circle.submitted {
    background: transparent;
    border-color: var(--muted);
    animation: submittedPulse 1.4s ease-in-out infinite;
}
@keyframes submittedPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* === MATCHMAKING SCREEN (#26) === */
#matchmakingContainer {
    max-width: 480px;
}

.matchmaking-radar {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 40px auto;
}
.matchmaking-radar .radar-ring {
    position: absolute;
    top: 50%; left: 50%;
    border: 2px solid var(--accent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    animation: radarPing 2s ease-out infinite;
    opacity: 0;
}
.matchmaking-radar .radar-ring:nth-child(1) { animation-delay: 0s; }
.matchmaking-radar .radar-ring:nth-child(2) { animation-delay: 0.5s; }
.matchmaking-radar .radar-ring:nth-child(3) { animation-delay: 1s; }
@keyframes radarPing {
    0% { width: 20px; height: 20px; opacity: 0.8; }
    100% { width: 120px; height: 120px; opacity: 0; }
}
.matchmaking-radar .radar-center {
    position: absolute;
    top: 50%; left: 50%;
    width: 8px; height: 8px;
    background: var(--accent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 12px var(--accent-glow-strong);
}

.matchmaking-status {
    font-family: var(--mono);
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 32px;
    letter-spacing: 0.5px;
}

/* Spinner (keep for compat) */
.spinner {
    width: 60px; height: 60px;
    border: 3px solid var(--border);
    border-top: 3px solid var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
    display: none;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* === MATCH END SCREEN (#17) === */
.match-end-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
    backdrop-filter: blur(8px);
}
.match-end-result {
    font-size: 56px;
    font-weight: 900;
    letter-spacing: -2px;
    margin-bottom: 8px;
    font-family: var(--sans);
}
.match-end-result.victory { color: var(--accent); }
.match-end-result.defeat { color: var(--wrong); }
.match-end-result.draw { color: #f97316; }
.match-end-score {
    font-family: var(--mono);
    font-size: 24px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 24px;
}
.match-end-rating {
    font-family: var(--mono);
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 32px;
}
.match-end-rating.positive { color: var(--accent); }
.match-end-rating.negative { color: var(--wrong); }
.match-end-buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.match-end-btn {
    min-width: 160px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    cursor: pointer;
    transition: opacity 0.15s ease, transform 0.1s ease;
    background: rgba(255,255,255,0.08);
    color: var(--text);
}
.match-end-btn:hover { opacity: 0.8; transform: translateY(-1px); }
.match-end-btn:disabled { opacity: 0.45; cursor: default; transform: none; }

.match-end-btn--rematch {
    background: var(--accent);
    color: #000;
}
.match-end-forfeit-label {
    font-size: 13px;
    font-family: var(--mono);
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--wrong);
    opacity: 0.7;
    margin-bottom: 6px;
}

/* === FORFEIT CONFIRMATION MODAL === */
.forfeit-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    animation: fadeIn 0.15s ease-out;
}
.forfeit-modal-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px 28px 24px;
    width: 100%;
    max-width: 340px;
    text-align: center;
    box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.forfeit-modal-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 10px;
    letter-spacing: -0.5px;
}
.forfeit-modal-body {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}
.forfeit-modal-rating {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 10px;
    margin-bottom: 24px;
    font-family: var(--mono);
}
.forfeit-modal-delta {
    font-size: 28px;
    font-weight: 700;
}
.forfeit-modal-delta.negative { color: var(--wrong); }
.forfeit-modal-arrow {
    font-size: 16px;
    color: var(--muted);
}
.forfeit-modal-newrating {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-secondary);
}
.forfeit-modal-actions {
    display: flex;
    gap: 10px;
}
.forfeit-modal-actions .difficulty-btn {
    flex: 1;
    margin: 0;
}

/* === ANTI-CHEAT OVERLAY === */
.anticheat-overlay {
    position: fixed;
    inset: 0;
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    cursor: pointer;
    color: #fff;
    text-align: center;
    animation: fadeIn 0.15s ease-out;
}

/* === VS INTRO SCREEN (#12) === */
.vs-intro {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--bg);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
}
.vs-intro-content {
    display: flex;
    align-items: center;
    gap: 48px;
}
.vs-intro-player {
    text-align: center;
}
.vs-intro-name {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}
.vs-intro-rating {
    font-family: var(--mono);
    font-size: 16px;
    color: var(--text-secondary);
}
.vs-intro-divider {
    font-size: 32px;
    font-weight: 900;
    color: var(--accent);
    letter-spacing: -1px;
}

/* === SESSION STATS OVERLAY === */
.session-stats-overlay {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%) translateY(40px);
    opacity: 0;
    pointer-events: none;
    display: none;
    z-index: 1000;
    transition: opacity 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    backdrop-filter: blur(4px);
}
.session-stats-overlay.active {
    opacity: 1;
    transform: translate(-50%, -50%) translateY(0);
    pointer-events: auto;
    display: block;
}
.session-stats-content {
    background: var(--card);
    border: 1px solid var(--accent);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.9);
    max-width: 420px;
    width: 90vw;
}
.overlay-stat {
    background: var(--card-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    text-align: center;
}
.overlay-stat .stat-label {
    font-size: 10px;
    color: var(--muted);
    margin-bottom: 4px;
}
.overlay-stat .stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
}

/* === META BAR === */
#meta {
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 0;
    font-size: 12px;
    display: none;
    font-family: var(--mono);
}

/* === STATS PAGES (#22) === */
.stats-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
}
.stats-tab-btn {
    padding: 12px 20px;
    background: transparent;
    color: var(--muted);
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s ease;
    font-family: var(--sans);
}
.stats-tab-btn:hover { color: var(--text-secondary); transform: none; }
.stats-tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.stats-tab-content {
    display: none;
    animation: pageIn 0.25s ease-out;
    width: 100%;
}
.stats-tab-content.active { display: block; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 32px;
    max-width: 960px;
    margin-left: auto;
    margin-right: auto;
}

#statsContainer .stats-tabs,
#competitiveStatsContainer .stats-tabs {
    margin-left: auto;
    margin-right: auto;
    max-width: 960px;
    padding: 0;
}

.stat-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px 16px;
    text-align: center;
    transition: all 0.2s ease;
}
.stat-box:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}
.stat-box .stat-label { font-size: 10px; color: var(--muted); margin-bottom: 6px; }
.stat-box .stat-value { font-size: 22px; font-weight: 700; color: var(--accent); font-family: var(--mono); }

/* Charts */
#sessionRatingChart, #historyRatingChart, #competitiveHistoryRatingChart {
    max-width: 100%; width: 100%; display: block;
    margin-left: auto; margin-right: auto; height: auto;
}

#sessionLevelTime, #historyLevelTime {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}

.level-time-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    font-size: 13px;
    transition: all 0.2s ease;
}
.level-time-box:hover { border-color: var(--accent); }
.level-time-box .label { color: var(--muted); margin-bottom: 4px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.level-time-box .value { font-size: 16px; font-weight: 700; color: var(--accent); font-family: var(--mono); }

/* === LEADERBOARD === */
#leaderboardContainer {
    background: transparent;
    padding: 20px;
    max-width: 960px;
    margin-left: auto; margin-right: auto;
    width: 100%;
}
#leaderboardContainer h2 {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 24px;
    color: var(--text);
}

.leaderboard-entry {
    display: grid;
    grid-template-columns: 48px 1fr 100px;
    gap: 16px;
    align-items: center;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 20px;
    font-size: 14px;
    transition: all 0.2s ease;
    margin-bottom: 8px;
}
.leaderboard-entry:hover {
    border-color: var(--accent);
    transform: translateX(4px);
}
.leaderboard-entry.top-1 { border-color: #fbbf24; }
.leaderboard-entry.top-2 { border-color: #9ca3af; }
.leaderboard-entry.top-3 { border-color: #d97706; }

.leaderboard-rank {
    font-weight: 700;
    text-align: center;
    font-size: 14px;
    font-family: var(--mono);
    color: var(--muted);
}
.leaderboard-entry.top-1 .leaderboard-rank { color: #fbbf24; }
.leaderboard-entry.top-2 .leaderboard-rank { color: #9ca3af; }
.leaderboard-entry.top-3 .leaderboard-rank { color: #d97706; }

.leaderboard-username { color: var(--text); font-weight: 500; display: flex; align-items: center; gap: 8px; }
.leaderboard-tier-badge {
    font-size: 10px;
    font-weight: 700;
    font-family: var(--mono);
    letter-spacing: 0.05em;
    opacity: 0.85;
}
.leaderboard-entry--me {
    border-color: var(--accent) !important;
    background: var(--accent-glow);
}
.leaderboard-entry--me .leaderboard-username { color: var(--accent); }
.leaderboard-rating {
    text-align: right;
    color: var(--accent);
    font-weight: 700;
    font-size: 15px;
    font-family: var(--mono);
}

/* === ADMIN PANEL === */
#adminContainer {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}
.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
}
.admin-title {
    font-size: 22px;
    font-weight: 800;
    margin: 0;
    color: var(--text);
}
.admin-loading {
    text-align: center;
    color: var(--muted);
    padding: 24px 0;
    font-size: 14px;
}
.admin-all-clear {
    background: rgba(34,197,94,0.1);
    border: 1px solid rgba(34,197,94,0.3);
    border-radius: 10px;
    padding: 12px 16px;
    color: #22c55e;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 24px;
}
.admin-flagged-section {
    margin-bottom: 28px;
}
.admin-flagged-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 10px;
}
.admin-flag-group {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 8px;
    font-size: 14px;
    border: 1px solid var(--border);
}
.flag-high { border-color: rgba(239,68,68,0.4); background: rgba(239,68,68,0.06); }
.flag-med  { border-color: rgba(234,179,8,0.4);  background: rgba(234,179,8,0.05); }
.admin-flag-badge { font-size: 12px; font-weight: 700; white-space: nowrap; }
.admin-flag-ip    { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.admin-flag-users { color: var(--text); }
.admin-flag-count { color: var(--muted); font-size: 12px; margin-left: 4px; }

.admin-table-wrap { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.admin-table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    background: rgba(255,255,255,0.02);
}
.admin-count { font-weight: 400; color: var(--muted); font-size: 12px; }
.admin-row {
    display: grid;
    grid-template-columns: 40px 1fr 90px 140px 90px 80px;
    gap: 0;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    align-items: center;
}
.admin-row:last-child { border-bottom: none; }
.admin-row--header {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    background: rgba(255,255,255,0.02);
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
}
.admin-row--flagged { background: rgba(239,68,68,0.04); }
.admin-cell-num  { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.admin-cell-name { font-weight: 600; color: var(--text); }
.admin-cell-muted { color: var(--muted); font-size: 12px; }
.admin-cell-mono  { font-family: var(--mono); font-size: 12px; color: var(--text-secondary); }
.admin-cell-flags { display: flex; gap: 4px; }
.admin-flag-tag {
    font-size: 10px;
    font-weight: 700;
    font-family: var(--mono);
    padding: 2px 5px;
    border-radius: 4px;
    cursor: default;
}
.flag-ip { background: rgba(234,179,8,0.15);  color: #eab308; }
.flag-fp { background: rgba(249,115,22,0.15); color: #f97316; }

/* === ADMIN FULL LEADERBOARD === */
#adminLeaderboardContainer {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}
.admin-lb-row {
    grid-template-columns: 40px 1fr 100px 70px 70px 60px 70px 90px;
}
.admin-lb-tier { font-size: 11px; font-weight: 800; letter-spacing: 0.04em; }
.admin-row--me { background: rgba(99,102,241,0.08); }
.admin-row--top .admin-cell-num { color: #ffd740; font-weight: 700; }

/* === ADMIN PLATFORM STATS === */
#adminStatsContainer {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}
.as-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 32px;
}
.as-card {
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 14px;
    text-align: center;
    transition: border-color 0.2s;
}
.as-card:hover { border-color: var(--accent); }
.as-card-icon { font-size: 20px; margin-bottom: 6px; }
.as-card-value {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
    font-family: var(--mono);
    line-height: 1.1;
}
.as-card-label {
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.as-section {
    margin-bottom: 32px;
}
.as-section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 12px 0;
}
.as-chart-wrap {
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    height: 260px;
    position: relative;
}
.as-chart-wrap canvas {
    width: 100% !important;
    height: 100% !important;
}
.admin-cohort-row {
    grid-template-columns: 120px 60px repeat(4, 1fr);
}
.as-cohort-cell {
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    padding: 4px 8px;
    border-radius: 6px;
    color: var(--text);
}
.admin-top-row {
    grid-template-columns: 40px 1fr 80px 70px 80px 80px;
}
.admin-recent-row {
    grid-template-columns: 40px 1fr 100px 70px 70px 90px;
}

/* === MAINTENANCE SCREEN === */
#maintenanceContainer {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    z-index: 9999;
    padding: 24px;
}
.maintenance-box {
    max-width: 480px;
    width: 100%;
    text-align: center;
}
.maintenance-icon {
    font-size: 48px;
    margin-bottom: 24px;
    opacity: 0.6;
}
.maintenance-title {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    margin: 0 0 20px 0;
    letter-spacing: -0.02em;
}
.maintenance-body {
    font-size: 15px;
    color: var(--text-secondary);
    margin: 0 0 12px 0;
    line-height: 1.6;
}
.maintenance-body strong { color: var(--text); }
.maintenance-sub {
    font-size: 13px;
    color: var(--muted);
    margin: 20px 0 0 0;
    font-family: var(--mono);
}

/* === BETA INFO === */
#betaInfo { color: var(--text-secondary); font-family: var(--mono); font-size: 11px; opacity: 0.4; }
html.light-mode #betaInfo { color: var(--text-secondary); }

/* === QUESTION ID === */
#questionIdDisplay {
    position: fixed;
    bottom: 10px; left: 10px;
    font-family: var(--mono);
    font-size: 11px;
    color: var(--muted);
    opacity: 0.3;
    z-index: 100;
    pointer-events: auto;
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    cursor: text !important;
}

/* === NUMBER ANIMATION (#29) === */
.number-animate {
    transition: transform 0.15s ease;
}
.number-animate.bump {
    transform: scale(1.15);
}

/* === ANIMATIONS === */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* === DIFFICULTY SELECTOR (legacy support) === */
.difficulty-selector {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-top: 32px;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

/* === QUESTION IMAGE === */
#questionImage {
    max-width: 100%;
    max-height: 420px;
    border-radius: 8px;
    margin: 12px auto;
    display: block;
}

/* === TIMER === */
#timer {
    font-family: var(--mono);
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
}

/* === TYPING PULSE (#3) === */
#answer:not(:placeholder-shown),
math-field#answer.has-value {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

/* === ROUND RESULT FLASH (#16) === */
.round-flash {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 999;
    animation: roundFlash 0.4s ease-out forwards;
}
.round-flash.correct {
    background: radial-gradient(ellipse at center, rgba(34, 197, 94, 0.15) 0%, transparent 70%);
}
.round-flash.wrong {
    background: radial-gradient(ellipse at center, rgba(239, 68, 68, 0.15) 0%, transparent 70%);
}
@keyframes roundFlash {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* === FEEDBACK MODAL === */
.feedback-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.6);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}
.feedback-overlay.open { opacity: 1; }
.feedback-modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}
.feedback-modal h3 {
    margin: 0 0 6px;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}
.feedback-modal p {
    margin: 0 0 16px;
    font-size: 13px;
    color: var(--muted);
}
.feedback-modal textarea {
    width: 100%;
    min-height: 100px;
    padding: 12px 14px;
    font-size: 14px;
    font-family: var(--sans);
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    outline: none;
    resize: vertical;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.feedback-modal textarea:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}
.feedback-modal textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.feedback-modal textarea::placeholder { color: var(--muted); }
.feedback-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 14px;
}
.feedback-actions button {
    padding: 10px 20px;
    font-size: 13px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text-secondary);
    font-weight: 600;
}
.feedback-actions button:hover {
    border-color: var(--accent);
}
.feedback-actions .feedback-submit {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}
.feedback-actions .feedback-submit:hover {
    box-shadow: 0 4px 16px var(--accent-glow-strong);
}

/* No mobile cursor detection — custom cursor shown on all devices */

/* ===== WAITLIST MODAL ===== */
.waitlist-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.2s;
}
.waitlist-modal-overlay.open { opacity: 1; }
.waitlist-modal {
    position: relative;
    width: 360px;
    max-width: 92vw;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 40px 32px 32px;
    text-align: center;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}
.waitlist-modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
}
.waitlist-modal-close:hover { color: var(--text); }
.waitlist-modal-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent);
    margin: 0 0 12px;
}
.waitlist-modal-lead {
    font-size: 15px;
    color: var(--text-secondary);
    margin: 0 0 22px;
    line-height: 1.6;
}
.waitlist-modal-input {
    display: block;
    width: 100%;
    padding: 12px 14px;
    font-size: 14px;
    font-family: var(--sans);
    background: var(--card-light, var(--card));
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    margin: 0 0 10px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}
.waitlist-modal-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.waitlist-modal-input::placeholder { color: var(--muted); }
.waitlist-modal-btn {
    display: block;
    width: 100%;
    padding: 13px;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--sans);
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: 10px;
    transition: opacity 0.2s;
    margin: 0 0 8px;
}
.waitlist-modal-btn:hover { opacity: 0.85; }
.waitlist-modal-btn:disabled { opacity: 0.5; }
.waitlist-modal-error {
    font-size: 13px;
    color: var(--wrong);
    margin: 6px 0 0;
    min-height: 18px;
}
.waitlist-modal-privacy {
    font-size: 11px;
    color: var(--muted);
    margin: 14px 0 0;
    line-height: 1.5;
}
.waitlist-modal-dismiss {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 22px;
    font-size: 13px;
    color: var(--text-secondary);
    font-family: var(--sans);
    transition: border-color 0.2s;
}
.waitlist-modal-dismiss:hover { border-color: var(--accent); }
html.is-mobile .waitlist-modal-input,
html.is-mobile .waitlist-modal-btn { font-size: 16px; padding: 14px; }

/* ===== UPGRADE MODAL ===== */
/* ===== UPGRADE MODAL (redesigned) ===== */
.upgrade-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.upgrade-modal {
    position: relative;
    width: 400px;
    max-width: 94vw;
    background: #080808;
    border: 1px solid rgba(34, 197, 94, 0.25);
    border-radius: 20px;
    padding: 36px 32px 28px;
    text-align: center;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.04), 0 32px 80px rgba(0, 0, 0, 0.8), 0 0 60px rgba(34,197,94,0.06);
}
html.light-mode .upgrade-modal {
    background: #ffffff;
    border-color: rgba(34, 197, 94, 0.3);
    box-shadow: 0 32px 80px rgba(0,0,0,0.18);
}
.upgrade-modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 22px;
    cursor: none !important;
    line-height: 1;
    padding: 4px 6px;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
}
.upgrade-modal-close:hover { color: var(--text); background: var(--border); }

/* Badge */
.upgrade-modal-badge {
    display: inline-block;
    padding: 3px 12px;
    border-radius: 20px;
    border: 1px solid var(--accent);
    color: var(--accent);
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.15em;
    margin-bottom: 14px;
    text-transform: uppercase;
}

/* Trigger line (contextual copy) */
.upgrade-modal-trigger-text {
    font-size: 12px;
    color: var(--muted);
    font-family: var(--mono);
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.upgrade-modal-title {
    font-family: var(--sans);
    font-size: 22px;
    font-weight: 900;
    color: var(--text);
    margin: 0 0 20px;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

/* Feature list */
.upgrade-modal-features {
    list-style: none;
    margin: 0 0 22px;
    padding: 0;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.upgrade-modal-features li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 13.5px;
    color: var(--text-secondary);
    font-family: var(--sans);
    line-height: 1.4;
}
.upgrade-feat-check {
    color: var(--accent);
    font-size: 13px;
    font-weight: 800;
    flex-shrink: 0;
    margin-top: 1px;
}

/* Price row */
.upgrade-modal-price-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 12px;
    padding: 14px;
    background: rgba(34,197,94,0.06);
    border: 1px solid rgba(34,197,94,0.12);
    border-radius: 12px;
}
.upgrade-modal-price-was {
    font-family: var(--mono);
    font-size: 14px;
    font-weight: 500;
    color: var(--muted);
    text-decoration: line-through;
}
.upgrade-modal-price {
    font-family: var(--mono);
    font-size: 30px;
    font-weight: 800;
    color: var(--accent);
}
.upgrade-modal-period {
    font-size: 14px;
    font-weight: 500;
    color: var(--muted);
}
.upgrade-modal-price-note {
    font-size: 11px;
    color: var(--muted);
    font-family: var(--mono);
    border-left: 1px solid var(--border);
    padding-left: 10px;
}
.upgrade-modal-coupon {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
    padding: 10px 14px;
    background: rgba(251,191,36,0.07);
    border: 1px dashed rgba(251,191,36,0.35);
    border-radius: 10px;
    font-size: 13px;
}
.upgrade-modal-coupon-label { color: var(--muted); }
.upgrade-modal-coupon-code {
    font-family: var(--mono);
    font-weight: 800;
    font-size: 15px;
    color: #fbbf24;
    letter-spacing: 0.08em;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 6px;
    background: rgba(251,191,36,0.12);
    transition: background 0.15s;
}
.upgrade-modal-coupon-code:hover { background: rgba(251,191,36,0.22); }
.upgrade-modal-coupon-code.copied::after {
    content: ' ✓';
    color: #22c55e;
}

/* ── Promo banner on home page ── */
.promo-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 10px 20px;
    background: linear-gradient(90deg, rgba(251,191,36,0.1), rgba(34,197,94,0.08));
    border-bottom: 1px solid rgba(251,191,36,0.2);
    font-size: 13px;
    line-height: 1.4;
    text-align: center;
}
.promo-banner-tag {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.1em;
    color: #fbbf24;
    background: rgba(251,191,36,0.15);
    padding: 2px 7px;
    border-radius: 4px;
    border: 1px solid rgba(251,191,36,0.3);
    white-space: nowrap;
}
.promo-banner-text { color: var(--text-secondary); }
.promo-banner-code {
    font-family: var(--mono);
    font-weight: 700;
    color: #fbbf24;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: underline;
    text-underline-offset: 3px;
}
.promo-banner-code:hover { color: #f59e0b; }

.upgrade-modal-btn {
    display: block;
    width: 100%;
    padding: 14px;
    margin-bottom: 10px;
    border-radius: 12px;
    border: none;
    background: var(--accent);
    color: #000;
    font-family: var(--sans);
    font-size: 15px;
    font-weight: 700;
    cursor: none !important;
    transition: background 0.2s, box-shadow 0.2s, transform 0.1s;
    letter-spacing: 0.01em;
}
.upgrade-modal-btn:hover {
    background: var(--accent-2);
    box-shadow: 0 0 24px var(--accent-glow-strong);
    transform: translateY(-1px);
}
.upgrade-modal-dismiss {
    display: block;
    width: 100%;
    padding: 8px;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 12px;
    cursor: none !important;
    font-family: var(--mono);
    letter-spacing: 0.04em;
    transition: color 0.15s;
}
.upgrade-modal-dismiss:hover { color: var(--text-secondary); }

.upgrade-coming-soon {
    background: rgba(255, 180, 0, 0.07);
    border: 1px solid rgba(255, 180, 0, 0.25);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 16px;
    text-align: center;
}
.upgrade-coming-soon-badge {
    display: inline-block;
    background: rgba(255, 180, 0, 0.18);
    color: #f5c400;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 4px;
    margin-bottom: 7px;
}
.upgrade-coming-soon-text {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.5;
}

/* Draw-mode button disabled state for free tier */
.mode-btn[disabled] {
    opacity: 0.4;
    pointer-events: auto;
    position: relative;
}

/* ===== UPGRADE TOP BUTTON ===== */
.upgrade-top-btn {
    height: 28px;
    padding: 0 11px;
    border-radius: 6px;
    border: 1px solid var(--accent);
    background: transparent;
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
    display: none;                  /* shown only when free tier */
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: all 0.2s ease;
    cursor: none !important;
    white-space: nowrap;
    flex-shrink: 0;
}
.upgrade-top-btn:hover {
    background: var(--accent);
    color: #000;
    box-shadow: 0 0 12px var(--accent-glow);
}

/* ===== CALCULATOR ===== */

/* Toggle button — top-right, beside the gear button */
.calc-toggle-btn {
    position: fixed;
    top: 16px;
    right: 60px;
    left: auto;
    z-index: 1001;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text-secondary);
    display: none;                  /* hidden until game screen */
    align-items: center;
    justify-content: center;
    font-size: 17px;
    transition: all 0.2s ease;
    padding: 0;
    cursor: none !important;
}
.calc-toggle-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}
.calc-toggle-btn.calc-toggle--active {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
    box-shadow: 0 0 12px var(--accent-glow-strong);
}

/* Modal shell */
.calc-modal {
    position: fixed;
    top: 60px;
    right: 16px;
    left: auto;
    z-index: 2000;
    width: 300px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.04);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: none;
    flex-direction: column;
    overflow: hidden;
    user-select: none;
}
.calc-modal--open { display: flex; }

/* Draggable header */
.calc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px 8px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    cursor: grab;
}
.calc-header:active { cursor: grabbing; }
.calc-title {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--accent);
}
.calc-close {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 13px;
    cursor: none !important;
    padding: 2px 4px;
    border-radius: 4px;
    line-height: 1;
    transition: color 0.15s;
}
.calc-close:hover { color: var(--wrong); }

/* Display */
.calc-display {
    padding: 10px 14px 8px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    min-height: 64px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-end;
    gap: 2px;
}
.calc-expr {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--muted);
    min-height: 14px;
    word-break: break-all;
    text-align: right;
}
.calc-result {
    font-family: var(--mono);
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.5px;
    word-break: break-all;
    text-align: right;
    line-height: 1.1;
}

/* Keypad grid — 6 columns */
.calc-keypad {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1px;
    background: var(--border);
    border-top: 1px solid var(--border);
}

/* Keys */
.calc-key {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--card);
    border: none;
    color: var(--text);
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 600;
    padding: 0;
    height: 42px;
    cursor: none !important;
    transition: background 0.1s, color 0.1s;
    position: relative;
    line-height: 1;
    gap: 1px;
}
.calc-key:hover   { background: var(--card-hover); }
.calc-key:active  { background: var(--card-light); }

/* Shift label — small, above main label */
.calc-label-shift {
    font-size: 8px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.3px;
    line-height: 1;
    transition: opacity 0.15s;
    opacity: 0;
    position: absolute;
    top: 5px;
}
.calc-label-main {
    font-size: 13px;
    transition: opacity 0.15s;
    line-height: 1;
}

/* Operator keys */
.calc-key--op {
    color: var(--accent);
    background: rgba(34, 197, 94, 0.06);
}
.calc-key--op:hover { background: rgba(34, 197, 94, 0.12); }

/* Function keys (trig, log, etc.) */
.calc-key--fn {
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--surface);
}
.calc-key--fn:hover { background: var(--card); }

/* Equals */
.calc-key--accent {
    background: var(--accent);
    color: #000;
    font-size: 18px;
}
.calc-key--accent:hover  { background: var(--accent-2); }
.calc-key--accent:active { filter: brightness(0.9); }

/* AC / C */
.calc-key--danger {
    color: var(--wrong);
    background: rgba(239,68,68,0.06);
}
.calc-key--danger:hover { background: rgba(239,68,68,0.14); }

/* SHIFT */
.calc-key--shift {
    color: var(--accent);
    font-size: 10px;
    letter-spacing: 0.5px;
    background: rgba(34,197,94,0.06);
}
.calc-key--shift:hover { background: rgba(34,197,94,0.14); }
.calc-key--active {
    background: var(--accent) !important;
    color: #000 !important;
}

/* Numeric keys — slightly lighter background */
.calc-key--num { background: var(--card-light); }
.calc-key--num:hover { background: var(--card-hover); }

/* Ghost (spacer) */
.calc-key--ghost {
    background: var(--surface);
    pointer-events: none;
    opacity: 0;
}

/* === RESPONSIVE === */
@media (max-width: 1100px) {
    .home-dashboard {
        grid-template-columns: 1fr 1fr;
    }
    .dashboard-panel-identity { grid-column: 1; }
    .dashboard-actions-column  { grid-column: 1 / -1; order: -1; }
    .dashboard-panel-progression { grid-column: 2; }
}

@media (max-width: 768px) {
    .card { padding: 0 16px 32px; }
    .header { margin-bottom: 32px; padding: 20px 0 24px; }
    h1 { font-size: 32px; }
    .home-dashboard {
        grid-template-columns: 1fr;
        gap: 14px;
    }
    .dashboard-panel-identity,
    .dashboard-actions-column,
    .dashboard-panel-progression { grid-column: 1; order: unset; }
    /* Collapse sidebar layout on mobile */
    #gameContainer[style*="grid"] {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto auto auto !important;
        width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    #gameSidebar {
        grid-column: 1 !important;
        grid-row: 1 !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 12px 24px !important;
        padding: 12px 16px !important;
        border-right: none !important;
        border-bottom: none !important;
    }
    #gameCenter { grid-column: 1 !important; grid-row: 2 !important; padding: 16px !important; }
    #gameRightBar { display: none !important; }
    #gameBottomBar { grid-column: 1 !important; grid-row: 3 !important; }
    .question-area { min-height: 80px; }
    #question { font-size: 15px !important; max-width: 100%; }
    .stats-panel { flex-wrap: wrap; gap: 16px; padding: 12px 16px; }
    .action-cards { grid-template-columns: 1fr; max-width: 360px; }
    .action-cards-stats { grid-template-columns: 1fr; max-width: 360px; }
    .dashboard-actions-column .action-card--competitive { min-height: 140px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .player-bar { max-width: 100%; padding: 10px 12px 16px; gap: 10px; }
    .player-bar-username { font-size: 11px; }
    .player-bar-rank { font-size: 10px; padding: 4px 9px; }
    .player-bar-rating { font-size: 42px; }
    .rank-progression-header { flex-direction: column; align-items: flex-start; gap: 4px; }
    .rank-ladder-compact { justify-content: flex-start; }
    /* In-game on mobile: smaller pill, tucked in top-right */
    .player-bar.visible.in-game {
        top: auto;
        bottom: auto;
        right: 8px;
        top: 56px;
        transform: none;
        padding: 10px;
        min-width: 120px;
        font-size: 11px;
    }
    .controls { flex-direction: column; }
    .controls #answer { max-width: 100%; }
    .input-mode-toggle { align-self: center; }
    .handwriting-canvas-container { height: 150px; }
    .leaderboard-entry { grid-template-columns: 40px 1fr; gap: 12px; padding: 12px 16px; }
    .leaderboard-rating { grid-column: 2; text-align: left; }
    .vs-intro-content { flex-direction: column; gap: 24px; }
    input[type="text"], input[type="password"], input[type="number"] { max-width: 100%; }
}

@media (max-width: 480px) {
    h1 { font-size: 28px; }
    .question-area { min-height: 60px; }
    #question { font-size: 14px !important; }
    .stats-panel { flex-direction: column; gap: 12px; }
    .stats-grid { grid-template-columns: 1fr; }
    .match-end-result { font-size: 40px; }
}

/* ============================================================
   MOBILE PHONE OVERRIDES
   html.is-mobile is set by an inline <script> at the top of
   index.html / waitlist.html using UA detection:
     /Android.*Mobile|iPhone|iPod|IEMobile|Opera Mini|BlackBerry/
   This matches phones but NOT Surface Pro (Windows UA) or iPads.
   ============================================================ */

/* Hide the custom JS cursor — phones have no mouse pointer */
html.is-mobile #customCursor {
    display: none !important;
}

/* Restore natural cursor so tappable elements behave correctly
   (index.html sets cursor:none globally via body inline style +
   the universal CSS rule above; this re-enables it on phones) */
html.is-mobile *,
html.is-mobile *::before,
html.is-mobile *::after {
    cursor: auto !important;
}
html.is-mobile a,
html.is-mobile button,
html.is-mobile [role="button"],
html.is-mobile input,
html.is-mobile textarea,
html.is-mobile select {
    cursor: pointer !important;
}
html.is-mobile input[type="text"],
html.is-mobile input[type="password"],
html.is-mobile input[type="email"],
html.is-mobile input[type="number"],
html.is-mobile textarea {
    cursor: text !important;
}

/* ── index.html login form ── */

/* Widen the fixed-220px inputs/button to fill the screen nicely */
html.is-mobile #loginUsername,
html.is-mobile #loginPassword {
    width: 82% !important;
    max-width: 340px !important;
    /* font-size >= 16px prevents iOS from zooming in on input focus */
    font-size: 16px !important;
    padding: 14px !important;
}

html.is-mobile #loginForm .difficulty-btn {
    width: 82% !important;
    max-width: 340px !important;
    padding: 14px !important;
}

/* The "Get 10% off" link box */
html.is-mobile #loginForm > div {
    width: 82% !important;
    max-width: 340px !important;
}

/* Tighten card side-padding on small phones */
html.is-mobile .card {
    padding-left: 16px !important;
    padding-right: 16px !important;
}

/* ===== FRIENDS MODAL ===== */

.friends-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.2s;
}
.friends-modal-overlay.open { opacity: 1; }

.friends-modal {
    position: relative;
    width: 500px;
    max-width: 92vw;
    max-height: 85vh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 28px 24px 24px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}

.friends-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}
.friends-modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.3px;
}
.friends-modal-close {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--muted);
    padding: 2px 6px;
    line-height: 1;
    transition: color 0.15s;
}
.friends-modal-close:hover { color: var(--text); }

/* Tabs */
.friends-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}
.friends-tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: -1px;
    font-family: var(--sans);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: color 0.15s, border-color 0.15s;
    white-space: nowrap;
}
.friends-tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}
.friends-tab:hover { color: var(--text-secondary); }

/* Notification badge (shared by tabs + action card) */
.friends-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--wrong);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    font-family: var(--mono);
    line-height: 1;
}
/* Badge sitting next to the card title text */
.friends-card-badge-inline {
    vertical-align: middle;
    margin-left: 6px;
    font-size: 10px;
}

/* Add-friend row */
.friends-add-row {
    display: flex;
    gap: 8px;
    margin-bottom: 4px;
}
.friends-add-row input {
    flex: 1;
    min-width: 0;
    padding: 10px 14px;
    font-size: 14px;
    font-family: var(--sans);
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.friends-add-row input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.friends-add-row input::placeholder { color: var(--muted); }
.friends-add-row button {
    padding: 10px 18px;
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    font-family: var(--sans);
    white-space: nowrap;
    transition: opacity 0.2s;
    flex-shrink: 0;
}
.friends-add-row button:hover { opacity: 0.85; }
.friends-add-row button:disabled { opacity: 0.5; }

.friends-add-error {
    font-size: 12px;
    min-height: 16px;
    margin: 0 0 8px;
    color: var(--wrong);
}

/* Friend / request cards list */
.friends-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    max-height: 360px;
    padding-right: 2px;
}
.friends-empty {
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    padding: 36px 0;
}
.friends-loading {
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    padding: 24px 0;
}

.friends-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    gap: 12px;
    transition: border-color 0.2s;
    flex-shrink: 0;
}
.friends-card:hover { border-color: var(--border-hover); }

.friends-card-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}
.friends-card-username {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    font-family: var(--mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.friends-card-rank {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    font-family: var(--mono);
    text-transform: uppercase;
}
.friends-card-rating {
    font-size: 11px;
    color: var(--muted);
    font-family: var(--mono);
}
.friends-card-meta {
    font-size: 11px;
    color: var(--muted);
    font-family: var(--mono);
}

.friends-card-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.friends-card-action {
    padding: 6px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
    font-family: var(--sans);
    background: var(--card);
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
    transition: border-color 0.15s, color 0.15s, opacity 0.15s;
}
.friends-card-accept {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}
.friends-card-accept:hover { opacity: 0.85; }
.friends-card-decline:hover,
.friends-card-remove:hover,
.friends-card-cancel:hover {
    border-color: var(--wrong);
    color: var(--wrong);
}

/* Friends action card — spans full width of the action-cards grid */
.action-card--friends {
    grid-column: 1 / -1;
    padding: 24px 20px;
}
.action-card--friends .action-card-icon { font-size: 24px; margin-bottom: 8px; }

/* Mobile adjustments */
html.is-mobile .friends-add-row input,
html.is-mobile .friends-add-row button { font-size: 16px; }
html.is-mobile .friends-modal { padding: 20px 16px 16px; }

/* ===== CHALLENGE SYSTEM ===== */

/* Online / offline presence dot */
.friends-card-name-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.friends-online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.friends-online-dot.online  { background: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
.friends-online-dot.offline { background: var(--muted); }

/* Challenge button on friend cards */
.friends-card-challenge {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}
.friends-card-challenge:hover { opacity: 0.85; }

/* ── Challenger waiting banner (fixed bottom strip) ── */
.challenge-waiting-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10001;
    background: var(--card);
    border-top: 1px solid var(--border);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateY(100%);
    transition: opacity 0.25s, transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.4);
}
.challenge-waiting-banner.open {
    opacity: 1;
    transform: translateY(0);
}
.challenge-waiting-content {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 14px;
    color: var(--text);
}
.challenge-waiting-content strong { color: var(--accent); }
.challenge-waiting-cancel {
    padding: 7px 16px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text-secondary);
    font-family: var(--sans);
    transition: border-color 0.15s, color 0.15s;
}
.challenge-waiting-cancel:hover { border-color: var(--wrong); color: var(--wrong); }

/* ── Incoming challenge banner (centred overlay) ── */
.challenge-banner-overlay {
    position: fixed;
    inset: 0;
    z-index: 10002;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.25s;
}
.challenge-banner-overlay.open { opacity: 1; }

.challenge-banner {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 36px 32px 28px;
    text-align: center;
    width: 340px;
    max-width: 90vw;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}
.challenge-banner-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--accent);
    font-family: var(--mono);
    margin-bottom: 12px;
}
.challenge-banner-from {
    font-size: 28px;
    font-weight: 900;
    color: var(--text);
    letter-spacing: -1px;
    margin-bottom: 6px;
    font-family: var(--mono);
}
.challenge-banner-rank {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    font-family: var(--mono);
    margin-bottom: 8px;
}
.challenge-banner-sub {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 24px;
}
.challenge-banner-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 14px;
}
.challenge-banner-accept {
    padding: 11px 28px;
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    font-family: var(--sans);
    transition: opacity 0.2s;
}
.challenge-banner-accept:hover { opacity: 0.85; }
.challenge-banner-decline {
    padding: 11px 24px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    font-family: var(--sans);
    transition: border-color 0.15s, color 0.15s;
}
.challenge-banner-decline:hover { border-color: var(--wrong); color: var(--wrong); }
.challenge-banner-timer {
    font-size: 11px;
    color: var(--muted);
    font-family: var(--mono);
}

/* ── Transient challenge notification toast ── */
.challenge-notification {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: 10003;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 20px;
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.25s, transform 0.25s;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    pointer-events: none;
}
.challenge-notification.open {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Unrated badge on finish screen ── */
.match-end-unrated {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--muted);
    font-family: var(--mono);
    border: 1px solid var(--border);
    border-radius: 6px;
    display: inline-block;
    padding: 4px 12px;
    margin-bottom: 16px;
}

/* ===== FRIENDS SIDEBAR (Valorant-style) ===== */

/* Outer container — invisible hover zone on right edge, no background */
.friends-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    z-index: 200;
    overflow: hidden;
    width: 50px;               /* collapsed = icon strip width */
    pointer-events: all;
    background: transparent;
    transition: width 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}
.friends-sidebar.expanded {
    width: 280px;
}

/* ── Hide during active match ── */
body.in-match .friends-sidebar {
    width: 0 !important;
    pointer-events: none;
    transition: width 0.2s;
}

/* ── Hide overlapping UI when friends sidebar is open ── */
body.friends-open .gear-btn,
body.friends-open .gear-dropdown,
body.friends-open #betaInfo,
body.friends-open .calc-toggle-btn,
body.friends-open .upgrade-top-btn,
body.friends-open .tier-badge,
body.friends-open .hero-upgrade-btn {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

/* ── Collapsed icons strip (transparent — only content has backgrounds) ── */
.friends-sidebar-icons {
    position: absolute;
    right: 0;
    top: 0;
    width: 50px;
    height: 100%;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 72px;
    gap: 8px;
    overflow: hidden;
    opacity: 1;
    transition: opacity 0.15s, padding-top 0.28s ease;
}
/* Slide icons down when sticky nav pushes the gear lower */
body.sticky-nav-visible .friends-sidebar-icons {
    padding-top: 116px;
}
.friends-sidebar.expanded .friends-sidebar-icons {
    opacity: 0;
    pointer-events: none;
}
/* No background on the icon strip — keep the page gradient unobstructed */

/* Icon in collapsed strip */
.fsb-icon {
    position: relative;
    cursor: default;
    flex-shrink: 0;
    /* Each icon carries its own subtle drop shadow so it reads against any bg */
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.7));
}
.fsb-icon-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #111;
    border: 2px solid;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 800;
    font-family: var(--mono);
    color: #fff;
}
.fsb-icon-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    border: 2px solid #000;
}
.fsb-icon-dot.in-lobby   { background: var(--accent); }
.fsb-icon-dot.in-match   { background: #ef4444; }
.fsb-icon-dot.in-unrated { background: #a78bfa; }
.fsb-icon-dot.in-queue   { background: #f59e0b; }
.fsb-icon-empty {
    font-size: 18px;
    opacity: 0.18;
    margin-top: 4px;
}

/* ── Full expanded panel ── */
.friends-sidebar-panel {
    position: absolute;
    right: 0;
    top: 0;
    width: 280px;
    height: 100%;
    background: #000;
    border-left: 1px solid rgba(255, 255, 255, 0.07);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.7);
}
.friends-sidebar.expanded .friends-sidebar-panel {
    opacity: 1;
    pointer-events: all;
}

/* ── Panel header ── */
.friends-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 14px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}
.friends-sidebar-title {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 2.5px;
    color: rgba(255, 255, 255, 0.55);
    font-family: var(--mono);
}
.friends-online-count {
    font-size: 10px;
    font-weight: 600;
    color: var(--accent);
    font-family: var(--mono);
}

/* ── Friend code display ── */
.friends-my-code {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--muted);
    padding: 6px 14px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}
.friends-my-code span {
    color: var(--text-secondary);
    font-weight: 700;
    letter-spacing: 2.5px;
    margin-left: 4px;
    user-select: all; /* easy to copy */
}

/* ── Incoming requests at top ── */
.friends-sidebar-incoming {
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding: 6px 0;
}
.fsb-incoming-req {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: rgba(239, 68, 68, 0.07);
    border-left: 3px solid #ef4444;
    gap: 8px;
}
.fsb-req-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}
.fsb-req-name {
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    font-family: var(--mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.fsb-req-sub {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.4);
    font-family: var(--mono);
}
.fsb-req-actions {
    display: flex;
    gap: 5px;
    flex-shrink: 0;
}
.fsb-req-accept,
.fsb-req-decline {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s;
}
.fsb-req-accept  { background: var(--accent); color: #000; }
.fsb-req-decline { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.5); }
.fsb-req-accept:hover  { opacity: 0.85; }
.fsb-req-decline:hover { color: #ef4444; }

/* ── Add friend inline row ── */
.friends-sidebar-add-row {
    margin: 8px 10px 0;
    flex-shrink: 0;
}
.friends-sidebar-add-row input {
    font-size: 13px;
    padding: 8px 10px;
    border-radius: 7px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: #fff;
}
.friends-sidebar-add-row input:focus {
    border-color: var(--accent);
    outline: none;
}
.friends-sidebar-add-row button {
    padding: 8px 12px;
    font-size: 12px;
    border-radius: 7px;
    background: var(--accent);
    color: #000;
    border: none;
    font-weight: 700;
    font-family: var(--sans);
}
.friends-add-error { margin: 4px 10px 0; font-size: 11px; min-height: 14px; color: #ef4444; }

/* ── Scrollable friends list ── */
.friends-sidebar .friends-list {
    flex: 1;
    overflow-y: auto;
    max-height: none;
    padding: 6px 0 8px;
    gap: 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.08) transparent;
}
.friends-sidebar .friends-list::-webkit-scrollbar { width: 3px; }
.friends-sidebar .friends-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.08);
    border-radius: 2px;
}
.friends-sidebar .friends-empty,
.friends-sidebar .friends-loading {
    padding: 24px 14px;
    font-size: 12px;
    color: rgba(255,255,255,0.3);
    text-align: center;
}

/* ── Friend row ── */
.friends-sidebar-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    transition: background 0.1s;
    cursor: default;
}
.friends-sidebar-row:hover { background: rgba(255,255,255,0.04); }

/* Avatar circle in row */
.fsb-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid;
    background: rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 800;
    font-family: var(--mono);
    color: #fff;
    flex-shrink: 0;
    position: relative;
}
.fsb-avatar .friends-online-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 9px;
    height: 9px;
    border: 2px solid #000;
    border-radius: 50%;
}
.fsb-row-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.fsb-row-name {
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    font-family: var(--mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.fsb-row-rank {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.6px;
    font-family: var(--mono);
    text-transform: uppercase;
}
/* Status labels */
.fsb-row-status {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.8px;
    font-family: var(--mono);
    text-transform: uppercase;
    white-space: nowrap;
}
.status-lobby   { color: var(--accent); }
.status-queue   { color: #f59e0b; }
.status-match   { color: #ef4444; }
.status-unrated { color: #a78bfa; }
.status-offline { color: rgba(255,255,255,0.25); }

/* ── Footer buttons ── */
.friends-sidebar-footer {
    display: flex;
    flex-shrink: 0;
    border-top: 1px solid rgba(255,255,255,0.06);
    padding: 8px 8px;
    gap: 5px;
    background: rgba(255,255,255,0.02);
}
.fsf-btn {
    flex: 1;
    padding: 7px 4px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.08);
    background: rgba(255,255,255,0.04);
    color: rgba(255,255,255,0.5);
    font-size: 11px;
    font-weight: 600;
    font-family: var(--mono);
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}
.fsf-btn:hover {
    background: rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.8);
}
.fsf-btn.active {
    background: rgba(var(--accent-rgb, 74, 222, 128), 0.12);
    border-color: var(--accent);
    color: var(--accent);
}
.fsf-btn .friends-badge {
    min-width: 15px;
    height: 15px;
    font-size: 9px;
    padding: 0 4px;
}
.fsf-btn.has-requests {
    border-color: #ef4444;
    color: #ef4444;
    animation: requestsPulse 2s ease-in-out infinite;
}
.fsf-btn.has-requests .friends-badge {
    background: #ef4444;
}
@keyframes requestsPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
    50%       { box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.3); }
}

/* Incoming/outgoing cards (legacy .friends-card) inside sidebar */
.friends-sidebar .friends-card {
    margin: 4px 8px;
    border-radius: 8px;
    background: rgba(255,255,255,0.03);
    border-color: rgba(255,255,255,0.07);
}
.friends-sidebar .friends-card-username { color: #fff; }
.friends-sidebar .friends-card-meta    { color: rgba(255,255,255,0.3); }

/* ── Hover card ── */
.friends-hover-card {
    position: fixed;
    width: 264px;
    background: #0a0a0f;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    padding: 16px;
    z-index: 300;
    box-shadow: 0 16px 48px rgba(0,0,0,0.8);
    opacity: 0;
    transform: translateX(10px);
    pointer-events: none;
    transition: opacity 0.15s, transform 0.15s;
}
/* Transparent bridge on the right edge — fills the gap between hover card and sidebar
   so moving the mouse rightward toward the sidebar doesn't trigger mouseleave */
.friends-hover-card::after {
    content: '';
    position: absolute;
    top: -8px;
    right: -16px;
    width: 16px;
    height: calc(100% + 16px);
    background: transparent;
}
.friends-hover-card.visible {
    opacity: 1;
    transform: translateX(0);
    pointer-events: all;
}
.friends-hover-card-loading {
    color: rgba(255,255,255,0.3);
    font-size: 12px;
    text-align: center;
    padding: 12px 0;
    font-family: var(--mono);
}
.friends-hover-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}
.friends-hover-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,0.06);
    border: 2px solid;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 800;
    font-family: var(--mono);
    color: #fff;
    flex-shrink: 0;
    position: relative;
}
.friends-hover-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 11px;
    height: 11px;
    border: 2px solid #0a0a0f;
    border-radius: 50%;
}
.friends-hover-identity { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.friends-hover-name {
    font-size: 15px;
    font-weight: 800;
    color: #fff;
    font-family: var(--mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.friends-hover-rank {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.8px;
    font-family: var(--mono);
    text-transform: uppercase;
}
.friends-live-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(74,222,128,0.07);
    border: 1px solid rgba(74,222,128,0.2);
    border-radius: 6px;
    padding: 7px 10px;
    margin-bottom: 12px;
}
.friends-live-badge {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.5px;
    color: var(--accent);
    font-family: var(--mono);
    flex-shrink: 0;
}
.friends-live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
    animation: friends-pulse 1.4s ease-in-out infinite;
}
@keyframes friends-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.4; transform: scale(0.75); }
}
.friends-live-score {
    font-size: 13px;
    font-weight: 800;
    color: #fff;
    font-family: var(--mono);
    flex-shrink: 0;
}
.friends-live-vs {
    font-size: 11px;
    color: rgba(255,255,255,0.4);
    font-family: var(--mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.friends-hover-matches-label {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 2px;
    color: rgba(255,255,255,0.3);
    font-family: var(--mono);
    margin-bottom: 7px;
    text-transform: uppercase;
}
.friends-hover-matches {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.friends-match-pill {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 4px 8px;
    border-radius: 5px;
    font-size: 11px;
    font-weight: 800;
    font-family: var(--mono);
    line-height: 1;
}
.friends-match-pill.win  { background: rgba(74,222,128,0.15); color: var(--accent); border: 1px solid rgba(74,222,128,0.25); }
.friends-match-pill.loss { background: rgba(239,68,68,0.12);  color: var(--wrong);  border: 1px solid rgba(239,68,68,0.22); }
.friends-match-delta { font-size: 10px; font-weight: 700; opacity: 0.8; }
.friends-no-matches  { font-size: 11px; color: rgba(255,255,255,0.3); font-family: var(--mono); font-style: italic; }
.friends-hover-actions { display: flex; gap: 6px; }
.friends-hover-challenge {
    flex: 1;
    padding: 8px 12px;
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 700;
    font-family: var(--sans);
    transition: opacity 0.15s;
}
.friends-hover-challenge:hover { opacity: 0.85; }
.friends-hover-remove {
    padding: 8px 12px;
    background: none;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 7px;
    font-size: 12px;
    font-weight: 600;
    color: rgba(255,255,255,0.4);
    font-family: var(--sans);
    transition: border-color 0.15s, color 0.15s;
}
.friends-hover-remove:hover { border-color: #ef4444; color: #ef4444; }

/* ── Online dot shared ── */
.friends-online-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.friends-online-dot.online  { background: var(--accent); box-shadow: 0 0 0 2px rgba(74,222,128,0.25); }
.friends-online-dot.offline { background: rgba(255,255,255,0.2); }

/* Mobile */
@media (max-width: 480px) {
    .friends-sidebar { width: 0 !important; }
    .friends-hover-card { display: none !important; }
}

/* ============================================================
   HOME STATS DASHBOARD
   ============================================================ */

/* ── Hero section ── */
#home-hero {
    min-height: calc(100vh - 180px);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding-bottom: 32px;
    gap: 28px;
}

/* Welcome header */
.welcome-header {
    text-align: center;
    margin-bottom: 4px;
}
.welcome-kicker {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--accent);
    opacity: 0.7;
    margin: 0 0 8px;
    text-transform: uppercase;
}
#welcomeMessage {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: -0.3px;
}
.welcome-username {
    color: var(--accent);
}

/* ── Beta notice ── */
.beta-notice {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--muted);
    text-align: center;
    line-height: 1.9;
    letter-spacing: 0.4px;
    padding: 0 24px;
    margin-bottom: 20px;
}
.beta-notice strong {
    color: var(--text-secondary);
    font-weight: 600;
}

/* ── Scroll hint ── */
.scroll-hint {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding-top: 32px;
    color: var(--muted);
    transition: color 0.2s;
}

.scroll-hint:hover {
    color: var(--text-secondary);
}

.scroll-hint-text {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1.6px;
    text-transform: uppercase;
}

.scroll-hint-arrow {
    font-size: 24px;
    line-height: 1;
    animation: arrowBounce 1.6s ease-in-out infinite;
}

@keyframes arrowBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(7px); }
}

/* ── Friends sidebar hint ── */
.friends-hint {
    position: absolute;
    bottom: 35%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: rgba(255,255,255,0.45);
    cursor: pointer;
    transition: color 0.2s, opacity 0.3s;
    pointer-events: all;
}
.friends-hint:hover {
    color: rgba(255,255,255,0.75);
}
.friends-hint-arrow {
    font-size: 20px;
    line-height: 1;
    display: block;
    animation: friendsHintBounce 1.8s ease-in-out infinite;
}
.friends-hint-arrow:nth-child(1) { animation-delay: 0s; }
.friends-hint-arrow:nth-child(2) { animation-delay: 0.18s; }
.friends-hint-arrow:nth-child(3) { animation-delay: 0.36s; }
.friends-hint-text {
    font-family: var(--mono);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-top: 4px;
    white-space: nowrap;
}
@keyframes friendsHintBounce {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(-5px); }
}

/* ── Sticky mini-nav ── */
#home-sticky-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1002;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 28px;
    background: rgba(4, 4, 4, 0.88);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 32px rgba(0, 0, 0, 0.48);
    opacity: 0;
    transform: translateY(-100%);
    pointer-events: none;
    transition: opacity 0.28s ease, transform 0.28s ease;
}

html.light-mode #home-sticky-nav {
    background: rgba(248, 248, 248, 0.92);
}

#home-sticky-nav.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.sticky-nav-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sticky-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 16px;
    border-radius: 8px;
    font-family: var(--sans);
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    transition: background 0.15s, border-color 0.15s;
}

.sticky-nav-btn:hover {
    background: rgba(255, 255, 255, 0.09);
    border-color: var(--border-hover);
}

.sticky-nav-btn--comp {
    border-color: rgba(34, 197, 94, 0.4);
    background: rgba(34, 197, 94, 0.07);
    color: var(--accent);
}

.sticky-nav-btn--comp:hover {
    background: rgba(34, 197, 94, 0.14);
    border-color: rgba(34, 197, 94, 0.6);
}

.sticky-nav-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sticky-nav-rank {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--mono);
}

.sticky-nav-rank-badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid rgba(var(--rank-tier-rgb, 34, 197, 94), 0.5);
    background: rgba(var(--rank-tier-rgb, 34, 197, 94), 0.12);
    color: var(--rank-tier-color, var(--accent));
}

.sticky-nav-elo-wrap {
    display: flex;
    align-items: baseline;
    gap: 4px;
    font-size: 15px;
    font-weight: 800;
    color: var(--text);
}

.sticky-nav-elo-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1.5px;
    color: var(--muted);
}

/* ── Sticky nav: section jump pills ── */
.sticky-nav-sections {
    display: flex;
    align-items: center;
    gap: 4px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}
.sticky-section-btn {
    background: none;
    border: none;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: rgba(255,255,255,0.35);
    padding: 4px 8px;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
    text-transform: uppercase;
}
.sticky-section-btn:hover {
    color: rgba(255,255,255,0.75);
    background: rgba(255,255,255,0.06);
}
.sticky-section-btn.active {
    color: var(--accent);
}
.sticky-section-sep {
    color: rgba(255,255,255,0.2);
    font-size: 11px;
    pointer-events: none;
    user-select: none;
}
html.light-mode .sticky-section-btn { color: rgba(0,0,0,0.35); }
html.light-mode .sticky-section-btn:hover { color: rgba(0,0,0,0.75); background: rgba(0,0,0,0.06); }
html.light-mode .sticky-section-sep { color: rgba(0,0,0,0.2); }
@media (max-width: 680px) { .sticky-nav-sections { display: none; } }

/* ── Stats sections: scroll-reveal ── */
.stats-section {
    padding: 64px 0 48px;
    border-top: 1px solid var(--border);
    opacity: 0;
    transform: translateY(44px);
    transition: opacity 0.55s ease, transform 0.55s ease;
}

.stats-section.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger delay per section index */
#stats-overview  { transition-delay: 0s; }
#stats-competitive { transition-delay: 0.06s; }
#stats-practice  { transition-delay: 0.12s; }

/* ── Section headers ── */
.stats-section-header {
    margin-bottom: 28px;
}

.stats-section-kicker {
    display: block;
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 8px;
}

.stats-section-title {
    margin: 0;
    font-family: var(--sans);
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.6px;
    line-height: 1.1;
}

/* ── Overview pill grid ── */
.stat-overview-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.stat-pill {
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    padding: 22px 14px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: background 0.2s, border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}

.stat-pill:hover {
    background: rgba(255, 255, 255, 0.055);
    border-color: rgba(255, 255, 255, 0.16);
    transform: translateY(-3px);
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.3);
}

.stat-pill--win {
    border-color: rgba(34, 197, 94, 0.22);
    background: rgba(34, 197, 94, 0.04);
}

.stat-pill--win .stat-pill-value { color: var(--accent); }

.stat-pill--loss {
    border-color: rgba(239, 68, 68, 0.22);
    background: rgba(239, 68, 68, 0.04);
}

.stat-pill--loss .stat-pill-value { color: var(--wrong); }

.stat-pill-value {
    font-family: var(--mono);
    font-size: 34px;
    font-weight: 800;
    line-height: 1;
    color: var(--text);
    letter-spacing: -0.5px;
}

.stat-pill-label {
    font-family: var(--mono);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--muted);
    text-align: center;
}

/* ── Charts ── */
.stats-chart-wrap {
    position: relative;
    height: 280px;
    margin-bottom: 32px;
    background: rgba(255, 255, 255, 0.018);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    overflow: hidden;
    padding: 14px;
}

.stats-chart-wrap canvas {
    width: 100% !important;
    height: 100% !important;
}

.stats-chart-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--muted);
    text-align: center;
    padding: 20px;
}

/* ── Form guide ── */
.form-guide-wrap {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
}

.form-guide-label {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
}

.form-guide {
    display: flex;
    gap: 5px;
    align-items: center;
}

.form-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    display: inline-block;
    transition: transform 0.15s;
    flex-shrink: 0;
}

.form-dot:hover { transform: scale(1.5); }

.form-dot--win {
    background: var(--accent);
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.55);
}

.form-dot--loss {
    background: var(--wrong);
    box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
}

/* ── Match history list ── */
.match-history-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.match-history-row {
    display: grid;
    grid-template-columns: 34px 1fr auto auto auto;
    align-items: center;
    gap: 14px;
    padding: 11px 16px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    transition: background 0.15s, border-color 0.15s;
}

.match-history-row:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

.match-wl-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 800;
}

.match-wl-pill--win  { background: rgba(34, 197, 94, 0.14); color: var(--accent); border: 1px solid rgba(34, 197, 94, 0.28); }
.match-wl-pill--loss { background: rgba(239, 68, 68, 0.11); color: var(--wrong);  border: 1px solid rgba(239, 68, 68, 0.24); }

.match-opponent {
    font-family: var(--sans);
    font-size: 13px;
    color: var(--text-secondary);
    text-align: left;
}

.match-opponent strong {
    color: var(--text);
    font-weight: 600;
}

.match-score {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--muted);
}

.match-rating-delta {
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 700;
    min-width: 42px;
    text-align: right;
}

.match-rating-delta.positive { color: var(--accent); }
.match-rating-delta.negative { color: var(--wrong); }

.match-date {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
}

/* ── Practice aggregates ── */
.practice-aggregate-row {
    display: flex;
    gap: 10px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.stat-aggregate {
    flex: 1;
    min-width: 90px;
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 18px 10px 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    transition: background 0.2s, transform 0.2s;
}

.stat-aggregate:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateY(-2px);
}

.stat-aggregate-value {
    font-family: var(--mono);
    font-size: 26px;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
}

.stat-aggregate-label {
    font-family: var(--mono);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 1.1px;
    text-transform: uppercase;
    color: var(--muted);
    text-align: center;
}

/* ── Session list ── */
.session-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.session-row {
    display: grid;
    grid-template-columns: 56px 1fr auto auto auto;
    align-items: center;
    gap: 14px;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    transition: background 0.15s, border-color 0.15s;
}

.session-row:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

.session-date {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
}

.session-questions {
    font-family: var(--sans);
    font-size: 13px;
    color: var(--text-secondary);
}

.session-accuracy {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 700;
}

.session-accuracy.high { color: var(--accent); }
.session-accuracy.mid  { color: var(--warning); }
.session-accuracy.low  { color: var(--wrong); }

.session-streak {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text-secondary);
}

.session-xp {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
}

/* ── Question history grid ── */
.question-history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 8px;
}

.question-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 13px;
    border-radius: 10px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.02);
    transition: transform 0.15s, background 0.15s, border-color 0.15s;
}

.question-card:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

.question-card--correct { border-color: rgba(34, 197, 94, 0.18); }
.question-card--wrong   { border-color: rgba(239, 68, 68, 0.18); }
.question-card--skip    { opacity: 0.55; }

.question-card-icon {
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 800;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.question-card--correct .question-card-icon { color: var(--accent); }
.question-card--wrong   .question-card-icon { color: var(--wrong); }
.question-card--skip    .question-card-icon { color: var(--muted); }

.question-card-text {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
}

.question-card-delta {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 700;
    flex-shrink: 0;
}

.question-card-delta.positive { color: var(--accent); }
.question-card-delta.negative { color: var(--wrong); }

/* ── Shared empty/loading states ── */
.home-stats-loading,
.match-history-empty,
.session-list-empty,
.question-history-empty {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--muted);
    text-align: center;
    padding: 36px 0;
    width: 100%;
}

/* ── Responsive tweaks for stats dashboard ── */
@media (max-width: 900px) {
    .stat-overview-grid { grid-template-columns: repeat(2, 1fr); }
    .match-history-row  { grid-template-columns: 32px 1fr auto auto; }
    .match-date         { display: none; }
    .session-row        { grid-template-columns: 50px 1fr auto auto; }
    .session-xp         { display: none; }
}

@media (max-width: 600px) {
    .stat-overview-grid { grid-template-columns: repeat(2, 1fr); }
    .practice-aggregate-row { gap: 8px; }
    #home-sticky-nav { padding: 8px 14px; }
    .sticky-nav-btn { padding: 6px 12px; font-size: 11px; }
}

/* ══════════════════════════════════════════
   MATCH DETAIL MODAL
══════════════════════════════════════════ */
#matchDetailModal {
    position: fixed;
    inset: 0;
    z-index: 600;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 24px 16px 48px;
    overflow-y: auto;
}

.match-detail-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 0;
}

.match-detail-panel {
    position: relative;
    z-index: 1;
    background: var(--surface, #0d0d0d);
    border: 1px solid var(--border, #1e1e1e);
    border-radius: 12px;
    width: 100%;
    max-width: 820px;
    padding: 32px;
    margin-top: 20px;
}

html.light-mode .match-detail-panel {
    background: #ffffff;
    border-color: #e0e0e0;
}

.match-detail-close {
    position: absolute;
    top: 16px;
    right: 18px;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
}
.match-detail-close:hover {
    color: var(--text);
    background: var(--border);
}

/* Header */
.match-detail-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.match-detail-result-badge {
    width: 52px;
    height: 52px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 900;
    font-family: var(--sans);
    flex-shrink: 0;
}
.match-detail-result-badge.win  { background: rgba(34, 197, 94, 0.18); color: #22c55e; }
.match-detail-result-badge.loss { background: rgba(239, 68, 68, 0.18); color: #ef4444; }

.match-detail-header-info {
    flex: 1;
}

.match-detail-opponent {
    font-size: 20px;
    font-weight: 700;
    font-family: var(--sans);
    margin-bottom: 4px;
}

.match-detail-meta {
    font-size: 13px;
    color: var(--muted);
    font-family: var(--mono);
}

.match-detail-score {
    font-size: 32px;
    font-weight: 900;
    font-family: var(--sans);
    letter-spacing: -1px;
}
.match-detail-score .score-you  { color: #22c55e; }
.match-detail-score .score-sep  { color: var(--muted); margin: 0 4px; }
.match-detail-score .score-opp  { color: #ef4444; }

/* Summary stats row */
.match-detail-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 12px;
    margin-bottom: 28px;
}

.match-detail-stat-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    text-align: center;
}

.match-detail-stat-value {
    display: block;
    font-size: 20px;
    font-weight: 800;
    font-family: var(--sans);
    margin-bottom: 2px;
}

.match-detail-stat-label {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-family: var(--mono);
}

/* Rounds */
.match-detail-rounds-header {
    display: grid;
    grid-template-columns: 44px 1fr 120px 120px;
    gap: 8px;
    padding: 6px 12px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-family: var(--mono);
    margin-bottom: 8px;
}

.match-detail-rounds {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.match-detail-round-card {
    display: grid;
    grid-template-columns: 44px 1fr 120px 120px;
    gap: 8px;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 12px;
    transition: border-color 0.15s;
}
.match-detail-round-card.round-won  { border-left: 3px solid #22c55e; }
.match-detail-round-card.round-lost { border-left: 3px solid #ef4444; }
.match-detail-round-card.round-tie  { border-left: 3px solid var(--muted); }

.round-num {
    font-size: 11px;
    font-weight: 700;
    font-family: var(--mono);
    color: var(--muted);
    text-align: center;
}

.round-question-wrap {
    min-width: 0;
}

.round-question-text {
    font-size: 14px;
    font-family: var(--sans);
    line-height: 1.4;
    margin-bottom: 4px;
    word-break: break-word;
}

.round-answer-tag {
    font-size: 11px;
    color: var(--muted);
    font-family: var(--mono);
}
.round-answer-tag strong {
    color: #22c55e;
}

.round-difficulty {
    display: inline-block;
    font-size: 10px;
    font-family: var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 2px 7px;
    border-radius: 4px;
    margin-top: 5px;
    background: rgba(34, 197, 94, 0.1);
    color: var(--muted);
}

.round-player-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-family: var(--mono);
    font-size: 12px;
}

.round-result-icon {
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
}
.round-result-icon.correct { color: #22c55e; }
.round-result-icon.wrong   { color: #ef4444; }
.round-result-icon.pending { color: var(--muted); }

.round-time-tag {
    font-size: 10px;
    color: var(--muted);
}

.round-winner-label {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #22c55e;
    font-family: var(--mono);
    margin-top: 2px;
}

/* Clickable match history rows */
.match-history-row {
    cursor: pointer;
    transition: background 0.15s;
}
.match-history-row:hover {
    background: var(--border);
    border-radius: 6px;
}

@media (max-width: 640px) {
    .match-detail-panel { padding: 20px 14px; }
    .match-detail-rounds-header { grid-template-columns: 36px 1fr 90px; }
    .match-detail-rounds-header span:last-child { display: none; }
    .match-detail-round-card { grid-template-columns: 36px 1fr 90px; }
    .match-detail-round-card .round-player-cell:last-child { display: none; }
    .match-detail-score { font-size: 24px; }
}
