/* ===== CSS Variables ===== */
:root {
    --green: #059669;
    --green-dark: #047857;
    --green-light: #10b981;
    --dark: #0f1a14;
    --darker: #0a1210;
    --surface: #162820;
    --surface-light: #1e3529;
    --text: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.65);
    --text-muted: rgba(255, 255, 255, 0.4);
    --correct: #22c55e;
    --correct-bg: rgba(34, 197, 94, 0.15);
    --wrong: #ef4444;
    --wrong-bg: rgba(239, 68, 68, 0.15);
    --border: rgba(255, 255, 255, 0.08);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --space-xs: 6px;
    --space-sm: 12px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--darker);
    color: var(--text);
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ===== Loading ===== */
#loading-screen {
    position: fixed; inset: 0; background: var(--darker);
    display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.loading-content { text-align: center; }
.loading-title { font-size: 28px; font-weight: 800; color: var(--green); margin-bottom: 20px; }
.loading-spinner {
    width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--green);
    border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 12px;
}
.loading-spinner.small { width: 24px; height: 24px; border-width: 2px; }
.loading-text { font-size: 14px; color: var(--text-secondary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Landing ===== */
#landing-screen {
    min-height: 100dvh; display: flex; flex-direction: column;
    background: linear-gradient(160deg, var(--darker) 0%, var(--dark) 50%, #0a1f12 100%);
}
.landing-header { padding: var(--space-md) var(--space-lg); padding-top: env(safe-area-inset-top, var(--space-md)); }
.landing-header-row { display: flex; align-items: flex-start; justify-content: space-between; }
.header-spacer { width: 40px; }
.landing-titles { text-align: center; }
.landing-title { font-size: 28px; font-weight: 800; color: var(--green); }
.landing-subtitle { font-size: 14px; color: var(--text-secondary); font-weight: 500; margin-top: 2px; }
.landing-date { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.header-right { width: 40px; text-align: right; }
.icon-btn { background: none; border: none; color: var(--text-secondary); font-size: 22px; cursor: pointer; padding: 4px; }

.landing-body {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: var(--space-lg); gap: var(--space-lg);
}
.landing-streak {
    display: flex; align-items: center; gap: 8px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 8px 20px; font-size: 15px; font-weight: 600;
}
.streak-icon { font-size: 20px; }

.football-hero { position: relative; }
.football-icon {
    font-size: 100px;
    animation: ballBounce 2s ease-in-out infinite;
    filter: drop-shadow(0 8px 24px rgba(5, 150, 105, 0.3));
}
@keyframes ballBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}

.play-button {
    background: var(--green); color: white; border: none; border-radius: var(--radius-lg);
    padding: 16px 64px; font-size: 18px; font-weight: 700; font-family: var(--font);
    cursor: pointer; transition: transform 0.15s; box-shadow: 0 4px 16px rgba(5, 150, 105, 0.4);
}
.play-button:active { transform: scale(0.97); }
.landing-best { font-size: 13px; color: var(--text-muted); }

/* ===== Game ===== */
#game-screen {
    min-height: 100dvh; display: flex; flex-direction: column;
    background: linear-gradient(160deg, var(--darker) 0%, var(--dark) 100%);
    padding: var(--space-sm) var(--space-md); padding-top: env(safe-area-inset-top, var(--space-sm));
}
.game-top-bar { margin-bottom: var(--space-sm); }
.progress-row { display: flex; align-items: center; gap: 10px; }
.progress-text { font-size: 13px; font-weight: 700; color: var(--text-secondary); min-width: 42px; }
.progress-bar-bg { flex: 1; height: 6px; background: var(--surface); border-radius: 3px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--green); border-radius: 3px; transition: width 0.4s ease; }
.timer { font-size: 13px; font-weight: 700; color: var(--text-secondary); min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }

.player-image-area {
    flex: 1; display: flex; align-items: center; justify-content: center;
    padding: var(--space-sm) 0; min-height: 0;
}
.player-card {
    position: relative; width: 100%; max-width: 260px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl);
    display: flex; flex-direction: column; align-items: center; overflow: hidden; padding-bottom: 8px;
}
.player-card.card-enter { animation: cardEnter 0.3s ease-out; }
@keyframes cardEnter { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }

.player-image {
    width: 100%; aspect-ratio: 1; object-fit: contain;
    transition: opacity 0.3s ease; background: linear-gradient(180deg, var(--surface-light) 0%, var(--surface) 100%);
}
.image-loading {
    position: absolute; top: 0; left: 0; right: 0; aspect-ratio: 1;
    display: flex; align-items: center; justify-content: center; background: var(--surface);
}
.player-hint {
    font-size: 12px; font-weight: 600; color: var(--green-light);
    padding: 6px 12px; text-align: center; letter-spacing: 0.3px;
}

.options-container { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: var(--space-xs) 0 var(--space-sm); }
.option-btn {
    background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius-md);
    color: var(--text); font-family: var(--font); font-size: 13px; font-weight: 600;
    padding: 14px 8px; cursor: pointer; transition: border-color 0.15s, background 0.15s, transform 0.1s;
    text-align: center; word-break: break-word;
}
.option-btn:active:not(:disabled) { transform: scale(0.97); }
.option-btn:not(:disabled):hover { border-color: var(--green); background: rgba(5, 150, 105, 0.08); }
.option-btn.correct { border-color: var(--correct); background: var(--correct-bg); color: var(--correct); }
.option-btn.wrong { border-color: var(--wrong); background: var(--wrong-bg); color: var(--wrong); }
.option-btn:disabled { cursor: default; opacity: 0.7; }

.feedback-container {
    text-align: center; padding: 10px; border-radius: var(--radius-md);
    font-weight: 600; font-size: 14px; display: flex; align-items: center;
    justify-content: center; gap: 8px; animation: feedbackIn 0.25s ease-out;
}
.feedback-correct { background: var(--correct-bg); color: var(--correct); }
.feedback-wrong { background: var(--wrong-bg); color: var(--wrong); }
@keyframes feedbackIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ===== End Screen ===== */
.end-screen-modal {
    position: fixed; inset: 0; z-index: 500;
    background: linear-gradient(135deg, var(--green-dark) 0%, #065f46 30%, var(--dark) 70%, var(--darker) 100%);
    overflow-y: auto; -webkit-overflow-scrolling: touch; animation: fadeIn 0.3s ease-out;
}
.end-screen-modal::before {
    content: ''; position: absolute; inset: 0;
    background: radial-gradient(circle at 30% 20%, rgba(255,255,255,0.08) 0%, transparent 60%),
                radial-gradient(circle at 80% 80%, rgba(5,150,105,0.15) 0%, transparent 50%);
    pointer-events: none;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.end-screen-content {
    position: relative; max-width: 480px; margin: 0 auto;
    padding: var(--space-sm) var(--space-md);
    padding-top: env(safe-area-inset-top, var(--space-sm));
    padding-bottom: env(safe-area-inset-bottom, var(--space-lg));
    min-height: 100dvh; display: flex; flex-direction: column; gap: var(--space-sm);
}

.end-hero { text-align: center; padding: var(--space-md) 0 var(--space-xs); }
.end-hero-title {
    font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 2.5px;
    color: rgba(255, 255, 255, 0.7); margin-bottom: 6px;
}
.end-hero-score {
    font-size: 64px; font-weight: 800; color: white; line-height: 1;
    text-shadow: 0 2px 16px rgba(0,0,0,0.2);
    animation: scoreIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
    font-variant-numeric: tabular-nums;
}
@keyframes scoreIn { 0% { opacity: 0; transform: scale(0.5); } 100% { opacity: 1; transform: scale(1); } }
.end-hero-sublabel { font-size: 14px; color: rgba(255, 255, 255, 0.7); font-weight: 600; margin-top: 2px; }

.end-stats { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; padding: 4px 0; }
.end-stat { padding: 12px 8px; text-align: center; position: relative; }
.end-stat:not(:last-child)::after {
    content: ''; position: absolute; right: 0; top: 12px; bottom: 12px;
    width: 1px; background: rgba(255, 255, 255, 0.15);
}
.end-stat-value { font-size: 22px; font-weight: 800; color: white; }
.end-stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: rgba(255, 255, 255, 0.5); margin-top: 2px; }

.end-ranking { text-align: center; font-size: 14px; font-weight: 600; color: rgba(255, 255, 255, 0.8); padding: 4px 0; }
.ranking-medal { font-size: 18px; }

.end-result-dots { display: flex; justify-content: center; gap: 6px; padding: 2px 0; }
.result-dot { width: 22px; height: 22px; border-radius: 50%; display: inline-block; animation: dotPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.dot-correct { background: rgba(110, 231, 183, 0.9); box-shadow: 0 0 6px rgba(110, 231, 183, 0.4); }
.dot-wrong { background: rgba(252, 165, 165, 0.9); box-shadow: 0 0 6px rgba(252, 165, 165, 0.4); }
@keyframes dotPop { 0% { opacity: 0; transform: scale(0); } 100% { opacity: 1; transform: scale(1); } }

.end-buttons { display: flex; flex-direction: column; gap: 8px; padding: var(--space-xs) 0; }
.end-btn {
    display: block; width: 100%; padding: 14px; border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-md); background: rgba(255, 255, 255, 0.08); color: white;
    font-family: var(--font); font-size: 15px; font-weight: 700; cursor: pointer; transition: background 0.15s;
}
.end-btn:hover { background: rgba(255, 255, 255, 0.12); }
.end-btn-primary { background: rgba(255, 255, 255, 0.18); border-color: rgba(255, 255, 255, 0.25); }

.end-detail-section { border-top: 1px solid rgba(255, 255, 255, 0.1); padding-top: var(--space-xs); }
.end-detail-toggle {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px; cursor: pointer; font-size: 13px; font-weight: 600;
    color: rgba(255, 255, 255, 0.6); transition: color 0.15s;
}
.end-detail-toggle:hover { color: rgba(255, 255, 255, 0.8); }
.detail-chevron { font-size: 10px; transition: transform 0.3s ease; }
.detail-chevron.open { transform: rotate(180deg); }
.end-detail-body { max-height: 0; overflow: hidden; transition: max-height 0.4s ease; }
.end-detail-body.open { max-height: 2000px; overflow-y: auto; }

.answer-row {
    display: flex; align-items: center; gap: 10px; padding: 10px;
    border-radius: var(--radius-sm); margin-bottom: 6px; background: rgba(255, 255, 255, 0.04);
}
.answer-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 50%; background: rgba(255, 255, 255, 0.05); }
.answer-info { flex: 1; display: flex; flex-direction: column; gap: 1px; }
.answer-name { font-size: 14px; font-weight: 600; }
.answer-team { font-size: 11px; color: var(--green-light); }
.answer-yours { font-size: 11px; color: rgba(252, 165, 165, 0.9); }
.answer-mark { font-size: 18px; font-weight: 700; }
.answer-correct .answer-mark { color: var(--correct); }
.answer-wrong .answer-mark { color: var(--wrong); }

/* ===== Game Chooser ===== */
.game-chooser { position: fixed; inset: 0; z-index: 600; display: flex; align-items: center; justify-content: center; padding: var(--space-lg); }
.game-chooser-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); }
.game-chooser-content {
    position: relative; background: #ffffff; border-radius: var(--radius-xl); padding: var(--space-lg);
    width: 100%; max-width: 340px; border: 1px solid #e2e8f0; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}
.game-chooser-content h2 { font-size: 18px; font-weight: 700; margin-bottom: var(--space-md); text-align: center; color: #0f172a; }
.game-chooser-item {
    display: flex; align-items: center; gap: 12px; padding: 12px; background: #f8fafc;
    border: 1px solid #e2e8f0; border-radius: var(--radius-md); margin-bottom: 8px;
    text-decoration: none; color: #0f172a; transition: background 0.15s;
}
.game-chooser-item:hover { background: #f1f5f9; }
.game-chooser-icon { font-size: 24px; }
.game-chooser-info { display: flex; flex-direction: column; }
.game-chooser-name { font-weight: 700; font-size: 14px; }
.game-chooser-desc { font-size: 12px; color: #64748b; }
.game-chooser-close {
    display: block; width: 100%; margin-top: var(--space-sm); padding: 12px; background: none;
    border: 1px solid #e2e8f0; border-radius: var(--radius-md); font-family: var(--font);
    font-size: 14px; font-weight: 600; color: #64748b; cursor: pointer;
}

/* ===== Side Menu ===== */
.side-menu-overlay {
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 899;
    opacity: 0; transition: opacity 0.3s ease; pointer-events: none;
}
.side-menu-overlay:not(.hidden) { opacity: 1; pointer-events: auto; }
.side-menu {
    position: fixed; top: 0; right: -280px; bottom: 0; width: 280px; background: var(--dark);
    z-index: 900; display: flex; flex-direction: column; transition: right 0.3s ease; border-left: 1px solid var(--border);
}
.side-menu.open { right: 0; }
.side-menu-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--space-md); padding-top: env(safe-area-inset-top, var(--space-md)); border-bottom: 1px solid var(--border);
}
.side-menu-title { font-size: 18px; font-weight: 700; color: var(--green); }
.side-menu-nav { padding: var(--space-md); flex: 1; }
.menu-link {
    display: flex; align-items: center; gap: 10px; padding: 12px var(--space-md);
    border-radius: var(--radius-md); text-decoration: none; color: var(--text);
    font-weight: 600; font-size: 14px; cursor: pointer; transition: background 0.15s ease;
}
.menu-link:hover { background: rgba(255, 255, 255, 0.06); }
.menu-icon { font-size: 18px; width: 24px; text-align: center; }
.menu-divider { height: 1px; background: var(--border); margin: var(--space-xs) var(--space-md); }
.side-menu-footer { padding: var(--space-md); border-top: 1px solid var(--border); }
.menu-credit { font-size: 12px; color: var(--text-muted); text-align: center; }

/* ===== Stats Modal ===== */
.stats-modal {
    position: fixed; inset: 0; z-index: 700; display: flex; align-items: center;
    justify-content: center; padding: var(--space-lg); opacity: 0; transition: opacity 0.3s ease;
}
.stats-modal.open { opacity: 1; }
.stats-modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); }
.stats-modal-content {
    position: relative; background: var(--dark); border: 1px solid var(--border);
    border-radius: var(--radius-xl); padding: var(--space-lg); width: 100%;
    max-width: 380px; max-height: 80vh; overflow-y: auto;
}
.stats-modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-md); }
.stats-modal-header h2 { font-size: 20px; font-weight: 700; }
.stats-close { background: none; border: none; color: var(--text-secondary); font-size: 28px; cursor: pointer; padding: 0; line-height: 1; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: var(--space-md); }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px 4px; text-align: center; }
.stat-card-value { font-size: 18px; font-weight: 800; color: var(--green); }
.stat-card-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-secondary); margin-top: 2px; }
.stats-section { margin-top: var(--space-md); }
.stats-section h3 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text-secondary); margin-bottom: var(--space-sm); }
.stat-bars { display: flex; align-items: flex-end; gap: 4px; height: 80px; padding: 0 4px; }
.stat-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.stat-bar { width: 100%; background: var(--green); border-radius: 3px 3px 0 0; min-height: 4px; opacity: 0.8; }
.stat-bar-label { font-size: 10px; color: var(--text-muted); margin-top: 4px; font-weight: 600; }
.stat-game-row { display: flex; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.stat-game-date { flex: 1; color: var(--text-secondary); }
.stat-game-score { font-weight: 700; margin-right: 12px; }
.stat-game-time { color: var(--text-secondary); font-variant-numeric: tabular-nums; }

/* ===== Group Leaderboards on End Screen ===== */
.end-group-leaderboards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.end-group-card {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    overflow: hidden;
}

.end-group-header {
    font-size: 13px;
    font-weight: 600;
    padding: 10px 12px 4px;
    color: var(--text);
}

.end-group-table {
    width: 100%;
    border-collapse: collapse;
}

.end-group-table th {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
    padding: 4px 12px;
    text-align: left;
}

.end-group-table th:first-child { width: 32px; text-align: center; }

.end-group-table td {
    padding: 4px 12px;
    font-size: 12px;
    color: var(--text-secondary);
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.end-group-table td:first-child {
    width: 32px;
    text-align: center;
    font-weight: 600;
    color: var(--text-muted);
}

.end-group-table td:last-child {
    text-align: right;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.end-group-table tr.leaderboard-me {
    background: rgba(5, 150, 105, 0.15);
}

.end-group-table tr.leaderboard-me td {
    color: var(--green-light);
    font-weight: 600;
}

.end-group-empty {
    font-size: 12px;
    color: var(--text-muted);
    padding: 10px 12px;
    text-align: center;
}
