/* ============================================
   CSS VARIABLES
   ============================================ */
:root {
    --color-bg: #0f0f23;
    --color-surface: #1a1a3e;
    --color-primary: #9333ea;
    --color-primary-dark: #7c22d3;
    --color-secondary: #6366f1;
    --color-accent: #22d3ee;
    --color-text: #ffffff;
    --color-text-dim: #a0a0c0;
    --color-correct: #22c55e;
    --color-incorrect: #ef4444;
    --color-gold: #fbbf24;
    --color-silver: #94a3b8;
    --color-bronze: #d97706;
    --color-waiting: #f59e0b;
    --transition-speed: 0.3s;
    --border-radius: 12px;
}

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

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   APP CONTAINER
   ============================================ */
.app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* ============================================
   SCREENS
   ============================================ */
.screen {
    display: none;
    flex-direction: column;
    padding: 24px 20px;
    flex: 1;
    animation: fadeIn 0.3s ease;
}

.screen.active {
    display: flex;
}

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

/* ============================================
   TYPOGRAPHY
   ============================================ */
h1 {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    text-align: center;
}

h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text-dim);
}

h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.subtitle {
    color: var(--color-text-dim);
    text-align: center;
    margin-bottom: 24px;
}

.tagline {
    color: var(--color-text-dim);
    font-size: 1rem;
    margin-top: 4px;
}

/* ============================================
   LOGO
   ============================================ */
.logo {
    text-align: center;
    margin-bottom: 48px;
    padding-top: 40px;
}

.logo-emoji {
    font-size: 4rem;
    display: block;
    margin-bottom: 12px;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 24px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--transition-speed);
    min-height: 56px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    width: 100%;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    color: white;
}

.btn-primary:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(147, 51, 234, 0.4);
}

.btn-primary:not(:disabled):active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border: 2px solid var(--color-primary);
}

.btn-secondary:not(:disabled):hover {
    background: rgba(147, 51, 234, 0.2);
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-dim);
}

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

.btn-small {
    padding: 10px 16px;
    min-height: 40px;
    font-size: 0.875rem;
    width: auto;
}

.btn-option {
    flex-direction: column;
    padding: 24px;
    background: var(--color-surface);
    border: 2px solid transparent;
    flex: 1;
}

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

.option-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.option-text {
    font-size: 0.875rem;
}

/* ============================================
   FORMS
   ============================================ */
.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    color: var(--color-text-dim);
    margin-bottom: 8px;
}

input[type="text"] {
    width: 100%;
    padding: 16px;
    font-size: 1rem;
    background: var(--color-surface);
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    color: var(--color-text);
    transition: border-color var(--transition-speed);
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--color-primary);
}

input[type="text"]::placeholder {
    color: var(--color-text-dim);
}

.code-input {
    text-align: center;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 0.5em;
    text-transform: uppercase;
}

/* ============================================
   ACTIONS
   ============================================ */
.actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: auto;
}

.player-options {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
}

/* ============================================
   ROOM CODE
   ============================================ */
.room-code-container {
    text-align: center;
    background: var(--color-surface);
    padding: 24px;
    border-radius: var(--border-radius);
    margin-bottom: 24px;
}

.room-code-container label {
    display: block;
    font-size: 0.875rem;
    color: var(--color-text-dim);
    margin-bottom: 8px;
}

.room-code {
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: 0.3em;
    color: var(--color-accent);
    margin-bottom: 16px;
}

/* ============================================
   PLAYERS LIST
   ============================================ */
.players-list {
    background: var(--color-surface);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 24px;
    flex: 1;
}

.players-list h3 {
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.players-list ul {
    list-style: none;
}

.players-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.players-list li:last-child {
    border-bottom: none;
}

.player-avatar {
    width: 40px;
    height: 40px;
    background: var(--color-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

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

.player-badge {
    font-size: 0.75rem;
    background: var(--color-primary);
    padding: 4px 8px;
    border-radius: 4px;
}

.player-waiting {
    color: var(--color-waiting);
    font-style: italic;
}

/* ============================================
   QUESTION SCREEN
   ============================================ */
.question-header {
    margin-bottom: 24px;
}

.question-progress {
    text-align: center;
    font-size: 0.875rem;
    color: var(--color-text-dim);
    margin-bottom: 12px;
}

.timer-container {
    text-align: center;
}

.timer {
    font-size: 3rem;
    font-weight: 800;
    color: var(--color-accent);
    margin-bottom: 8px;
}

.timer.urgent {
    color: var(--color-incorrect);
    animation: pulse 0.5s infinite;
}

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

.timer-bar {
    height: 6px;
    background: var(--color-surface);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.timer-bar::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: var(--timer-progress, 100%);
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
    border-radius: 3px;
    transition: width 0.1s linear;
}

.question-content {
    text-align: center;
    margin-bottom: 24px;
}

.category-badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-accent);
    background: rgba(34, 211, 238, 0.1);
    padding: 6px 12px;
    border-radius: 20px;
    margin-bottom: 16px;
}

.question-text {
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.4;
}

/* ============================================
   OPTIONS
   ============================================ */
.options-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.option-btn {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    font-size: 1rem;
    font-weight: 500;
    text-align: left;
    background: var(--color-surface);
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    color: var(--color-text);
    cursor: pointer;
    transition: all var(--transition-speed);
    min-height: 56px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.option-btn:not(:disabled):hover {
    border-color: var(--color-primary);
}

.option-btn:disabled {
    cursor: not-allowed;
}

.option-btn.selected {
    border-color: var(--color-primary);
    background: rgba(147, 51, 234, 0.2);
}

.option-btn.correct {
    border-color: var(--color-correct);
    background: rgba(34, 197, 94, 0.2);
}

.option-btn.incorrect {
    border-color: var(--color-incorrect);
    background: rgba(239, 68, 68, 0.2);
}

.option-letter {
    width: 32px;
    height: 32px;
    background: rgba(255,255,255,0.1);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    margin-right: 12px;
    flex-shrink: 0;
}

/* ============================================
   ANSWERED STATUS
   ============================================ */
.answered-status {
    text-align: center;
    font-size: 0.875rem;
    color: var(--color-text-dim);
}

.answered-list {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 8px;
}

.answered-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--color-surface);
    border-radius: 20px;
    font-size: 0.8rem;
}

.answered-item.answered {
    background: rgba(34, 197, 94, 0.2);
    color: var(--color-correct);
}

/* ============================================
   RESULTS SCREEN
   ============================================ */
.result-header {
    text-align: center;
    padding: 24px;
    margin-bottom: 24px;
}

.result-header .result-emoji {
    font-size: 3rem;
    display: block;
    margin-bottom: 8px;
}

.result-header .result-text {
    font-size: 1.5rem;
    font-weight: 700;
}

.result-header.correct {
    color: var(--color-correct);
}

.result-header.incorrect {
    color: var(--color-incorrect);
}

.result-header.timeout {
    color: var(--color-waiting);
}

.correct-answer {
    text-align: center;
    background: var(--color-surface);
    padding: 20px;
    border-radius: var(--border-radius);
    margin-bottom: 24px;
}

.correct-answer p {
    font-size: 0.875rem;
    color: var(--color-text-dim);
    margin-bottom: 8px;
}

.correct-answer strong {
    font-size: 1.25rem;
    color: var(--color-correct);
}

.round-scores {
    margin-bottom: 24px;
}

.round-scores h3 {
    margin-bottom: 12px;
    text-align: center;
}

.round-scores ul {
    list-style: none;
}

.round-scores li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--color-surface);
    border-radius: 8px;
    margin-bottom: 8px;
}

.round-scores .score-name {
    display: flex;
    align-items: center;
    gap: 8px;
}

.round-scores .score-medal {
    font-size: 1.25rem;
}

.round-scores .score-points {
    font-weight: 700;
    color: var(--color-correct);
}

.round-scores .score-points.zero {
    color: var(--color-text-dim);
}

.round-scores .score-time {
    font-size: 0.75rem;
    color: var(--color-text-dim);
}

.current-standings {
    text-align: center;
    margin-bottom: 24px;
}

.current-standings h4 {
    margin-bottom: 12px;
}

.standings-list {
    display: flex;
    justify-content: center;
    gap: 16px;
}

.standing-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 20px;
    background: var(--color-surface);
    border-radius: 8px;
}

.standing-item .standing-name {
    font-size: 0.875rem;
    color: var(--color-text-dim);
    margin-bottom: 4px;
}

.standing-item .standing-score {
    font-size: 1.5rem;
    font-weight: 700;
}

.next-timer {
    text-align: center;
    color: var(--color-text-dim);
    margin-top: auto;
}

/* ============================================
   FINISHED SCREEN
   ============================================ */
.trophy-container {
    text-align: center;
    padding: 24px 0;
}

.trophy-emoji {
    font-size: 5rem;
    display: block;
    margin-bottom: 16px;
    animation: shine 2s infinite;
}

@keyframes shine {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.3); }
}

.leaderboard {
    margin-bottom: 32px;
}

.leaderboard ul {
    list-style: none;
}

.leaderboard li {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    background: var(--color-surface);
    border-radius: var(--border-radius);
    margin-bottom: 12px;
}

.leaderboard li:first-child {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.2), rgba(251, 191, 36, 0.1));
    border: 2px solid var(--color-gold);
}

.leaderboard li:nth-child(2) {
    background: linear-gradient(135deg, rgba(148, 163, 184, 0.2), rgba(148, 163, 184, 0.1));
    border: 2px solid var(--color-silver);
}

.leaderboard li:nth-child(3) {
    background: linear-gradient(135deg, rgba(217, 119, 6, 0.2), rgba(217, 119, 6, 0.1));
    border: 2px solid var(--color-bronze);
}

.leaderboard .medal {
    font-size: 2rem;
    margin-right: 16px;
}

.leaderboard .player-info {
    flex: 1;
}

.leaderboard .player-name {
    font-weight: 600;
    font-size: 1.125rem;
}

.leaderboard .player-subtitle {
    font-size: 0.75rem;
    color: var(--color-text-dim);
}

.leaderboard .player-score {
    font-size: 1.5rem;
    font-weight: 800;
}

.leaderboard li:first-child .player-score {
    color: var(--color-gold);
}

.final-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: auto;
}

/* ============================================
   ERROR SCREEN
   ============================================ */
.error-container {
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.error-emoji {
    font-size: 5rem;
    display: block;
    margin-bottom: 24px;
}

.error-container h2 {
    margin-bottom: 12px;
}

.error-container p {
    color: var(--color-text-dim);
    margin-bottom: 32px;
}

/* ============================================
   LOADING OVERLAY
   ============================================ */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 35, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--color-surface);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

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

.loading-overlay p {
    color: var(--color-text-dim);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (min-width: 768px) {
    .app {
        padding: 20px;
    }

    .screen {
        padding: 32px;
        max-width: 420px;
        margin: 0 auto;
    }

    h1 {
        font-size: 3rem;
    }

    .room-code {
        font-size: 4rem;
    }
}

/* ============================================
   SAFE AREAS (notch support)
   ============================================ */
@supports (padding-top: env(safe-area-inset-top)) {
    .app {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}
