/* ─── CSS Variables ────────────────────────────────────────────────── */
:root {
    --cell-size: 32px;
    --cell-radius: 4px;
    --board-gap: 1px;
    --board-padding: 4px;

    /* Dark theme (default) */
    --bg-1: #0f0c29;
    --bg-2: #302b63;
    --bg-3: #24243e;
    --surface: rgba(22, 22, 40, 0.7);
    --surface-border: rgba(255, 255, 255, 0.06);
    --text-primary: #eee;
    --text-secondary: #888;
    --text-muted: #555;
    --accent: #e94560;
    --accent-bg: rgba(233, 69, 96, 0.15);
    --accent-glow: rgba(233, 69, 96, 0.3);
    --accent-gradient: linear-gradient(135deg, #e94560, #4fc3f7);
    --input-bg: rgba(255, 255, 255, 0.04);
    --input-border: rgba(255, 255, 255, 0.08);
    --input-focus: rgba(233, 69, 96, 0.4);
    --cell-bg: rgba(255, 255, 255, 0.04);
    --cell-hover: rgba(255, 255, 255, 0.08);
    --cell-revealed: rgba(255, 255, 255, 0.02);
    --cell-flagged-bg: rgba(233, 69, 96, 0.06);
    --modal-overlay: rgba(0, 0, 0, 0.6);
    --scrollbar: rgba(255, 255, 255, 0.08);
    --scrollbar-hover: rgba(255, 255, 255, 0.15);
    --btn-secondary-bg: rgba(255, 255, 255, 0.03);
    --tab-bg: rgba(255, 255, 255, 0.04);
    --n1: #4fc3f7;
    --n2: #81c784;
    --n3: #e94560;
    --n4: #ba68c8;
    --n5: #ff8a65;
    --n6: #4dd0e1;
    --n7: #ddd;
    --n8: #888;
}

/* ─── Light Theme ─────────────────────────────────────────────────── */
html.light {
    --bg-1: #e8eaf6;
    --bg-2: #c5cae9;
    --bg-3: #d1d4ed;
    --surface: rgba(255, 255, 255, 0.82);
    --surface-border: rgba(0, 0, 0, 0.08);
    --text-primary: #1a1a2e;
    --text-secondary: #666;
    --text-muted: #999;
    --accent: #d63851;
    --accent-bg: rgba(214, 56, 81, 0.1);
    --accent-glow: rgba(214, 56, 81, 0.25);
    --accent-gradient: linear-gradient(135deg, #d63851, #7c4dff);
    --input-bg: rgba(0, 0, 0, 0.03);
    --input-border: rgba(0, 0, 0, 0.1);
    --input-focus: rgba(214, 56, 81, 0.3);
    --cell-bg: rgba(0, 0, 0, 0.04);
    --cell-hover: rgba(0, 0, 0, 0.06);
    --cell-revealed: rgba(0, 0, 0, 0.02);
    --cell-flagged-bg: rgba(214, 56, 81, 0.05);
    --modal-overlay: rgba(0, 0, 0, 0.3);
    --scrollbar: rgba(0, 0, 0, 0.08);
    --scrollbar-hover: rgba(0, 0, 0, 0.15);
    --btn-secondary-bg: rgba(0, 0, 0, 0.03);
    --tab-bg: rgba(0, 0, 0, 0.04);
    --n1: #0288d1;
    --n2: #388e3c;
    --n3: #d32f2f;
    --n4: #7b1fa2;
    --n5: #e65100;
    --n6: #00838f;
    --n7: #333;
    --n8: #777;
}

/* ─── Comfortable Mode (larger cells for touch) ───────────────────── */
html.mode-comfortable {
    --cell-size: 44px;
    --cell-radius: 6px;
    --board-gap: 2px;
    --board-padding: 6px;
}

@media (max-width: 480px) {
    html:not(.mode-pc) {
        --cell-size: 40px;
        --cell-radius: 5px;
        --board-gap: 2px;
        --board-padding: 5px;
    }
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    position: relative;
    transition: background 0.4s ease;
}

/* ─── Animated Background ──────────────────────────────────────────── */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -2;
    background: linear-gradient(135deg, var(--bg-1), var(--bg-2), var(--bg-3));
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
    transition: background 0.4s ease;
}

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

body::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    background:
        radial-gradient(600px circle at 20% 30%, rgba(233,69,96,0.12) 0%, transparent 70%),
        radial-gradient(500px circle at 80% 20%, rgba(79,195,247,0.08) 0%, transparent 70%),
        radial-gradient(400px circle at 40% 80%, rgba(129,199,132,0.06) 0%, transparent 70%),
        radial-gradient(300px circle at 70% 60%, rgba(186,104,200,0.08) 0%, transparent 70%);
    animation: orbFloat 20s ease-in-out infinite alternate;
    transition: opacity 0.4s ease;
}

html.light body::after {
    opacity: 0.4;
}

@keyframes orbFloat {
    0% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(2%, -3%) scale(1.05); }
    66% { transform: translate(-1%, 2%) scale(0.95); }
    100% { transform: translate(1%, -1%) scale(1.02); }
}

#noise {
    position: fixed;
    inset: 0;
    z-index: -1;
    opacity: 0.03;
    pointer-events: none;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
}

#app {
    width: 100%;
    max-width: 620px;
    padding: 16px;
    position: relative;
    z-index: 1;
}

.screen {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.hidden { display: none !important; }

/* ─── Shared ──────────────────────────────────────────────────────── */
.glass {
    background: var(--surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--surface-border);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
}

/* ─── Animations ──────────────────────────────────────────────────── */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeScale {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(233,69,96,0.4); }
    50% { box-shadow: 0 0 0 12px rgba(233,69,96,0); }
}
@keyframes glowPulse {
    0%, 100% { filter: drop-shadow(0 0 6px rgba(233,69,96,0.3)); }
    50% { filter: drop-shadow(0 0 18px rgba(233,69,96,0.5)); }
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes revealCell {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}
@keyframes mineExplode {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}
@keyframes rankEntry {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ─── Container ───────────────────────────────────────────────────── */
.auth-container, .menu-container, .leaderboard-container {
    padding: 36px 32px;
    border-radius: 20px;
    width: 100%;
    text-align: center;
    animation: fadeUp 0.5s ease;
    background: var(--surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--surface-border);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
}

/* ─── Toggle Bar ──────────────────────────────────────────────────── */
.toggle-bar {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    margin-bottom: 16px;
}

.toggle-btn {
    padding: 6px 12px;
    border: 1px solid var(--surface-border);
    border-radius: 10px;
    background: var(--btn-secondary-bg);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.3s ease;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 4px;
    line-height: 1;
}

.toggle-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-bg);
}

.toggle-btn .icon {
    font-size: 1rem;
}

/* ─── Auth ─────────────────────────────────────────────────────────── */
.auth-container h1 {
    font-size: 2.8rem;
    margin-bottom: 8px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -1px;
    animation: glowPulse 3s ease-in-out infinite;
}

.auth-container > p {
    color: var(--text-secondary);
    margin-bottom: 28px;
    font-size: 0.95rem;
}

.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    border-radius: 12px;
    background: var(--tab-bg);
    padding: 4px;
}

.tab {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.3s ease;
    font-family: inherit;
}

.tab.active {
    background: var(--accent-bg);
    color: var(--accent);
    box-shadow: 0 0 20px var(--accent-glow);
}

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

html.light .tab:hover:not(.active) {
    background: rgba(0,0,0,0.03);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    animation: slideDown 0.3s ease;
}

.auth-form input {
    padding: 14px 18px;
    border: 1px solid var(--input-border);
    border-radius: 12px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: all 0.3s ease;
    font-family: inherit;
}

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

.auth-form input:focus {
    border-color: var(--input-focus);
    background: color-mix(in srgb, var(--input-bg) 80%, transparent);
    box-shadow: 0 0 30px var(--accent-glow);
}

.auth-form button {
    padding: 14px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 85%, black));
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    letter-spacing: 0.3px;
    position: relative;
    overflow: hidden;
    font-family: inherit;
}

.auth-form button::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent, rgba(255,255,255,0.12), transparent);
    transform: translateX(-100%);
    transition: transform 0.5s ease;
}

.auth-form button:hover::before { transform: translateX(100%); }

.auth-form button:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 30px var(--accent-glow);
}

.auth-form button:active { transform: translateY(0); }

.error-msg {
    color: var(--accent);
    font-size: 0.85rem;
    min-height: 1.2em;
    animation: shake 0.4s ease;
}

/* ─── Menu ─────────────────────────────────────────────────────────── */
.menu-container h1 {
    font-size: 2.8rem;
    margin-bottom: 4px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -1px;
    animation: glowPulse 3s ease-in-out infinite;
}

.menu-container p {
    margin-bottom: 28px;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.menu-container p span {
    color: var(--text-primary);
    font-weight: 600;
}

.difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.diff-btn {
    padding: 18px 24px;
    border: 1px solid var(--surface-border);
    border-radius: 16px;
    background: var(--btn-secondary-bg);
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
    font-family: inherit;
}

.diff-btn::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent);
    transform: scaleY(0);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.diff-btn:hover::before { transform: scaleY(1); }

.diff-btn:hover {
    border-color: var(--accent-glow);
    background: var(--accent-bg);
    transform: translateX(6px);
    box-shadow: 0 4px 20px var(--accent-glow);
}

.diff-btn:active { transform: translateX(3px) scale(0.99); }

.diff-name {
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.diff-desc {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.secondary-btn {
    padding: 12px 24px;
    border: 1px solid var(--surface-border);
    border-radius: 12px;
    background: var(--btn-secondary-bg);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    margin: 4px 0;
    transition: all 0.3s ease;
    width: 100%;
    font-family: inherit;
}

.secondary-btn:hover {
    border-color: var(--accent-glow);
    color: var(--accent);
    background: var(--accent-bg);
    transform: translateY(-1px);
}

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

/* ─── Game ─────────────────────────────────────────────────────────── */
#game-screen {
    animation: fadeScale 0.3s ease;
    width: 100%;
}

.game-header {
    width: 100%;
    max-width: 500px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    gap: 8px;
}

.game-header-left {
    display: flex;
    gap: 8px;
    align-items: center;
}

.game-info {
    display: flex;
    gap: 20px;
    align-items: center;
}

.info-item {
    text-align: center;
}

.info-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 2px;
    white-space: nowrap;
}

.info-value {
    font-size: 1.4rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 1px;
}

.timer {
    color: var(--accent);
    min-width: 3ch;
}

.game-header-btn {
    padding: 8px 14px;
    border: 1px solid var(--surface-border);
    border-radius: 10px;
    background: var(--btn-secondary-bg);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.3s ease;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    line-height: 1;
}

.game-header-btn:hover {
    border-color: var(--accent-glow);
    color: var(--accent);
    background: var(--accent-bg);
}

.game-header-btn.active {
    background: var(--accent-bg);
    border-color: var(--accent);
    color: var(--accent);
    animation: pulse 1.5s ease-in-out infinite;
}

#board-container {
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
    overflow-x: auto;
    max-width: 100%;
    padding: 2px;
}

#board {
    display: inline-grid;
    gap: var(--board-gap);
    background: var(--surface-border);
    border: 1px solid var(--surface-border);
    border-radius: 8px;
    user-select: none;
    padding: var(--board-padding);
    animation: fadeScale 0.3s ease;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--cell-bg);
    border: none;
    border-radius: var(--cell-radius);
    cursor: pointer;
    font-size: calc(var(--cell-size) * 0.45);
    font-weight: 700;
    transition: all 0.12s ease;
    color: transparent;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.cell:hover:not(.revealed):not(.flagged) {
    background: var(--cell-hover);
    transform: scale(1.05);
}

.cell:active:not(.revealed):not(.flagged) {
    transform: scale(0.93);
}

.cell.revealed {
    background: var(--cell-revealed);
    cursor: default;
    animation: revealCell 0.18s ease;
}

.cell.flagged {
    background: var(--cell-flagged-bg);
}

.cell.flagged::after {
    content: '🚩';
    font-size: calc(var(--cell-size) * 0.5);
    animation: slideDown 0.2s ease;
}

.cell.mine {
    background: rgba(233,69,96,0.12);
    color: var(--accent);
    animation: mineExplode 0.35s ease;
}

.cell.mine-hit {
    background: rgba(255, 60, 60, 0.2) !important;
    color: #ff4444;
    animation: mineExplode 0.45s ease;
}

.cell.wrong-flag {
    background: rgba(255, 200, 0, 0.1);
    color: #ffc107;
}

.cell.n1 { color: var(--n1); }
.cell.n2 { color: var(--n2); }
.cell.n3 { color: var(--n3); }
.cell.n4 { color: var(--n4); }
.cell.n5 { color: var(--n5); }
.cell.n6 { color: var(--n6); }
.cell.n7 { color: var(--n7); }
.cell.n8 { color: var(--n8); }

.game-footer {
    display: flex;
    justify-content: center;
    gap: 8px;
    width: 100%;
    max-width: 500px;
}

#reset-btn {
    padding: 10px 32px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 85%, black));
    color: #fff;
    font-size: 0.95rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    font-family: inherit;
    letter-spacing: 0.3px;
}

#reset-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 30px var(--accent-glow);
}

#reset-btn:active { transform: translateY(0); }

/* ─── Leaderboard ──────────────────────────────────────────────────── */
.leaderboard-container h1 {
    margin-bottom: 20px;
    font-size: 2rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.lb-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-radius: 12px;
    background: var(--tab-bg);
    padding: 4px;
}

.lb-tab {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.3s ease;
    font-family: inherit;
}

.lb-tab.active {
    background: var(--accent-bg);
    color: var(--accent);
    box-shadow: 0 0 20px var(--accent-glow);
}

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

html.light .lb-tab:hover:not(.active) {
    background: rgba(0,0,0,0.03);
}

#lb-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}

#lb-table th {
    padding: 10px 8px;
    border-bottom: 1px solid var(--surface-border);
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 500;
}

#lb-table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--surface-border);
    font-size: 0.9rem;
    transition: background 0.2s ease;
    color: var(--text-primary);
}

#lb-table tbody tr:hover td { background: var(--accent-bg); }

#lb-table .rank-1 { color: #ffd700; font-weight: 700; }
#lb-table .rank-2 { color: #c0c0c0; font-weight: 700; }
#lb-table .rank-3 { color: #cd7f32; font-weight: 700; }

#lb-table tbody tr { animation: rankEntry 0.3s ease backwards; }
#lb-table tbody tr:nth-child(1) { animation-delay: 0.05s; }
#lb-table tbody tr:nth-child(2) { animation-delay: 0.1s; }
#lb-table tbody tr:nth-child(3) { animation-delay: 0.15s; }
#lb-table tbody tr:nth-child(4) { animation-delay: 0.2s; }
#lb-table tbody tr:nth-child(5) { animation-delay: 0.25s; }
#lb-table tbody tr:nth-child(6) { animation-delay: 0.3s; }
#lb-table tbody tr:nth-child(7) { animation-delay: 0.35s; }
#lb-table tbody tr:nth-child(8) { animation-delay: 0.4s; }
#lb-table tbody tr:nth-child(9) { animation-delay: 0.45s; }
#lb-table tbody tr:nth-child(10) { animation-delay: 0.5s; }

.empty-msg {
    color: var(--text-muted);
    margin-bottom: 16px;
    font-size: 0.9rem;
}

/* ─── Duel ─────────────────────────────────────────────────────────── */
.duel-challenge-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.duel-challenge-form input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--input-border);
    border-radius: 10px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    font-family: inherit;
    transition: border-color 0.3s ease;
}

.duel-challenge-form input:focus {
    border-color: var(--input-focus);
}

.duel-challenge-form select {
    padding: 10px 14px;
    border: 1px solid var(--input-border);
    border-radius: 10px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    font-family: inherit;
    cursor: pointer;
}

.duel-card {
    background: var(--btn-secondary-bg);
    border: 1px solid var(--surface-border);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    animation: fadeUp 0.3s ease;
    text-align: left;
}

.duel-card-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.duel-card-title {
    font-size: 0.95rem;
    font-weight: 600;
}

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

.duel-card-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.duel-btn-sm {
    padding: 6px 14px;
    border: 1px solid var(--surface-border);
    border-radius: 8px;
    background: var(--btn-secondary-bg);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.duel-btn-sm:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-bg);
}

.duel-btn-sm.primary {
    background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 85%, black));
    color: #fff;
    border-color: transparent;
}

.duel-btn-sm.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.duel-btn-sm.accept {
    border-color: #81c784;
    color: #81c784;
}

.duel-btn-sm.accept:hover {
    background: rgba(129,199,132,0.1);
}

.duel-btn-sm.reject {
    border-color: var(--accent);
    color: var(--accent);
}

.duel-btn-sm.reject:hover {
    background: var(--accent-bg);
}

@media (max-width: 480px) {
    .duel-challenge-form { flex-wrap: wrap; }
    .duel-challenge-form input { min-width: 100%; }
    .duel-card { flex-wrap: wrap; }
    .duel-card-actions { width: 100%; justify-content: flex-end; }
}

/* ─── Modal ────────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-overlay);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    animation: fadeScale 0.25s ease;
}

.modal-content {
    background: var(--surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--surface-border);
    padding: 36px 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    min-width: 280px;
    animation: fadeUp 0.3s ease;
}

.modal-content h2 {
    font-size: 2rem;
    margin-bottom: 4px;
    letter-spacing: -0.5px;
}

.modal-content p {
    font-size: 1.1rem;
    margin-bottom: 24px;
    color: var(--text-secondary);
}

.modal-content button {
    padding: 12px 40px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 85%, black));
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    font-family: inherit;
    letter-spacing: 0.3px;
}

.modal-content button:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 30px var(--accent-glow);
}

/* ─── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 480px) {
    #app { padding: 10px; }
    .auth-container, .menu-container, .leaderboard-container { padding: 28px 20px; border-radius: 16px; }
    .auth-container h1, .menu-container h1 { font-size: 2.2rem; }
    .game-header { flex-wrap: wrap; gap: 6px; }
    .game-header-left { order: 2; width: 100%; justify-content: center; }
    .game-info { order: 1; flex: 1; justify-content: center; }
    .game-info .info-value { font-size: 1.2rem; }
    .diff-btn { padding: 14px 18px; }
    .diff-name { font-size: 1rem; }
    .toggle-bar { margin-bottom: 12px; }
}

/* ─── Stats Modal ─────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.stat-item {
    background: var(--btn-secondary-bg);
    border-radius: 12px;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    border: 1px solid var(--surface-border);
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

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

.stat-time-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--btn-secondary-bg);
    border: 1px solid var(--surface-border);
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.stat-time-row span:first-child {
    color: var(--text-secondary);
}

.stat-time-row span:last-child {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

/* ─── Leaderboard username clickable ──────────────────────────────── */
.lb-user-btn {
    background: none;
    border: none;
    color: var(--n1);
    cursor: pointer;
    font-size: inherit;
    font-family: inherit;
    font-weight: 500;
    padding: 0;
    transition: color 0.2s ease;
    text-decoration: none;
}

.lb-user-btn:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* ─── Theme Transition ────────────────────────────────────────────── */
html.theme-switching body,
html.theme-switching .glass,
html.theme-switching .modal-content,
html.theme-switching input,
html.theme-switching .toggle-btn,
html.theme-switching .game-header-btn,
html.theme-switching .secondary-btn,
html.theme-switching .diff-btn,
html.theme-switching .cell,
html.theme-switching .lb-tab,
html.theme-switching .tab,
html.theme-switching .stat-item,
html.theme-switching .stat-time-row {
    transition: background-color 0.35s ease, color 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
}

/* ─── Scrollbar ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); }
