:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --success: #10b981;
    --gradient-primary: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --gradient-secondary: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 500ms cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

[data-protected] {
    position: relative;
    user-select: none;
    -webkit-user-select: none;
}

[data-protected] input,
[data-protected] textarea,
[data-protected] select,
[data-protected] button,
[data-protected] [contenteditable="true"],
[data-protected] [data-allow-copy] {
    user-select: text;
    -webkit-user-select: text;
}

.anti-theft-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.82);
    backdrop-filter: blur(6px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.anti-theft-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.anti-theft-overlay[hidden] {
    display: none;
}

.anti-theft-message {
    max-width: 28rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 1.5rem;
    padding: 2.5rem 2rem;
    text-align: center;
    color: var(--text-primary);
    box-shadow: var(--shadow-xl);
    display: grid;
    gap: 1.25rem;
}

.anti-theft-message svg {
    margin: 0 auto;
    color: var(--accent);
}

.anti-theft-message h2 {
    font-size: 1.5rem;
    font-weight: 700;
}

.anti-theft-message p {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

[data-theme="dark"] {
    --bg-primary: #0b1020;
    --bg-secondary: rgba(15, 23, 42, 0.92);
    --bg-tertiary: rgba(99, 102, 241, 0.16);
    --text-primary: #f8fafc;
    --text-secondary: #cbd5f5;
    --text-tertiary: #94a3b8;
    --border-color: rgba(71, 85, 105, 0.45);
    --shadow-sm: 0 10px 24px rgba(15, 23, 42, 0.35);
    --shadow-md: 0 30px 60px rgba(15, 23, 42, 0.45);
    --shadow-glow: 0 28px 70px rgba(99, 102, 241, 0.45);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar {
    width: 0;
    height: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: background var(--transition-base), color var(--transition-base);
    min-height: 100vh;
    padding: 4rem 1.5rem 6rem;
}

/* Theme Toggle */
.theme-toggle-games {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 1001;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 2rem;
    cursor: pointer;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-lg);
}

.theme-toggle-games:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-xl);
}

.toggle-track {
    width: 4rem;
    height: 2rem;
    border-radius: 2rem;
    position: relative;
    background: var(--gradient-primary);
}

.toggle-thumb {
    position: absolute;
    top: 0.25rem;
    left: 0.25rem;
    width: 1.5rem;
    height: 1.5rem;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-bounce);
    box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .toggle-thumb {
    transform: translateX(2rem);
}

.sun-icon {
    color: #f59e0b;
    transition: opacity var(--transition-base);
}

.moon-icon {
    color: #6366f1;
    position: absolute;
    opacity: 0;
    transition: opacity var(--transition-base);
}

[data-theme="dark"] .sun-icon {
    opacity: 0;
}

[data-theme="dark"] .moon-icon {
    opacity: 1;
}

.back-button {
    position: fixed;
    top: 1.5rem;
    left: 1.5rem;
    z-index: 1001;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.2rem;
    border-radius: 0.8rem;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 500;
    transition: transform var(--transition-base), box-shadow var(--transition-base), color var(--transition-base);
    box-shadow: var(--shadow-sm);
}

.back-button:hover {
    transform: translateX(-4px);
    color: var(--primary);
    box-shadow: var(--shadow-md);
}

.page-hero {
    max-width: 780px;
    margin: 0 auto 3.5rem;
    text-align: center;
}

.page-kicker {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    background: var(--bg-tertiary);
    color: var(--primary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 0.75rem;
}

.page-hero h1 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: clamp(2.5rem, 4vw, 3.5rem);
    margin: 1.25rem 0 1rem;
    line-height: 1.1;
}

.page-lede {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin: 0 auto;
    max-width: 620px;
}

.games-grid {
    display: grid;
    gap: 2.5rem;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    max-width: 1200px;
    margin: 0 auto 5rem;
}

.game-card {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding: 1.75rem;
    border-radius: 1.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.game-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--card-gradient);
    opacity: 0;
    transition: opacity var(--transition-base);
    pointer-events: none;
}

.game-card:hover::before {
    opacity: 1;
}

.game-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-md);
}

.card-top {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    background: rgba(99, 102, 241, 0.12);
    color: var(--primary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.7rem;
}

.card-description {
    color: var(--text-secondary);
    margin: 0;
}

.card-cta,
.ghost-btn {
    cursor: pointer;
    border: none;
    border-radius: 0.75rem;
    padding: 0.8rem 1.1rem;
    font-weight: 600;
    transition: transform var(--transition-base), box-shadow var(--transition-base), background var(--transition-base), color var(--transition-base);
}

.card-cta {
    background: var(--gradient-primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

.card-cta:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.ghost-btn {
    background: transparent;
    color: var(--primary);
    border: 1px dashed rgba(99, 102, 241, 0.35);
}

.ghost-btn:hover {
    border-style: solid;
    color: var(--primary-dark);
}

.status-message {
    min-height: 1.25rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Sudoku */
.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.4rem;
    padding: 1rem;
    border-radius: 1rem;
    border: 1px solid var(--border-color);
    background: rgba(99, 102, 241, 0.06);
}

.sudoku-cell {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 0.65rem;
    border: 1px solid var(--border-color);
    font-size: 1.2rem;
    text-align: center;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.85);
    font-weight: 600;
}

[data-theme="dark"] .sudoku-cell {
    background: rgba(15, 23, 42, 0.85);
}

.sudoku-cell[data-fixed="true"] {
    background: rgba(99, 102, 241, 0.16);
    color: var(--primary-dark);
}

.sudoku-cell:focus {
    outline: 2px solid var(--primary);
}

.sudoku-cell.error {
    border-color: rgba(239, 68, 68, 0.65);
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.15);
}

/* Calculator */
.calculator {
    background: rgba(99, 102, 241, 0.08);
    border-radius: 1.25rem;
    padding: 1.25rem;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.calculator-display {
    background: var(--bg-secondary);
    border-radius: 1rem;
    padding: 1rem;
    font-size: 2rem;
    text-align: right;
    font-weight: 700;
    border: 1px solid var(--border-color);
    min-height: 3.2rem;
}

.calculator-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.calculator-grid button {
    padding: 0.9rem;
    border-radius: 0.9rem;
    border: none;
    font-size: 1.1rem;
    font-weight: 600;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    transition: transform var(--transition-base), box-shadow var(--transition-base), background var(--transition-base);
}

.calculator-grid button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.calculator-grid button[data-calc="operator"],
.calculator-grid button[data-calc="equals"] {
    background: var(--gradient-primary);
    color: white;
    border: none;
}

.calculator-grid button[data-calc="clear"] {
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
}

.calculator-grid button.span-two {
    grid-column: span 2;
}

/* Tic Tac Toe */
.tictactoe-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
    background: rgba(99, 102, 241, 0.08);
    padding: 1rem;
    border-radius: 1.2rem;
    border: 1px solid var(--border-color);
}

.ttt-cell {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 1rem;
    border: 1px dashed rgba(99, 102, 241, 0.35);
    background: var(--bg-secondary);
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
    cursor: pointer;
    transition: background var(--transition-base), transform var(--transition-base);
}

.ttt-cell:hover {
    transform: translateY(-3px);
}

/* Rock Paper Scissors */
.rps-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.rps-actions button {
    flex: 1 1 30%;
    min-width: 120px;
    padding: 0.85rem 1rem;
    border-radius: 0.9rem;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-weight: 600;
    cursor: pointer;
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.rps-actions button:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-sm);
}

/* Number Guess */
.guessing-game {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.guessing-game input {
    padding: 0.85rem;
    border-radius: 0.85rem;
    border: 1px solid var(--border-color);
    font-size: 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Word Scramble */
.scramble-display {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.scrambled-word {
    font-size: 1.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4rem;
    text-align: center;
}

.scramble-display input {
    padding: 0.85rem;
    border-radius: 0.85rem;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    font-size: 1rem;
}

/* Trivia */
.trivia {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.trivia-options {
    display: grid;
    gap: 0.75rem;
}

.trivia-options button {
    padding: 0.9rem 1.1rem;
    border-radius: 0.85rem;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: background var(--transition-base), transform var(--transition-base);
}

.trivia-options button:hover {
    transform: translateY(-2px);
    background: rgba(99, 102, 241, 0.12);
}

.trivia-options button.correct {
    border-color: rgba(16, 185, 129, 0.45);
    background: rgba(16, 185, 129, 0.12);
    color: var(--success);
}

.trivia-options button.incorrect {
    border-color: rgba(239, 68, 68, 0.45);
    background: rgba(239, 68, 68, 0.12);
    color: var(--danger);
}

/* Memory */
.memory-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(60px, 1fr));
    gap: 0.6rem;
    padding: 1rem;
    border-radius: 1.2rem;
    border: 1px solid var(--border-color);
    background: rgba(99, 102, 241, 0.08);
}

.memory-card {
    position: relative;
    padding: 1.2rem 0;
    border-radius: 1rem;
    background: var(--bg-secondary);
    border: 1px dashed rgba(99, 102, 241, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform var(--transition-base), box-shadow var(--transition-base), background var(--transition-base);
}

.memory-card.revealed,
.memory-card.matched {
    background: rgba(99, 102, 241, 0.16);
    border-style: solid;
    transform: translateY(-3px);
}

.memory-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

/* Color Match */
.color-match {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.color-swatch {
    width: 100%;
    aspect-ratio: 3 / 2;
    border-radius: 1.25rem;
    border: 1px solid var(--border-color);
    box-shadow: inset 0 0 20px rgba(15, 23, 42, 0.12);
}

.color-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.color-options button {
    padding: 0.8rem 1rem;
    border-radius: 0.9rem;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.95rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform var(--transition-base), box-shadow var(--transition-base), border-color var(--transition-base);
}

.color-options button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.color-options button.correct {
    border-color: rgba(16, 185, 129, 0.6);
    background: rgba(16, 185, 129, 0.14);
    color: var(--success);
}

.color-options button.incorrect {
    border-color: rgba(239, 68, 68, 0.6);
    background: rgba(239, 68, 68, 0.14);
    color: var(--danger);
}

/* Reaction */
.reaction-area {
    position: relative;
    padding: 2.5rem 1rem;
    border-radius: 1.5rem;
    text-align: center;
    border: 1px dashed rgba(99, 102, 241, 0.35);
    background: rgba(99, 102, 241, 0.08);
    cursor: pointer;
    transition: background var(--transition-base), border-color var(--transition-base), transform var(--transition-base), box-shadow var(--transition-base);
    outline: none;
}

.reaction-area span {
    font-size: 1.15rem;
    font-weight: 600;
}

.reaction-area.ready {
    background: rgba(253, 224, 71, 0.18);
    border-color: rgba(250, 204, 21, 0.6);
}

.reaction-area.active {
    background: rgba(34, 197, 94, 0.22);
    border-color: rgba(16, 185, 129, 0.7);
    box-shadow: 0 12px 32px rgba(16, 185, 129, 0.25);
}

.reaction-area:focus-visible {
    transform: translateY(-3px);
    box-shadow: var(--shadow-glow);
}

.reaction-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.reaction-best {
    margin: 0;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Math Sprint */
.math-challenge {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1.25rem;
    border-radius: 1.25rem;
    border: 1px solid var(--border-color);
    background: rgba(99, 102, 241, 0.06);
}

.math-question {
    font-size: 1.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-align: center;
}

.math-challenge input {
    padding: 0.85rem;
    border-radius: 0.9rem;
    border: 1px solid var(--border-color);
    font-size: 1rem;
    background: var(--bg-secondary);
}

.math-actions {
    display: flex;
    gap: 0.75rem;
}

.math-actions .ghost-btn {
    flex: 1;
    text-align: center;
}

/* Dice Duel */
.dice-display {
    display: flex;
    justify-content: center;
    gap: 2rem;
    padding: 1.4rem;
    border-radius: 1.25rem;
    border: 1px dashed rgba(99, 102, 241, 0.35);
    background: rgba(99, 102, 241, 0.08);
}

.dice-column {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    align-items: center;
    min-width: 90px;
}

.dice-label {
    margin: 0;
    font-weight: 600;
    color: var(--text-secondary);
}

.dice-face {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 1rem;
    border: 2px solid rgba(99, 102, 241, 0.35);
    background: var(--bg-secondary);
    font-size: 1.8rem;
    font-weight: 700;
}

.dice-scoreboard {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.dice-scoreboard span {
    display: inline-flex;
    gap: 0.35rem;
    align-items: center;
}

@media (max-width: 768px) {
    body {
        padding: 3.5rem 1rem 5rem;
    }

    .theme-toggle,
    .back-button {
        position: static;
        margin-bottom: 1.5rem;
    }

    .page-hero {
        margin-bottom: 2.5rem;
    }

    .memory-grid {
        grid-template-columns: repeat(4, minmax(50px, 1fr));
    }

    .reaction-controls {
        flex-direction: column;
        align-items: flex-start;
    }

    .dice-display {
        gap: 1rem;
    }

    .dice-scoreboard {
        flex-direction: column;
        align-items: flex-start;
    }
}

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

    .memory-grid {
        grid-template-columns: repeat(4, minmax(42px, 1fr));
    }
}
