/* ============================================================
   SimulateCubing — Design System & Styles
   ============================================================ */

/* --- CSS Reset & Variables --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Core Palette - Competitive & Comfortable */
    --hue-primary: 250;
    --hue-accent: 16;

    --clr-bg: #0B0D17;
    --clr-bg-elevated: #12152A;
    --clr-bg-card: #161933;
    --clr-bg-card-hover: #1C2040;
    --clr-surface: #1E2244;
    --clr-border: rgba(255, 255, 255, 0.06);
    --clr-border-active: rgba(99, 102, 241, 0.4);

    --clr-text: #E8E9F0;
    --clr-text-secondary: #8B8FA8;
    --clr-text-muted: #5A5E7A;

    --clr-primary: #6366F1;
    --clr-primary-hover: #818CF8;
    --clr-primary-glow: rgba(99, 102, 241, 0.25);

    --clr-accent: #F97316;
    --clr-accent-hover: #FB923C;
    --clr-accent-glow: rgba(249, 115, 22, 0.25);

    --clr-success: #10B981;
    --clr-success-glow: rgba(16, 185, 129, 0.2);
    --clr-danger: #EF4444;
    --clr-danger-glow: rgba(239, 68, 68, 0.2);
    --clr-warning: #F59E0B;
    --clr-info: #3B82F6;

    --clr-gold: #F59E0B;
    --clr-silver: #94A3B8;
    --clr-bronze: #D97706;

    --clr-timer: #22D3EE;
    --clr-timer-running: #10B981;
    --clr-timer-inspection: #F59E0B;
    --clr-timer-stopped: #EF4444;

    /* Typography */
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;
    --space-3xl: 64px;

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow-primary: 0 0 30px var(--clr-primary-glow);
    --shadow-glow-accent: 0 0 30px var(--clr-accent-glow);

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Theme */
[data-theme="light"] {
    --clr-bg: #F0F2F9;
    --clr-bg-elevated: #FFFFFF;
    --clr-bg-card: #FFFFFF;
    --clr-bg-card-hover: #F5F6FA;
    --clr-surface: #E8EAF2;
    --clr-border: rgba(0, 0, 0, 0.08);
    --clr-border-active: rgba(99, 102, 241, 0.5);

    --clr-text: #1A1D30;
    --clr-text-secondary: #5A5E7A;
    --clr-text-muted: #9196B0;

    --clr-primary-glow: rgba(99, 102, 241, 0.15);
    --clr-accent-glow: rgba(249, 115, 22, 0.15);
    --clr-success-glow: rgba(16, 185, 129, 0.12);
    --clr-danger-glow: rgba(239, 68, 68, 0.12);

    --clr-timer: #6366F1;
    --clr-timer-running: #059669;
    --clr-timer-inspection: #D97706;
    --clr-timer-stopped: #DC2626;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/* --- Base Styles --- */
html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background: var(--clr-bg);
    color: var(--clr-text);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* --- Animated Background --- */
.bg-grid {
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(99, 102, 241, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(99, 102, 241, 0.03) 1px, transparent 1px);
    background-size: 60px 60px;
    z-index: 0;
    pointer-events: none;
}

[data-theme="light"] .bg-grid {
    background-image:
        linear-gradient(rgba(99, 102, 241, 0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(99, 102, 241, 0.06) 1px, transparent 1px);
}

.bg-glow {
    position: fixed;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.4;
    pointer-events: none;
    z-index: 0;
    animation: floatGlow 20s infinite ease-in-out;
}

.bg-glow--1 {
    width: 500px;
    height: 500px;
    background: var(--clr-primary);
    top: -15%;
    left: -10%;
    opacity: 0.15;
    animation-delay: 0s;
}

.bg-glow--2 {
    width: 400px;
    height: 400px;
    background: var(--clr-accent);
    bottom: -10%;
    right: -5%;
    opacity: 0.1;
    animation-delay: -7s;
}

.bg-glow--3 {
    width: 350px;
    height: 350px;
    background: var(--clr-success);
    top: 50%;
    left: 40%;
    opacity: 0.06;
    animation-delay: -14s;
}

@keyframes floatGlow {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -20px) scale(1.05); }
    50% { transform: translate(-20px, 30px) scale(0.95); }
    75% { transform: translate(20px, 20px) scale(1.02); }
}

/* --- Navigation --- */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-xl);
    background: rgba(11, 13, 23, 0.8);
    backdrop-filter: blur(20px) saturate(1.5);
    -webkit-backdrop-filter: blur(20px) saturate(1.5);
    border-bottom: 1px solid var(--clr-border);
    transition: background var(--transition-base);
}

[data-theme="light"] .navbar {
    background: rgba(240, 242, 249, 0.85);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    user-select: none;
}

.brand-icon {
    display: flex;
    color: var(--clr-text);
}

.brand-name {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--clr-text);
}

.brand-accent {
    background: linear-gradient(135deg, var(--clr-primary), var(--clr-accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    position: fixed;
    top: 20px;
    right: 32px;
    z-index: 101;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: var(--space-sm) var(--space-md);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--clr-text-secondary);
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.nav-btn:hover, .nav-btn.active {
    color: var(--clr-text);
    background: var(--clr-bg-card);
    border-color: var(--clr-border);
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    color: var(--clr-text-secondary);
}

.theme-toggle:hover {
    background: var(--clr-bg-card);
    border-color: var(--clr-border);
    color: var(--clr-text);
}

.theme-icon.moon { display: none; }
[data-theme="light"] .theme-icon.sun { display: none; }
[data-theme="light"] .theme-icon.moon { display: block; }

/* --- Views --- */
.view {
    display: none;
    min-height: 100vh;
    padding-top: 80px;
    position: relative;
    z-index: 1;
}

.view.active {
    display: block;
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   SETUP VIEW
   ============================================================ */
.setup-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-2xl) var(--space-xl);
}

.setup-hero {
    text-align: center;
    margin-bottom: var(--space-3xl);
}

.hero-badge {
    display: inline-block;
    padding: 6px 16px;
    background: var(--clr-primary-glow);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--clr-primary-hover);
    margin-bottom: var(--space-lg);
    animation: pulseGlow 3s ease-in-out infinite;
}

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 0 0 var(--clr-primary-glow); }
    50% { box-shadow: 0 0 20px 4px var(--clr-primary-glow); }
}

.hero-title {
    font-size: clamp(2rem, 5vw, 3.5rem);
    font-weight: 900;
    line-height: 1.1;
    letter-spacing: -0.03em;
    margin-bottom: var(--space-md);
}

.gradient-text {
    background: linear-gradient(135deg, var(--clr-primary) 0%, var(--clr-accent) 50%, var(--clr-primary-hover) 100%);
    background-size: 200% auto;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientShift 4s ease-in-out infinite;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% center; }
    50% { background-position: 100% center; }
}

.hero-subtitle {
    font-size: 1.1rem;
    color: var(--clr-text-secondary);
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.7;
}

/* Setup Grid */
.setup-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
}

@media (max-width: 768px) {
    .setup-grid {
        grid-template-columns: 1fr;
    }
}

/* Setup Cards */
.setup-card {
    background: var(--clr-bg-card);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all var(--transition-base);
}

.setup-card:hover {
    border-color: var(--clr-border-active);
    box-shadow: var(--shadow-glow-primary);
    transform: translateY(-2px);
}

.card-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-lg) var(--space-lg) 0;
}

.card-icon {
    font-size: 1.5rem;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.card-body {
    padding: var(--space-lg);
}

/* Form Elements */
.form-group {
    margin-bottom: var(--space-md);
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--clr-text-secondary);
    margin-bottom: 6px;
}

.form-input, .form-select {
    width: 100%;
    padding: 10px 14px;
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-sm);
    color: var(--clr-text);
    font-family: var(--font-body);
    font-size: 0.95rem;
    transition: all var(--transition-fast);
    outline: none;
}

.form-input:focus, .form-select:focus {
    border-color: var(--clr-primary);
    box-shadow: 0 0 0 3px var(--clr-primary-glow);
}

.form-input::placeholder {
    color: var(--clr-text-muted);
}

.form-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--clr-text-muted);
    margin-top: 4px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

/* Event Chips */
.event-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.event-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

.event-chip input { display: none; }

.chip-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--clr-text-secondary);
    transition: color var(--transition-fast);
}

.event-chip:hover {
    border-color: var(--clr-primary);
    background: var(--clr-primary-glow);
}

.event-chip:hover .chip-label {
    color: var(--clr-text);
}

.event-chip.selected {
    background: var(--clr-primary);
    border-color: var(--clr-primary);
    box-shadow: 0 0 16px var(--clr-primary-glow);
}

.event-chip.selected .chip-label {
    color: #fff;
}

/* Toggle Switch */
.toggle-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--clr-text);
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--clr-surface);
    border-radius: 999px;
    transition: all var(--transition-fast);
    border: 1px solid var(--clr-border);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: var(--clr-text-muted);
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--clr-primary);
    border-color: var(--clr-primary);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
    background: #fff;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    outline: none;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--clr-primary);
    color: #fff;
    box-shadow: 0 4px 16px var(--clr-primary-glow);
}

.btn-primary:hover {
    background: var(--clr-primary-hover);
    box-shadow: 0 6px 24px var(--clr-primary-glow);
    transform: translateY(-1px);
}

.btn-accent {
    background: var(--clr-accent);
    color: #fff;
    box-shadow: 0 4px 16px var(--clr-accent-glow);
}

.btn-accent:hover {
    background: var(--clr-accent-hover);
    box-shadow: 0 6px 24px var(--clr-accent-glow);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--clr-text-secondary);
    border: 1px solid var(--clr-border);
}

.btn-ghost:hover {
    background: var(--clr-bg-card);
    color: var(--clr-text);
    border-color: var(--clr-border-active);
}

.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-lg { padding: 14px 32px; font-size: 1rem; }

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

.setup-actions {
    display: flex;
    justify-content: center;
    padding-top: var(--space-md);
}

.btn-lg svg {
    animation: pulsePlay 2s ease-in-out infinite;
}

@keyframes pulsePlay {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* ============================================================
   DASHBOARD VIEW
   ============================================================ */
.dashboard-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: var(--space-md) var(--space-lg);
    position: relative;
}

.dash-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
    gap: var(--space-md);
}

.dash-comp-title {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 6px;
}

.dash-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.dash-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.event-badge {
    background: var(--clr-primary-glow);
    color: var(--clr-primary-hover);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.round-badge {
    background: var(--clr-accent-glow);
    color: var(--clr-accent);
    border: 1px solid rgba(249, 115, 22, 0.3);
}

.solve-badge {
    background: var(--clr-success-glow);
    color: var(--clr-success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.dash-actions {
    display: flex;
    gap: 8px;
}

/* Volume Controls */
.dash-volume-control {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 6px;
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
}

.dash-volume-control #mute-noise-btn {
    padding: 4px 6px;
    border: none;
    background: transparent;
    color: var(--clr-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    min-width: auto;
    transition: color var(--transition-fast);
}

.dash-volume-control #mute-noise-btn:hover {
    color: var(--clr-primary);
}

.comp-volume-slider {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--clr-border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.comp-volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--clr-primary);
    border: 2px solid var(--clr-bg);
    cursor: pointer;
    box-shadow: 0 0 6px var(--clr-primary-glow);
}

.comp-volume-slider::-webkit-slider-thumb:hover {
    background: var(--clr-primary-hover);
    transform: scale(1.1);
}

.comp-volume-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--clr-primary);
    border: 2px solid var(--clr-bg);
    cursor: pointer;
    box-shadow: 0 0 6px var(--clr-primary-glow);
}

/* Dashboard Grid */
.dash-grid {
    display: grid;
    grid-template-columns: 1fr 1.4fr 1fr;
    grid-template-rows: auto auto 1fr;
    gap: var(--space-md);
    grid-template-areas:
        "scramble timer scorecard"
        "goal     timer leaderboard"
        "goal     timer leaderboard";
    min-height: calc(100vh - 160px);
}

@media (max-width: 1200px) {
    .dash-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto;
        grid-template-areas:
            "scramble timer"
            "scorecard timer"
            "goal leaderboard";
    }
}

@media (max-width: 768px) {
    .dash-grid {
        grid-template-columns: 1fr;
        grid-template-areas:
            "timer"
            "scramble"
            "scorecard"
            "goal"
            "leaderboard";
    }
}

/* Dashboard Cards */
.dash-card {
    background: var(--clr-bg-card);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: border-color var(--transition-base);
}

.dash-card:hover {
    border-color: var(--clr-border-active);
}

.card-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--clr-border);
    flex-shrink: 0;
}

.card-bar-title {
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.card-bar-info {
    font-size: 0.75rem;
    color: var(--clr-text-muted);
}

/* Grid Areas */
.scramble-card { grid-area: scramble; }
.timer-card { grid-area: timer; }
.scorecard-card { grid-area: scorecard; }
.goal-card { grid-area: goal; }
.leaderboard-card { grid-area: leaderboard; }

/* ============================================================
   SCRAMBLE PANEL
   ============================================================ */
.scramble-content {
    padding: var(--space-md) var(--space-lg);
}

.scramble-text {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.8;
    color: var(--clr-text);
    word-spacing: 4px;
    min-height: 60px;
}

/* Dual-colored scramble moves (anti-cheat removed per request - all white) */
.scramble-move-a,
.scramble-move-b,
.scramble-move-c {
    color: #FFFFFF;
    font-weight: 500;
}

/* Hidden scramble indicator */
.scramble-hidden {
    color: var(--clr-text-muted);
    font-style: italic;
    opacity: 0.5;
    font-family: var(--font-body);
    font-size: 0.7rem;
    letter-spacing: 0.05em;
}

.scramble-visual {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--space-md) var(--space-lg) var(--space-lg);
    flex-grow: 1;
}

.scramble-visual:not(.show-colors) twisty-player {
    filter: grayscale(100%) opacity(0.85); /* Desaturate to prevent visual cheating */
}

/* Cube Net Display */
.cube-net {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 4px;
    width: fit-content;
}

.cube-face {
    display: grid;
    gap: 1px;
    padding: 1px;
    background: rgba(0,0,0,0.3);
    border-radius: 2px;
}

.cube-face.f3 { grid-template-columns: repeat(3, 14px); grid-template-rows: repeat(3, 14px); }

.cube-sticker {
    border-radius: 2px;
    transition: background var(--transition-fast);
}

/* Cube colors */
.sticker-W { background: #FFFFFF; }
.sticker-Y { background: #FFD500; }
.sticker-R { background: #E8312A; }
.sticker-O { background: #FF7B1C; }
.sticker-B { background: #2B72D7; }
.sticker-G { background: #00A651; }

/* ============================================================
   TIMER PANEL
   ============================================================ */
.timer-card {
    border-color: var(--clr-border-active);
    position: relative;
    overflow: visible;
}

.timer-status {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--clr-surface);
    color: var(--clr-text-muted);
}

.timer-status.ready { background: var(--clr-primary-glow); color: var(--clr-primary-hover); }
.timer-status.inspecting { background: rgba(245, 158, 11, 0.2); color: var(--clr-timer-inspection); }
.timer-status.running { background: var(--clr-success-glow); color: var(--clr-timer-running); }
.timer-status.stopped { background: var(--clr-danger-glow); color: var(--clr-timer-stopped); }

.timer-display-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl) var(--space-lg);
    flex-grow: 1;
    min-height: 220px;
    position: relative;
    user-select: none;
}

.manual-time-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 2px solid var(--clr-border);
    border-radius: var(--radius-lg);
    text-align: center;
    font-family: var(--font-mono);
    font-size: clamp(3rem, 6vw, 5rem);
    font-weight: 800;
    color: var(--clr-text);
    outline: none;
    letter-spacing: -2px;
    padding: var(--space-sm) 0;
    margin: var(--space-md) 0;
    transition: all var(--transition-normal);
    box-shadow: inset 0 4px 10px rgba(0,0,0,0.2);
}

.manual-time-input:focus {
    border-color: var(--clr-primary);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 0 20px rgba(0, 168, 255, 0.15), inset 0 4px 10px rgba(0,0,0,0.2);
}

.manual-time-input::placeholder {
    color: var(--clr-text-muted);
    opacity: 0.2;
}

.inspection-count {
    font-family: var(--font-mono);
    font-size: 2rem;
    font-weight: 700;
    color: var(--clr-timer-inspection);
}

.inspection-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--clr-timer-inspection);
    opacity: 0.7;
    text-align: center;
}

.timer-hint {
    font-size: 0.85rem;
    color: var(--clr-text-muted);
    margin-top: var(--space-xs);
    text-align: center;
}

.timer-hint kbd {
    display: inline-block;
    padding: 2px 8px;
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--clr-primary-hover);
}

/* Penalty Bar */
.penalty-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--clr-border);
    flex-shrink: 0;
}

.penalty-btn {
    padding: 6px 16px;
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--clr-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.penalty-btn:hover {
    background: var(--clr-bg-card-hover);
    color: var(--clr-text);
}

.penalty-btn.active {
    background: var(--clr-primary);
    border-color: var(--clr-primary);
    color: #fff;
}

.penalty-btn[data-penalty="+2"].active {
    background: var(--clr-warning);
    border-color: var(--clr-warning);
    color: #000;
}

.penalty-btn[data-penalty="dnf"].active {
    background: var(--clr-danger);
    border-color: var(--clr-danger);
    color: #fff;
}

.penalty-divider {
    width: 1px;
    height: 24px;
    background: var(--clr-border);
    margin: 0 4px;
}

/* ============================================================
   SCORECARD PANEL
   ============================================================ */
.scorecard-wrap {
    padding: var(--space-md) var(--space-lg);
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.scorecard-player-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px dashed var(--clr-border);
}

.scorecard-name {
    font-weight: 700;
    font-size: 0.95rem;
}

.scorecard-event {
    font-size: 0.8rem;
    color: var(--clr-text-muted);
}

.scorecard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.scorecard-table th {
    text-align: left;
    padding: 8px 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--clr-text-muted);
    border-bottom: 1px solid var(--clr-border);
}

.scorecard-table td {
    padding: 10px 4px;
    border-bottom: 1px solid var(--clr-border);
    color: var(--clr-text-secondary);
    font-family: var(--font-mono);
    font-size: 0.82rem;
}

.scorecard-table td:nth-child(3),
.scorecard-table td:nth-child(5) {
    font-weight: 600;
}

.scorecard-table tr.current-solve td {
    color: var(--clr-primary-hover);
    background: var(--clr-primary-glow);
}

.scorecard-table tr.completed td {
    color: var(--clr-text);
}

.scorecard-table td.best-time {
    color: var(--clr-success) !important;
}

.scorecard-table td.worst-time {
    color: var(--clr-danger) !important;
}

.scorecard-table td.scramble-cell {
    font-size: 0.65rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--clr-text-muted);
}

/* Scorecard Summary */
.scorecard-summary {
    display: flex;
    gap: var(--space-md);
    margin-top: auto;
    padding-top: var(--space-md);
    border-top: 2px solid var(--clr-border);
}

.summary-stat {
    flex: 1;
    text-align: center;
    padding: var(--space-sm) 0;
}

.summary-stat.highlight {
    background: var(--clr-primary-glow);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.stat-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--clr-text-muted);
    margin-bottom: 2px;
}

.stat-value {
    display: block;
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 700;
    color: var(--clr-text);
}

/* ============================================================
   GOAL PANEL
   ============================================================ */
.goal-content {
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-lg);
    flex-grow: 1;
}

.goal-ring-wrap {
    position: relative;
    width: 120px;
    height: 120px;
}

.goal-ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.ring-bg {
    fill: none;
    stroke: var(--clr-surface);
    stroke-width: 8;
}

.ring-fill {
    fill: none;
    stroke: var(--clr-primary);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 326.7;
    stroke-dashoffset: 326.7;
    transition: stroke-dashoffset 0.8s cubic-bezier(0.4, 0, 0.2, 1), stroke 0.3s;
}

.goal-ring-text {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.ring-pct {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--clr-text);
}

.ring-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--clr-text-muted);
}

.goal-details {
    width: 100%;
}

.goal-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) 0;
    border-bottom: 1px solid var(--clr-border);
    font-size: 0.85rem;
    color: var(--clr-text-secondary);
}

.goal-val {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--clr-text);
}

.goal-status {
    font-family: var(--font-body) !important;
    font-weight: 700 !important;
}

.goal-status.on-track { color: var(--clr-success) !important; }
.goal-status.behind { color: var(--clr-danger) !important; }
.goal-status.achieved { color: var(--clr-gold) !important; }

/* ============================================================
   LEADERBOARD PANEL
   ============================================================ */
.leaderboard-card {
    min-height: 200px;
}

.leaderboard-wrap {
    flex-grow: 1;
    overflow-y: auto;
    padding: 0 var(--space-lg);
    max-height: 500px;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.leaderboard-table th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--clr-bg-card);
    text-align: left;
    padding: 10px 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--clr-text-muted);
    border-bottom: 1px solid var(--clr-border);
}

.leaderboard-table td {
    padding: 8px 4px;
    border-bottom: 1px solid var(--clr-border);
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

.leaderboard-table .lb-rank { width: 36px; }
.leaderboard-table .lb-name {
    font-family: var(--font-body);
    font-weight: 500;
}
.leaderboard-table .lb-pr {
    font-weight: 500;
    color: var(--clr-text-muted);
    font-size: 0.75rem;
}
.leaderboard-table .lb-avg { font-weight: 600; }

/* Country flag images */
.country-flag {
    display: inline-block;
    vertical-align: middle;
    border-radius: 2px;
    object-fit: cover;
    margin-right: 3px;
    box-shadow: 0 0 2px rgba(0,0,0,0.2);
}

.flag-placeholder {
    font-size: 0.9rem;
    margin-right: 3px;
}

.leaderboard-table tr.user-row {
    background: var(--clr-primary-glow);
}

.leaderboard-table tr.user-row td {
    color: var(--clr-primary-hover);
    font-weight: 700;
    border-bottom-color: rgba(99, 102, 241, 0.2);
}

.leaderboard-table .lb-status { text-align: center; }

.status-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-full);
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    min-width: 60px;
    text-align: center;
}

.status-badge.solving {
    background: rgba(255, 170, 0, 0.15);
    color: var(--clr-warning);
}

.status-badge.waiting {
    background: rgba(100, 100, 100, 0.15);
    color: var(--clr-text-muted);
}

.status-badge.finished {
    background: rgba(0, 200, 83, 0.15);
    color: var(--clr-success);
}

.status-badge.user {
    background: var(--clr-primary-glow);
    color: var(--clr-primary);
}

.leaderboard-table tr:not(.user-row):hover {
    background: var(--clr-bg-card-hover);
}

.lb-medal { font-size: 1rem; }

/* ============================================================
   ROUND END OVERLAY
   ============================================================ */
.round-end-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.round-end-card {
    background: var(--clr-bg-card);
    border: 1px solid var(--clr-border-active);
    border-radius: var(--radius-xl);
    padding: var(--space-2xl) var(--space-3xl);
    text-align: center;
    max-width: 500px;
    width: 90%;
    position: relative;
    box-shadow: var(--shadow-glow-primary);
    animation: scaleIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes scaleIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.round-end-title {
    font-size: 1.8rem;
    font-weight: 900;
    margin-bottom: var(--space-lg);
    background: linear-gradient(135deg, var(--clr-primary), var(--clr-accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.round-end-stats {
    display: flex;
    gap: var(--space-lg);
    margin-bottom: var(--space-lg);
    justify-content: center;
}

.end-stat {
    text-align: center;
}

.end-stat-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--clr-text-muted);
    margin-bottom: 4px;
}

.end-stat-value {
    font-family: var(--font-mono);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--clr-text);
}

.round-end-message {
    font-size: 1rem;
    color: var(--clr-text-secondary);
    margin-bottom: var(--space-xl);
    line-height: 1.6;
}

.round-end-actions {
    display: flex;
    gap: var(--space-sm);
    justify-content: center;
    flex-wrap: wrap;
}

/* Confetti */
.confetti-piece {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    animation: confettiFall 2.5s ease-in-out forwards;
}

@keyframes confettiFall {
    0% { transform: translateY(-100px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(400px) rotate(720deg); opacity: 0; }
}

/* ============================================================
   HISTORY VIEW
   ============================================================ */
.history-container {
    max-width: 900px;
    margin: 0 auto;
    padding: var(--space-2xl) var(--space-xl);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-xl);
}

.history-header h2 {
    font-size: 1.5rem;
    font-weight: 800;
}

.history-empty {
    text-align: center;
    padding: var(--space-3xl) var(--space-xl);
    color: var(--clr-text-muted);
}

.history-empty p {
    margin-top: var(--space-md);
    line-height: 1.8;
}

.history-item {
    background: var(--clr-bg-card);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    margin-bottom: var(--space-md);
    transition: all var(--transition-fast);
}

.history-item:hover {
    border-color: var(--clr-border-active);
    transform: translateY(-1px);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-sm);
}

.history-item-title {
    font-weight: 700;
    font-size: 1rem;
}

.history-item-date {
    font-size: 0.8rem;
    color: var(--clr-text-muted);
}

.history-item-stats {
    display: flex;
    gap: var(--space-lg);
    flex-wrap: wrap;
}

.history-stat {
    display: flex;
    flex-direction: column;
}

.history-stat-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--clr-text-muted);
}

.history-stat-value {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--clr-text);
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
    position: fixed;
    bottom: var(--space-xl);
    right: var(--space-xl);
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    background: var(--clr-bg-card);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.9rem;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s;
    animation-fill-mode: forwards;
    backdrop-filter: blur(10px);
}

.toast.success { border-color: var(--clr-success); }
.toast.error { border-color: var(--clr-danger); }
.toast.info { border-color: var(--clr-info); }

@keyframes toastIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes toastOut {
    from { opacity: 1; }
    to { opacity: 0; transform: translateY(10px); }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--clr-text-muted);
    border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover { background: var(--clr-text-secondary); }

/* ============================================================
   WCA API INTEGRATION COMPONENTS
   ============================================================ */

/* Input with action button */
.input-with-action {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.input-with-action .form-input {
    flex: 1;
}

.input-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    flex-shrink: 0;
    background: var(--clr-primary);
    border: 1px solid var(--clr-primary);
    border-radius: var(--radius-sm);
    color: #fff;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.input-action-btn:hover {
    background: var(--clr-primary-hover);
    border-color: var(--clr-primary-hover);
    box-shadow: 0 0 12px var(--clr-primary-glow);
}

.input-action-btn:active {
    transform: scale(0.95);
}

.input-action-btn.loading {
    pointer-events: none;
    opacity: 0.6;
}

/* API Info Card */
.api-info-card {
    margin-top: var(--space-md);
    padding: var(--space-md);
    background: var(--clr-surface);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: var(--radius-md);
    animation: fadeIn 0.3s ease;
}

.api-info-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.api-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.api-status-dot.success {
    background: var(--clr-success);
    box-shadow: 0 0 8px var(--clr-success-glow);
}

.api-status-dot.error {
    background: var(--clr-danger);
    box-shadow: 0 0 8px var(--clr-danger-glow);
}

.api-info-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--clr-text);
}

.api-info-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.api-detail {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    color: var(--clr-text-secondary);
}

.api-detail-icon {
    font-size: 0.9rem;
    flex-shrink: 0;
}

/* API Error Card */
.api-error-card {
    margin-top: var(--space-md);
    padding: var(--space-md);
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.85rem;
    color: var(--clr-danger);
    animation: fadeIn 0.3s ease;
}

/* API Loading */
.api-loading {
    margin-top: var(--space-md);
    padding: var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.85rem;
    color: var(--clr-text-muted);
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--clr-border);
    border-top-color: var(--clr-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* WCA Avatar */
.wca-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--clr-primary);
    object-fit: cover;
    flex-shrink: 0;
}

/* PR Display */
.pr-display {
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--clr-border);
}

.pr-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--clr-text-muted);
    margin-bottom: var(--space-sm);
}

.pr-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

.pr-stat {
    text-align: center;
    padding: var(--space-sm) var(--space-xs);
    background: var(--clr-bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid var(--clr-border);
}

.pr-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--clr-text-muted);
    margin-bottom: 2px;
}

.pr-value {
    display: block;
    font-family: var(--font-mono);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--clr-primary-hover);
}

.pr-rank {
    display: block;
    font-size: 0.7rem;
    color: var(--clr-text-muted);
    margin-top: 2px;
}

/* Event competition info */
.event-comp-info {
    margin-top: var(--space-md);
    padding: var(--space-md);
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
}

.event-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 0.82rem;
}

.event-info-row + .event-info-row {
    border-top: 1px solid var(--clr-border);
}

.event-info-label {
    color: var(--clr-text-muted);
    font-weight: 500;
}

.event-info-value {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--clr-text);
}

/* Disabled event chip */
.event-chip.disabled {
    opacity: 0.3;
    pointer-events: none;
    cursor: not-allowed;
}

/* ============================================================
   ENHANCED RECORDS VIEW
   ============================================================ */
.records-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-xl);
}

/* --- Records Stats Strip --- */
.records-stats-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.records-stat-card {
    background: var(--clr-bg-card);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg) var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    transition: all var(--transition-base);
}

.records-stat-card:hover {
    border-color: var(--clr-border-active);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow-primary);
}

.records-stat-icon {
    font-size: 1.8rem;
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--clr-primary-glow);
    border-radius: var(--radius-md);
}

.records-stat-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.records-stat-value {
    font-family: var(--font-mono);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--clr-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.records-stat-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--clr-text-muted);
    margin-top: 2px;
}

/* Upcoming competition cards */
.upcoming-comp-card .records-stat-icon {
    background: var(--clr-accent-glow);
}

.upcoming-comp-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.upcoming-comp-details {
    text-transform: none;
    letter-spacing: 0;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    line-height: 1.5;
}

/* --- Records Table Card --- */
.records-table-card {
    border: 1px solid var(--clr-border);
    background: var(--clr-bg-card);
}

.records-loading-state {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: var(--space-2xl);
    color: var(--clr-text-muted);
}

.records-table-wrap {
    overflow-x: auto;
}

/* --- Enhanced Records Table --- */
.records-table-enhanced {
    width: 100%;
    border-collapse: collapse;
}

.records-table-enhanced thead th {
    text-align: left;
    padding: var(--space-md) var(--space-md);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--clr-text-muted);
    border-bottom: 2px solid var(--clr-border);
    background: rgba(255, 255, 255, 0.02);
    position: sticky;
    top: 0;
    z-index: 5;
}

[data-theme="light"] .records-table-enhanced thead th {
    background: rgba(0, 0, 0, 0.02);
}

.rec-th-event { min-width: 130px; }
.rec-th-time { min-width: 90px; }
.rec-th-holder { min-width: 150px; }
.rec-th-expand { width: 40px; }

/* Table Rows */
.records-row {
    cursor: pointer;
    transition: all var(--transition-fast);
}

.records-row td {
    padding: 14px var(--space-md);
    border-bottom: 1px solid var(--clr-border);
    font-size: 0.88rem;
    vertical-align: middle;
}

.records-row:hover {
    background: var(--clr-bg-card-hover);
}

.records-row.active {
    background: var(--clr-primary-glow);
    border-bottom-color: rgba(99, 102, 241, 0.2);
}

.records-row.active td {
    border-bottom-color: rgba(99, 102, 241, 0.15);
}

/* Event name cell */
.rec-event-name {
    font-weight: 700;
    color: var(--clr-text);
    font-size: 0.92rem;
}

/* Time cells */
.rec-time {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 0.9rem;
}

.rec-single {
    color: var(--clr-primary);
}

.rec-average {
    color: var(--clr-accent);
}

/* Holder cells */
.rec-holder {
    font-size: 0.82rem;
    color: var(--clr-text-secondary);
    white-space: nowrap;
}

/* Expand icon */
.rec-expand-icon {
    color: var(--clr-text-muted);
    text-align: center;
    transition: transform var(--transition-fast);
}

.records-row.active .rec-expand-icon svg {
    transform: rotate(180deg);
}

/* --- Record Detail Row (expandable) --- */
.record-detail-row {
    animation: recordDetailOpen 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.record-detail-row.closing {
    animation: recordDetailClose 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes recordDetailOpen {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes recordDetailClose {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-8px);
    }
}

.record-detail-row td {
    padding: 0 !important;
    border-bottom: 2px solid var(--clr-primary-glow);
}

.record-detail-content {
    padding: var(--space-lg) var(--space-xl);
    background: linear-gradient(180deg, var(--clr-primary-glow) 0%, transparent 100%);
}

[data-theme="light"] .record-detail-content {
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.06) 0%, transparent 100%);
}

/* Detail Cards Grid */
.record-detail-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}

.record-detail-card {
    background: var(--clr-bg-card);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    position: relative;
    overflow: hidden;
    transition: all var(--transition-base);
}

.record-detail-card:hover {
    border-color: var(--clr-border-active);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.record-detail-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
}

.record-detail-single::before {
    background: linear-gradient(90deg, var(--clr-primary), var(--clr-primary-hover));
}

.record-detail-average::before {
    background: linear-gradient(90deg, var(--clr-accent), var(--clr-accent-hover));
}

/* Detail Badge */
.record-detail-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    background: var(--clr-primary-glow);
    color: var(--clr-primary-hover);
    border: 1px solid rgba(99, 102, 241, 0.3);
    margin-bottom: var(--space-sm);
}

.record-detail-badge.avg-badge {
    background: var(--clr-accent-glow);
    color: var(--clr-accent);
    border-color: rgba(249, 115, 22, 0.3);
}

/* Detail Time */
.record-detail-time {
    font-family: var(--font-mono);
    font-size: 2rem;
    font-weight: 800;
    color: var(--clr-text);
    letter-spacing: -1px;
    margin-bottom: var(--space-sm);
    line-height: 1.2;
}

/* Detail Holder */
.record-detail-holder {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.record-detail-flag {
    font-size: 1.3rem;
}

.record-detail-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--clr-text);
}

/* Detail Competition */
.record-detail-comp {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--clr-text-muted);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--clr-border);
}

.record-detail-comp svg {
    flex-shrink: 0;
    opacity: 0.5;
}

/* --- Comparison Bar --- */
.record-comparison {
    background: var(--clr-bg-card);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
    padding: var(--space-md) var(--space-lg);
}

.comparison-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--clr-text-muted);
    margin-bottom: var(--space-sm);
}

.comparison-bar-wrap {
    width: 100%;
    height: 8px;
    background: var(--clr-surface);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: var(--space-xs);
}

.comparison-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--clr-primary), var(--clr-accent));
    border-radius: 999px;
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.comparison-values {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--clr-text-secondary);
}

.comparison-diff {
    font-weight: 600;
    color: var(--clr-text-muted);
    font-size: 0.7rem;
}

/* --- Records Footer Hint --- */
.records-footer-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: var(--space-md);
    font-size: 0.78rem;
    color: var(--clr-text-muted);
    border-top: 1px solid var(--clr-border);
    background: rgba(255, 255, 255, 0.01);
}

.records-footer-hint svg {
    opacity: 0.5;
    flex-shrink: 0;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
    .records-stats-strip {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .setup-container { padding: var(--space-lg) var(--space-md); }
    .dashboard-container { padding: var(--space-sm); }
    .form-row { grid-template-columns: 1fr; }
    .navbar { padding: var(--space-sm) var(--space-md); }
    .round-end-card { padding: var(--space-xl); }
    .round-end-stats { flex-direction: column; gap: var(--space-sm); }
    .scorecard-table td.scramble-cell { max-width: 60px; }
    .penalty-bar { flex-wrap: wrap; }

    .records-container { padding: var(--space-md); }
    .records-stats-strip {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-sm);
    }
    .records-stat-card { padding: var(--space-md) var(--space-sm); }
    .records-stat-icon { width: 36px; height: 36px; font-size: 1.3rem; }
    .records-stat-value { font-size: 0.95rem; }

    .rec-th-holder,
    .rec-holder { display: none; }
    .rec-th-expand, .rec-expand-icon { display: none; }

    .record-detail-cards { grid-template-columns: 1fr; }
    .record-detail-content { padding: var(--space-md); }
}

/* ========== UPCOMING COMPETITIONS (WCA LIVE STYLE) ========== */
.upcoming-comps-section {
    background-color: #ffffff; /* Cleaner WCA Live white */
    border-radius: var(--radius-lg);
    padding: var(--space-xl) var(--space-xl) var(--space-md);
    margin-bottom: var(--space-xl);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.03); /* Softer shadow */
    color: #333333;
    font-family: var(--font-body); /* Use the app's clean system font stack */
    -webkit-font-smoothing: antialiased;
    border: 1px solid rgba(0,0,0,0.05); /* Very subtle border */
}

.upcoming-comps-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid #000000; /* Active tab underline style */
}

.upcoming-comps-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #333333;
}

.upcoming-comps-link {
    font-size: 0.85rem;
    color: #1976d2;
    text-decoration: none;
    font-weight: 500;
}

.upcoming-comps-link:hover {
    text-decoration: underline;
}

.upcoming-comps-list {
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Custom scrollbar for list */
.upcoming-comps-list::-webkit-scrollbar {
    width: 6px;
}
.upcoming-comps-list::-webkit-scrollbar-track {
    background: transparent;
}
.upcoming-comps-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.upcoming-comp-item {
    display: flex;
    align-items: center;
    padding: var(--space-md) var(--space-sm);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06); /* Lighter border */
    text-decoration: none;
    color: inherit;
    transition: background-color 0.2s ease, transform 0.1s ease;
    border-radius: var(--radius-sm);
}

.upcoming-comp-item:last-child {
    border-bottom: none;
}

.upcoming-comp-item:hover {
    background-color: rgba(0, 0, 0, 0.025);
    transform: translateX(2px); /* Slight hover pop */
}

.upcoming-comp-flag {
    margin-right: var(--space-md);
    margin-left: var(--space-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
}

.upcoming-comp-flag img {
    border-radius: 2px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.upcoming-comp-info {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.upcoming-comp-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: #111111;
    margin-bottom: 3px;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.upcoming-comp-date {
    font-size: 0.8rem;
    color: #666666;
    font-weight: 400;
}

.upcoming-comps-loading,
.upcoming-comps-empty {
    padding: var(--space-xl);
    text-align: center;
    color: #757575;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-md);
}

.upcoming-comps-loading .spinner {
    border-color: rgba(0, 0, 0, 0.1);
    border-top-color: #1976d2;
}

/* WCA Live styles adapted for dark mode */
[data-theme="dark"] .upcoming-comps-section {
    background-color: var(--clr-bg-card);
    border-color: var(--clr-border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    color: var(--clr-text);
}

[data-theme="dark"] .upcoming-comps-header {
    border-bottom-color: var(--clr-text);
}

[data-theme="dark"] .upcoming-comps-title {
    color: var(--clr-text);
}

[data-theme="dark"] .upcoming-comps-link {
    color: #90caf9;
}

[data-theme="dark"] .upcoming-comp-item {
    border-bottom-color: var(--clr-border);
}

[data-theme="dark"] .upcoming-comp-item:hover {
    background-color: var(--clr-bg-card-hover);
}

[data-theme="dark"] .upcoming-comp-name {
    color: var(--clr-text);
    font-weight: 600;
}

[data-theme="dark"] .upcoming-comp-date {
    color: var(--clr-text-secondary);
}

[data-theme="dark"] .upcoming-comps-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

.home-feature-card {
    padding: 2rem;
    min-height: 180px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.4s ease;
    background-color: var(--clr-surface);
    border: 1px solid var(--clr-border);
}
.home-feature-card:hover {
    transform: translateY(-12px) scale(1.03);
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
    border-color: var(--clr-primary);
}
.home-feature-card .card-title {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.home-feature-card .icon {
    font-size: 2.2rem;
    margin-bottom: 1rem;
    display: block;
}
[data-theme="dark"] .home-feature-card {
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
[data-theme="dark"] .home-feature-card:hover {
    box-shadow: 0 20px 40px rgba(0,0,0,0.7);
}

/* ============================================================
   BOTTOM NAVIGATION BAR OVERHAUL
   ============================================================ */

@media (max-width: 850px) {
    /* Center logo at the top and fix containing block bug */
    .navbar {
        padding: 0.5rem;
        justify-content: center;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: var(--clr-surface);
    }
    .nav-brand {
        margin: 0 auto;
    }

    /* Bottom Bar */
    .nav-links {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        height: 70px;
        background: rgba(11, 13, 23, 0.95);
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        padding: 0 10px;
        gap: 10px;
        overflow-x: auto;
        overflow-y: hidden;
        border-top: 1px solid var(--clr-border);
        z-index: 999;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
    .nav-links::-webkit-scrollbar {
        display: none;
    }

    /* Button formatting for bottom bar */
    .nav-btn {
        flex-direction: column;
        gap: 5px;
        font-size: 0.65rem;
        padding: 0.5rem;
        white-space: nowrap;
        min-width: 70px;
        height: 100%;
        border-radius: 0;
        background: transparent !important;
        opacity: 0.7;
    }
    .nav-btn.active, .nav-btn:hover {
        opacity: 1;
        color: var(--clr-primary);
        border-bottom: 2px solid var(--clr-primary);
    }
    .nav-btn svg {
        margin-right: 0;
        width: 22px;
        height: 22px;
        margin-bottom: 2px;
    }
    
    /* Theme Toggle */
    .theme-toggle {
        min-width: 60px;
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 0;
    }

    /* Prevent bottom bar from hiding content */
    body {
        padding-bottom: 75px;
    }

    /* Home Page Hero */
    .hero-title {
        font-size: 2.5rem;
    }
    .hero-subtitle {
        font-size: 1rem;
        padding: 0 1rem;
    }

    /* Feature Cards */
    .home-feature-card {
        padding: 1.5rem;
        min-height: 120px;
    }
    .home-feature-card .card-title {
        font-size: 1.2rem;
    }
    .home-feature-card .icon {
        font-size: 2rem;
    }

    /* Grids */
    .setup-grid {
        grid-template-columns: 1fr !important;
    }
    .dash-grid {
        grid-template-columns: 1fr !important;
    }

    /* Dashboard Timer */
    .timer-display {
        font-size: 20vw;
    }
    .scramble-display {
        font-size: 1.2rem;
    }
    
    /* Layout */
    .setup-container {
        padding: var(--space-md);
    }
}

@media (max-width: 480px) {
    .scramble-display {
        font-size: 1rem;
    }
    .timer-display {
        font-size: 25vw;
    }
}

/* ============================================================
   ALG PRACTICE TRAINER
   ============================================================ */

/* Trainer Container — fills the practice-view */
.alg-trainer-overlay {
    background: var(--clr-bg);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 80px); /* minus the navbar padding */
    animation: trainerFadeIn 0.25s ease;
}

@keyframes trainerFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Trainer Top Bar */
.alg-trainer-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--clr-surface);
    border-bottom: 1px solid var(--clr-border);
    flex-shrink: 0;
    gap: 1rem;
}

.trainer-back-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--clr-border);
    color: var(--clr-text-secondary);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.trainer-back-btn:hover {
    color: var(--clr-text);
    border-color: var(--clr-primary);
    background: rgba(99, 102, 241, 0.08);
}

.trainer-topbar-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.trainer-set-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--clr-text);
}

.trainer-case-count {
    font-size: 0.75rem;
    color: var(--clr-primary);
    letter-spacing: 0.5px;
}

.trainer-icon-btn {
    background: transparent;
    border: 1px solid var(--clr-border);
    color: var(--clr-text-secondary);
    border-radius: var(--radius-sm);
    padding: 0.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: all 0.15s ease;
    width: 36px;
    height: 36px;
    justify-content: center;
}

.trainer-icon-btn:hover {
    color: var(--clr-text);
    border-color: var(--clr-primary);
}

/* Scramble Bar */
.alg-trainer-scramble-bar {
    padding: 0.75rem 1.5rem;
    background: var(--clr-bg-elevated);
    border-bottom: 1px solid var(--clr-border);
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

.alg-trainer-scramble-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--clr-text-muted);
    text-transform: uppercase;
    white-space: nowrap;
}

.alg-trainer-scramble {
    font-family: var(--font-mono);
    font-size: 1rem;
    color: var(--clr-text);
    letter-spacing: 0.5px;
    line-height: 1.5;
    word-break: break-all;
}

/* Main Body: Timer + Sidebar */
.alg-trainer-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Center Timer Area */
.alg-trainer-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    gap: 1.5rem;
    cursor: pointer;
    user-select: none;
    position: relative;
}

.trainer-case-viz {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--clr-bg-elevated);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-lg);
    padding: 1rem;
    transition: border-color 0.2s ease;
}

.trainer-timer-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.trainer-timer-status {
    font-size: 0.85rem;
    color: var(--clr-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
    transition: color 0.2s;
}

.trainer-timer-time {
    font-size: clamp(3.5rem, 8vw, 6rem);
    font-weight: 800;
    font-family: var(--font-mono);
    color: var(--clr-timer);
    line-height: 1;
    transition: color 0.15s;
    letter-spacing: -2px;
}

.trainer-timer-time.running {
    color: var(--clr-timer-running);
}

.trainer-timer-time.ready {
    color: #F59E0B;
}

/* Action Bar */
.trainer-action-bar {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}

.trainer-action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    color: var(--clr-text-secondary);
    border-radius: var(--radius-sm);
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    cursor: pointer;
    font-family: var(--font-body);
    font-weight: 500;
    transition: all 0.15s ease;
}

.trainer-action-btn:hover {
    color: var(--clr-primary);
    border-color: var(--clr-primary);
    background: rgba(99, 102, 241, 0.08);
}

.trainer-keyboard-hint {
    font-size: 0.75rem;
    color: var(--clr-text-muted);
    letter-spacing: 0.5px;
    position: absolute;
    bottom: 1.5rem;
}

/* Sidebar Time List */
.alg-trainer-sidebar {
    width: 280px;
    min-width: 220px;
    background: var(--clr-surface);
    border-left: 1px solid var(--clr-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.trainer-sidebar-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--clr-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--clr-text-secondary);
}

.trainer-clear-btn {
    background: transparent;
    border: none;
    color: var(--clr-text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.15s;
    font-family: var(--font-body);
}

.trainer-clear-btn:hover {
    color: var(--clr-danger);
    background: var(--clr-danger-glow);
}

.trainer-stats-row {
    display: flex;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--clr-border);
    gap: 0;
}

.trainer-stat {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.trainer-stat-label {
    font-size: 0.65rem;
    color: var(--clr-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.trainer-stat-value {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--clr-primary);
    font-family: var(--font-mono);
}

.trainer-times-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}

.trainer-times-empty {
    text-align: center;
    color: var(--clr-text-muted);
    font-size: 0.8rem;
    padding: 2rem 1rem;
    line-height: 1.5;
}

.trainer-time-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    gap: 0.5rem;
    transition: background 0.1s;
}

.trainer-time-entry:hover {
    background: rgba(255,255,255,0.03);
}

.trainer-time-num {
    font-size: 0.7rem;
    color: var(--clr-text-muted);
    width: 20px;
    flex-shrink: 0;
}

.trainer-time-case {
    flex: 1;
    font-size: 0.8rem;
    color: var(--clr-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.trainer-time-val {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--clr-text);
    flex-shrink: 0;
}

.trainer-time-val.pb {
    color: var(--clr-gold);
}

/* ====== HINT MODAL ====== */
.alg-hint-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: modalFadeIn 0.2s ease;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.alg-hint-content {
    background: var(--clr-bg-card);
    border: 1px solid var(--clr-border-active);
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 380px;
    width: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 0 1px var(--clr-border);
    animation: contentSlideUp 0.2s ease;
}

@keyframes contentSlideUp {
    from { transform: translateY(20px) scale(0.97); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}

.alg-hint-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: transparent;
    border: none;
    color: var(--clr-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: 50%;
    transition: all 0.15s;
}

.alg-hint-close:hover {
    color: var(--clr-text);
    background: rgba(255,255,255,0.05);
}

.alg-hint-case-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--clr-text);
    text-align: center;
    line-height: 1.3;
}

.alg-hint-viz {
    background: var(--clr-bg-elevated);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.alg-hint-alg-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--clr-primary);
    text-transform: uppercase;
}

.alg-hint-alg {
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    color: var(--clr-primary);
    font-family: var(--font-mono);
    letter-spacing: 0.5px;
    text-align: center;
    word-break: break-all;
    width: 100%;
}

.alg-hint-footer {
    font-size: 0.75rem;
    color: var(--clr-text-muted);
}

/* ====== CASE SELECTION MODAL ====== */
.alg-case-select-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(6px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: modalFadeIn 0.2s ease;
}

.alg-case-select-content {
    background: var(--clr-bg-card);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 700px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    animation: contentSlideUp 0.2s ease;
}

.alg-case-select-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--clr-border);
    flex-shrink: 0;
}

.alg-case-select-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
}

.case-select-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--clr-border);
    flex-shrink: 0;
}

.alg-case-select-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.case-select-card {
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
    padding: 0.65rem;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--clr-bg-elevated);
}

.case-select-card:hover {
    border-color: var(--clr-primary);
    background: rgba(99, 102, 241, 0.05);
}

.case-select-card.selected {
    border-color: var(--clr-primary);
    background: rgba(99, 102, 241, 0.12);
}

.case-select-checkbox {
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--clr-border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}

.case-select-card.selected .case-select-checkbox {
    background: var(--clr-primary);
    border-color: var(--clr-primary);
}

.case-select-card.selected .case-select-checkbox::after {
    content: '✓';
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
}

.case-select-name {
    font-size: 0.78rem;
    color: var(--clr-text);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.alg-case-select-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--clr-border);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* Responsive trainer */
@media (max-width: 700px) {
    .alg-trainer-sidebar {
        display: none;
    }
    .trainer-timer-time {
        font-size: 4rem;
    }
}
/* Premium Auth Modal Styles */
.auth-modal {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
}
.glass-panel {
    background: rgba(30, 30, 35, 0.7);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border-radius: 20px;
    padding: 2.5rem;
    max-width: 420px;
    width: 90%;
}
.auth-subtitle {
    color: var(--clr-text-muted);
    font-size: 0.95rem;
    margin-top: 0.5rem;
    margin-bottom: 1.5rem;
    text-align: center;
}
.auth-provider-btn {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 0.8rem;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 12px;
    transition: all 0.2s ease;
}
.wca-auth-btn {
    background: linear-gradient(135deg, #FF7B00, #FF5500);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(255, 85, 0, 0.3);
}
.wca-auth-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 85, 0, 0.4);
    background: linear-gradient(135deg, #FF8C1A, #FF661A);
}
.auth-divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 1.5rem 0;
    color: var(--clr-text-muted);
    font-size: 0.85rem;
}
.auth-divider::before, .auth-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.auth-divider span {
    padding: 0 10px;
}
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}
.form-floating {
    position: relative;
}
.form-floating input {
    width: 100%;
    padding: 1.2rem 1rem 0.4rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: white;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-floating input:focus {
    border-color: var(--clr-primary);
    box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.2);
    outline: none;
}
.form-floating label {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--clr-text-muted);
    transition: all 0.2s ease;
    pointer-events: none;
    font-size: 1rem;
}
.form-floating input:focus ~ label,
.form-floating input:not(:placeholder-shown) ~ label {
    top: 0.5rem;
    font-size: 0.75rem;
    color: var(--clr-primary);
}
.auth-submit-btn {
    padding: 0.9rem;
    border-radius: 12px;
    font-size: 1.05rem;
    font-weight: 600;
    margin-top: 0.5rem;
    transition: all 0.3s ease;
}
.auth-submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(10, 132, 255, 0.3);
}
.auth-footer {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.9rem;
    color: var(--clr-text-muted);
}
.auth-link {
    color: var(--clr-primary);
    text-decoration: none;
    font-weight: 500;
}
.auth-link:hover {
    text-decoration: underline;
}
/* =========================================
   MODAL BASE STYLES
   ========================================= */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: none; /* Default state */
    align-items: center;
    justify-content: center;
}

.modal-content {
    position: relative;
    width: 100%;
    animation: slideUpFade 0.3s ease-out forwards;
}

@keyframes slideUpFade {
    0% { opacity: 0; transform: translateY(20px); }
    100% { opacity: 1; transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--clr-text);
}

.modal-close-btn {
    background: transparent;
    border: none;
    color: var(--clr-text-muted);
    cursor: pointer;
    border-radius: 50%;
    padding: 0.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
}

.modal-close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--clr-primary);
}
/* =========================================
   USER PROFILE
   ========================================= */
.nav-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--clr-primary);
    box-shadow: 0 2px 8px rgba(10, 132, 255, 0.3);
}
.nav-btn.active .nav-avatar {
    border-color: #ff9500;
    box-shadow: 0 0 12px rgba(255, 149, 0, 0.6);
    transform: scale(1.1);
    transition: all 0.3s ease;
}

/* ============================================================
   BATTLE FEATURE
   ============================================================ */

.nav-btn--battle { position: relative; color: #FF6B35 !important; font-weight: 600; }
.nav-btn--battle::after { content: 'NEW'; position: absolute; top: -4px; right: -4px; background: linear-gradient(135deg, #FF6B35, #E74C3C); color: #fff; font-size: 0.45rem; font-weight: 800; padding: 1px 4px; border-radius: 4px; letter-spacing: 0.05em; }
.nav-btn--battle.active { background: linear-gradient(135deg, #FF6B35 0%, #E74C3C 100%) !important; color: #fff !important; border-color: transparent !important; }

#battle-view { padding-top: 80px; min-height: 100vh; }

.battle-login-gate { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 80px); padding: 2rem; }
.battle-gate-card { background: var(--clr-surface); border: 1px solid var(--clr-border); border-radius: 24px; padding: 3rem; text-align: center; max-width: 480px; width: 100%; animation: fadeIn 0.4s ease; }
.battle-gate-icon { width: 100px; height: 100px; border-radius: 50%; background: linear-gradient(135deg, #FF6B35, #E74C3C); display: flex; align-items: center; justify-content: center; margin: 0 auto 1.5rem; box-shadow: 0 0 40px rgba(255,107,53,0.35); }
.battle-gate-icon svg { color: #fff; }
.battle-gate-card h2 { font-size: 2rem; font-weight: 800; margin-bottom: 0.75rem; background: linear-gradient(135deg,#FF6B35,#E74C3C); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.battle-gate-card p { color: var(--clr-text-muted); margin-bottom: 0.75rem; line-height: 1.6; }
.battle-gate-sub { font-size: 0.85rem; font-style: italic; }

.battle-lobby-container { max-width: 1300px; margin: 0 auto; padding: 2rem var(--space-xl); animation: fadeIn 0.35s ease; }
.battle-lobby-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap; }
.battle-title { display: flex; align-items: center; gap: 0.65rem; font-size: 2rem; font-weight: 800; background: linear-gradient(135deg,#FF6B35,#E74C3C); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; margin: 0 0 0.3rem; }
.battle-title svg { -webkit-text-fill-color: initial; color: #FF6B35; flex-shrink: 0; }
.battle-lobby-subtitle { color: var(--clr-text-muted); font-size: 0.95rem; }

.battle-create-btn { background: linear-gradient(135deg, #FF6B35, #E74C3C) !important; border: none !important; padding: 0.75rem 1.5rem !important; font-size: 1rem !important; font-weight: 700 !important; display: flex; align-items: center; gap: 8px; box-shadow: 0 4px 20px rgba(255,107,53,0.35) !important; white-space: nowrap; }
.battle-create-btn:hover { box-shadow: 0 6px 28px rgba(255,107,53,0.5) !important; transform: translateY(-1px); }

.battle-event-filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem; }
.battle-filter-chip { background: var(--clr-surface); border: 1px solid var(--clr-border); color: var(--clr-text-muted); padding: 0.4rem 1rem; border-radius: 999px; font-size: 0.82rem; font-weight: 500; cursor: pointer; transition: all 0.2s; }
.battle-filter-chip:hover { border-color: #FF6B35; color: #FF6B35; }
.battle-filter-chip.active { background: linear-gradient(135deg,#FF6B35,#E74C3C); color: #fff; border-color: transparent; font-weight: 700; }

.battle-rooms-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.25rem; }
.battle-room-card { background: var(--clr-surface); border: 1px solid var(--clr-border); border-radius: 16px; padding: 1.25rem; display: flex; flex-direction: column; gap: 0.6rem; transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s; position: relative; overflow: hidden; }
.battle-room-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, var(--evt-color, #FF6B35), transparent); }
.battle-room-card:hover:not(.full) { transform: translateY(-3px); box-shadow: 0 8px 30px rgba(0,0,0,0.25); border-color: var(--evt-color, #FF6B35); }
.battle-room-card.full { opacity: 0.55; }
.battle-room-card-header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.battle-room-card-event { font-size: 0.75rem; font-weight: 700; padding: 0.2rem 0.6rem; border-radius: 6px; border: 1px solid; letter-spacing: 0.04em; text-transform: uppercase; }
.battle-room-private-badge { display: flex; align-items: center; gap: 4px; font-size: 0.7rem; color: var(--clr-text-muted); background: rgba(255,255,255,0.05); border-radius: 999px; padding: 0.2rem 0.5rem; border: 1px solid var(--clr-border); }
.battle-room-card-name { font-size: 1rem; font-weight: 700; color: var(--clr-text); line-height: 1.3; }
.battle-room-card-host { font-size: 0.8rem; color: var(--clr-text-muted); }
.battle-room-card-footer { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-top: 0.25rem; }
.battle-room-card-players { display: flex; align-items: center; gap: 5px; font-size: 0.8rem; color: var(--clr-text-muted); }
.battle-room-card-status { font-size: 0.75rem; padding: 0.2rem 0.6rem; border-radius: 999px; font-weight: 600; }
.battle-status--waiting { background: rgba(46,204,113,0.12); color: #2ECC71; }
.battle-status--in-progress { background: rgba(241,196,15,0.12); color: #F1C40F; }
.battle-join-btn { width: 100%; padding: 0.6rem; border-radius: 10px; border: 1px solid var(--evt-color, #FF6B35); background: transparent; color: var(--evt-color, #FF6B35); font-weight: 700; font-size: 0.9rem; cursor: pointer; transition: all 0.2s; margin-top: 0.25rem; }
.battle-join-btn:hover:not(.disabled) { background: var(--evt-color, #FF6B35); color: #fff; box-shadow: 0 4px 15px rgba(255,107,53,0.3); }
.battle-join-btn.disabled { border-color: var(--clr-border); color: var(--clr-text-muted); cursor: not-allowed; }
.battle-empty-state { grid-column: 1/-1; text-align: center; padding: 4rem 2rem; color: var(--clr-text-muted); display: flex; flex-direction: column; align-items: center; gap: 1rem; }

.battle-room-view { display: flex; flex-direction: column; height: calc(100vh - 80px); animation: fadeIn 0.3s ease; }
.battle-room-topbar { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1.5rem; background: var(--clr-surface); border-bottom: 1px solid var(--clr-border); gap: 1rem; flex-wrap: wrap; flex-shrink: 0; }
.battle-back-btn { display: flex; align-items: center; gap: 6px; background: none; border: 1px solid var(--clr-border); color: var(--clr-text-muted); padding: 0.45rem 1rem; border-radius: 8px; cursor: pointer; font-size: 0.85rem; font-weight: 600; transition: all 0.2s; white-space: nowrap; }
.battle-back-btn:hover { border-color: #E74C3C; color: #E74C3C; }
.battle-room-info { display: flex; align-items: center; gap: 0.75rem; flex: 1; justify-content: center; }
.battle-room-name-tag { font-size: 1.1rem; font-weight: 700; color: var(--clr-text); }
.battle-room-event-badge { font-size: 0.78rem; font-weight: 700; padding: 0.2rem 0.6rem; border-radius: 6px; text-transform: uppercase; letter-spacing: 0.05em; }
.battle-round-counter { font-size: 0.85rem; color: var(--clr-text-muted); font-weight: 600; }
.battle-room-status { display: flex; align-items: center; gap: 7px; font-size: 0.85rem; color: var(--clr-text-muted); white-space: nowrap; }
.battle-status-dot { width: 8px; height: 8px; border-radius: 50%; background: #2ECC71; animation: battlePulse 1.5s infinite; }
@keyframes battlePulse { 0%,100%{opacity:1;} 50%{opacity:0.35;} }

.battle-room-body { display: grid; grid-template-columns: 1fr 340px; flex: 1; overflow: hidden; }
.battle-room-left { display: flex; flex-direction: column; border-right: 1px solid var(--clr-border); overflow-y: auto; }
.battle-scramble-panel { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--clr-border); background: var(--clr-surface); }
.battle-scramble-label { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; color: var(--clr-text-muted); margin-bottom: 0.5rem; }
.battle-scramble-text { font-family: 'JetBrains Mono', monospace; font-size: 0.95rem; font-weight: 600; color: var(--clr-text); line-height: 1.5; word-break: break-all; }
.battle-scramble-viz { margin-top: 0.75rem; }
.battle-timer-panel { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem; gap: 1.25rem; min-height: 250px; }
.battle-timer-status { font-size: 0.9rem; font-weight: 600; color: var(--clr-text-muted); letter-spacing: 0.05em; text-transform: uppercase; }
.battle-timer-time { font-family: 'JetBrains Mono', monospace; font-size: 5rem; font-weight: 700; color: var(--clr-text); letter-spacing: -0.03em; line-height: 1; transition: color 0.1s; }
.battle-timer-time.running { color: #2ECC71; text-shadow: 0 0 40px rgba(46,204,113,0.35); }
.battle-timer-time.pb { color: #F7C948; text-shadow: 0 0 40px rgba(247,201,72,0.35); }
.battle-ready-btn { display: flex; align-items: center; gap: 8px; background: linear-gradient(135deg,#2ECC71,#1ABC9C); color: #fff; border: none; border-radius: 12px; padding: 0.75rem 2rem; font-size: 1rem; font-weight: 700; cursor: pointer; transition: all 0.2s; box-shadow: 0 4px 20px rgba(46,204,113,0.3); }
.battle-ready-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 28px rgba(46,204,113,0.45); }
.battle-ready-btn.is-ready { background: linear-gradient(135deg,#3498DB,#2980B9); box-shadow: 0 4px 20px rgba(52,152,219,0.3); }
.battle-keyboard-hint { font-size: 0.78rem; color: var(--clr-text-muted); font-style: italic; }
.battle-round-results { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem; gap: 1rem; animation: fadeIn 0.3s ease; }
.battle-results-title { display: flex; align-items: center; gap: 8px; font-size: 1.2rem; font-weight: 800; color: var(--clr-text); margin-bottom: 0.5rem; }
.battle-final-header { font-size: 1.3rem; font-weight: 800; text-align: center; margin-bottom: 0.75rem; }
.battle-results-table { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 0.5rem; }
.battle-result-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem; background: var(--clr-surface); border: 1px solid var(--clr-border); border-radius: 10px; transition: all 0.2s; }
.battle-result-row.is-user { border-color: #FF6B35; background: rgba(255,107,53,0.06); }
.battle-result-rank { font-size: 1.3rem; min-width: 32px; }
.battle-result-name { flex: 1; font-weight: 600; font-size: 0.95rem; }
.battle-result-time { font-family: 'JetBrains Mono', monospace; font-weight: 700; color: var(--clr-accent); font-size: 0.95rem; }

.battle-room-right { display: flex; flex-direction: column; overflow: hidden; }
.battle-players-panel { border-bottom: 1px solid var(--clr-border); overflow-y: auto; flex: 0 0 auto; max-height: 50%; }
.battle-scores-panel { flex: 1; overflow-y: auto; }
.battle-panel-header { display: flex; align-items: center; gap: 6px; padding: 0.75rem 1rem; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--clr-text-muted); border-bottom: 1px solid var(--clr-border); background: var(--clr-surface); position: sticky; top: 0; z-index: 2; }
.battle-players-list { padding: 0.5rem; display: flex; flex-direction: column; gap: 0.4rem; }
.battle-player-row { display: flex; align-items: center; gap: 0.65rem; padding: 0.6rem 0.5rem; border-radius: 8px; transition: background 0.15s; }
.battle-player-row.is-user { background: rgba(255,107,53,0.07); }
.battle-player-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 0.85rem; color: #fff; flex-shrink: 0; }
.battle-player-info { flex: 1; min-width: 0; }
.battle-player-name { font-size: 0.85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.battle-player-status { font-size: 0.72rem; font-weight: 700; padding: 0.2rem 0.55rem; border-radius: 999px; background: rgba(128,128,128,0.12); color: var(--clr-text-muted); white-space: nowrap; }
.battle-player-status.ready { background: rgba(46,204,113,0.12); color: #2ECC71; }
.battle-player-status.solving { background: rgba(52,152,219,0.12); color: #3498DB; animation: battlePulse 1s infinite; }
.battle-player-status.finished { background: rgba(247,201,72,0.12); color: #F7C948; }
.battle-scores-list { padding: 0.5rem; }
.battle-scores-empty { color: var(--clr-text-muted); font-size: 0.8rem; text-align: center; padding: 1rem; }
.battle-score-round { margin-bottom: 0.75rem; }
.battle-score-round-label { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--clr-text-muted); padding: 0.25rem 0.5rem; }
.battle-score-entry { display: flex; align-items: center; gap: 0.5rem; padding: 0.35rem 0.5rem; border-radius: 6px; font-size: 0.8rem; }
.battle-score-entry.is-user { background: rgba(255,107,53,0.08); }
.battle-score-rank { font-weight: 700; color: var(--clr-text-muted); min-width: 22px; font-size: 0.75rem; }
.battle-score-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.battle-score-time { font-family: 'JetBrains Mono', monospace; font-weight: 700; color: var(--clr-accent); font-size: 0.8rem; }

.battle-modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.75); backdrop-filter: blur(6px); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 1rem; animation: fadeIn 0.2s ease; }
.battle-modal-card { background: var(--clr-surface); border: 1px solid var(--clr-border); border-radius: 20px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.5); animation: scaleIn 0.25s cubic-bezier(0.34,1.56,0.64,1); }
@keyframes scaleIn { from{transform:scale(0.9);opacity:0;} to{transform:scale(1);opacity:1;} }
.battle-modal-card--sm { max-width: 400px; }
.battle-modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--clr-border); }
.battle-modal-header h3 { display: flex; align-items: center; gap: 8px; font-size: 1.15rem; font-weight: 700; margin: 0; }
.battle-modal-body { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.battle-modal-footer { display: flex; justify-content: flex-end; gap: 0.75rem; padding: 1rem 1.5rem; border-top: 1px solid var(--clr-border); }
.battle-visibility-toggle { display: flex; gap: 0.5rem; }
.battle-vis-btn { display: flex; align-items: center; gap: 6px; flex: 1; justify-content: center; padding: 0.65rem; border-radius: 10px; border: 1px solid var(--clr-border); background: var(--clr-bg); color: var(--clr-text-muted); font-weight: 600; font-size: 0.9rem; cursor: pointer; transition: all 0.2s; }
.battle-vis-btn.active { border-color: #FF6B35; background: rgba(255,107,53,0.1); color: #FF6B35; }
.form-group-row { display: flex; gap: 1rem; }
.battle-pw-error { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: #E74C3C; background: rgba(231,76,60,0.08); border: 1px solid rgba(231,76,60,0.2); border-radius: 8px; padding: 0.5rem 0.75rem; }


/* ============================================================
   BATTLE — Updated styles (real-time rooms, lock badges, event chips)
   ============================================================ */

/* Loading spinner */
.battle-lobby-loading { grid-column:1/-1; display:flex; flex-direction:column; align-items:center; gap:1rem; padding:4rem 2rem; color:var(--clr-text-muted); }
.battle-loading-spinner { width:36px; height:36px; border:3px solid var(--clr-border); border-top-color:#FF6B35; border-radius:50%; animation:spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Privacy badge — top-right corner of room card */
.battle-privacy-badge { position:absolute; top:10px; right:10px; display:flex; align-items:center; gap:5px; font-size:0.7rem; font-weight:700; padding:0.25rem 0.55rem; border-radius:999px; letter-spacing:0.03em; }
.battle-privacy-badge.is-private { background:rgba(231,76,60,0.12); color:#E74C3C; border:1px solid rgba(231,76,60,0.25); }
.battle-privacy-badge.is-public  { background:rgba(46,204,113,0.12); color:#2ECC71; border:1px solid rgba(46,204,113,0.25); }

/* Room card — ensure position:relative for absolute badge */
.battle-room-card { position:relative; }
.battle-room-card-name { padding-right:110px; } /* avoid overlap with badge */

/* In-room: event selector bar */
.battle-event-selector-bar { display:flex; align-items:center; gap:0.5rem; padding:0.65rem 1.25rem; background:var(--clr-surface); border-bottom:1px solid var(--clr-border); flex-wrap:wrap; flex-shrink:0; }
.battle-event-selector-label { font-size:0.75rem; font-weight:700; text-transform:uppercase; letter-spacing:0.08em; color:var(--clr-text-muted); white-space:nowrap; }
.battle-event-chips { display:flex; flex-wrap:wrap; gap:0.35rem; flex:1; }
.battle-event-chip { background:var(--clr-surface); border:1px solid var(--clr-border); color:var(--clr-text-muted); padding:0.3rem 0.75rem; border-radius:999px; font-size:0.78rem; font-weight:600; cursor:pointer; transition:all 0.15s; }
.battle-event-chip:hover:not(:disabled) { border-color:#FF6B35; color:#FF6B35; }
.battle-event-chip.active { background:linear-gradient(135deg,#FF6B35,#E74C3C); color:#fff; border-color:transparent; }
.battle-event-chip:disabled { opacity:0.45; cursor:default; }

/* Refresh button */
#battle-refresh-btn { display:flex; align-items:center; gap:6px; }

/* Timer area — slightly tighter since no ready button */
.battle-timer-panel { flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; padding:2rem 1.5rem; gap:1rem; }

/* Player count badge */
#battle-player-count { font-size:0.8rem; }


/* ---- Battle: Input mode toggle ---- */
.battle-input-mode-bar { display:flex; gap:0.4rem; justify-content:center; padding-bottom:0.25rem; }
.battle-mode-btn { display:flex; align-items:center; gap:6px; padding:0.4rem 1rem; border-radius:999px; border:1px solid var(--clr-border); background:var(--clr-surface); color:var(--clr-text-muted); font-size:0.8rem; font-weight:600; cursor:pointer; transition:all 0.18s; }
.battle-mode-btn:hover { border-color:#FF6B35; color:#FF6B35; }
.battle-mode-btn.active { background:linear-gradient(135deg,#FF6B35,#E74C3C); color:#fff; border-color:transparent; }

/* ---- Battle: Typing mode ---- */
.battle-typing-input-wrap { display:flex; gap:0.6rem; align-items:center; width:100%; max-width:320px; }
.battle-typing-input { flex:1; font-family:'JetBrains Mono',monospace; font-size:1.4rem; font-weight:700; text-align:center; padding:0.6rem 0.8rem; border-radius:12px; border:2px solid var(--clr-border); background:var(--clr-surface); color:var(--clr-text); transition:border-color 0.2s; letter-spacing:0.05em; }
.battle-typing-input:focus { border-color:#FF6B35; outline:none; box-shadow:0 0 0 3px rgba(255,107,53,0.15); }
#battle-typing-submit { flex-shrink:0; padding:0.6rem 1rem; border-radius:10px; }

/* ---- Keyboard mode wrapper ---- */
#battle-keyboard-mode { display:flex; flex-direction:column; align-items:center; gap:0.75rem; width:100%; }


/* ================================================================
   BATTLE — Cross-table (.bct) styles
   ================================================================ */

/* Container */
.battle-cross-table-wrap {
    flex: 1;
    overflow: auto;
    padding: 0;
    background: var(--clr-surface);
}

/* Table */
.bct {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    table-layout: fixed;
}

/* Columns */
.bct-th-num, .bct-td-num {
    width: 48px;
    min-width: 44px;
    text-align: center;
    font-weight: 700;
    font-size: 0.75rem;
    background: var(--clr-surface);
    color: var(--clr-text-muted);
    position: sticky;
    left: 0;
    z-index: 2;
    border-right: 1px solid var(--clr-border);
    padding: 6px 4px;
    white-space: nowrap;
}

.bct-th-player {
    padding: 8px 10px;
    text-align: center;
    font-weight: 700;
    font-size: 0.82rem;
    color: var(--clr-text);
    border-bottom: 2px solid var(--clr-border);
    position: sticky;
    top: 0;
    background: var(--clr-surface);
    z-index: 3;
    min-width: 100px;
    line-height: 1.3;
}
.bct-th-player.bct-me {
    background: rgba(255, 107, 53, 0.06);
    border-bottom-color: #FF6B35;
}

.bct-player-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: middle;
}
.bct-you-tag {
    font-size: 0.68rem;
    font-weight: 400;
    color: var(--clr-text-muted);
}

/* Header row */
.bct-header-row th {
    position: sticky;
    top: 0;
    z-index: 4;
    background: var(--clr-surface);
    border-bottom: 2px solid var(--clr-border);
}
.bct-th-num.bct-td-num { z-index: 5; }

/* Stat rows (mean / wins) */
.bct-stat-row td {
    padding: 5px 8px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--clr-text-muted);
}
.bct-td-stat { text-align: center; }
.bct-best-stat {
    color: #2ECC71;
    font-weight: 700;
}

/* Divider row */
.bct-divider-row td {
    height: 2px;
    background: var(--clr-border);
    padding: 0;
}

/* Solve rows */
.bct-row td {
    padding: 5px 8px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.82rem;
    color: var(--clr-text);
    transition: background 0.15s;
}
.bct-row:hover td { background: rgba(255,255,255,0.03); }

/* Current scramble row */
.bct-current { background: rgba(255, 107, 53, 0.04); }
.bct-current td { background: rgba(255, 107, 53, 0.04); }
.bct-current-dot {
    display: inline-block;
    width: 6px; height: 6px;
    background: #FF6B35;
    border-radius: 50%;
    margin-left: 4px;
    vertical-align: middle;
    animation: pulse 1.2s ease-in-out infinite;
}

/* Winner highlight */
.bct-winner {
    color: #2ECC71 !important;
    font-weight: 700;
    background: rgba(46, 204, 113, 0.08) !important;
}

/* Me column */
.bct-me-time {
    background: rgba(255, 107, 53, 0.04);
}

/* Pending (current scramble, no solve yet) */
.bct-pending {
    color: rgba(255,255,255,0.15) !important;
    font-size: 1.2em;
}

/* Empty state */
.bct-empty {
    text-align: center;
    color: var(--clr-text-muted);
    padding: 2rem;
    font-size: 0.85rem;
}

/* Footer rows (single, ao5...) */
.bct-footer-row td {
    padding: 4px 8px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--clr-text-muted);
    border-bottom: 1px solid rgba(255,255,255,0.03);
}
.bct-footer-row .bct-td-num {
    font-style: italic;
}
.bct-footer-row .bct-best-stat {
    color: #3498DB;
}

/* Right panel sizing */
.battle-room-right {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.battle-room-right .battle-panel-header {
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.7); }
}

.spinning-icon { animation: spin 1s linear infinite; }

/* ============================================================
   MOBILE RESPONSIVE — Comprehensive overhaul
   ============================================================ */
@media (max-width: 768px) {

    /* === NAV === */
    .nav-links { gap: 0.25rem; }
    .nav-btn { font-size: 0.7rem; padding: 0.4rem 0.5rem; gap: 0.25rem; }
    .nav-btn svg { width: 14px; height: 14px; }
    .nav-logo-text { font-size: 1rem; }

    /* === GENERAL VIEWS === */
    .view { padding: 0.75rem; }
    .setup-grid { grid-template-columns: 1fr; gap: 0.75rem; }
    .setup-card { padding: 0; }
    .card-body { padding: 0.75rem; }

    /* === SIMULATION SETUP === */
    .setup-actions { padding: 0.75rem; }
    .wca-profile-card { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
    .pr-display { max-height: 200px; }
    .records-table-wrap { max-height: 180px; }

    /* === STATS PAGE === */
    .stats-medals-row { gap: 0.5rem; }
    .lb-wrapper { overflow-x: auto; }
    .lb-table { font-size: 0.78rem; min-width: 340px; }
    .lb-table th, .lb-table td { padding: 0.5rem 0.4rem; }

    /* === BATTLE LOBBY === */
    .battle-lobby-container { padding: 0.75rem; }
    .battle-room-grid { grid-template-columns: 1fr !important; }
    .battle-room-card { padding: 1rem; }

    /* ========================
       BATTLE IN-GAME — MOBILE
       Stacks left panel above right panel
       Order: Event selector → Scramble → Timer → Results table
       ======================== */

    /* The top bar */
    .battle-room-topbar { padding: 0.5rem 0.75rem; gap: 0.4rem; }
    .battle-back-btn { font-size: 0.75rem; padding: 0.35rem 0.65rem; gap: 0.3rem; }
    .battle-back-btn svg { width: 14px; height: 14px; }
    .battle-room-name-tag { font-size: 0.9rem; }
    .battle-room-status { font-size: 0.75rem; }

    /* Stack body into single column */
    .battle-room-body {
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        overflow-x: hidden;
        height: auto;
        max-height: calc(100vh - 100px);
    }

    /* Left panel: no border, full width */
    .battle-room-left {
        border-right: none;
        border-bottom: 1px solid var(--clr-border);
        overflow-y: visible;
        flex-shrink: 0;
    }

    /* Event selector bar: wrap chips nicely */
    .battle-event-selector-bar {
        flex-wrap: wrap;
        gap: 0.4rem;
        padding: 0.65rem 0.75rem;
    }
    .battle-event-selector-label { width: 100%; margin-bottom: 0.1rem; }
    .battle-event-chips { gap: 0.3rem; }
    .battle-event-chip { font-size: 0.72rem; padding: 0.25rem 0.55rem; border-radius: 6px; }

    /* New Scramble button goes full-width below chips */
    #battle-new-scramble-btn {
        width: 100% !important;
        justify-content: center;
        margin-top: 0.35rem;
    }

    /* Scramble panel: compact */
    .battle-scramble-panel {
        padding: 0.75rem;
    }
    .battle-scramble-text {
        font-size: 0.8rem;
        line-height: 1.4;
        word-break: break-all;
    }
    .battle-scramble-viz {
        display: flex;
        justify-content: center;
        margin-top: 0.5rem;
    }
    #battle-twisty {
        width: 110px !important;
        height: 110px !important;
    }

    /* Timer panel: shrink font */
    .battle-timer-panel {
        padding: 1rem 0.75rem;
        gap: 0.75rem;
        min-height: 180px;
    }
    .battle-timer-time {
        font-size: 3.5rem;
    }
    .battle-keyboard-hint {
        font-size: 0.7rem;
        text-align: center;
    }
    .battle-input-mode-bar { gap: 0.3rem; }
    .battle-mode-btn { font-size: 0.75rem; padding: 0.4rem 0.65rem; gap: 0.25rem; }

    /* Right panel: results table shown BELOW left panel */
    .battle-room-right {
        flex-shrink: 0;
        overflow: visible;
        border-top: 2px solid var(--clr-border);
    }

    /* Show full cross table without height cap on mobile */
    .battle-cross-table-wrap {
        overflow-x: auto;
        overflow-y: visible;
        max-height: none;
    }

    /* BCT (cross table) — smaller text */
    .bct-td-num, .bct-th-num { width: 28px; font-size: 0.72rem; }
    .bct-player-header { min-width: 80px; font-size: 0.72rem; }
    .bct-row td, .bct-stat-row td, .bct-footer-row td {
        font-size: 0.72rem;
        padding: 4px 5px;
    }

    /* Typing mode input */
    .battle-typing-input-wrap { flex-direction: column; align-items: stretch; gap: 0.5rem; }
    .battle-typing-input { font-size: 1.1rem; text-align: center; padding: 0.6rem; }
    #battle-typing-submit { width: 100%; justify-content: center; }

    /* Battle modal */
    .battle-modal-card { border-radius: 16px; max-height: 95vh; }
    .battle-modal-body { padding: 1rem; gap: 0.75rem; }
    .battle-modal-header { padding: 1rem; }
    .battle-modal-footer { padding: 0.75rem 1rem; flex-direction: column; }
    .battle-modal-footer .btn { width: 100%; justify-content: center; }
    .form-group-row { flex-direction: column; gap: 0.5rem; }

    /* Ready button */
    .battle-ready-btn { width: 100%; justify-content: center; font-size: 0.95rem; }

    /* === SCORECARD TABLE === */
    .scorecard-table { font-size: 0.75rem; }
    .scorecard-table th, .scorecard-table td { padding: 0.4rem 0.3rem; }
    .scorecard-table td.scramble-cell { max-width: 80px; font-size: 0.65rem; }

    /* === LEADERBOARD / RECORDS === */
    .records-table-enhanced { font-size: 0.78rem; }
    .records-table-enhanced th, .records-table-enhanced td { padding: 0.45rem 0.35rem; }

    /* === GOAL TRACKER === */
    .goal-tracker { padding: 0.75rem; }
    .goal-ring-wrap { width: 100px; }
    .goal-ring-wrap svg { width: 100px; height: 100px; }

    /* === COMPETITION VIEW === */
    .wca-info-display { padding: 0.75rem; }
    .api-info-details { flex-wrap: wrap; gap: 0.35rem; }

    /* === MODALS === */
    .glass-panel { padding: 1.5rem 1rem; border-radius: 16px; width: 95%; }
    .modal-content { max-height: 95vh; overflow-y: auto; }
}

/* Extra small screens */
@media (max-width: 400px) {
    .nav-btn span { display: none; }
    .nav-btn { padding: 0.4rem; }
    .nav-btn svg { width: 18px; height: 18px; }
    .battle-timer-time { font-size: 2.8rem; }
    .battle-event-chip { font-size: 0.68rem; padding: 0.2rem 0.45rem; }
    #battle-twisty { width: 90px !important; height: 90px !important; }
}

/* ==========================================================================
   TIMER VIEW (csTimer Clone)
   ========================================================================== */
.timer-view-container {
    display: flex;
    flex-direction: row;
    height: calc(100vh - 140px); /* Leave space for header/nav */
    gap: var(--space-lg);
    padding: var(--space-md);
    margin-top: 20px;
}

.timer-sidebar {
    flex: 0 0 300px;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    overflow-y: auto;
}

.timer-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    user-select: none;
}

.timer-scramble {
    font-size: 1.8rem;
    font-weight: 600;
    text-align: center;
    max-width: 80%;
    margin-bottom: auto;
    margin-top: 20px;
    line-height: 1.4;
    color: var(--text-main);
}

.timer-display-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.timer-display {
    font-size: clamp(6rem, 15vw, 15rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: -2px;
    color: var(--text-main);
    transition: color 0.1s ease;
}

.timer-display.timer-red {
    color: var(--clr-danger);
}

.timer-display.timer-green {
    color: var(--clr-success);
}

.timer-hint {
    margin-top: auto;
    margin-bottom: 20px;
    font-size: 1rem;
    color: var(--text-muted);
    opacity: 0.7;
}

/* Stats Panel */
.timer-stats-grid {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-top: var(--space-sm);
}

.timer-stats-grid .stat-item {
    display: flex;
    justify-content: space-between;
    padding: var(--space-sm);
    background: rgba(255,255,255,0.03);
    border-radius: var(--radius-md);
}

/* Solves List */
.timer-solves-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 200px;
}

.timer-solves-list {
    flex: 1;
    overflow-y: auto;
    margin-top: var(--space-sm);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.timer-solve-item {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.02);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.95rem;
    cursor: pointer;
}

.timer-solve-item:hover {
    background: rgba(255,255,255,0.05);
}

.timer-solve-item .solve-index {
    color: var(--text-muted);
    width: 30px;
}

.timer-solve-item .solve-time {
    font-weight: 600;
    color: var(--clr-primary);
}

/* Responsive Timer View */
@media (max-width: 900px) {
    .timer-view-container {
        flex-direction: column-reverse;
        height: auto;
    }
    .timer-sidebar {
        flex: none;
        width: 100%;
    }
    .timer-main {
        min-height: 400px;
    }
}

/* ==========================================================================
   THEMES
   ========================================================================== */

/* Ocean Theme */
[data-theme="ocean"] {
    --bg-main: #0B192C;
    --bg-card: #1A2E46;
    --text-main: #E2E8F0;
    --text-muted: #94A3B8;
    
    --clr-primary: #38BDF8;
    --clr-primary-hover: #0EA5E9;
    --clr-accent: #14B8A6;
    
    --clr-primary-glow: rgba(56, 189, 248, 0.15);
    --clr-accent-glow: rgba(20, 184, 166, 0.15);
}

/* Matrix Theme */
[data-theme="matrix"] {
    --bg-main: #050505;
    --bg-card: #0A0A0A;
    --text-main: #10B981;
    --text-muted: #065F46;
    
    --clr-primary: #10B981;
    --clr-primary-hover: #059669;
    --clr-accent: #34D399;
    
    --clr-primary-glow: rgba(16, 185, 129, 0.15);
    --clr-accent-glow: rgba(52, 211, 153, 0.15);
}

/* Sunset Theme */
[data-theme="sunset"] {
    --bg-main: #1C1917;
    --bg-card: #292524;
    --text-main: #FEF3C7;
    --text-muted: #D6D3D1;
    
    --clr-primary: #F97316;
    --clr-primary-hover: #EA580C;
    --clr-accent: #E11D48;
    
    --clr-primary-glow: rgba(249, 115, 22, 0.15);
    --clr-accent-glow: rgba(225, 29, 72, 0.15);
}

/* ==========================================================================
   csTimer CLONE — Layout & components for #timer-view (NEW)
   ========================================================================== */
.cstimer-layout {
    display: grid;
    grid-template-columns: 280px 1fr 300px;
    height: calc(100vh - 80px);
    gap: var(--space-md);
    padding: var(--space-md);
    margin-top: 0;
    background: transparent;
}

.cstimer-left, .cstimer-right {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    overflow: hidden;
    min-height: 0;
}

.cstimer-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    user-select: none;
    padding: var(--space-md);
    position: relative;
    min-width: 0;
}

.cs-session-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    padding: var(--space-xs);
    background: var(--clr-bg-card);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
}

.cs-session-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--clr-text-secondary);
    font-family: var(--font-body);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;




/* === Added by upcoming-search feature === */

.competitions-dual-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-xl);
  margin-bottom: var(--space-xl);
  align-items: start;
}

@media (max-width: 1280px) {
  .competitions-dual-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 980px) {
  .competitions-dual-grid {
    grid-template-columns: 1fr;
  }
}


/* Registration status badges for upcoming-by-WCA-ID cards */
.reg-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-left: 8px;
  vertical-align: middle;
  border: 1px solid transparent;
}
.reg-status-scheduled {
  background: rgba(99,102,241,0.18);
  color: var(--clr-primary-hover);
  border-color: rgba(99,102,241,0.35);
}


/* ============================================================
   COMPETITIONS SEARCH GRID (Past + Upcoming side-by-side)
   ============================================================ */

.competitions-search-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
}

.competitions-search-grid > .setup-card {
    width: 100%;
}

@media (max-width: 768px) {
    .competitions-search-grid {
        grid-template-columns: 1fr;
    }
}


/* ============================================================
   BATTLE ROOM CHAT
   ============================================================ */

.battle-chat-panel {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 200px;
    max-height: 320px;
    border-top: 1px solid var(--clr-border);
    background: var(--clr-surface);
}

.battle-chat-status {
    margin-left: auto;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--clr-text-muted);
    text-transform: none;
    letter-spacing: 0;
}

.battle-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm);
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
    scroll-behavior: smooth;
}

.battle-chat-empty {
    text-align: center;
    color: var(--clr-text-muted);
    font-size: 0.8rem;
    padding: var(--space-lg) var(--space-sm);
    line-height: 1.5;
}

.battle-chat-message {
    font-size: 0.82rem;
    background: rgba(255, 255, 255, 0.03);
    padding: 6px 10px;
    border-radius: 8px;
    word-wrap: break-word;
    line-height: 1.4;
    border-left: 2px solid var(--clr-primary);
}

.battle-chat-message .chat-user {
    font-weight: 700;
    color: var(--clr-primary);
    margin-right: 4px;
    font-size: 0.78rem;
}

.battle-chat-message .chat-time {
    font-size: 0.65rem;
    color: var(--clr-text-muted);
    float: right;
    margin-top: 3px;
    margin-left: 6px;
}

.battle-chat-message .chat-text {
    color: var(--clr-text);
}

.battle-chat-input-row {
    display: flex;
    gap: 6px;
    padding: var(--space-sm);
    border-top: 1px solid var(--clr-border);
    background: var(--clr-bg-elevated);
}

.battle-chat-input-row input {
    flex: 1;
    min-width: 0;
    background: var(--clr-bg);
    border: 1px solid var(--clr-border);
    color: var(--clr-text);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: var(--font-body);
    transition: border-color var(--transition-fast);
}

.battle-chat-input-row input:focus {
    border-color: var(--clr-primary);
    outline: none;
    box-shadow: 0 0 0 2px var(--clr-primary-glow);
}

.battle-chat-input-row input:disabled,
.battle-chat-input-row button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.battle-chat-input-row button {
    flex-shrink: 0;
    padding: 6px 14px;
}


/* Inline event panel */
#wca-comp-event-panel {
    animation: fadeIn 0.25s ease;
}

/* Event header inline (has icon + name side by side) */
#wca-event-header-inline h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.3rem;
    margin-bottom: 4px;
}

#wca-event-header-inline h2 svg {
    width: 28px;
    height: 28px;
    opacity: 0.8;
    flex-shrink: 0;
}

#wca-event-header-inline .event-subtitle {
    font-size: 0.82rem;
    color: var(--clr-text-muted);
    margin-bottom: var(--space-md);
}
