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

:root {
    --color-bg: #1a1a2e;
    --color-surface: #16213e;
    --color-primary: #e94560;
    --color-success: #4ecca3;
    --color-warning: #f5a623;
    --color-text: #ffffff;
    --color-text-muted: #a0a0b0;
    --color-accent: #0f3460;

    --font-main: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono: 'Courier New', monospace;

    --text-xl: clamp(2rem, 5vw, 3.5rem);
    --text-lg: clamp(1.5rem, 3.5vw, 2.5rem);
    --text-md: clamp(1.1rem, 2.5vw, 1.5rem);
    --text-sm: clamp(0.9rem, 2vw, 1.1rem);

    --radius: 12px;
    --spacing: clamp(0.75rem, 2vw, 1.5rem);
}

body {
    font-family: var(--font-main);
    background-color: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing);
    -webkit-user-select: none;
    user-select: none;
}

/* === Screen Management === */
.screen {
    display: none;
    width: 100%;
    max-width: 600px;
}

.screen.active {
    display: flex;
}

.screen__content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing);
    width: 100%;
    padding: var(--spacing);
}

/* === Typography === */
.title {
    font-size: var(--text-xl);
    font-weight: 800;
    color: var(--color-primary);
    text-align: center;
}

.subtitle {
    font-size: var(--text-lg);
    font-weight: 700;
    text-align: center;
}

.section-title {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--color-text-muted);
    text-align: center;
}

.highlight {
    color: var(--color-primary);
    font-weight: 700;
}

/* === Buttons === */
.btn {
    font-family: var(--font-main);
    font-size: var(--text-md);
    font-weight: 600;
    padding: 0.75rem 2rem;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    color: var(--color-text);
    background-color: var(--color-accent);
}

.btn:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn:active {
    transform: scale(0.96);
}

.btn:focus-visible {
    outline: 3px solid var(--color-text);
    outline-offset: 3px;
}

.btn--start {
    font-size: var(--text-lg);
    background-color: var(--color-success);
    color: var(--color-bg);
    padding: 1rem 3rem;
}

.btn--play-again {
    background-color: var(--color-success);
    color: var(--color-bg);
}

.btn--menu {
    background-color: var(--color-accent);
}

.btn--add-player {
    background-color: var(--color-primary);
    padding: 0.6rem 1.5rem;
    font-size: var(--text-sm);
}

.btn-link {
    font-family: var(--font-main);
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
    padding: 0.25rem;
}

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

/* === Player Select === */
.player-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    width: 100%;
    min-height: 3rem;
}

.btn--player {
    padding: 0.75rem 1.5rem;
    background-color: var(--color-surface);
    border: 2px solid var(--color-accent);
    font-size: var(--text-md);
}

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

.btn--player-last {
    border-color: var(--color-success);
    box-shadow: 0 0 8px rgba(78, 204, 163, 0.4);
}

.add-player-row {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    width: 100%;
    max-width: 400px;
}

/* === Inputs === */
.input {
    font-family: var(--font-main);
    font-size: var(--text-md);
    padding: 0.6rem 1rem;
    border: 2px solid var(--color-text-muted);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    outline: none;
    transition: border-color 0.15s ease;
    -webkit-user-select: text;
    user-select: text;
}

.input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.3);
}

.input--player-name {
    flex: 1;
}

.answer-input {
    font-family: var(--font-mono);
    font-size: var(--text-lg);
    text-align: center;
    width: min(300px, 80vw);
    padding: 0.75rem 1rem;
    border-width: 3px;
}

.answer-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    width: min(340px, 90vw);
}

.answer-row .answer-input {
    flex: 1;
    width: auto;
    min-width: 0;
}

.btn--submit-answer {
    flex-shrink: 0;
    width: 3rem;
    height: 3rem;
    padding: 0;
    font-size: 1.4rem;
    background-color: var(--color-success);
    color: var(--color-bg);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: opacity 0.15s;
}

.btn--submit-answer:disabled {
    opacity: 0.4;
    cursor: default;
}

/* === Menu Screen === */
.menu-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    justify-content: center;
}

.stage-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    max-width: 400px;
}

.btn--stage {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    font-size: var(--text-md);
    background-color: var(--color-surface);
    border: 2px solid var(--color-accent);
}

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

.best-score {
    font-size: var(--text-sm);
    color: var(--color-success);
    font-weight: 400;
}

/* === Difficulty Select === */
.difficulty-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    max-width: 400px;
}

.btn--difficulty {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 1rem 1.5rem;
    font-size: var(--text-md);
    background-color: var(--color-surface);
    border: 2px solid var(--color-accent);
}

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

.difficulty-name {
    font-weight: 700;
    font-size: var(--text-md);
}

.difficulty-detail {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

.difficulty-prize {
    font-size: var(--text-sm);
    color: var(--color-warning);
    font-weight: 600;
}

.difficulty-prize--claimed {
    color: var(--color-success);
}

.prizes-count {
    font-size: var(--text-sm);
    color: var(--color-success);
    font-weight: 400;
}

/* === Game Screen === */
.game-layout {
    gap: clamp(0.5rem, 1.5vw, 1rem);
    position: relative;
}

.countdown-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(26, 26, 46, 0.85);
    border-radius: var(--radius);
}

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

.countdown-display {
    font-size: clamp(5rem, 20vw, 10rem);
    font-weight: 800;
    color: var(--color-success);
    line-height: 1;
    animation: countdown-pop 0.35s ease-out;
}

@keyframes countdown-pop {
    from {
        transform: scale(0.5);
        opacity: 0.4;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 1rem;
}

.game-player {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    font-weight: 600;
}

.timer {
    font-size: var(--text-lg);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    min-width: 3ch;
    text-align: center;
}

.timer--warning {
    color: var(--color-warning);
}

.timer--danger {
    color: var(--color-primary);
    animation: pulse 0.5s ease-in-out infinite alternate;
}

.score {
    font-size: var(--text-md);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.question {
    font-size: var(--text-xl);
    font-weight: 700;
    text-align: center;
    padding: var(--spacing) 0;
    min-height: 4rem;
}

.feedback {
    font-size: var(--text-md);
    font-weight: 600;
    min-height: 2em;
    text-align: center;
}

.feedback--correct {
    color: var(--color-success);
}

.feedback--wrong {
    color: var(--color-primary);
}

/* === Results Screen === */
.results-outcome {
    font-size: var(--text-xl);
    font-weight: 800;
    text-align: center;
}

.results-outcome--win {
    color: var(--color-success);
}

.results-outcome--lose {
    color: var(--color-primary);
}

.results-score {
    font-size: var(--text-lg);
    font-variant-numeric: tabular-nums;
}

.new-best {
    font-size: var(--text-lg);
    font-weight: 800;
    color: var(--color-warning);
    animation: new-best-glow 0.6s ease-in-out infinite alternate;
    text-align: center;
}

.prize-result {
    font-size: var(--text-md);
    font-weight: 700;
    text-align: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
}

.prize-result--new {
    color: var(--color-warning);
    animation: new-best-glow 0.6s ease-in-out infinite alternate;
}

.prize-result--already-claimed {
    color: var(--color-text-muted);
}

.results-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

/* === Animations === */
@keyframes pulse {
    from { transform: scale(1); }
    to   { transform: scale(1.15); }
}

@keyframes new-best-glow {
    from { text-shadow: 0 0 4px rgba(245, 166, 35, 0.4); }
    to   { text-shadow: 0 0 16px rgba(245, 166, 35, 0.8); }
}

@keyframes feedback-flash {
    from { opacity: 1; }
    to   { opacity: 0; }
}

/* === Accessibility === */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* === Touch devices — remove persistent hover effects === */
@media (hover: none) {
    .btn:hover {
        box-shadow: none;
        transform: none;
    }
    .btn--player:hover {
        border-color: var(--color-accent);
    }
    .btn--player-last:hover {
        border-color: var(--color-success);
    }
    .btn--stage:hover {
        border-color: var(--color-accent);
    }
}

/* === Landscape phones — compact vertical spacing === */
@media (max-height: 500px) and (orientation: landscape) {
    .screen__content {
        gap: 0.25rem;
    }
    .game-header {
        gap: 0.5rem;
    }
    .question {
        padding: 0.25rem 0;
        min-height: 2rem;
    }
}
