/* ═══════════════════════════════════════════════════════════════
   AAA Cinematic Design System
   Premium dark luxury theme with glassmorphism & cinematic polish
   ═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Cinzel:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ── CSS Custom Properties (Design Tokens) ──────────────────── */
:root {
    /* ─── Background Palette ─── */
    --bg-primary: #081018;
    --bg-secondary: #0B1220;
    --bg-card: rgba(14, 20, 35, 0.75);
    --bg-elevated: #101826;
    --bg-hover: rgba(47, 93, 255, 0.08);
    --bg-input: rgba(8, 16, 24, 0.9);
    --bg-surface: rgba(16, 24, 38, 0.85);

    /* ─── Text Palette ─── */
    --text-primary: #EAEAEA;
    --text-secondary: #B8C1CC;
    --text-muted: #5A6A7E;
    --text-inverse: #081018;

    /* ─── Accent Colors ─── */
    --accent-primary: #2F5DFF;
    --accent-primary-hover: #4A7BFF;
    --accent-primary-glow: rgba(47, 93, 255, 0.25);
    --accent-primary-dim: rgba(47, 93, 255, 0.12);
    --accent-secondary: #4FC3F7;
    --accent-gold: #D4B26A;
    --accent-gold-dim: rgba(212, 178, 106, 0.2);
    --accent-success: #34C759;
    --accent-success-dark: #28A745;
    --accent-warning: #FF9F0A;
    --accent-danger: #FF3B30;
    --accent-danger-dark: #CC2D25;

    /* ─── Board Colors ─── */
    --board-light: #DEC8A0;
    --board-dark: #8B6B4A;
    --board-frame: #4A3728;
    --board-frame-light: #6B5240;
    --board-highlight-last: rgba(212, 178, 106, 0.45);
    --board-highlight-selected: rgba(47, 93, 255, 0.45);
    --board-legal-dot: rgba(0, 0, 0, 0.22);
    --board-check: rgba(255, 40, 40, 0.6);

    /* ─── Glassmorphism ─── */
    --glass-bg: rgba(11, 18, 32, 0.72);
    --glass-bg-strong: rgba(11, 18, 32, 0.88);
    --glass-border: rgba(255, 255, 255, 0.06);
    --glass-border-accent: rgba(47, 93, 255, 0.15);
    --glass-blur: 20px;

    /* ─── Borders ─── */
    --border-subtle: rgba(255, 255, 255, 0.04);
    --border-default: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.12);
    --border-glow: rgba(47, 93, 255, 0.3);

    /* ─── Typography ─── */
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-display: 'Cinzel', 'Playfair Display', Georgia, serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --font-size-xs: 0.6875rem;
    --font-size-sm: 0.8125rem;
    --font-size-base: 0.875rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 2rem;
    --font-size-4xl: 2.5rem;
    --line-height: 1.55;

    /* ─── Spacing Scale ─── */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;

    /* ─── Radii ─── */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-2xl: 28px;
    --radius-full: 9999px;

    /* ─── Shadows ─── */
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.55);
    --shadow-glow: 0 0 24px var(--accent-primary-glow);
    --shadow-gold-glow: 0 0 20px var(--accent-gold-dim);
    --shadow-inset: inset 0 1px 0 rgba(255,255,255,0.04);

    /* ─── Transitions ─── */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-in-out: cubic-bezier(0.45, 0, 0.55, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration-fast: 120ms;
    --duration-normal: 220ms;
    --duration-slow: 380ms;
    --duration-slower: 600ms;

    /* ─── Layout ─── */
    --nav-height: 60px;
    --sidebar-width: 320px;
    --board-max-size: 620px;
    --content-max-width: 1320px;
}

/* ── Light Marble Theme ──────────────────────────────────────── */
[data-theme="light"] {
    --bg-primary: #F2EDE6;
    --bg-secondary: #FFFFFF;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-elevated: #F8F5F0;
    --bg-hover: rgba(47, 93, 255, 0.06);
    --bg-input: rgba(245, 240, 232, 0.95);
    --bg-surface: rgba(255, 255, 255, 0.9);
    --text-primary: #1A1A2E;
    --text-secondary: #546E7A;
    --text-muted: #90A4AE;
    --glass-bg: rgba(255, 255, 255, 0.78);
    --glass-bg-strong: rgba(255, 255, 255, 0.92);
    --glass-border: rgba(0, 0, 0, 0.06);
    --glass-border-accent: rgba(47, 93, 255, 0.12);
    --border-subtle: rgba(0, 0, 0, 0.04);
    --border-default: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.12);
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.12);
}

/* ── Tournament Theme ────────────────────────────────────────── */
[data-theme="tournament"] {
    --bg-primary: #0A0E14;
    --bg-secondary: #0E1319;
    --bg-card: rgba(14, 19, 25, 0.8);
    --bg-elevated: #131920;
    --accent-primary: #00B4D8;
    --accent-primary-hover: #00C9EF;
    --accent-primary-glow: rgba(0, 180, 216, 0.25);
    --accent-gold: #FFD700;
}

/* ── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-primary);
    font-size: var(--font-size-base);
    line-height: var(--line-height);
    color: var(--text-primary);
    background: var(--bg-primary);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Cinematic Background ────────────────────────────────────── */
body::before {
    content: '';
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background:
        radial-gradient(ellipse at 15% 50%, rgba(47, 93, 255, 0.05) 0%, transparent 55%),
        radial-gradient(ellipse at 85% 15%, rgba(79, 195, 247, 0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 85%, rgba(47, 93, 255, 0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(212, 178, 106, 0.015) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

/* Ambient vignette */
body::after {
    content: '';
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(0,0,0,0.4) 100%);
    pointer-events: none;
    z-index: 0;
}

/* Subtle geometric dot pattern */
.ambient-particles {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.4;
    background-image:
        radial-gradient(circle at 1px 1px, rgba(255,255,255,0.03) 1px, transparent 0);
    background-size: 40px 40px;
}

a {
    color: var(--accent-secondary);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease-out);
}

/* Exclude anchors styled as buttons: a .btn sets its own label colour, and the
   global link-hover colour would repaint it on hover — e.g. the white label on a
   .btn--primary turning into the hover blue, i.e. dark-on-blue and unreadable
   (the "Replay" button). Real links keep the hover colour. */
a:hover:not(.btn) {
    color: var(--accent-primary-hover);
}

img {
    max-width: 100%;
    display: block;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    outline: none;
}

input, select, textarea {
    font-family: inherit;
    font-size: inherit;
}

/* ── Accessibility: focus, skip link, screen-reader utilities (#6) ── */

/* Visible focus ring for keyboard users only (mouse clicks stay clean). */
:focus-visible {
    outline: 2px solid var(--accent-primary-hover);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}
/* Gold ring on dark luxury surfaces where blue blends in. */
.btn--gold:focus-visible,
.navbar__icon-btn:focus-visible,
.theme-swatch:focus-visible,
.piece-option:focus-visible {
    outline-color: var(--accent-gold);
}
/* The canvas board owns its own on-canvas focus cursor (#80). */
canvas:focus-visible { outline: none; }

/* Visually hidden but available to assistive tech. */
.sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Skip-to-content link — hidden until focused, then pinned top-left. */
.skip-link {
    position: fixed;
    top: -120px;
    left: var(--space-3);
    z-index: 10001;
    padding: var(--space-2) var(--space-4);
    background: var(--accent-primary);
    color: #fff;
    font-weight: 600;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    transition: top var(--duration-fast) var(--ease-out);
}
.skip-link:focus {
    top: var(--space-3);
    color: #fff;
}

/* ═══════════════════════════════════════════════════════════════
   NAVIGATION BAR — Premium Glassmorphism
   ═══════════════════════════════════════════════════════════════ */
.navbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--nav-height);
    background: var(--glass-bg-strong);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-bottom: 1px solid var(--glass-border);
    box-shadow:
        0 1px 0 var(--glass-border-accent),
        0 4px 24px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    padding: 0 var(--space-6);
    z-index: 1000;
    transition: background var(--duration-normal) var(--ease-out);
}

/* Bottom glow line */
.navbar::after {
    content: '';
    position: absolute;
    bottom: -1px; left: 10%; right: 10%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-primary-glow), transparent);
    pointer-events: none;
}

.navbar__logo {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    text-decoration: none;
    color: var(--text-primary);
    flex-shrink: 0;
}

.navbar__logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent-gold), #C49B4A);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: 0 2px 8px rgba(212, 178, 106, 0.3);
    color: #1A1A2E;
}

.navbar__logo-text {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: var(--font-size-lg);
    letter-spacing: 0.04em;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent-gold) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.navbar__nav {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    margin-left: var(--space-8);
    list-style: none;
}

.navbar__link {
    position: relative;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 500;
    transition: all var(--duration-normal) var(--ease-out);
    text-decoration: none;
    letter-spacing: 0.02em;
}

.navbar__link::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%; right: 50%;
    height: 2px;
    background: var(--accent-primary);
    border-radius: 1px;
    transition: all var(--duration-normal) var(--ease-out);
    box-shadow: 0 0 8px var(--accent-primary-glow);
    opacity: 0;
}

.navbar__link:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.navbar__link:hover::after {
    left: 25%; right: 25%;
    opacity: 0.5;
}

.navbar__link.active {
    color: var(--text-primary);
    background: rgba(47, 93, 255, 0.1);
}

.navbar__link.active::after {
    left: 15%; right: 15%;
    opacity: 1;
}

.navbar__right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.navbar__user {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-3) var(--space-1) var(--space-1);
    border-radius: var(--radius-full);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-out);
    text-decoration: none;
    color: var(--text-primary);
}

.navbar__user:hover {
    background: var(--bg-hover);
    border-color: var(--border-default);
    box-shadow: var(--shadow-sm);
}

.navbar__user-wrap {
    position: relative;
}

.navbar__user-chevron {
    color: var(--text-muted);
    transition: transform var(--duration-fast) var(--ease-out);
}

.navbar__user-wrap.open .navbar__user-chevron {
    transform: rotate(180deg);
}

.navbar__user-wrap.open .navbar__user {
    background: var(--bg-hover);
    border-color: var(--border-default);
}

/* Themed like the notification/mega dropdowns rather than hardcoded dark —
   resolves per theme so it stays readable in both light and dark mode. */
.navbar__user-dropdown {
    position: absolute;
    top: calc(100% + 10px); right: 0;
    min-width: 200px;
    background: var(--glass-bg-strong);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl), 0 8px 40px rgba(0, 0, 0, 0.45);
    z-index: 9000;
    overflow: hidden;
    padding: var(--space-2);
    animation: notifFadeIn 0.15s ease;
}

.navbar__user-dropdown__link {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-primary);
    text-decoration: none;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-out);
}

.navbar__user-dropdown__link:hover {
    background: var(--bg-hover);
}

.navbar__user-dropdown__link--danger {
    color: var(--accent-danger, #FF3B30);
}

.navbar__user-dropdown__link--danger:hover {
    background: rgba(255, 59, 48, 0.1);
}

.navbar__user-dropdown__divider {
    height: 1px;
    background: var(--border-subtle);
    margin: var(--space-2) 0;
}

.navbar__avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-gold), #C49B4A);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xs);
    font-weight: 700;
    color: #1A1A2E;
    box-shadow: 0 0 0 2px var(--accent-gold-dim);
}

.navbar__elo {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--accent-gold);
    font-weight: 600;
}

.navbar__icon-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-secondary);
    transition: all var(--duration-fast) var(--ease-out);
    border: none;
    cursor: pointer;
    font-size: 16px;
}

.navbar__icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ── Notification bell ──────────────────────────────────────── */
.notification-badge {
    position: absolute;
    top: 2px; right: 2px;
    min-width: 16px; height: 16px;
    padding: 0 4px;
    background: var(--accent-danger, #FF3B30);
    color: #fff;
    font-size: 10px; font-weight: 700;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none;
    line-height: 1;
}
/* Themed like the mega menu (the app's other dropdown) rather than hardcoded
   dark: the panel used to be a fixed dark gradient while its text stayed
   var(--text-primary), so in light mode it rendered near-black text on a
   near-black panel — the bell dropdown was simply unreadable. Everything here
   resolves per theme, which also makes it correct under [data-theme=tournament]. */
.notification-dropdown {
    position: absolute;
    top: calc(100% + 10px); right: 0;
    width: 320px;
    background: var(--glass-bg-strong);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl), 0 8px 40px rgba(0, 0, 0, 0.45);
    z-index: 9000;
    overflow: hidden;
    animation: notifFadeIn 0.15s ease;
}
@keyframes notifFadeIn { from { opacity:0; transform:translateY(-6px); } to { opacity:1; transform:none; } }
/* The dividers/hover below were white-on-white in light mode (rgba(255,255,255,…)
   only ever reads as a separator on a dark panel) — themed vars instead. */
.notification-dropdown__header {
    display: flex; justify-content: space-between; align-items: center;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-default);
    font-size: var(--font-size-sm); font-weight: 600;
    color: var(--text-primary);
}
.notification-list {
    max-height: 360px; overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}
.notification__item {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: background 0.15s;
}
.notification__item:hover { background: var(--bg-hover); }
.notification__item--unread { background: rgba(212,178,106,0.06); }
.notification__item--unread .notification__title { color: var(--text-primary); font-weight: 600; }
.notification__title { font-size: var(--font-size-sm); color: var(--text-secondary); }
.notification__time  { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.notification__empty { padding: var(--space-6) var(--space-4); text-align: center; font-size: var(--font-size-sm); color: var(--text-muted); }

/* ═══════════════════════════════════════════════════════════════
   MAIN CONTENT
   ═══════════════════════════════════════════════════════════════ */
.main-content {
    margin-top: var(--nav-height);
    min-height: calc(100vh - var(--nav-height));
    position: relative;
    z-index: 1;
}

.container {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: var(--space-6);
}

/* ═══════════════════════════════════════════════════════════════
   GLASS CARDS — Premium Panels
   ═══════════════════════════════════════════════════════════════ */
.card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    transition: all var(--duration-normal) var(--ease-out);
    box-shadow: var(--shadow-sm), var(--shadow-inset);
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent);
    pointer-events: none;
}

.card:hover {
    border-color: var(--border-default);
    box-shadow: var(--shadow-md), var(--shadow-inset);
}

.card--glass {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border-accent);
}

.card--glow {
    border-color: var(--glass-border-accent);
    box-shadow: var(--shadow-md), 0 0 20px rgba(47, 93, 255, 0.06);
}

.card__title {
    font-size: var(--font-size-md);
    font-weight: 600;
    margin-bottom: var(--space-4);
    color: var(--text-primary);
    letter-spacing: 0.01em;
}

.card__title--display {
    font-family: var(--font-display);
    letter-spacing: 0.03em;
}

/* ═══════════════════════════════════════════════════════════════
   PREMIUM BUTTONS
   ═══════════════════════════════════════════════════════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-5);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: all var(--duration-normal) var(--ease-out);
    position: relative;
    overflow: hidden;
    white-space: nowrap;
    height: 40px;
    border: 1px solid transparent;
}

/* Glass shimmer overlay */
.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.06) 0%, transparent 60%);
    pointer-events: none;
    transition: opacity var(--duration-fast);
}

.btn:hover::after {
    opacity: 0.8;
}

/* Primary CTA — the site's signature gold (#D4B26A). Dark label for a strong,
   theme-consistent contrast (same treatment as the admin active-nav / text-gold).
   NOTE: uses the gold literals here rather than repainting --accent-primary,
   which is still the blue used for links, focus rings, badges and glows. The
   label stays #1a1a1a in every state — never white — so hover can't wash it out. */
.btn--primary {
    background: linear-gradient(135deg, var(--accent-gold), #C49B4A);
    color: #1a1a1a;
    box-shadow: 0 2px 12px var(--accent-gold-dim);
}

.btn--primary:hover {
    color: #1a1a1a;
    background: linear-gradient(135deg, #E0C075, #D4B26A);
    box-shadow: 0 4px 20px var(--accent-gold-dim), var(--shadow-gold-glow);
    transform: translateY(-2px);
}

.btn--primary:active {
    color: #1a1a1a;
    transform: translateY(0);
    box-shadow: 0 1px 8px var(--accent-gold-dim);
}

.btn--secondary {
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    color: var(--text-primary);
    border: 1px solid var(--border-default);
}

.btn--secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn--danger {
    background: linear-gradient(135deg, var(--accent-danger), var(--accent-danger-dark));
    color: white;
    box-shadow: 0 2px 8px rgba(255, 59, 48, 0.2);
}

.btn--danger:hover {
    box-shadow: 0 4px 16px rgba(255, 59, 48, 0.3);
    transform: translateY(-1px);
}

.btn--success {
    background: linear-gradient(135deg, var(--accent-success), var(--accent-success-dark));
    color: white;
}

.btn--success:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(52, 199, 89, 0.25);
}

.btn--ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}

.btn--ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-default);
    transform: translateY(-1px);
}

.btn--gold {
    background: linear-gradient(135deg, var(--accent-gold), #B8963A);
    color: #1A1A2E;
    box-shadow: 0 2px 8px var(--accent-gold-dim);
}

.btn--gold:hover {
    box-shadow: 0 4px 16px var(--accent-gold-dim), var(--shadow-gold-glow);
    transform: translateY(-1px);
}

.btn--lg {
    height: 48px;
    padding: var(--space-3) var(--space-8);
    font-size: var(--font-size-md);
    border-radius: var(--radius-lg);
}

.btn--sm {
    height: 34px;
    padding: var(--space-1) var(--space-4);
    font-size: var(--font-size-xs);
}

.btn--icon {
    width: 40px;
    padding: 0;
}

.btn--full {
    width: 100%;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn__icon {
    width: 16px;
    height: 16px;
    opacity: 0.8;
}

/* ═══════════════════════════════════════════════════════════════
   INPUTS — Luxury Form Controls
   ═══════════════════════════════════════════════════════════════ */
.input-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin-bottom: var(--space-4);
}

.input-group__label {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.input {
    height: 42px;
    padding: 0 var(--space-4);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--font-size-base);
    transition: all var(--duration-normal) var(--ease-out);
    outline: none;
    box-shadow: var(--shadow-inset);
}

.input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-primary-dim), var(--shadow-inset);
}

/* A .input <textarea> must grow with its rows, not be pinned to the 42px
   single-line input height — that fixed height is what made the Clubs "about"
   box overlap the name field. (Applies everywhere a bare .input textarea is
   used: Clubs, coach profile, study description/comment.) */
textarea.input {
    height: auto;
    min-height: 84px;
    padding-top: var(--space-2);
    padding-bottom: var(--space-2);
    line-height: 1.5;
    width: 100%;
}

.input--error {
    border-color: var(--accent-danger);
}

.input-error {
    font-size: var(--font-size-xs);
    color: var(--accent-danger);
    margin-top: var(--space-1);
}

/* ═══════════════════════════════════════════════════════════════
   BADGE — Category Labels
   ═══════════════════════════════════════════════════════════════ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
}

.badge--bullet { background: rgba(255, 82, 82, 0.15); color: #FF5252; border: 1px solid rgba(255, 82, 82, 0.2); }
.badge--blitz { background: rgba(255, 145, 0, 0.15); color: #FF9100; border: 1px solid rgba(255, 145, 0, 0.2); }
.badge--rapid { background: rgba(52, 199, 89, 0.15); color: #34C759; border: 1px solid rgba(52, 199, 89, 0.2); }
.badge--classical { background: rgba(47, 93, 255, 0.15); color: #4A7BFF; border: 1px solid rgba(47, 93, 255, 0.2); }
.badge--online { background: var(--accent-success); color: white; }

/* ═══════════════════════════════════════════════════════════════
   PLAYER CARD — Premium Glass
   ═══════════════════════════════════════════════════════════════ */
.player-card {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    transition: all var(--duration-normal) var(--ease-out);
    box-shadow: var(--shadow-sm);
}

.player-card__avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-gold), #C49B4A);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #1a1a1a;
    font-size: var(--font-size-md);
    flex-shrink: 0;
    box-shadow: 0 0 0 2px var(--accent-gold-dim);
    position: relative;
}

.player-card__avatar--ai {
    background: linear-gradient(135deg, #FF6B00, #FF9500);
    box-shadow: 0 0 0 2px rgba(255, 107, 0, 0.2);
}

.player-card__info {
    flex: 1;
    min-width: 0;
}

.player-card__name {
    font-weight: 600;
    font-size: var(--font-size-base);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

.player-card__meta {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: 2px;
}

.player-card__rating {
    font-size: var(--font-size-xs);
    color: var(--accent-gold);
    font-weight: 600;
    font-family: var(--font-mono);
}

.player-card__winrate {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.player-card__clock {
    font-family: var(--font-mono);
    font-size: var(--font-size-2xl);
    font-weight: 700;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    min-width: 100px;
    text-align: center;
    transition: all var(--duration-normal) var(--ease-out);
    color: var(--text-primary);
}

.player-card__clock--active {
    background: linear-gradient(135deg, var(--accent-gold), #C49B4A);
    color: #1a1a1a;
    border-color: transparent;
    box-shadow: 0 0 16px var(--accent-gold-dim);
    animation: clock-glow 2s ease-in-out infinite;
}

.player-card__clock--low {
    background: linear-gradient(135deg, var(--accent-danger), var(--accent-danger-dark));
    color: white;
    border-color: transparent;
    box-shadow: 0 0 16px rgba(255, 59, 48, 0.3);
    animation: clock-urgent 0.6s ease-in-out infinite;
}

.player-card__clock--warning {
    background: linear-gradient(135deg, #F59E0B, #D97706);
    color: white;
    border-color: transparent;
    box-shadow: 0 0 16px rgba(245, 158, 11, 0.3);
    animation: clock-warning 1.2s ease-in-out infinite;
}

.player-card__clock--critical {
    background: linear-gradient(135deg, var(--accent-danger), var(--accent-danger-dark));
    color: white;
    border-color: transparent;
    box-shadow: 0 0 20px rgba(255, 59, 48, 0.45);
    animation: clock-critical 0.45s ease-in-out infinite;
}

@keyframes clock-glow {
    0%, 100% { box-shadow: 0 0 16px var(--accent-gold-dim); }
    50% { box-shadow: 0 0 24px var(--accent-gold-dim); }
}

@keyframes clock-urgent {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes clock-warning {
    0%, 100% { box-shadow: 0 0 12px rgba(245, 158, 11, 0.3); }
    50% { box-shadow: 0 0 24px rgba(245, 158, 11, 0.55); }
}

@keyframes clock-critical {
    0%, 100% { opacity: 1; box-shadow: 0 0 20px rgba(255, 59, 48, 0.45); }
    50% { opacity: 0.72; box-shadow: 0 0 32px rgba(255, 59, 48, 0.65); }
}

/* ═══════════════════════════════════════════════════════════════
   GAME ROOM LAYOUT — Cinematic
   ═══════════════════════════════════════════════════════════════ */
.game-room {
    display: grid;
    /* minmax(0,…) so a wide child (nowrap control row, engine line, table)
       can never inflate the track past the viewport — the child clips or
       wraps inside its own card instead of pushing the whole page wider. */
    grid-template-columns: auto minmax(0, 1fr);
    gap: var(--space-5);
    padding: var(--space-5);
    max-width: 1200px;
    margin: 0 auto;
    align-items: start;
}

.game-room__board-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-width: 0;
}

.game-room__board-wrapper {
    position: relative;
    width: min(calc(100vh - 220px), var(--board-max-size));
    /* Global safety cap: even a page that sets width:100% (e.g. the Openings
       explorer in a wide grid column) can never render a giant board — it is
       clamped to --board-max-size. The drag-grip lifts this by writing an
       inline max-width when the user actually resizes, so resizing still works;
       a refresh drops the inline style and returns to this sensible default. */
    max-width: min(100%, var(--board-max-size));
    aspect-ratio: 1;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow:
        0 0 0 4px var(--board-frame),
        0 0 0 5px rgba(255,255,255,0.05),
        var(--shadow-xl),
        0 0 60px rgba(0, 0, 0, 0.4);
}

.game-room__board-wrapper canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
}

.game-room__panels {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-width: 290px;
    max-width: 340px;
}

.game-room__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    justify-content: center;
    padding: var(--space-2) 0;
}

/* Panel Section Headers */
.panel-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--border-subtle);
}

.panel-header__icon {
    width: 20px;
    height: 20px;
    color: var(--accent-primary);
    opacity: 0.8;
}

.panel-header__title {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.panel-header__badge {
    margin-left: auto;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-weight: 500;
}

/* ═══════════════════════════════════════════════════════════════
   MOVE LIST — Premium
   ═══════════════════════════════════════════════════════════════ */
.move-list {
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    max-height: 350px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-primary-dim) transparent;
}

.move-list::-webkit-scrollbar {
    width: 4px;
}

.move-list::-webkit-scrollbar-track {
    background: transparent;
}

.move-list::-webkit-scrollbar-thumb {
    background: var(--accent-primary-dim);
    border-radius: 2px;
}

.move-list::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary-glow);
    box-shadow: 0 0 4px var(--accent-primary-glow);
}

.move-list__row {
    display: flex;
    align-items: center;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    transition: background var(--duration-fast);
}

.move-list__row:nth-child(odd) {
    background: rgba(255, 255, 255, 0.02);
}

.move-list__number {
    min-width: 36px;
    color: var(--text-muted);
    font-size: var(--font-size-xs);
    flex-shrink: 0;
    text-align: right;
    padding-right: var(--space-2);
}

.move-list__move {
    flex: 1;
    padding: 3px var(--space-2);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
    color: var(--text-secondary);
}

.move-list__move:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.move-list__move--active {
    background: var(--accent-primary-dim);
    color: var(--accent-primary-hover);
    font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════════
   OPENING DETAILS PANEL
   ═══════════════════════════════════════════════════════════════ */
.opening-panel {
    padding: var(--space-3);
}

.opening-panel__name {
    font-weight: 600;
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.opening-panel__eco {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--accent-gold);
    font-weight: 600;
}

.opening-panel__stats {
    display: flex;
    gap: var(--space-3);
    margin-top: var(--space-2);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════
   ENGINE ANALYSIS PANEL
   ═══════════════════════════════════════════════════════════════ */
.analysis-panel {
    padding: var(--space-3);
}

.analysis-panel__header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.analysis-panel__avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10B981, #059669);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: white;
}

.analysis-panel__eval {
    font-family: var(--font-mono);
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--text-primary);
}

.analysis-panel__depth {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-left: auto;
}

.analysis-panel__best-move {
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    color: var(--accent-secondary);
    padding: var(--space-2);
    background: rgba(79, 195, 247, 0.06);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(79, 195, 247, 0.1);
}

/* Evaluation Bar */
.eval-bar {
    width: 24px;
    height: 100%;
    min-height: 200px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #1a1a1a;
    border: 1px solid var(--border-default);
    position: relative;
    flex-shrink: 0;
}

.eval-bar__fill {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50%;
    background: linear-gradient(to top, #f0f0f0, #e0e0e0);
    transition: height var(--duration-slow) var(--ease-out);
}

.eval-bar__label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 700;
    color: var(--text-primary);
    z-index: 1;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* ═══════════════════════════════════════════════════════════════
   CHAT — Glass Panel
   ═══════════════════════════════════════════════════════════════ */
.chat {
    display: flex;
    flex-direction: column;
    height: 220px;
    border-radius: var(--radius-lg);
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.chat__messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    scrollbar-width: thin;
    scrollbar-color: var(--accent-primary-dim) transparent;
}

.chat__message {
    font-size: var(--font-size-sm);
    line-height: 1.4;
    color: var(--text-secondary);
}

.chat__message-author {
    font-weight: 600;
    color: var(--accent-secondary);
}

.chat__input-row {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-2);
    border-top: 1px solid var(--border-subtle);
    background: rgba(0, 0, 0, 0.15);
}

.chat__input {
    flex: 1;
    height: 34px;
    padding: 0 var(--space-3);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    outline: none;
    transition: all var(--duration-fast);
}

.chat__input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-primary-dim);
}

/* ═══════════════════════════════════════════════════════════════
   LOBBY — Premium Layout
   ═══════════════════════════════════════════════════════════════ */
.lobby {
    display: grid;
    /* minmax(0,…): the open-games table's min-content must scroll in its card
       (see #lobby-games) rather than widen every card past the viewport. */
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: var(--space-6);
    padding: var(--space-6);
    max-width: var(--content-max-width);
    margin: 0 auto;
}

.lobby__main {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    min-width: 0;
}

.lobby__sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    min-width: 0;
}

.quick-play {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-3);
}

.quick-play__btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-5) var(--space-3);
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-out);
    color: var(--text-primary);
    position: relative;
    overflow: hidden;
}

/* Top glow line on quick-play buttons */
.quick-play__btn::before {
    content: '';
    position: absolute;
    top: 0; left: 20%; right: 20%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
    transition: all var(--duration-normal);
}

.quick-play__btn:hover {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow), var(--shadow-md);
    transform: translateY(-3px);
}

.quick-play__btn:hover::before {
    left: 10%; right: 10%;
    background: linear-gradient(90deg, transparent, var(--accent-primary-glow), transparent);
}

.quick-play__btn:active {
    transform: translateY(-1px);
}

.quick-play__time {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    font-family: var(--font-mono);
}

.quick-play__label {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════════
   GAME TABLE — Glass Rows
   ═══════════════════════════════════════════════════════════════ */
.game-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 var(--space-1);
}

.game-table th {
    padding: var(--space-2) var(--space-3);
    text-align: left;
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.game-table td {
    padding: var(--space-3);
    background: rgba(255, 255, 255, 0.02);
    font-size: var(--font-size-sm);
    transition: background var(--duration-fast);
}

.game-table tr td:first-child {
    border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.game-table tr td:last-child {
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.game-table tr:hover td {
    background: var(--bg-hover);
}

/* Wide tables scroll inside their own card on narrow screens; combined with
   the minmax(0,…) grid tracks above, a table's min-content can no longer
   push the whole page wider than the viewport. */
#lobby-games,
#leaderboard-card {
    overflow-x: auto;
}

/* Leaderboard category chips live in an overflow-x:auto row: without this
   they shrink instead of scrolling, and .btn's overflow:hidden then crops
   the labels mid-word ("Overal", "Bulle", …). */
.leaderboard-tab {
    flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════
   RESULT DIALOG — Cinematic
   ═══════════════════════════════════════════════════════════════ */
.result-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--duration-slow) var(--ease-out);
}

.result-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.result-dialog {
    background: var(--glass-bg-strong);
    backdrop-filter: blur(24px);
    border: 1px solid var(--glass-border-accent);
    border-radius: var(--radius-2xl);
    padding: var(--space-10) var(--space-12);
    text-align: center;
    box-shadow: var(--shadow-xl), 0 0 40px rgba(47, 93, 255, 0.08);
    transform: scale(0.9) translateY(20px);
    transition: transform var(--duration-slow) var(--ease-spring);
    max-width: 420px;
    width: 90%;
    position: relative;
    overflow: hidden;
}

/* Top glow accent */
.result-dialog::before {
    content: '';
    position: absolute;
    top: 0; left: 15%; right: 15%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent-primary), transparent);
    border-radius: 1px;
}

.result-overlay.visible .result-dialog {
    transform: scale(1) translateY(0);
}

.result-dialog__icon {
    font-size: 56px;
    margin-bottom: var(--space-4);
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}

.result-dialog__title {
    font-family: var(--font-display);
    font-size: var(--font-size-3xl);
    font-weight: 700;
    margin-bottom: var(--space-2);
    letter-spacing: 0.02em;
}

.result-dialog__subtitle {
    font-size: var(--font-size-md);
    color: var(--text-secondary);
    margin-bottom: var(--space-6);
}

.result-dialog__rating {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    font-family: var(--font-mono);
    font-size: var(--font-size-lg);
    margin-bottom: var(--space-6);
}

.result-dialog__rating-change--positive {
    color: var(--accent-success);
}

.result-dialog__rating-change--negative {
    color: var(--accent-danger);
}

.result-dialog__actions {
    display: flex;
    gap: var(--space-3);
    justify-content: center;
}

/* ═══════════════════════════════════════════════════════════════
   MATCHMAKING MODAL — Cinematic
   ═══════════════════════════════════════════════════════════════ */
.matchmaking-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--duration-slow) var(--ease-out);
}

.matchmaking-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.matchmaking-dialog {
    background: var(--glass-bg-strong);
    backdrop-filter: blur(24px);
    border: 1px solid var(--glass-border-accent);
    border-radius: var(--radius-2xl);
    padding: var(--space-10);
    text-align: center;
    min-width: 340px;
    box-shadow: var(--shadow-xl);
}

.matchmaking-spinner {
    width: 52px;
    height: 52px;
    border: 3px solid var(--border-default);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto var(--space-6);
    box-shadow: 0 0 12px var(--accent-primary-glow);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ═══════════════════════════════════════════════════════════════
   PROMOTION DIALOG
   ═══════════════════════════════════════════════════════════════ */
.promotion-dialog {
    position: absolute;
    display: flex;
    flex-direction: column;
    background: var(--glass-bg-strong);
    backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border-accent);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl), 0 0 20px rgba(47, 93, 255, 0.1);
    z-index: 100;
    overflow: hidden;
}

.promotion-dialog__piece {
    width: 64px;
    height: 64px;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
    display: flex;
    align-items: center;
    justify-content: center;
}

.promotion-dialog__piece:hover {
    background: var(--bg-hover);
    transform: scale(1.05);
}

/* ═══════════════════════════════════════════════════════════════
   PROMOTION OVERLAY — Full-screen modal (replaces inline dialog)
   ═══════════════════════════════════════════════════════════════ */
.promotion-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4000;
    opacity: 0;
    transition: opacity var(--duration-normal) var(--ease-out);
}

.promotion-overlay--visible {
    opacity: 1;
}

.promotion-overlay__dialog {
    background: var(--glass-bg-strong);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--glass-border-accent);
    border-radius: var(--radius-2xl);
    padding: var(--space-6) var(--space-8);
    text-align: center;
    box-shadow: var(--shadow-xl), 0 0 40px rgba(47, 93, 255, 0.1);
    transform: scale(0.9) translateY(16px);
    transition: transform var(--duration-normal) var(--ease-spring);
}

.promotion-overlay--visible .promotion-overlay__dialog {
    transform: scale(1) translateY(0);
}

.promotion-overlay__title {
    font-family: var(--font-display);
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-bottom: var(--space-5);
    color: var(--text-primary);
    letter-spacing: 0.03em;
}

.promotion-overlay__pieces {
    display: flex;
    gap: var(--space-3);
    justify-content: center;
}

.promotion-overlay__piece {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    background: var(--glass-bg);
    border: 2px solid var(--border-default);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
    color: var(--text-secondary);
    outline: none;
    min-width: 80px;
}

.promotion-overlay__piece:hover,
.promotion-overlay__piece:focus {
    background: var(--bg-hover);
    border-color: var(--border-strong);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.promotion-overlay__piece.selected {
    background: var(--accent-primary-dim);
    border-color: var(--accent-primary);
    box-shadow: 0 0 16px var(--accent-primary-glow);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.promotion-overlay__label {
    font-size: var(--font-size-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.promotion-overlay__hint {
    margin-top: var(--space-4);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    opacity: 0.7;
}

/* ═══════════════════════════════════════════════════════════════
   PREMOVE INDICATOR
   ═══════════════════════════════════════════════════════════════ */
.premove-indicator {
    display: none;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: rgba(47, 93, 255, 0.08);
    border: 1px solid rgba(47, 93, 255, 0.2);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    color: var(--accent-primary-hover);
    font-weight: 500;
    transition: all var(--duration-normal) var(--ease-out);
}

.premove-indicator.visible {
    display: flex;
}

.premove-indicator__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-primary);
    animation: premove-pulse 1.2s ease-in-out infinite;
    flex-shrink: 0;
    box-shadow: 0 0 6px var(--accent-primary-glow);
}

.premove-indicator__text {
    white-space: nowrap;
    font-family: var(--font-mono);
}

.premove-indicator__cancel {
    margin-left: auto;
    padding: 2px 8px;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.premove-indicator__cancel:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

@keyframes premove-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.75); }
}

/* ═══════════════════════════════════════════════════════════════
   DRAW OFFER BANNER
   ═══════════════════════════════════════════════════════════════ */
.draw-offer-banner {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: rgba(212, 178, 106, 0.08);
    border: 1px solid rgba(212, 178, 106, 0.2);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    color: var(--accent-gold);
}

.draw-offer-banner.hidden { display: none; }

.draw-offer-banner__text { flex: 1; }

.draw-offer-banner__actions {
    display: flex;
    gap: var(--space-2);
}

/* Premove Board Overlay (CSS fallback) */
.board-premove-overlay {
    position: absolute;
    pointer-events: none;
    z-index: 2;
    border: 2.5px dashed rgba(47, 93, 255, 0.6);
    background: rgba(47, 93, 255, 0.15);
    border-radius: 2px;
    animation: premove-border-march 0.8s linear infinite;
}

@keyframes premove-border-march {
    0% { border-color: rgba(47, 93, 255, 0.6); }
    50% { border-color: rgba(47, 93, 255, 0.25); }
    100% { border-color: rgba(47, 93, 255, 0.6); }
}

/* ═══════════════════════════════════════════════════════════════
   AUTH FORMS — Premium Glass
   ═══════════════════════════════════════════════════════════════ */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--nav-height));
    padding: var(--space-6);
}

.auth-form {
    width: 100%;
    max-width: 420px;
}

.auth-form__title {
    font-family: var(--font-display);
    font-size: var(--font-size-3xl);
    font-weight: 700;
    text-align: center;
    margin-bottom: var(--space-2);
    letter-spacing: 0.02em;
}

.auth-form__subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: var(--space-8);
}

.auth-form__divider {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    margin: var(--space-6) 0;
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

.auth-form__divider::before,
.auth-form__divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-default);
}

/* ═══════════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS — Premium
   ═══════════════════════════════════════════════════════════════ */
.toast-container {
    position: fixed;
    top: calc(var(--nav-height) + var(--space-4));
    right: var(--space-4);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.toast {
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-md);
    background: var(--glass-bg-strong);
    backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
    font-size: var(--font-size-sm);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    animation: toast-in var(--duration-slow) var(--ease-spring);
    max-width: 380px;
}

.toast--success { border-left: 3px solid var(--accent-success); }
.toast--error { border-left: 3px solid var(--accent-danger); }
.toast--info { border-left: 3px solid var(--accent-primary); }

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateX(60px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

/* ═══════════════════════════════════════════════════════════════
   LOADING SCREEN — Cinematic
   ═══════════════════════════════════════════════════════════════ */
.loading-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.6s ease, visibility 0.6s ease;
}

.loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-screen__logo {
    font-family: var(--font-display);
    font-size: var(--font-size-4xl);
    font-weight: 700;
    letter-spacing: 0.06em;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: var(--space-6);
    animation: logo-breathe 2s ease-in-out infinite;
}

.loading-screen__bar {
    width: 200px;
    height: 2px;
    background: var(--border-default);
    border-radius: 1px;
    overflow: hidden;
}

.loading-screen__bar-fill {
    width: 40%;
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-gold));
    border-radius: 1px;
    animation: loading-slide 1.5s ease-in-out infinite;
}

@keyframes logo-breathe {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 1; }
}

@keyframes loading-slide {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}

/* ═══════════════════════════════════════════════════════════════
   SKELETON LOADERS
   ═══════════════════════════════════════════════════════════════ */
.skeleton {
    background: linear-gradient(90deg,
        rgba(255,255,255,0.02) 25%,
        rgba(255,255,255,0.05) 50%,
        rgba(255,255,255,0.02) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.8s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ═══════════════════════════════════════════════════════════════
   SCROLLBAR — Premium Minimal
   ═══════════════════════════════════════════════════════════════ */
::-webkit-scrollbar {
    width: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(47, 93, 255, 0.3);
}

/* ═══════════════════════════════════════════════════════════════
   PANEL ANIMATIONS — Fade In
   ═══════════════════════════════════════════════════════════════ */
.fade-in {
    animation: fadeInUp var(--duration-slower) var(--ease-out) both;
}

.fade-in-delay-1 { animation-delay: 100ms; }
.fade-in-delay-2 { animation-delay: 200ms; }
.fade-in-delay-3 { animation-delay: 300ms; }
.fade-in-delay-4 { animation-delay: 400ms; }

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Glow pulse for accents */
@keyframes glow-pulse {
    0%, 100% { box-shadow: 0 0 8px var(--accent-primary-glow); }
    50% { box-shadow: 0 0 20px var(--accent-primary-glow); }
}

/* ═══════════════════════════════════════════════════════════════
   UTILITY CLASSES
   ═══════════════════════════════════════════════════════════════ */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--accent-success); }
.text-danger { color: var(--accent-danger); }
.text-gold { color: var(--accent-gold); }
.text-mono { font-family: var(--font-mono); }
.text-display { font-family: var(--font-display); }
.font-bold { font-weight: 700; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════════════
   COACH COMMENTATOR — animated Play-vs-AI character (Duolingo-style)
   Moods are driven by .coach--happy/--shocked/--thinking/--sad/--smug
   classes set by ChessCommentator; expressions swap SVG parts via CSS.
   ═══════════════════════════════════════════════════════════════ */
.coach-card {
    padding: var(--space-3) var(--space-4);
    overflow: visible;
}

.coach {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    position: relative;
}

.coach__avatar {
    flex-shrink: 0;
    width: 64px;
    text-align: center;
}

.coach__name {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
}

.coach-svg {
    width: 64px;
    height: 64px;
    display: block;
    animation: coach-bob 3.6s ease-in-out infinite;
}

@keyframes coach-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

/* ── Speech bubble ── */
.coach__bubble {
    position: relative;
    flex: 1;
    min-width: 0;
    min-height: 56px;
    display: flex;
    align-items: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-3);
}

.coach__bubble::before {
    content: '';
    position: absolute;
    left: -6px;
    top: 22px;
    width: 10px;
    height: 10px;
    background: var(--bg-elevated);
    border-left: 1px solid var(--border-default);
    border-bottom: 1px solid var(--border-default);
    transform: rotate(45deg);
}

.coach__bubble--pop {
    animation: coach-bubble-pop 0.28s var(--ease-out, ease-out);
}

@keyframes coach-bubble-pop {
    0% { transform: scale(0.94); opacity: 0.5; }
    60% { transform: scale(1.02); }
    100% { transform: scale(1); opacity: 1; }
}

.coach__text {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    line-height: 1.45;
    word-break: break-word;
}

.coach__mute {
    position: absolute;
    top: -4px;
    right: 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    padding: 4px;
    opacity: 0.45;
    transition: opacity var(--duration-fast, 0.15s) ease;
}

.coach__mute:hover { opacity: 1; }

.coach--muted .coach__bubble { opacity: 0.45; }
.coach--muted .coach-svg { animation: none; opacity: 0.7; }

/* ── Character parts ── */
.coach-svg__face { fill: #E8B98A; }
.coach-svg__hair, .coach-svg__stache { fill: #4B5058; }
.coach-svg__body { fill: var(--accent-primary); }
.coach-svg__collar { fill: var(--accent-gold); }
.coach-svg__eye { fill: #23262B; }
.coach-svg__brow { fill: #4B5058; }
.coach-svg__mouth {
    fill: none;
    stroke: #7A4A32;
    stroke-width: 2.5;
    stroke-linecap: round;
    display: none;
}
.coach-svg__mouth--shocked { fill: #7A4A32; stroke: none; }
.coach-svg__mouth--neutral { display: block; }

.coach-svg__head,
.coach-svg__eyes,
.coach-svg__brow,
.coach-svg__mouth {
    transform-box: fill-box;
    transform-origin: center;
    transition: transform 0.25s ease;
}

/* Idle blink */
.coach-svg__eyes { animation: coach-blink 4.2s infinite; }

@keyframes coach-blink {
    0%, 93%, 100% { transform: scaleY(1); }
    96% { transform: scaleY(0.12); }
}

/* ── Moods ── */
.coach--happy .coach-svg__mouth--neutral,
.coach--shocked .coach-svg__mouth--neutral,
.coach--thinking .coach-svg__mouth--neutral,
.coach--sad .coach-svg__mouth--neutral,
.coach--smug .coach-svg__mouth--neutral { display: none; }

.coach--happy .coach-svg__mouth--happy { display: block; }
.coach--happy .coach-svg__head { animation: coach-hop 0.5s ease; }
.coach--happy .coach-svg__brow { transform: translateY(-2px); }

.coach--shocked .coach-svg__mouth--shocked { display: block; }
.coach--shocked .coach-svg__head { animation: coach-shake 0.4s ease; }
.coach--shocked .coach-svg__eyes { transform: scale(1.35); animation: none; }
.coach--shocked .coach-svg__brow { transform: translateY(-4px); }

.coach--thinking .coach-svg__mouth--neutral { display: block; }
.coach--thinking .coach-svg__head { transform: rotate(-4deg); }
.coach--thinking .coach-svg__eyes { transform: translate(2px, -1.5px); }
.coach--thinking .coach-svg__brow--l { transform: translateY(-3px) rotate(-6deg); }

.coach--sad .coach-svg__mouth--sad { display: block; }
.coach--sad .coach-svg__head { transform: translateY(2px); }
.coach--sad .coach-svg__brow--l { transform: rotate(8deg); }
.coach--sad .coach-svg__brow--r { transform: rotate(-8deg); }

.coach--smug .coach-svg__mouth--smug { display: block; }
.coach--smug .coach-svg__brow--r { transform: translateY(-3px) rotate(-8deg); }

@keyframes coach-hop {
    0%, 100% { transform: translateY(0); }
    40% { transform: translateY(-4px); }
}

@keyframes coach-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2.5px); }
    75% { transform: translateX(2.5px); }
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — Adaptive Layouts
   ═══════════════════════════════════════════════════════════════ */

/* ── Navbar: "More ▾" mega menu + fit ─────────────────────────────
   The signed-in nav has far more destinations than fit one row (which used
   to shove the user menu + Logout off-screen). Most now live in a "More ▾"
   mega menu; the bar keeps a few shortcuts (icons kept) and the right-hand
   cluster is pinned so it can never be pushed off. */
.navbar__right { flex-shrink: 0; }
.navbar__nav { min-width: 0; }
.navbar__link { white-space: nowrap; }

.navbar__more { position: static; }   /* so .mega anchors to the fixed .navbar, unclipped */
.navbar__more-btn {
    display: inline-flex;
    align-items: center;
    background: none;
    border: none;
    cursor: pointer;
    font: inherit;
    position: relative;
}
.navbar__more-chevron { transition: transform var(--duration-normal) var(--ease-out); opacity: 0.7; }
.navbar__more.open .navbar__more-chevron { transform: rotate(180deg); }
.navbar__more.open .navbar__more-btn { color: var(--text-primary); background: var(--bg-hover); }
.navbar__more-hamburger { display: none; }   /* shown only as the mobile menu trigger (≤640px) */

/* Mega panel — absolutely positioned against the fixed .navbar so the nav's
   own box never clips it; hidden until #nav-more gets the .open class. */
.mega {
    position: absolute;
    top: calc(100% - 2px);
    left: var(--space-6);
    max-width: calc(100vw - 2 * var(--space-6));
    background: var(--glass-bg-strong);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl), 0 8px 40px rgba(0, 0, 0, 0.45);
    padding: var(--space-4);
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity var(--duration-normal) var(--ease-out),
                transform var(--duration-normal) var(--ease-out),
                visibility var(--duration-normal);
    pointer-events: none;
}
.navbar__more.open .mega {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.mega__grid { display: flex; flex-wrap: wrap; gap: var(--space-4) var(--space-5); }
.mega__col { min-width: 166px; }
.mega__col--account { border-left: 1px solid var(--border-subtle); padding-left: var(--space-4); }
.mega__head {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 0 var(--space-2) var(--space-2);
    margin-bottom: var(--space-1);
    border-bottom: 1px solid var(--border-subtle);
}
.mega__link {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    text-decoration: none;
    position: relative;
    transition: background var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}
.mega__link svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.7; }
.mega__link > span { display: flex; flex-direction: column; line-height: 1.3; }
.mega__link em { font-style: normal; font-size: var(--font-size-xs); color: var(--text-muted); }
.mega__link:hover { background: var(--bg-hover); color: var(--text-primary); }
.mega__link:hover svg { opacity: 1; }
.mega__link.active { background: var(--accent-primary-dim); color: var(--text-primary); }
.mega__link.active svg { color: var(--accent-primary); opacity: 1; }
.mega__link .notification-badge { position: static; margin-left: auto; }

.mega__link--feature { background: var(--accent-primary-dim); color: var(--text-primary); padding: var(--space-3) var(--space-2); }
.mega__link--feature svg { width: 22px; height: 22px; color: var(--accent-primary); opacity: 1; }
.mega__link--feature strong { font-weight: 600; }
.mega__link--feature:hover { background: var(--accent-primary-glow); }

.mega__link--admin { color: var(--accent-gold); }
.mega__link--admin svg { color: var(--accent-gold); opacity: 0.9; }
.mega__link--admin:hover { background: var(--accent-gold-dim); color: var(--accent-gold); }

.mega__mobile { display: none; }   /* drawer-only extras (theme toggle), shown ≤640px */
.mega__mobile .mega__link { width: 100%; text-align: left; background: none; border: none; cursor: pointer; font: inherit; }

/* Reclaim width on smaller desktops; collapse bar shortcuts into More.
   Bar order: 1 Play · 2 Puzzles · 3 Openings · 4 Legends · 5 Broadcasts ·
   6 Learn · 7 Leaderboard · 8 More.
   Hidden shortcuts remain reachable inside the More menu — #mega-link-legends
   and #mega-link-broadcasts below mirror these same two breakpoints so each
   item shows in exactly one place (bar or More) at any given width. */
@media (max-width: 1400px) {
    .navbar { padding: 0 var(--space-4); }
    .navbar__nav { margin-left: var(--space-4); gap: 2px; }
    .navbar__link { padding: var(--space-2) var(--space-3); }
    .mega { left: var(--space-4); }
}
@media (max-width: 1200px) {
    .navbar__nav > li:nth-child(5),
    .navbar__nav > li:nth-child(6),
    .navbar__nav > li:nth-child(7) { display: none; }
}
@media (max-width: 1000px) {
    .navbar__nav > li:nth-child(3),
    .navbar__nav > li:nth-child(4) { display: none; }
    .navbar__nav { margin-left: var(--space-3); }
}
@media (min-width: 1001px) {
    #mega-link-legends { display: none; }
}
@media (min-width: 1201px) {
    #mega-link-broadcasts { display: none; }
}

@media (max-width: 1024px) {
    .game-room {
        grid-template-columns: minmax(0, 1fr);
        max-width: 640px;
    }
    .game-room__board-wrapper {
        width: min(calc(100vw - 32px), 540px);
        margin: 0 auto;
    }
    .game-room__panels {
        max-width: none;
        min-width: 0;
    }
    .lobby {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 640px) {
    :root {
        --nav-height: 52px;
        --space-6: 16px;
    }

    /* Mobile nav: hide the bar shortcuts and turn "More" into a hamburger that
       opens the mega menu as a full-width drawer (it already holds every link). */
    .navbar { padding: 0 var(--space-2); }
    .navbar__nav { display: flex; margin-left: var(--space-2); }
    .navbar__nav > li:not(.navbar__more) { display: none; }
    /* Push the hamburger to the far right, after the avatar/logout/bell —
       .navbar__right's margin-left:auto carries it (and whatever visually
       follows it) to the end, so reordering here is enough; no DOM change. */
    .navbar__right { order: 1; }
    .navbar__nav { order: 2; }
    .navbar__more-dots, .navbar__more-label, .navbar__more-chevron { display: none; }
    .navbar__more-hamburger { display: block; }
    .navbar__more-btn { padding: var(--space-1) var(--space-2); }
    .navbar__logo { gap: var(--space-1); }
    .navbar__right { gap: var(--space-1); }
    /* Trim the mobile bar so the hamburger + account controls fit one row:
       drop the theme toggle (moved into the drawer) and the username text. */
    #btn-theme-toggle { display: none; }
    .navbar__user span { display: none; }
    .mega__mobile { display: block; margin-top: var(--space-3); border-top: 1px solid var(--border-subtle); padding-top: var(--space-2); }

    .mega {
        position: fixed;
        top: var(--nav-height);
        left: 0;
        right: 0;
        max-width: none;
        max-height: calc(100vh - var(--nav-height));
        overflow-y: auto;
        border-radius: 0;
        border-left: none;
        border-right: none;
        padding: var(--space-4) var(--space-4) var(--space-6);
    }
    /* Grid, not a single stacked column: each category (Play/Learn/Explore/Tools)
       sits two-up (three-up on the wider end of this breakpoint) so the drawer
       reads in half the scroll height instead of one long list. The account
       section (border-top divider) always spans the full width as its own row. */
    .mega__grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: var(--space-4) var(--space-3);
    }
    .mega__col { min-width: 0; }
    .mega__col--account {
        grid-column: 1 / -1;
        border-left: none;
        padding-left: 0;
        padding-top: var(--space-3);
        border-top: 1px solid var(--border-subtle);
    }

    .navbar__logo-text {
        font-size: var(--font-size-base);
    }

    .quick-play {
        grid-template-columns: repeat(2, 1fr);
    }

    .game-room__board-wrapper {
        width: min(calc(100vw - 16px), calc(100vh - 200px));
    }

    .game-room {
        padding: var(--space-2);
        gap: var(--space-2);
    }

    .container {
        padding: var(--space-3);
    }

    .auth-form {
        padding: 0 var(--space-2);
    }

    .player-card {
        padding: var(--space-2) var(--space-3);
    }

    .player-card__clock {
        font-size: var(--font-size-lg);
        min-width: 80px;
        padding: var(--space-1) var(--space-3);
    }

    .chat {
        height: min(220px, 30vh);
    }

    .promotion-overlay__pieces {
        gap: var(--space-2);
    }

    .promotion-overlay__piece {
        min-width: 64px;
        padding: var(--space-2) var(--space-3);
    }

    .promotion-overlay__piece img {
        width: 44px !important;
        height: 44px !important;
    }
}

/* Narrow phones: collapse the wordmark to the crown icon so the hamburger and
   account controls (Sign In/Register or avatar/Logout/bell) fit one row. */
@media (max-width: 440px) {
    .navbar__logo-text { display: none; }
}

/* Landscape on small screens — keep board in view without scrolling */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 600px) {
    .game-room {
        grid-template-columns: auto minmax(0, 1fr);
        padding: var(--space-2);
        gap: var(--space-2);
        max-width: none;
    }

    .game-room__board-wrapper {
        width: min(calc(100vh - 80px), 440px);
    }

    .game-room__board-section {
        gap: var(--space-1);
    }

    .player-card {
        padding: var(--space-1) var(--space-2);
    }

    .player-card__avatar {
        width: 30px;
        height: 30px;
        font-size: var(--font-size-sm);
    }

    .player-card__clock {
        font-size: var(--font-size-base);
        min-width: 70px;
        padding: var(--space-1) var(--space-2);
    }

    .game-room__panels {
        gap: var(--space-2);
    }

    .chat {
        height: 120px;
    }

    .move-list {
        max-height: 180px;
    }
}

/* ── Reduced motion (#26) ─────────────────────────────────────────
   Honour the OS "reduce motion" setting: neutralise non-essential
   animations/transitions and decorative ambient motion. Opacity-based
   fades are kept near-instant so content never gets stuck hidden. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    html { scroll-behavior: auto; }

    /* Decorative ambient layers add motion with no informational value. */
    .ambient-particles { display: none; }

    /* Ensure entrance animations leave content fully visible. */
    .fade-in,
    .fade-in-up,
    [class*="fade-in-delay"] {
        opacity: 1 !important;
        transform: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   BOARD RESIZE GRIP — attached by assets/js/util/board-resize.js
   to every board wrapper (drag the corner to resize, double-click
   to reset, arrow keys when focused).
   ═══════════════════════════════════════════════════════════════ */
.board-resize-grip {
    position: absolute;
    right: 3px;
    bottom: 3px;
    z-index: 6;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.38);
    color: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: nwse-resize;
    touch-action: none;
    opacity: 0.55;
    transition: opacity 0.15s, background 0.15s;
}
.board-resize-grip:hover,
.board-resize-grip:focus-visible {
    opacity: 1;
    background: rgba(0, 0, 0, 0.6);
    outline: none;
}
.board-resize-grip svg { pointer-events: none; display: block; }
body.board-resizing { cursor: nwse-resize; user-select: none; }
@media (pointer: coarse) {
    .board-resize-grip { width: 30px; height: 30px; opacity: 0.7; }
}
