/* ============================================
   Number Click Speed Game - Styles
   ============================================ */

/* CSS Variables for easy theming */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --error-color: #ef4444;
    --warning-color: #f59e0b;

    --bg-color: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #334155;

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --border-color: #475569;
    --border-radius: 12px;
    --border-radius-sm: 8px;

    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);

    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;

    --grid-gap: 6px;
    --cell-size: 52px;

    /* Dynamic viewport height for mobile (set by JS, fallback to 1vh) */
    --vh: 1vh;
}

/* ============================================
   News Ticker for Sub-40 Achievements
   ============================================ */

.news-ticker {
    position: relative;
    height: 32px;
    background: linear-gradient(90deg, #1e293b 0%, #334155 50%, #1e293b 100%);
    border-bottom: 1px solid var(--primary-color);
    border-radius: var(--border-radius) var(--border-radius) 0 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    margin-bottom: 0;
}

.ticker-content {
    display: inline-block;
    white-space: nowrap;
    padding-left: 100%;
    animation: ticker-scroll 30s linear infinite;
    font-size: 0.85rem;
    color: var(--primary-color);
    font-weight: 500;
    letter-spacing: 0.5px;
}

.ticker-content .achievement-item {
    display: inline;
    padding: 0 2rem;
}

.ticker-content .player-name {
    color: #22c55e;
    font-weight: 600;
}

.ticker-content .achievement-time {
    color: #fbbf24;
    font-weight: 700;
}

@keyframes ticker-scroll {
    0% {
        transform: translateX(0);
    }
    100% {
        transform: translateX(-100%);
    }
}

/* No more body padding needed since ticker is inside container */

/* Reset and Base Styles */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    /* Prevent pull-to-refresh and overscroll on mobile */
    overscroll-behavior: none;
    overflow-x: hidden;
    overflow-y: auto;
    height: 100%;
    height: -webkit-fill-available;
}

body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, var(--bg-color) 0%, #1a1a2e 100%);
    color: var(--text-primary);
    line-height: 1.5;

    /* Height handling */
    min-height: 100vh;
    min-height: -webkit-fill-available;
    min-height: 100dvh;

    /* Scrolling & zoom (Safari-safe) */
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;

    /* IMPORTANT: allow pinch zoom */
    /* touch-action: pan-x pan-y; */

    /* Prevent layout issues */
    width: 100%;
}

body.duel-open {
    position: fixed;
    overflow: hidden;
    width: 100%;
}



/* Container */
    /* Allow scrolling within container on mobile */

/* .container {
    max-width: 900px;
    margin: 0 auto;
    padding: 1rem;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
} */

.container {
    width: 100%;
    max-width: 1100px;  
    margin: 0 auto;
    padding: 1rem;
}




/* Header */
header {
    text-align: center;
    padding: 1.5rem 0;
}

/* Games Today Banner */
.games-today-banner {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.3);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--primary-color);
    margin-bottom: 0.75rem;
}

#games-today-count {
    font-weight: 600;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #6366f1, #8b5cf6, #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Stats Bar */
.stats-bar {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 1rem;
    flex-wrap: nowrap; /* Prevent wrapping that causes glitchy reflow */
}

.stat {
    background: var(--bg-secondary);
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    text-align: center;
    min-width: 100px;
    border: 1px solid var(--border-color);
    /* Prevent size changes from causing reflow */
    flex-shrink: 0;
}

.stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* Timer needs fixed width to prevent reflow when digits change */
#timer {
    width: 5ch; /* Fixed width for "0:00.00" */
    display: inline-block;
}

.next-number .stat-value {
    color: var(--primary-color);
    font-size: 1.75rem;
}

/* Pace indicator */
.pace-stat .stat-value {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.pace-stat.good .stat-value {
    color: #22c55e; /* Green for sub-40 pace */
}

.pace-stat.warning .stat-value {
    color: #f59e0b; /* Yellow for 40-50s pace */
}

.pace-stat.slow .stat-value {
    color: var(--text-muted); /* Muted for >50s pace */
}

.mistakes .stat-value {
    color: var(--text-secondary);
}

.mistakes .stat-value.danger {
    color: var(--error-color);
    animation: pulse 0.5s ease infinite;
}

/* Game Area */
.game-area {
    position: relative;
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
    width : 100%;
    /* Prevent double-tap zoom on mobile */
    touch-action: manipulation;
    -webkit-touch-callout: none;
    /* Prevent text selection */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Grid */
.grid {
    display: grid;
    width: fit-content;
    margin: 0 auto;
    grid-template-columns: repeat(7, var(--cell-size));
    grid-template-rows: repeat(7, var(--cell-size));
    gap: var(--grid-gap);
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: var(--border-radius);
    border: 2px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    /* Prevent double-tap zoom on mobile */
    touch-action: manipulation;
    /* Prevent text selection */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Grid Cells */
.cell {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border-radius: var(--border-radius-sm);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 2px solid transparent;
    position: relative;
    /* Prevent double-tap zoom and other touch gestures */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    /* Prevent text selection on touch */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-touch-callout: none;
}

/* Cell number text - also prevent touch zoom */
.cell span {
    touch-action: manipulation;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

/* Larger hitbox for cells without changing visual size */
.cell::before {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    /* Invisible expanded tap area */
}

@media (pointer: coarse) {
    .cell::before {
        top: -8px;
        left: -8px;
        right: -8px;
        bottom: -8px;
    }
}

/* Hide numbers before game starts */
.grid.hidden-numbers .cell span {
    visibility: hidden;
}

.cell:hover:not(.clicked):not(.wrong) {
    background: #3d4f6a;
    transform: scale(1.05);
    border-color: var(--primary-color);
}

.cell:active:not(.clicked) {
    transform: scale(0.95);
}

/* Clicked state */
.cell.clicked {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: white;
    cursor: default;
    border-color: #15803d;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.cell.clicked::after {
    content: '✓';
    position: absolute;
    font-size: 1.25rem;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.cell.clicked span {
    opacity: 0;
}

/* Wrong click animation */
.cell.wrong {
    animation: shake 0.4s ease;
    background: var(--error-color);
    border-color: #dc2626;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* Overlay */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
    pointer-events: none;
}

.overlay.visible {
    opacity: 1;
    visibility: visible;
}

/* Only block clicks when showing end-game overlay with button */
.overlay.visible.blocking {
    pointer-events: auto;
}

.overlay-content {
    text-align: center;
    padding: 2rem;
}

.overlay-content h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.overlay-content p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* Error Feedback */
.error-feedback {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--error-color);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    font-weight: 500;
    box-shadow: var(--shadow-md);
    transition: transform var(--transition-normal);
    z-index: 100;
}

.error-feedback.visible {
    transform: translateX(-50%) translateY(0);
}

#error-number {
    font-weight: 700;
    font-size: 1.1em;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius-sm);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    /* Prevent touch issues */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-secondary);
    border-color: var(--primary-color);
}

.btn-large {
    padding: 1rem 3rem;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 2px;
}

.icon {
    font-size: 1.2em;
}

/* Controls */
.controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

/* Mute button */
#mute-btn {
    min-width: auto;
    padding: 0.75rem 1rem;
}

/* Leaderboard Section */
.leaderboard-section {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
}

.leaderboard-section h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    text-align: center;
    color: var(--text-primary);
}

/* Leaderboard Controls */
.leaderboard-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.toggle-group {
    display: flex;
    background: var(--bg-card);
    border-radius: var(--border-radius-sm);
    padding: 3px;
    border: 1px solid var(--border-color);
}

.toggle-btn {
    padding: 0.5rem 0.75rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all var(--transition-fast);
}

.toggle-btn:hover {
    color: var(--text-primary);
}

.toggle-btn.active {
    background: var(--primary-color);
    color: white;
}

.btn-small {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
}

/* Player Search */
.player-search {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.player-search input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
}

.player-search input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.player-search input::placeholder {
    color: var(--text-muted);
}

/* Your Rank Section */
.your-rank-section {
    margin-top: 1rem;
    padding-top: 0.5rem;
}

.your-rank-separator {
    text-align: center;
    color: var(--text-muted);
    font-size: 1.25rem;
    letter-spacing: 0.5rem;
    margin-bottom: 0.5rem;
}

.your-rank-section .leaderboard-entry {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid var(--primary-color);
}

.search-result-highlight {
    background: rgba(251, 191, 36, 0.2) !important;
    border: 1px solid #fbbf24 !important;
}

.leaderboard {
    min-height: 200px;
}

.leaderboard-loading {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

.leaderboard-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

.leaderboard-entry {
    display: flex;
    flex-direction: column;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius-sm);
    margin-bottom: 0.5rem;
    background: var(--bg-card);
    transition: all var(--transition-fast);
}

.leaderboard-entry:hover {
    background: #3d4f6a;
}

.leaderboard-entry.highlight {
    background: rgba(99, 102, 241, 0.2);
    border: 1px solid var(--primary-color);
}

.entry-rank {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    margin-right: 1rem;
    border-radius: 50%;
    font-size: 0.875rem;
}

.entry-rank.gold {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #1a1a1a;
}

.entry-rank.silver {
    background: linear-gradient(135deg, #94a3b8, #64748b);
    color: #1a1a1a;
}

.entry-rank.bronze {
    background: linear-gradient(135deg, #d97706, #b45309);
    color: white;
}

.entry-rank.normal {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.entry-name {
    flex: 1;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.entry-time {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--primary-color);
    margin-right: 0.75rem;
}

.entry-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* BLD breakdown (memo + exec) inline */
.entry-bld-breakdown {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    margin-right: 0.5rem;
    white-space: nowrap;
}

/* Leaderboard entry main row */
.entry-main {
    display: flex;
    align-items: center;
    width: 100%;
}

/* Other times display for best-per-player mode */
.entry-other-times {
    font-size: 0.7rem;
    color: var(--text-muted);
    padding-left: 48px;
    margin-top: 0.25rem;
    font-style: italic;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
    padding: 1rem;
}

.modal.visible {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: var(--border-radius);
    max-width: 400px;
    width: 100%;
    text-align: center;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    transform: scale(0.9);
    transition: transform var(--transition-normal);
}

.modal.visible .modal-content {
    transform: scale(1);
}

.modal-content h2 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}

.final-time {
    font-size: 1.5rem;
    color: var(--primary-color);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.rank-info {
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

/* Percentile display */
.percentile-info {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    background: rgba(99, 102, 241, 0.1);
    color: var(--text-secondary);
}

.percentile-info.top-10 {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.2), rgba(255, 165, 0, 0.2));
    color: #fbbf24;
}

.percentile-info.top-25 {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}

.percentile-info.top-50 {
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary-color);
}

.percentile-info.bottom-half {
    background: rgba(148, 163, 184, 0.1);
    color: var(--text-muted);
}

.modal-content label {
    display: block;
    text-align: left;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.modal-content input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: inherit;
    /* Use 16px minimum to prevent iOS zoom on focus */
    font-size: max(16px, 1rem);
    margin-bottom: 1rem;
    transition: border-color var(--transition-fast);
    /* Mobile input fixes */
    -webkit-appearance: none;
    appearance: none;
    box-sizing: border-box;
}

.modal-content input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Name with flag input */
.name-with-flag {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.name-with-flag input[type="text"] {
    flex: 1;
    margin-bottom: 0;
}

.flag-selector {
    position: relative;
}

.flag-btn {
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    height: 100%;
    transition: all var(--transition-fast);
}

.flag-btn:hover {
    border-color: var(--primary-color);
}

.flag-preview {
    width: 24px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.flag-preview img {
    width: 24px;
    height: 18px;
    object-fit: cover;
    border-radius: 2px;
}

.flag-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    width: 250px;
    max-height: 300px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 1001;
    display: none;
    flex-direction: column;
}

.flag-dropdown.visible {
    display: flex;
}

.flag-dropdown input {
    margin: 0.5rem;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.85rem;
}

.flag-list {
    overflow-y: auto;
    max-height: 240px;
}

.flag-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.flag-option:hover {
    background: var(--bg-card);
}

.flag-option img {
    width: 24px;
    height: 18px;
    object-fit: cover;
    border-radius: 2px;
}

.flag-option span {
    font-size: 0.85rem;
    color: var(--text-primary);
}

/* Flag in leaderboard entries */
.entry-flag {
    width: 20px;
    height: 15px;
    object-fit: cover;
    border-radius: 2px;
    margin-right: 0.5rem;
    flex-shrink: 0;
}

.modal-buttons {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.modal-buttons .btn {
    flex: 1;
}

/* Footer */
footer {
    text-align: center;
    padding: 1rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

footer .credits {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    opacity: 0.7;
}

/* Responsive Design */
@media (max-width: 600px) {
    :root {
        --cell-size: 42px;
        --grid-gap: 4px;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 0.875rem;
    }

    .stats-bar {
        gap: 0.5rem;
        padding: 0 0.5rem;
    }

    .stat {
        padding: 0.5rem 0.75rem;
        min-width: 70px;
    }

    .stat-value {
        font-size: 1.1rem;
    }

    #timer {
        width: 5ch;
    }

    .grid {
        padding: 0.75rem;
    }

    .cell {
        font-size: 0.95rem;
    }

    .leaderboard-section {
        padding: 1rem;
    }

    .leaderboard-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .toggle-group {
        justify-content: center;
    }

    .btn-small {
        width: 100%;
        justify-content: center;
    }

    .leaderboard-entry {
        padding: 0.5rem 0.75rem;
    }

    .entry-main {
        flex-wrap: wrap;
    }

    .entry-date {
        font-size: 0.7rem;
        width: 100%;
        text-align: right;
        margin-top: 0.25rem;
        padding-left: 48px;
    }

    .modal-content {
        padding: 1.5rem;
    }
}

@media (max-width: 400px) {
    :root {
        --cell-size: 36px;
        --grid-gap: 3px;
    }

    .container {
        padding: 0.5rem;
    }

    header {
        padding: 0.75rem 0;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .cell {
        font-size: 0.85rem;
        border-radius: 4px;
    }

    .cell.clicked::after {
        font-size: 1.1rem;
    }

    .stats-bar {
        gap: 0.35rem;
    }

    .stat {
        padding: 0.4rem 0.5rem;
        min-width: 60px;
    }

    .stat-label {
        font-size: 0.6rem;
    }

    .stat-value {
        font-size: 1rem;
    }

    #timer {
        width: 4.5ch;
    }
}

/* Animation for new leaderboard entry */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.leaderboard-entry.new {
    animation: slideIn 0.3s ease forwards;
}

/* Pulse animation for next number hint */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.next-number .stat-value {
    animation: pulse 1.5s ease infinite;
}

/* Game complete celebration */
@keyframes celebrate {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.game-complete .grid {
    animation: celebrate 0.5s ease;
}

/* ============================================
   Replay System Styles
   ============================================ */

/* Replay button in leaderboard */
.replay-btn {
    background: var(--primary-color);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 0.5rem;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.replay-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.1);
}

/* Replay Modal Content */
.replay-modal-content {
    max-width: 500px;
    position: relative;
}

.replay-close-btn {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.75rem;
    cursor: pointer;
    line-height: 1;
    padding: 0.25rem;
    transition: color var(--transition-fast);
}

.replay-close-btn:hover {
    color: var(--text-primary);
}

/* Replay Stats */
.replay-stats {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 1rem;
}

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

.replay-stat .stat-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.replay-stat .stat-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary-color);
    font-variant-numeric: tabular-nums;
}

/* Replay Grid Container */
.replay-grid-container {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
}

.replay-grid {
    --cell-size: 38px;
    --grid-gap: 4px;
}

/* Replay Controls */
.replay-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.replay-speed-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-right: 0.5rem;
}

.replay-speed-btn {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all var(--transition-fast);
}

.replay-speed-btn:hover {
    border-color: var(--primary-color);
    color: var(--text-primary);
}

.replay-speed-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

/* Replay grid cell animation */
@keyframes replayClick {
    0% { transform: scale(1); }
    50% { transform: scale(0.9); }
    100% { transform: scale(1); }
}

.replay-grid .cell.clicked {
    animation: replayClick 0.15s ease;
}

/* Responsive replay modal */
@media (max-width: 600px) {
    .replay-modal-content {
        padding: 1.25rem;
    }

    .replay-grid {
        --cell-size: 32px;
        --grid-gap: 3px;
    }

    .replay-stats {
        gap: 1rem;
    }

    .replay-stat .stat-value {
        font-size: 1.1rem;
    }
}

@media (max-width: 400px) {
    .replay-grid {
        --cell-size: 28px;
        --grid-gap: 2px;
    }

    .replay-speed-btn {
        padding: 0.3rem 0.5rem;
        font-size: 0.75rem;
    }
}

/* ============================================
   Game Over Explosion Animation
   ============================================ */

.explosion-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
    overflow: visible;
}

.explosion-particle {
    position: absolute;
    top: 50%;
    left: 50%;
    font-size: 2rem;
    animation: explode 1s ease-out forwards;
    opacity: 0;
}

@keyframes explode {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(0.5) rotate(0deg);
    }
    20% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform:
            translate(
                calc(-50% + var(--x)),
                calc(-50% + var(--y))
            )
            scale(var(--scale))
            rotate(var(--rotation));
    }
}

/* Screen shake effect */
.screen-shake {
    animation: shake-it 0.5s ease-in-out;
}

@keyframes shake-it {
    0%, 100% { transform: translateX(0); }
    10% { transform: translateX(-10px) rotate(-1deg); }
    20% { transform: translateX(10px) rotate(1deg); }
    30% { transform: translateX(-10px) rotate(-1deg); }
    40% { transform: translateX(10px) rotate(1deg); }
    50% { transform: translateX(-5px) rotate(-0.5deg); }
    60% { transform: translateX(5px) rotate(0.5deg); }
    70% { transform: translateX(-5px) rotate(-0.5deg); }
    80% { transform: translateX(5px) rotate(0.5deg); }
    90% { transform: translateX(-2px); }
}

/* DNF text */
.dnf-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    font-weight: 900;
    color: white;
    text-shadow:
        3px 3px 0 #ff0000,
        -3px -3px 0 #ff0000,
        3px -3px 0 #ff0000,
        -3px 3px 0 #ff0000,
        0 0 30px rgba(255, 0, 0, 0.9),
        0 0 60px rgba(255, 0, 0, 0.6);
    animation: dnf-appear 0.5s ease-out 0.3s forwards,
               dnf-flicker 0.1s ease-in-out infinite 0.3s;
    opacity: 0;
    white-space: nowrap;
    z-index: 101;
    letter-spacing: 0.2em;
}

.dnf-text span {
    display: inline-block;
    animation: dnf-shake 0.1s ease-in-out infinite;
}

@keyframes dnf-appear {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(5) rotate(-10deg);
    }
    50% {
        transform: translate(-50%, -50%) scale(0.8) rotate(5deg);
    }
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
    }
}

@keyframes dnf-flicker {
    0%, 100% {
        filter: brightness(1);
        text-shadow:
            3px 3px 0 #ff0000,
            -3px -3px 0 #ff0000,
            3px -3px 0 #ff0000,
            -3px 3px 0 #ff0000,
            0 0 30px rgba(255, 0, 0, 0.9),
            0 0 60px rgba(255, 0, 0, 0.6);
    }
    50% {
        filter: brightness(1.3);
        text-shadow:
            3px 3px 0 #ff3300,
            -3px -3px 0 #ff3300,
            3px -3px 0 #ff3300,
            -3px 3px 0 #ff3300,
            0 0 40px rgba(255, 50, 0, 1),
            0 0 80px rgba(255, 50, 0, 0.8);
    }
}

@keyframes dnf-shake {
    0%, 100% { transform: translateX(0) rotate(0deg); }
    25% { transform: translateX(-2px) rotate(-1deg); }
    75% { transform: translateX(2px) rotate(1deg); }
}

/* Fire border effect on game area during explosion */
.game-area.screen-shake::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    background: linear-gradient(
        45deg,
        #ff0000,
        #ff6600,
        #ffcc00,
        #ff6600,
        #ff0000
    );
    background-size: 400% 400%;
    animation: fire-gradient 0.5s ease infinite;
    border-radius: calc(var(--border-radius) + 10px);
    z-index: -1;
    opacity: 0.8;
}

@keyframes fire-gradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* ============================================
   DUEL MODE STYLES
   ============================================ */

/* Duel Mode Button (inline with controls) */
.btn-duel {
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: white;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--border-radius-sm);
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.btn-duel:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.5);
}

/* Lobby notification badge */
.lobby-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: #ef4444;
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.5);
    animation: pulse-badge 2s ease-in-out infinite;
}

@keyframes pulse-badge {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Duel Lobby Modal */
.duel-lobby-content {
    max-width: 500px;
    position: relative;
}

#duel-modal {
    touch-action: auto;
}

/* Allow pinch-to-zoom on duel game modal (mobile) */
#duel-game-modal {
    touch-action: pinch-zoom pan-x pan-y;
    -webkit-overflow-scrolling: touch;
    overflow: auto;
}

#duel-game-modal .modal-content {
    touch-action: pinch-zoom pan-x pan-y;
    max-height: none;
    overflow: visible;
}

/* The game area itself should allow pinch zoom */
.duel-game-content {
    touch-action: pinch-zoom pan-x pan-y;
}

#duel-game-area {
    touch-action: pinch-zoom pan-x pan-y;
}

/* Duel grid cells should allow interaction */
.duel-grid .cell {
    touch-action: manipulation;
}

.modal-close-btn {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.75rem;
    cursor: pointer;
    line-height: 1;
    padding: 0.25rem;
    transition: color var(--transition-fast);
    z-index: 10;
}

.modal-close-btn:hover {
    color: var(--text-primary);
}

.lobby-section {
    margin-top: 1rem;
}

.lobby-desc {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    text-align: center;
}

.lobby-name-input {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.lobby-name-input label {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.lobby-name-input input {
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
}

.lobby-name-input input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Lobby Header */
.lobby-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: var(--border-radius-sm);
    margin-bottom: 1rem;
}

.lobby-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.online-dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    animation: online-pulse 2s ease-in-out infinite;
}

@keyframes online-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Online Players List */
.online-players-list {
    min-height: 150px;
    max-height: 300px;
    overflow-y: auto;
    background: var(--bg-card);
    border-radius: var(--border-radius-sm);
    padding: 0.5rem;
}

.no-players {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
    font-style: italic;
}

.online-player {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: var(--border-radius-sm);
    transition: background var(--transition-fast);
}

.online-player:hover {
    background: var(--bg-secondary);
}

.online-player .player-name {
    flex: 1;
    font-weight: 500;
}

.btn-challenge {
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: white;
    border: none;
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all var(--transition-fast);
}

.btn-challenge:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4);
}

/* Challenge Alert */
.challenge-alert {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(239, 68, 68, 0.2));
    border: 2px solid #f59e0b;
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-top: 1rem;
    animation: challenge-appear 0.3s ease-out;
}

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

.challenge-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.challenge-icon {
    font-size: 1.5rem;
    animation: swords-shake 0.5s ease-in-out infinite;
}

@keyframes swords-shake {
    0%, 100% { transform: rotate(-5deg); }
    50% { transform: rotate(5deg); }
}

.challenge-text {
    color: var(--text-primary);
}

.challenge-buttons {
    display: flex;
    gap: 0.5rem;
}

/* Challenge Waiting */
.challenge-waiting {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--bg-card);
    border-radius: var(--border-radius-sm);
    margin-top: 1rem;
    color: var(--text-secondary);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ============================================
   DUEL GAME MODAL
   ============================================ */

.duel-game-content {
    max-width: 95vw;
    width: 900px;
    padding: 1.5rem;
    position: relative;
}

.duel-header {
    text-align: center;
    margin-bottom: 1rem;
}

.duel-header h2 {
    font-size: 1.75rem;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.25rem;
}

/* Waiting Room */
.waiting-room-content {
    text-align: center;
    padding: 2rem;
}

.waiting-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

.duel-players-status {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    margin: 1.5rem 0;
}

.duel-player-card {
    background: var(--bg-card);
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    min-width: 150px;
    text-align: center;
}

.duel-player-card .player-name {
    display: block;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.duel-player-card .player-status {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.duel-player-card .player-status.ready {
    color: #22c55e;
    font-weight: 600;
}

.vs-divider {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-muted);
}

/* Countdown */
#duel-countdown {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 300px;
}

.countdown-display {
    font-size: 8rem;
    font-weight: 900;
    color: var(--primary-color);
    text-shadow: 0 0 30px rgba(99, 102, 241, 0.5);
    animation: countdown-pulse 1s ease-in-out infinite;
}

@keyframes countdown-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

/* ============================================
   DUEL GAME AREA (Side by Side)
   ============================================ */

/* Give Up Button Container - positioned under opponent's board */
.duel-give-up-container {
    display: flex;
    justify-content: center;
    margin-top: 0.75rem;
}

.btn-give-up {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    padding: 0.3rem 0.75rem;
    font-size: 0.7rem;
    opacity: 0.7;
    transition: all var(--transition-fast);
}

.btn-give-up:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error-color);
    border-color: var(--error-color);
    opacity: 1;
}

.duel-game-container {
    display: flex;
    justify-content: center;
    gap: 2rem;
    flex-wrap: wrap;
    transform-origin: top center;
    transition: transform 0.2s ease;
}

.duel-side {
    flex: 1;
    min-width: 300px;
    max-width: 400px;
}

.duel-side-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-card);
    border-radius: var(--border-radius-sm);
}

.my-side .duel-side-header {
    border-left: 3px solid #22c55e;
}

.opponent-side .duel-side-header {
    border-left: 3px solid #ef4444;
}

.duel-side-name {
    font-weight: 600;
    font-size: 1rem;
}

.duel-side-timer {
    font-family: monospace;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary-color);
    font-variant-numeric: tabular-nums;
}

.duel-side-stats {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.duel-stat {
    text-align: center;
    background: var(--bg-secondary);
    padding: 0.4rem 0.75rem;
    border-radius: var(--border-radius-sm);
}

.duel-stat .stat-label {
    display: block;
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.duel-stat .stat-value {
    font-size: 1rem;
    font-weight: 600;
}

.duel-stat.mistakes .stat-value.danger {
    color: var(--error-color);
    animation: pulse 0.5s ease infinite;
}

/* Duel Grid */
.duel-grid {
    --cell-size: 38px;
    --grid-gap: 4px;
}

.opponent-grid {
    opacity: 0.9;
    pointer-events: none;
}

.opponent-grid .cell {
    background: #2d3748;
}

.opponent-grid .cell.clicked {
    background: #ef4444;
    opacity: 0.7;
}

/* ============================================
   DUEL RESULTS
   ============================================ */

#duel-results {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

.duel-results-content {
    text-align: center;
    padding: 2rem;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

.duel-result-icon {
    font-size: 5rem;
    margin-bottom: 1rem;
    animation: result-bounce 0.5s ease-out;
}

@keyframes result-bounce {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

#duel-results.victory .duel-result-icon { animation: victory-glow 2s ease-in-out infinite; }
#duel-results.defeat .duel-result-icon { animation: defeat-shake 0.5s ease-in-out; }

@keyframes victory-glow {
    0%, 100% { filter: drop-shadow(0 0 10px rgba(251, 191, 36, 0.5)); }
    50% { filter: drop-shadow(0 0 30px rgba(251, 191, 36, 0.8)); }
}

@keyframes defeat-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

#duel-result-title {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

#duel-results.victory #duel-result-title {
    color: #fbbf24;
}

#duel-results.defeat #duel-result-title {
    color: var(--text-secondary);
}

#duel-result-message {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.duel-final-scores {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 2rem;
}

.duel-final-score {
    background: var(--bg-card);
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    min-width: 150px;
}

.score-name {
    display: block;
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
}

.score-time {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.score-time.winner {
    color: #fbbf24;
}

.duel-result-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Save to leaderboard button */
.btn-save {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
    border: none;
}

.btn-save:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4);
}

.btn-save.saved {
    background: #64748b;
    cursor: default;
}

.btn-save.saved:hover {
    transform: none;
    box-shadow: none;
}

/* ============================================
   RESPONSIVE DUEL STYLES
   ============================================ */

@media (max-width: 800px) {
    .duel-game-container {
        flex-direction: column;
        align-items: center;
    }

    .duel-side {
        max-width: 400px;
        width: 100%;
    }

    .duel-grid {
        --cell-size: 40px;
        --grid-gap: 4px;
    }
}

@media (max-width: 600px) {
    .btn-duel {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }

    .duel-game-content {
        padding: 0.75rem;
    }

    .duel-header h2 {
        font-size: 1.5rem;
    }

    .countdown-display {
        font-size: 5rem;
    }

    /* Larger grid cells on mobile for better touch targets */
    .duel-grid {
        --cell-size: 38px;
        --grid-gap: 3px;
    }

    .duel-players-status {
        flex-direction: column;
        gap: 0.75rem;
    }

    .vs-divider {
        font-size: 1rem;
    }

    .duel-player-card {
        padding: 0.75rem 1rem;
        min-width: 120px;
    }

    .duel-final-scores {
        flex-direction: column;
        gap: 1rem;
    }

    .duel-result-buttons {
        flex-direction: column;
    }

    .duel-result-buttons .btn {
        width: 100%;
    }
}

@media (max-width: 400px) {
    /* Keep reasonable cell size even on very small screens */
    .duel-grid {
        --cell-size: 34px;
        --grid-gap: 2px;
    }

    .duel-side-stats {
        gap: 0.5rem;
    }

    .duel-stat {
        padding: 0.25rem 0.5rem;
    }

    .duel-side-header {
        padding: 0.3rem 0.5rem;
    }

    .duel-side-name {
        font-size: 0.9rem;
    }

    .duel-side-timer {
        font-size: 1rem;
    }
}

/* ============================================
   LIGHT MODE STYLES
   ============================================ */

body.light-mode {
    --bg-color: #f8fafc;
    --bg-secondary: #e2e8f0;
    --bg-card: #ffffff;

    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #64748b;

    --border-color: #cbd5e1;

    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);

    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
}

body.light-mode header h1 {
    background: linear-gradient(135deg, #4f46e5, #7c3aed, #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

body.light-mode .news-ticker {
    background: linear-gradient(90deg, #e2e8f0 0%, #f1f5f9 50%, #e2e8f0 100%);
    border-bottom-color: var(--primary-color);
}

body.light-mode .cell {
    background: #f1f5f9;
    color: #1e293b;
    border-color: #e2e8f0;
}

body.light-mode .cell:hover:not(.clicked):not(.wrong) {
    background: #e2e8f0;
    border-color: var(--primary-color);
}

body.light-mode .grid {
    background: #ffffff;
    border-color: #cbd5e1;
}

body.light-mode .overlay {
    background: rgba(248, 250, 252, 0.95);
}

body.light-mode .modal-content {
    background: #ffffff;
    border-color: #cbd5e1;
}

body.light-mode .leaderboard-entry {
    background: #f1f5f9;
}

body.light-mode .leaderboard-entry:hover {
    background: #e2e8f0;
}

body.light-mode .btn-secondary {
    background: #f1f5f9;
    color: #1e293b;
    border-color: #cbd5e1;
}

body.light-mode .btn-secondary:hover {
    background: #e2e8f0;
    border-color: var(--primary-color);
}

body.light-mode .opponent-grid .cell {
    background: #e2e8f0;
}

body.light-mode .stat {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

body.light-mode .games-today-banner {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.3);
}

body.light-mode .toggle-group {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

body.light-mode .toggle-btn {
    color: #475569;
}

body.light-mode .toggle-btn:hover {
    color: #1e293b;
}

body.light-mode .player-search input {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #1e293b;
}

body.light-mode .online-players-list {
    background: #f1f5f9;
}

body.light-mode .online-player:hover {
    background: #e2e8f0;
}

body.light-mode .duel-player-card {
    background: #f1f5f9;
}

body.light-mode .duel-side-header {
    background: #f1f5f9;
}

body.light-mode .duel-stat {
    background: #f1f5f9;
}

body.light-mode .duel-final-score {
    background: #f1f5f9;
}

body.light-mode .flag-dropdown {
    background: #ffffff;
    border-color: #cbd5e1;
}

body.light-mode .flag-option:hover {
    background: #f1f5f9;
}

body.light-mode .flag-btn {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

body.light-mode .flag-dropdown input {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #1e293b;
}

/* Light mode button styling */
#light-mode-btn {
    min-width: auto;
    padding: 0.75rem 1rem;
}

/* Big numbers button */
#big-numbers-btn {
    min-width: auto;
    padding: 0.75rem 1rem;
}

/* ============================================
   BIG NUMBERS MODE
   ============================================ */

body.big-numbers .cell {
    font-size: 1.5rem;
    font-weight: 700;
}

body.big-numbers .cell span {
    font-size: 1.5rem;
}

@media (max-width: 600px) {
    body.big-numbers .cell {
        font-size: 1.3rem;
    }
    body.big-numbers .cell span {
        font-size: 1.3rem;
    }
}

@media (max-width: 400px) {
    body.big-numbers .cell {
        font-size: 1.15rem;
    }
    body.big-numbers .cell span {
        font-size: 1.15rem;
    }
}

/* Big numbers in duel grids */
body.big-numbers .duel-grid .cell {
    font-size: 1.3rem;
}

body.big-numbers .duel-grid .cell span {
    font-size: 1.3rem;
}

/* Big numbers in replay grids */
body.big-numbers .replay-grid .cell {
    font-size: 1.2rem;
}

body.big-numbers .replay-grid .cell span {
    font-size: 1.2rem;
}

/* ============================================
   BLD MODE STYLES
   ============================================ */

/* BLD Mode Button */
.btn-bld {
    background: linear-gradient(135deg, #8b5cf6, #6d28d9);
    color: white;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--border-radius-sm);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.btn-bld:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.5);
}

.btn-bld.active {
    background: linear-gradient(135deg, #6d28d9, #4c1d95);
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.6), inset 0 0 8px rgba(255, 255, 255, 0.1);
}

/* "Back to Normal" button when in BLD mode */
.btn-back-normal {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: 2px solid var(--primary-color) !important;
    box-shadow: none !important;
    padding: 0.75rem 1.25rem;
    font-weight: 600;
}

.btn-back-normal:hover {
    background: var(--primary-color) !important;
    color: white !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4) !important;
}

body.light-mode .btn-back-normal {
    background: #f1f5f9 !important;
    color: #1e293b !important;
    border-color: var(--primary-color) !important;
}

body.light-mode .btn-back-normal:hover {
    background: var(--primary-color) !important;
    color: white !important;
}

/* BLD Stats Bar */
.bld-stats-bar {
    margin-bottom: 1rem;
    text-align: center;
}

.bld-phase-indicator {
    display: inline-block;
    padding: 0.4rem 1.5rem;
    border-radius: 20px;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 0.75rem;
    transition: all 0.3s ease;
}

.bld-phase-indicator.memo-phase {
    background: linear-gradient(135deg, #8b5cf6, #6d28d9);
    color: white;
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.4);
    animation: memo-glow 2s ease-in-out infinite;
}

.bld-phase-indicator.exec-phase {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.4);
    animation: exec-pulse 1s ease-in-out infinite;
}

.bld-phase-indicator.complete-phase {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
    box-shadow: 0 0 15px rgba(34, 197, 94, 0.4);
}

@keyframes memo-glow {
    0%, 100% { box-shadow: 0 0 15px rgba(139, 92, 246, 0.4); }
    50% { box-shadow: 0 0 25px rgba(139, 92, 246, 0.7); }
}

@keyframes exec-pulse {
    0%, 100% { box-shadow: 0 0 15px rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 25px rgba(239, 68, 68, 0.7); }
}

.bld-timers-row {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: nowrap;
}

.bld-memo-timer-stat .stat-value {
    color: #a78bfa;
}

.bld-exec-timer-stat .stat-value {
    color: #f87171;
}

/* BLD Ready Button */
.bld-ready-container {
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
}

.btn-bld-ready {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 2.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-family: inherit;
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-fast);
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
    letter-spacing: 0.5px;
    animation: ready-btn-pulse 2s ease-in-out infinite;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-bld-ready:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.6);
}

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

@keyframes ready-btn-pulse {
    0%, 100% { box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 4px 25px rgba(239, 68, 68, 0.7); }
}

/* BLD Leaderboard Section */
.bld-leaderboard-section h2 {
    background: linear-gradient(135deg, #8b5cf6, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* BLD Name Modal */
.bld-final-times {
    margin-bottom: 1rem;
}

.bld-final-breakdown {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-top: 0.5rem;
}

.bld-breakdown-item {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.bld-breakdown-item strong {
    color: var(--text-primary);
}

/* BLD cell states during execution */
.bld-exec .cell:not(.clicked):not(.wrong) {
    background: var(--bg-card);
    cursor: pointer;
}

.bld-exec .cell.clicked {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: white;
    cursor: default;
    border-color: #15803d;
}

/* BLD correct click - show checkmark only, no number */
.bld-exec .cell.clicked::after {
    content: '✓';
    position: absolute;
    font-size: 1.25rem;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.bld-exec .cell.clicked span {
    opacity: 0;
}

/* BLD grid border during memo phase */
.grid.bld-memo-grid {
    border-color: #8b5cf6;
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.2);
}

/* BLD grid border during exec phase */
.grid.bld-exec-grid {
    border-color: #ef4444;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.2);
}

/* ============================================
   BLD MODE RESPONSIVE
   ============================================ */

@media (max-width: 600px) {
    .btn-bld {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }

    .bld-timers-row {
        gap: 0.35rem;
        flex-wrap: wrap;
    }

    .bld-timers-row .stat {
        padding: 0.4rem 0.6rem;
        min-width: 60px;
    }

    .bld-timers-row .stat-value {
        font-size: 1rem;
    }

    .bld-phase-indicator {
        font-size: 0.85rem;
        padding: 0.3rem 1rem;
    }

    .btn-bld-ready {
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
    }

    .bld-final-breakdown {
        gap: 1rem;
    }
}

@media (max-width: 400px) {
    .bld-timers-row .stat {
        padding: 0.3rem 0.4rem;
        min-width: 50px;
    }

    .bld-timers-row .stat-value {
        font-size: 0.9rem;
    }

    .bld-timers-row .stat-label {
        font-size: 0.55rem;
    }
}

/* ============================================
   BLD MODE LIGHT MODE
   ============================================ */

body.light-mode .bld-phase-indicator.memo-phase {
    background: linear-gradient(135deg, #7c3aed, #5b21b6);
}

body.light-mode .bld-phase-indicator.exec-phase {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
}

body.light-mode .bld-stats-bar .stat {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

body.light-mode .bld-leaderboard-section h2 {
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ============================================
   LEGAL PAGES (Privacy Policy, Terms of Service)
   ============================================ */

.legal-page {
    max-width: 800px;
    padding-bottom: 2rem;
}

.legal-back-link {
    display: inline-block;
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    transition: opacity var(--transition-fast);
}

.legal-back-link:hover {
    opacity: 0.8;
    text-decoration: underline;
}

.legal-content {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 2rem;
    margin-top: 1rem;
}

.legal-content section {
    margin-bottom: 2rem;
}

.legal-content section:last-child {
    margin-bottom: 0;
}

.legal-content h2 {
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.legal-content h3 {
    color: var(--text-primary);
    font-size: 1.05rem;
    font-weight: 500;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

.legal-content p {
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 0.75rem;
}

.legal-content ul {
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 0.75rem;
    padding-left: 1.5rem;
}

.legal-content li {
    margin-bottom: 0.4rem;
}

.legal-content a {
    color: var(--primary-color);
    text-decoration: none;
}

.legal-content a:hover {
    text-decoration: underline;
}

.legal-page footer {
    margin-top: 1.5rem;
}

.legal-page footer a {
    color: var(--primary-color);
    text-decoration: none;
}

.legal-page footer a:hover {
    text-decoration: underline;
}

/* Footer links on game page */
.footer-links {
    margin-bottom: 0.25rem;
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.footer-links a:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

/* ============================================
   COOKIE CONSENT BANNER
   ============================================ */

.cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    z-index: 10000;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
}

.cookie-banner-content {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.cookie-banner-content p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 0;
    flex: 1;
    line-height: 1.5;
}

.cookie-banner-content a {
    color: var(--primary-color);
    text-decoration: none;
}

.cookie-banner-content a:hover {
    text-decoration: underline;
}

.cookie-banner-buttons {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.cookie-btn {
    padding: 0.4rem 1rem !important;
    font-size: 0.8rem !important;
    min-width: auto !important;
}

@media (max-width: 600px) {
    .cookie-banner-content {
        flex-direction: column;
        text-align: center;
    }

    .cookie-banner-buttons {
        width: 100%;
        justify-content: center;
    }

    .legal-content {
        padding: 1.25rem;
    }

    .legal-content h2 {
        font-size: 1.1rem;
    }
}

/* Light mode adjustments for cookie banner */
body.light-mode .cookie-banner {
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.1);
}

/* ========== Splits Breakdown (post-game) ========== */

.splits-breakdown {
    margin: 0.75rem 0 1rem;
    padding: 0.75rem;
    background: rgba(99, 102, 241, 0.08);
    border-radius: var(--border-radius-sm);
    border: 1px solid rgba(99, 102, 241, 0.15);
}

.splits-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-align: center;
}

.splits-row {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.split-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 60px;
    padding: 0.35rem 0.5rem;
    background: var(--bg-card);
    border-radius: var(--border-radius-sm);
}

.split-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-bottom: 0.15rem;
}

.split-time {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary-color);
    font-variant-numeric: tabular-nums;
}

/* ========== Clickable Player Names ========== */

.entry-name.clickable {
    cursor: pointer;
    transition: color var(--transition-fast), text-decoration var(--transition-fast);
}

.entry-name.clickable:hover {
    color: var(--primary-color);
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* ========== Player Stats Modal ========== */

.player-stats-content {
    max-width: 750px !important;
    width: 95vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.stats-table-container {
    overflow: auto;
    max-height: 60vh;
    margin-top: 1rem;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
}

.stats-loading,
.stats-empty {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-style: italic;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
    font-size: 0.85rem;
}

.stats-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.stats-table th {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.6rem 0.5rem;
    text-align: center;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.stats-table td {
    padding: 0.5rem 0.5rem;
    text-align: center;
    border-bottom: 1px solid rgba(71, 85, 105, 0.3);
    color: var(--text-primary);
    white-space: nowrap;
}

.stats-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.06);
}

.stats-table td:first-child {
    color: var(--text-muted);
    font-size: 0.75rem;
    width: 30px;
}

.stats-total-time {
    font-weight: 600;
    color: var(--text-primary) !important;
}

.stats-date {
    font-size: 0.75rem;
    color: var(--text-muted) !important;
}

.no-data {
    color: var(--text-muted) !important;
}

/* Best split highlight */
.best-split {
    background: rgba(251, 191, 36, 0.15) !important;
    color: #fbbf24 !important;
    font-weight: 700;
}

/* ========== Light mode overrides for splits & stats ========== */

body.light-mode .splits-breakdown {
    background: rgba(99, 102, 241, 0.06);
    border-color: rgba(99, 102, 241, 0.12);
}

body.light-mode .split-item {
    background: var(--bg-card);
}

body.light-mode .stats-table th {
    background: var(--bg-secondary);
}

body.light-mode .stats-table td {
    border-bottom-color: rgba(0, 0, 0, 0.08);
}

body.light-mode .stats-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.04);
}

body.light-mode .best-split {
    background: rgba(245, 158, 11, 0.12) !important;
    color: #d97706 !important;
}

/* ========== Responsive: Stats & Splits ========== */

@media (max-width: 600px) {
    .player-stats-content {
        padding: 1rem !important;
    }

    .stats-table-container {
        max-height: 50vh;
    }

    .stats-table {
        font-size: 0.75rem;
    }

    .stats-table th,
    .stats-table td {
        padding: 0.4rem 0.3rem;
    }

    .split-item {
        min-width: 52px;
        padding: 0.25rem 0.35rem;
    }

    .split-time {
        font-size: 0.75rem;
    }

    .split-label {
        font-size: 0.6rem;
    }
}

/* ========== Auth System ========== */

.auth-area {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    z-index: 10;
}

header {
    position: relative;
}

#auth-logged-out,
#auth-logged-in {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.auth-username {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary-color);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.auth-elo {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 0.15rem 0.4rem;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    cursor: help;
}

.btn-sm {
    padding: 0.3rem 0.7rem;
    font-size: 0.75rem;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    transition: all var(--transition-fast);
    /* Mobile touch fixes */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
}

.btn-sm:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-sm.btn-primary {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn-sm.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: white;
}

/* Auth modals */
.auth-modal-content {
    max-width: 380px !important;
}

.auth-field {
    margin-bottom: 1rem;
}

.auth-field label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
}

.auth-field input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    /* Use 16px minimum on mobile to prevent iOS zoom on focus */
    font-size: max(16px, 0.9rem);
    font-family: inherit;
    box-sizing: border-box;
    /* Mobile input fixes */
    -webkit-appearance: none;
    appearance: none;
}

.auth-field input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.auth-hint {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.auth-error {
    color: var(--error-color, #ef4444);
    font-size: 0.85rem;
    margin: 0.5rem 0;
    padding: 0.5rem;
    background: rgba(239, 68, 68, 0.1);
    border-radius: var(--border-radius-sm);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.auth-switch {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 1rem;
}

.auth-switch a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.auth-switch a:hover {
    text-decoration: underline;
}

.auth-forgot {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.75rem;
}

.auth-forgot a {
    color: var(--text-muted);
    text-decoration: none;
}

.auth-forgot a:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

/* Guest names in leaderboard - italic */
.entry-name em {
    font-style: italic;
}

/* Locked name input (logged-in user) */
.locked-name {
    opacity: 0.7;
    cursor: not-allowed;
    background: var(--bg-secondary) !important;
}

/* Modal close button (shared pattern) */
.modal-close-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0.25rem;
    transition: color var(--transition-fast);
}

.modal-close-btn:hover {
    color: var(--text-primary);
}

/* ========== Light mode auth overrides ========== */

body.light-mode .btn-sm {
    border-color: rgba(0, 0, 0, 0.15);
}

body.light-mode .auth-field input {
    border-color: rgba(0, 0, 0, 0.15);
}

/* ========== Responsive: Auth ========== */

@media (max-width: 600px) {
    .auth-area {
        position: static;
        justify-content: center;
        margin-bottom: 0.5rem;
    }

    .btn-sm {
        /* Larger touch targets on mobile */
        padding: 0.4rem 0.6rem;
        font-size: 0.75rem;
        min-height: 36px;
        min-width: 60px;
    }

    .auth-username {
        max-width: 80px;
        font-size: 0.7rem;
    }

    /* Better touch targets for modal buttons */
    .modal-buttons .btn {
        min-height: 44px;
        padding: 0.75rem 1.25rem;
    }

    /* Ensure auth modal inputs are large enough on mobile */
    .auth-field input {
        min-height: 44px;
        padding: 0.75rem;
    }
}

/* ========== Mobile Touch Device Fixes ========== */

@media (pointer: coarse) {
    /* Ensure all buttons have minimum touch target size (44px recommended) */
    .btn, .btn-sm, .toggle-btn, .btn-small {
        min-height: 40px;
    }

    /* Modal buttons should be easy to tap */
    .modal-buttons .btn {
        min-height: 44px;
    }

    /* Prevent ghost clicks on modals */
    .modal {
        -webkit-tap-highlight-color: transparent;
    }

    .modal-content {
        -webkit-tap-highlight-color: transparent;
    }

    /* Ensure form submission works properly on mobile */
    .modal-content form button[type="submit"] {
        -webkit-appearance: none;
        appearance: none;
    }

    /* CRITICAL: Prevent double-tap zoom on game grid (mobile) */
    .game-area,
    .grid,
    .cell,
    .cell span,
    .duel-grid,
    .duel-grid .cell,
    .replay-grid,
    .replay-grid .cell {
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
    }
}

/* ============================================
   DESKTOP AD BANNERS
   ============================================ */

/* Container for game area with side ads */
.game-with-ads {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 2rem;
    margin-bottom: 1rem;
}

/* Ad banner containers - hidden by default (mobile first) */
.ad-banner {
    display: none;
    width: 160px;
    min-height: 600px;
    flex-shrink: 0;
}

/* Ad placeholder styling */
.ad-placeholder {
    width: 160px;
    height: 600px;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-card) 100%);
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.ad-label {
    font-weight: 600;
    opacity: 0.5;
}

/* Show ads only on desktop (min-width: 1200px for enough space) */
@media (min-width: 1200px) {
    .container {
        max-width: 1400px;
    }

    /* Increase container max-width to accommodate ads */
    .container {
        max-width: 1400px;
    }
}

/* Light mode ad styling */
body.light-mode .ad-placeholder {
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    border-color: #cbd5e1;
}

/* ============================================
   ELO RANKING STYLES
   ============================================ */

.elo-leaderboard-section {
    margin-top: 1rem;
}

.elo-leaderboard-section h2 {
    color: var(--primary-color);
}

.entry-elo-stats {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.1rem;
}

.elo-value {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--primary-color);
    min-width: 45px;
    text-align: right;
}

.elo-record {
    font-size: 0.65rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ELO entries - ELO value next to name */
.elo-entry {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
}

.elo-entry .entry-rank {
    min-width: 32px;
    font-size: 0.9rem;
    font-weight: 600;
    width: auto;
    height: auto;
}

.elo-entry .entry-name {
    font-size: 0.95rem;
}

.elo-entry .elo-value {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
}

.elo-entry .elo-record {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-left: auto;
}

.elo-leaderboard .leaderboard-entry {
    margin-bottom: 0.5rem;
}

/* ============================================
   FULL PLAYER STATS MODAL
   ============================================ */

.full-player-stats {
    text-align: left;
}

.full-player-stats .stats-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.full-player-stats .flag-icon {
    font-size: 1.5rem;
}

.full-player-stats .player-status {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 0.2rem 0.5rem;
    border-radius: var(--border-radius-sm);
}

.full-player-stats .stats-section {
    margin-bottom: 1.5rem;
}

.full-player-stats .stats-section h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.full-player-stats .stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 0.75rem;
}

.full-player-stats .stat-item {
    background: var(--bg-secondary);
    padding: 0.75rem;
    border-radius: var(--border-radius-sm);
    text-align: center;
}

.full-player-stats .stat-item .stat-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
}

.full-player-stats .stat-item .stat-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.full-player-stats .elo-stat .stat-value {
    color: var(--primary-color);
}

.full-player-stats .win-stat .stat-value {
    color: #22c55e;
}

.full-player-stats .loss-stat .stat-value {
    color: #ef4444;
}

.full-player-stats .recent-games {
    margin-top: 1rem;
}

.full-player-stats .recent-games h4 {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.full-player-stats .recent-games-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.full-player-stats .recent-game-item {
    background: var(--bg-card);
    padding: 0.25rem 0.5rem;
    border-radius: var(--border-radius-sm);
    font-size: 0.8rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

/* Clickable names in leaderboard */
.entry-name.clickable {
    cursor: pointer;
    transition: color var(--transition-fast);
}

.entry-name.clickable:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

/* ============================================
   DUEL GAME SECTION (New Layout - replaces popup)
   ============================================ */

.duel-game-section {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    position: relative;
    min-height: 500px;
}

/* Duel Overlays (waiting room, countdown, results) */
.duel-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.95);
    z-index: 20;
    border-radius: var(--border-radius);
    padding: 2rem;
}

/* Waiting Room Overlay */
#duel-waiting-overlay h2 {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.waiting-players {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    justify-content: center;
}

.waiting-player-card {
    background: var(--bg-card);
    padding: 1.5rem 2rem;
    border-radius: var(--border-radius);
    min-width: 180px;
    text-align: center;
    border: 2px solid var(--border-color);
    transition: border-color var(--transition-fast);
}

.waiting-player-card.me {
    border-color: #22c55e;
}

.waiting-player-card.opponent {
    border-color: #6366f1;
}

.waiting-player-card .player-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    letter-spacing: 1px;
}

.waiting-player-card .player-name {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.waiting-player-card .player-status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.waiting-player-card .player-status.waiting {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

.waiting-player-card .player-status.ready {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.waiting-player-card .player-status .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 1.5s ease-in-out infinite;
}

#duel-ready-btn {
    padding: 1rem 3rem;
    font-size: 1.25rem;
    font-weight: 600;
}

#duel-ready-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Countdown Overlay */
#duel-countdown-overlay {
    background: rgba(15, 23, 42, 0.98);
}

#duel-countdown-number {
    font-size: 8rem;
    font-weight: 700;
    color: var(--primary-color);
    text-shadow: 0 0 40px rgba(99, 102, 241, 0.5);
    animation: countdown-pulse 1s ease-in-out infinite;
}

@keyframes countdown-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.8; }
}

/* Duel Arena (the actual game area) */
.duel-arena {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
}

/* Shared Timer at Top */
.duel-shared-timer {
    text-align: center;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
}

.duel-shared-timer .timer-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 0.25rem;
}

.duel-shared-timer .timer-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2rem;
    font-weight: 600;
    color: var(--primary-color);
    font-variant-numeric: tabular-nums;
}

/* Two Grids Container */
.duel-grids-container {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Each Player Side */
.duel-player-side {
    flex: 1;
    min-width: 280px;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Player Header */
.duel-player-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.8rem;
    background: var(--bg-card);
    border-radius: var(--border-radius-sm);
    border-left: 3px solid var(--border-color);
}

.my-side .duel-player-header {
    border-left-color: #22c55e;
}

.opponent-side .duel-player-header {
    border-left-color: #ef4444;
}

.duel-player-header .player-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.duel-player-header .player-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* Player Stats Row */
.duel-player-stats {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
}

.duel-player-stat {
    flex: 1;
    text-align: center;
    background: var(--bg-secondary);
    padding: 0.4rem 0.5rem;
    border-radius: var(--border-radius-sm);
}

.duel-player-stat .stat-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.duel-player-stat .stat-value {
    font-size: 0.95rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

.duel-player-stat.mistakes .stat-value.danger {
    color: var(--error-color);
    animation: pulse 0.5s ease infinite;
}

/* Duel Grid Wrapper */
.duel-grid-wrapper {
    background: var(--bg-secondary);
    padding: 0.5rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.my-side .duel-grid-wrapper {
    border-color: rgba(34, 197, 94, 0.3);
}

.opponent-side .duel-grid-wrapper {
    border-color: rgba(239, 68, 68, 0.3);
}

/* Duel Grid Sizing */
.duel-game-section .duel-grid {
    --cell-size: 38px;
    --grid-gap: 4px;
}

.opponent-side .duel-grid {
    opacity: 0.85;
    pointer-events: none;
}

.opponent-side .duel-grid .cell {
    background: #2d3748;
}

.opponent-side .duel-grid .cell.clicked {
    background: #ef4444;
    opacity: 0.7;
}

/* Give Up Button */
.duel-give-up {
    text-align: center;
    margin-top: 0.5rem;
}

.duel-give-up .btn-give-up {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    padding: 0.3rem 0.75rem;
    font-size: 0.7rem;
    opacity: 0.6;
    transition: all var(--transition-fast);
}

.duel-give-up .btn-give-up:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error-color);
    border-color: var(--error-color);
    opacity: 1;
}

/* Results Overlay */
#duel-results-overlay {
    text-align: center;
}

#duel-results-overlay.victory {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.1) 0%, rgba(15, 23, 42, 0.95) 50%);
}

#duel-results-overlay.defeat {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1) 0%, rgba(15, 23, 42, 0.95) 50%);
}

.results-icon {
    font-size: 5rem;
    margin-bottom: 1rem;
}

#duel-results-overlay.victory .results-icon {
    animation: victory-glow 2s ease-in-out infinite;
}

#duel-results-overlay.defeat .results-icon {
    animation: defeat-shake 0.5s ease-in-out;
}

.results-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

#duel-results-overlay.victory .results-title {
    color: #22c55e;
}

#duel-results-overlay.defeat .results-title {
    color: #ef4444;
}

.results-message {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* Score Cards */
.results-scores {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.score-card {
    background: var(--bg-card);
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    min-width: 140px;
    border: 2px solid var(--border-color);
}

.score-card.winner {
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.1);
}

.score-card.loser {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.05);
    opacity: 0.8;
}

.score-card .score-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.score-card .score-name {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.score-card .score-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.25rem;
    font-weight: 600;
}

.score-card.winner .score-time {
    color: #22c55e;
}

.score-card .score-status {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.score-card .score-status.dnf {
    color: var(--error-color);
}

/* Elo Change Display */
.elo-change {
    margin-bottom: 1.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-sm);
    display: inline-block;
}

.elo-change .elo-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
}

.elo-change .elo-value {
    font-size: 1.25rem;
    font-weight: 600;
}

.elo-change .elo-value.positive {
    color: #22c55e;
}

.elo-change .elo-value.negative {
    color: #ef4444;
}

/* Results Buttons */
.results-buttons {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.results-buttons .btn {
    min-width: 140px;
}

#duel-save-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   DUEL SECTION RESPONSIVE STYLES
   ============================================ */

@media (max-width: 700px) {
    .duel-game-section {
        min-height: auto;
    }

    .duel-grids-container {
        flex-direction: column;
        align-items: center;
    }

    .duel-player-side {
        width: 100%;
        max-width: 350px;
    }

    .duel-game-section .duel-grid {
        --cell-size: 36px;
        --grid-gap: 3px;
    }

    .duel-shared-timer .timer-value {
        font-size: 1.5rem;
    }

    .waiting-players {
        flex-direction: column;
        gap: 1rem;
    }

    .waiting-player-card {
        min-width: 200px;
    }

    #duel-countdown-number {
        font-size: 5rem;
    }

    .results-scores {
        flex-direction: column;
        align-items: center;
    }

    .score-card {
        width: 100%;
        max-width: 200px;
    }

    .results-buttons {
        flex-direction: column;
        align-items: center;
    }

    .results-buttons .btn {
        width: 100%;
        max-width: 250px;
    }
}

@media (max-width: 400px) {
    .duel-game-section .duel-grid {
        --cell-size: 32px;
        --grid-gap: 2px;
    }

    .duel-player-header {
        padding: 0.4rem 0.6rem;
    }

    .duel-player-stats {
        gap: 0.3rem;
    }

    .duel-player-stat {
        padding: 0.3rem 0.4rem;
    }

    .duel-player-stat .stat-label {
        font-size: 0.55rem;
    }

    .duel-player-stat .stat-value {
        font-size: 0.85rem;
    }
}

/* Light Mode Adjustments */
body.light-mode .duel-overlay {
    background: rgba(248, 250, 252, 0.98);
}

body.light-mode #duel-waiting-overlay {
    background: rgba(248, 250, 252, 0.98);
}

body.light-mode .duel-finished-overlay {
    background: rgba(34, 197, 94, 0.2);
}

body.light-mode .waiting-player-card {
    background: white;
    border-color: #e2e8f0;
}

body.light-mode .duel-player-header {
    background: white;
}

body.light-mode .duel-grid-wrapper {
    background: white;
    border-color: #e2e8f0;
}

body.light-mode .score-card {
    background: white;
}

body.light-mode .elo-change {
    background: white;
}

/* Big Numbers Mode for Duel */
body.big-numbers .duel-game-section .duel-grid .cell {
    font-size: 1.1rem;
}

body.big-numbers .duel-game-section .duel-grid .cell span {
    font-size: 1.1rem;
}

/* Duel Overlay Content */
.duel-overlay-content {
    text-align: center;
    max-width: 500px;
    padding: 2rem;
}

.duel-overlay-content h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* Duel Controls (Give Up button container) */
.duel-controls {
    display: flex;
    justify-content: center;
    margin-top: 1rem;
    gap: 1rem;
}

/* DNF text styling */
.score-time.dnf,
.duel-final-score .score-time.dnf {
    color: var(--error-color);
    font-size: 1rem;
}

/* Duel final score cards */
.duel-final-scores {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    margin: 1.5rem 0;
    flex-wrap: wrap;
}

.duel-final-score {
    background: var(--bg-card);
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    min-width: 140px;
    border: 2px solid var(--border-color);
    text-align: center;
}

.duel-final-score.winner {
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.1);
}

.duel-final-score .score-name {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.duel-final-score .score-time {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.25rem;
    font-weight: 600;
}

.duel-final-score.winner .score-time {
    color: #22c55e;
}

/* Waiting spinner animation */
.waiting-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

/* VS Divider */
.vs-divider {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-muted);
    display: flex;
    align-items: center;
}

/* Duel player cards in waiting room */
.duel-players-status {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.duel-player-card {
    background: var(--bg-card);
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    text-align: center;
    min-width: 150px;
}

.duel-player-card .player-name {
    display: block;
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.duel-player-card .player-status {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.duel-player-card .player-status.waiting {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

.duel-player-card .player-status.ready {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

/* Duel Result Buttons */
.duel-result-buttons {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 1.5rem;
}

.duel-result-buttons .btn {
    min-width: 140px;
}

/* Duel DNF Overlay */
.duel-dnf-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(239, 68, 68, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius);
    z-index: 10;
    animation: dnf-fade-in 0.3s ease;
}

@keyframes dnf-fade-in {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.duel-dnf-overlay .dnf-text {
    font-size: 2rem;
    font-weight: 700;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    animation: dnf-pulse 0.5s ease-in-out infinite alternate;
}

.duel-dnf-overlay .dnf-text span {
    font-size: 2.5rem;
}

@keyframes dnf-pulse {
    from { transform: scale(1); }
    to { transform: scale(1.1); }
}

/* Duel Waiting Overlay - use semi-transparent background */
#duel-waiting-overlay {
    background: rgba(15, 23, 42, 0.95);
}

#duel-waiting-overlay .duel-overlay-content {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 2rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
}

/* Fix duel player cards solid background */
#duel-waiting-overlay .duel-player-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

/* Duel finished overlay */
.duel-finished-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(34, 197, 94, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    border-radius: var(--border-radius);
}

.duel-finished-overlay .finished-text {
    font-size: 1.5rem;
    font-weight: 700;
    color: #22c55e;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* ============================================
   LIVE DUELS PANEL (COMPACT - in game area)
   ============================================ */

.live-duels-compact {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 0.5rem 0.75rem;
    margin-top: 1rem;
    border: 1px solid var(--border-color);
}

.live-duels-compact .live-duels-header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.4rem;
}

.live-duels-compact .live-indicator {
    font-size: 0.6rem;
    /* Only pulse when active class is added */
}

.live-duels-compact .live-indicator.active {
    animation: live-pulse 1.5s ease-in-out infinite;
}

.live-duels-compact .live-duels-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 120px;
    overflow-y: auto;
}

.live-duels-compact .no-live-duels {
    text-align: center;
    color: var(--text-muted);
    padding: 0.5rem;
    font-size: 0.75rem;
    font-style: italic;
}

.live-duels-compact .live-duel-card {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
}

.live-duels-compact .live-duel-header {
    margin-bottom: 0.25rem;
    font-size: 0.65rem;
}

.live-duels-compact .live-duel-players {
    gap: 0.4rem;
}

.live-duels-compact .live-duel-player {
    padding: 0.2rem 0.4rem;
    font-size: 0.75rem;
}

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

/* Old live-duels-section styles (keeping for backwards compatibility) */
.live-duels-section {
    max-width: 400px;
}

.live-duels-section h2 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.live-duels-section h2::before {
    content: '';
    width: 10px;
    height: 10px;
    background: #ef4444;
    border-radius: 50%;
    animation: live-pulse 1.5s ease-in-out infinite;
}

.live-duels-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
}

.no-live-duels {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 1rem;
    font-style: italic;
}

/* Individual Live Duel Card */
.live-duel-card {
    background: var(--bg-card);
    border-radius: var(--border-radius-sm);
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    transition: border-color var(--transition-fast);
}

.live-duel-card:hover {
    border-color: var(--primary-color);
}

.live-duel-card.finished {
    opacity: 0.7;
    border-color: var(--success-color);
}

.live-duel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.live-duel-status {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.live-duel-status .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22c55e;
    animation: status-blink 1s ease-in-out infinite;
}

.live-duel-card.finished .status-dot {
    background: var(--text-muted);
    animation: none;
}

@keyframes status-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.live-duel-timer {
    font-family: 'JetBrains Mono', monospace;
    color: var(--primary-color);
}

/* Players in Live Duel */
.live-duel-players {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.live-duel-player {
    flex: 1;
    text-align: center;
    min-width: 0;
}

.live-duel-player.leading {
    color: var(--success-color);
}

.live-duel-player.trailing {
    color: var(--text-secondary);
}

.live-duel-player.dnf {
    color: var(--error-color);
}

.live-duel-player .player-name {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.live-duel-player .player-progress {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

.live-duel-player .progress-num {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}

.live-duel-player .mistakes {
    color: var(--error-color);
}

.live-duel-vs {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* Progress Bars */
.live-duel-progress-bars {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.5rem;
}

.progress-bar-container {
    flex: 1;
    height: 4px;
    background: var(--bg-secondary);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar-container:first-child .progress-bar-fill {
    background: #22c55e;
}

.progress-bar-container:last-child .progress-bar-fill {
    background: var(--primary-color);
}

.progress-bar-fill {
    height: 100%;
    transition: width 0.3s ease;
    border-radius: 2px;
}

/* Light Mode */
body.light-mode .live-duel-card {
    background: white;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .live-duels-section {
        max-width: 100%;
    }

    .live-duels-list {
        max-height: 250px;
    }
}

/* ============================================
   LEADERBOARD TABS
   ============================================ */

.leaderboard-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 4px;
}

.leaderboard-tab {
    flex: 1;
    padding: 0.6rem 0.8rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--border-radius-sm);
    transition: all var(--transition-fast);
}

.leaderboard-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.leaderboard-tab.active {
    background: var(--primary-color);
    color: white;
}

.leaderboard-panel {
    display: none;
}

.leaderboard-panel.active {
    display: block;
}

/* WCA Info Section */
.wca-info {
    background: var(--bg-secondary);
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius-sm);
    margin-bottom: 1rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.wca-info p {
    margin: 0;
}

.wca-join-hint {
    margin-top: 0.5rem !important;
    color: var(--primary-color);
    font-style: italic;
}

/* ============================================
   USER PROFILE DROPDOWN
   ============================================ */

.user-profile-dropdown {
    position: relative;
    display: inline-block;
}

.user-profile-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.75rem;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    color: var(--text-primary);
}

.user-profile-btn:hover {
    border-color: var(--primary-color);
}

.dropdown-arrow {
    font-size: 0.6rem;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
}

.user-profile-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

.user-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.75rem;
    min-width: 200px;
    z-index: 100;
    display: none;
    box-shadow: var(--shadow-lg);
}

.user-profile-dropdown.open .user-dropdown-menu {
    display: block;
}

.dropdown-section {
    margin-bottom: 0.75rem;
}

.dropdown-section label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    letter-spacing: 0.5px;
}

.community-selector {
    display: flex;
    gap: 0.5rem;
}

.community-option {
    width: 40px;
    height: 40px;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.community-option:hover {
    border-color: var(--primary-color);
}

.community-option.active {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.community-option .no-community {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.community-option .community-logo {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.75rem 0;
}

.dropdown-logout {
    width: 100%;
}

/* ELO badge in leaderboard entries */
.entry-elo {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary-color);
    border-radius: 4px;
    font-weight: 600;
    margin-left: 0.3rem;
}

/* Login prompt in success modal */
.login-prompt {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.login-prompt p {
    margin: 0;
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    text-decoration: underline;
    font-size: inherit;
    padding: 0;
}

.btn-link:hover {
    color: var(--primary-hover);
}

/* Light mode adjustments */
body.light-mode .leaderboard-tabs {
    background: #e2e8f0;
}

body.light-mode .leaderboard-tab.active {
    background: var(--primary-color);
}

body.light-mode .user-profile-btn {
    background: white;
}

body.light-mode .user-dropdown-menu {
    background: white;
}

body.light-mode .community-option {
    background: #f1f5f9;
}

/* ================================
   Mobile Sticky Bottom Ad
   ================================ */

/* Reserve space so content is never hidden */
body {
  padding-bottom: env(safe-area-inset-bottom);
}

@media (max-width: 768px) {
  body {
    padding-bottom: calc(60px + env(safe-area-inset-bottom));
  }

  #mobile-sticky-ad {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;

    /* IMPORTANT: do not block gestures */
    pointer-events: none;
  }

  #mobile-sticky-ad .ad-slot {
    width: 100%;
    max-width: 360px;
    height: 50px;

    display: flex;
    align-items: center;
    justify-content: center;

    /* Allow clicks ONLY on the ad */
    pointer-events: auto;
  }
}

/* Desktop: completely hidden */
@media (min-width: 769px) {
  #mobile-sticky-ad {
    display: none;
  }
}
