/* Base Variables & Theme */
:root {
    /* Colors */
    --bg-dark: #0a0a0f;
    --bg-light: #1a1a2e;
    --primary: #00ff88;
    --danger: #ff3366;
    --accent: #ffd700;
    --text-main: #ffffff;
    --text-muted: #8892b0;
    
    /* UI */
    --card-bg: rgba(255, 255, 255, 0.05);
    --border-color: rgba(255, 255, 255, 0.1);
    --glass-blur: blur(10px);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    
    /* Fonts */
    --font-main: 'Inter', sans-serif;
    
    /* Scoreboard */
    --score-bg: #0d1b3e;
}

/* Reset & Global */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-light) 100%);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

#app {
    width: 100%;
    height: 100vh;
    position: relative;
    overflow: hidden;
}

/* Screens */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow-y: auto;
}

.screen.active {
    display: flex;
    animation: fadeIn 0.4s ease-out forwards;
}

/* Glassmorphism Classes */
.glass-card {
    background: var(--card-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.glass-bar {
    background: var(--card-bg);
    backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--border-color);
}

/* Typography & Utilities */
h1, h2, h3 {
    font-weight: 800;
    margin-bottom: 1rem;
}

.mt-4 { margin-top: 1.5rem; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

.primary-btn {
    background: linear-gradient(45deg, #00b09b, var(--primary));
    color: #000;
    box-shadow: 0 4px 15px rgba(0, 255, 136, 0.3);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 255, 136, 0.4);
}

.secondary-btn {
    background: rgba(255,255,255,0.1);
    color: var(--text-main);
}

.secondary-btn:hover {
    background: rgba(255,255,255,0.2);
}

.text-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.5rem;
    margin-top: 1rem;
}

.text-btn:hover {
    color: var(--text-main);
    text-decoration: underline;
}

/* --- 1. LOADING SCREEN --- */
#loading-screen .logo-text {
    font-size: 3rem;
    font-weight: 900;
    text-align: center;
    text-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
    animation: pulse 2s infinite ease-in-out;
    margin-bottom: 0.5rem;
}

#loading-screen .subtitle {
    color: var(--primary);
    text-align: center;
    font-weight: 500;
    margin-bottom: 2rem;
}

.spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto;
    border: 4px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s infinite linear;
}

/* --- 2. AUTH SCREEN --- */
.auth-card {
    width: 100%;
    max-width: 400px;
}

.auth-tabs {
    display: flex;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.auth-tab {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s;
}

.auth-tab.active {
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
}

.auth-form {
    display: none;
    flex-direction: column;
    gap: 1rem;
}

.auth-form.active-form {
    display: flex;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.input-group input {
    width: 100%;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: rgba(0,0,0,0.2);
    color: var(--text-main);
    font-family: var(--font-main);
    transition: all 0.2s;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(0, 255, 136, 0.2);
}

.auth-divider {
    text-align: center;
    margin: 1.5rem 0;
    position: relative;
}

.auth-divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--border-color);
    z-index: 1;
}

.auth-divider span {
    background: var(--bg-light); /* match card approx */
    padding: 0 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    position: relative;
    z-index: 2;
}

.google-btn {
    background: white;
    color: #333;
    font-weight: 500;
}

.google-icon {
    width: 24px;
    height: 24px;
    margin-right: 0.5rem;
}

.error-msg {
    color: var(--danger);
    font-size: 0.85rem;
    text-align: center;
    margin-top: 1rem;
    min-height: 20px;
}

/* --- 3. HOME SCREEN --- */
.top-bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.avatar {
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.username {
    font-weight: 700;
}

.elo-badge {
    font-size: 0.75rem;
    color: var(--accent);
}

.rank-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    background: rgba(255, 215, 0, 0.15);
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 600;
}

.home-content {
    width: 100%;
    max-width: 500px;
    text-align: center;
    margin-top: 4rem;
}

.main-title {
    font-size: 3.5rem;
    background: linear-gradient(to right, var(--primary), #00b0ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 2rem;
    text-shadow: 0 4px 20px rgba(0, 255, 136, 0.2);
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.menu-btn {
    display: flex;
    align-items: center;
    padding: 1.25rem;
    border: none;
    border-radius: var(--radius-lg);
    font-size: 1.2rem;
    font-weight: 700;
    color: white;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}

.menu-btn:hover {
    transform: scale(1.02);
}

.ai-btn {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    box-shadow: 0 4px 15px rgba(56, 239, 125, 0.3);
}

.online-btn {
    background: linear-gradient(135deg, #2193b0 0%, #6dd5ed 100%);
    box-shadow: 0 4px 15px rgba(33, 147, 176, 0.3);
}

.leaderboard-btn {
    background: linear-gradient(135deg, #8E2DE2 0%, #4A00E0 100%);
    box-shadow: 0 4px 15px rgba(142, 45, 226, 0.3);
}

.profile-btn {
    background: linear-gradient(135deg, #f12711 0%, #f5af19 100%);
    box-shadow: 0 4px 15px rgba(245, 175, 25, 0.3);
}

.btn-icon {
    font-size: 1.5rem;
    margin-right: 1rem;
}

/* --- 4. MODE SCREEN --- */
.mode-content {
    width: 100%;
    max-width: 600px;
}

.mode-content h2 {
    text-align: center;
    margin-bottom: 2rem;
}

.difficulty-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

@media (min-width: 600px) {
    .difficulty-cards {
        grid-template-columns: 1fr 1fr;
    }
}

.diff-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    position: relative;
    overflow: hidden;
}

.diff-card:hover {
    transform: translateY(-2px);
}

.diff-card.selected {
    border-color: var(--primary);
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
    transform: translateY(-2px);
}

.diff-card.selected.easy { border-color: var(--primary); box-shadow: 0 0 20px rgba(0, 255, 136, 0.3); }
.diff-card.selected.medium { border-color: #ffeb3b; box-shadow: 0 0 20px rgba(255, 235, 59, 0.3); }
.diff-card.selected.hard { border-color: var(--danger); box-shadow: 0 0 20px rgba(255, 51, 102, 0.3); }
.diff-card.selected.legend { border-color: #9c27b0; box-shadow: 0 0 20px rgba(156, 39, 176, 0.3); }

.diff-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
}

.diff-card.easy::before { background: var(--primary); }
.diff-card.easy:hover { border-color: var(--primary); }

.diff-card.medium::before { background: #ffeb3b; }
.diff-card.medium:hover { border-color: #ffeb3b; }

.diff-card.hard::before { background: var(--danger); }
.diff-card.hard:hover { border-color: var(--danger); }

.diff-card.legend::before { background: #9c27b0; }
.diff-card.legend:hover { border-color: #9c27b0; }

.diff-indicator {
    font-size: 2rem;
    margin-right: 1rem;
}

.diff-info h3 {
    margin-bottom: 0.25rem;
    font-size: 1.1rem;
}

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

.time-selector {
    margin-bottom: 2rem;
    text-align: center;
}

.time-pills {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.time-pill {
    background: rgba(255,255,255,0.1);
    border: none;
    padding: 0.5rem 1.5rem;
    border-radius: 20px;
    color: white;
    cursor: pointer;
    transition: 0.2s;
}

.time-pill.active {
    background: var(--primary);
    color: black;
    font-weight: bold;
}

/* --- 5. GAME SCREEN --- */
#game-screen {
    padding: 0;
    justify-content: flex-start;
}

.game-layout {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.scoreboard {
    background: var(--score-bg);
    padding: 0.5rem 1rem 1rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    z-index: 10;
}

.match-title {
    text-align: center;
    font-size: 0.75rem;
    font-weight: 800;
    color: rgba(255,255,255,0.5);
    letter-spacing: 2px;
    margin-bottom: 0.5rem;
}

.scoreboard-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 800px;
    margin: 0 auto;
}

.player-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
}

.p2-card {
    justify-content: flex-end;
}

/* Hexagon Avatar */
.hex-avatar-wrapper {
    position: relative;
    width: 50px;
    height: 50px;
}

.hex-avatar {
    width: 100%;
    height: 100%;
    background: #2a3a60;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    position: absolute;
    z-index: 2;
}

.hex-avatar-wrapper::before {
    content: '';
    position: absolute;
    top: -2px; left: -2px; right: -2px; bottom: -2px;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    z-index: 1;
}

.hex-avatar-wrapper.p1::before { background: var(--primary); }
.hex-avatar-wrapper.p2::before { background: var(--danger); }

.player-info {
    display: flex;
    flex-direction: column;
}

.right-align {
    text-align: right;
}

.p-name {
    font-weight: 700;
    font-size: 1rem;
}

.p-elo {
    font-size: 0.75rem;
    color: var(--accent);
}

.timer-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 1rem;
}

.time-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 800;
}

#game-timer {
    font-size: 1.5rem;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
}

/* Score Row */
.score-progress-row {
    background: #091024;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    z-index: 9;
}

.score-left, .score-right {
    font-size: 2.5rem;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    min-width: 60px;
}

.score-left { color: var(--primary); text-align: right; }
.score-right { color: var(--danger); text-align: left; }

.progress-bar {
    flex: 1;
    height: 20px;
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
    position: relative;
    overflow: hidden;
}

.progress-fill {
    position: absolute;
    top: 0;
    height: 100%;
    width: 0%;
    transition: width 0.3s ease-out;
}

.fill-left {
    left: 0;
    background: var(--primary);
    box-shadow: 0 0 10px rgba(0,255,136,0.5);
}

.fill-right {
    right: 0;
    background: var(--danger);
    box-shadow: 0 0 10px rgba(255,51,102,0.5);
}

.progress-center-mark {
    position: absolute;
    left: 50%;
    top: -5px;
    bottom: -5px;
    width: 2px;
    background: white;
    z-index: 3;
}

/* Camera Area */
.camera-area {
    flex: 1;
    position: relative;
    background: #000;
    overflow: hidden;
}

#game-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* Mirror */
}

#game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    pointer-events: none;
}

.camera-status-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #05050a;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    z-index: 8;
    color: var(--text-muted);
    font-weight: 500;
}

.pushup-counter-container {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
}

.coin {
    width: 80px;
    height: 80px;
    background: radial-gradient(circle at 30% 30%, #fff700, #b38f00);
    border: 4px solid #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 900;
    color: #4a3300;
    text-shadow: 1px 1px 0px rgba(255,255,255,0.5);
    box-shadow: 0 10px 20px rgba(0,0,0,0.5), inset 0 -5px 10px rgba(0,0,0,0.3);
}

.quit-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 51, 102, 0.15);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s;
    z-index: 10;
}

.quit-btn:hover {
    background: var(--danger);
    color: white;
    box-shadow: 0 0 15px rgba(255, 51, 102, 0.4);
    transform: translateY(-1px);
}

/* Countdown Overlay */
.overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.overlay.hidden {
    display: none;
}

#countdown-text {
    font-size: 8rem;
    font-weight: 900;
    color: white;
    text-shadow: 0 0 30px rgba(255,255,255,0.5);
}

/* --- 6. RESULT SCREEN --- */
.result-card {
    text-align: center;
    width: 100%;
    max-width: 500px;
}

#result-title {
    font-size: 3rem;
    margin-bottom: 2rem;
}

.score-comparison {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    margin-bottom: 2rem;
}

.final-score {
    display: flex;
    flex-direction: column;
}

.score-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 700;
}

.score-val {
    font-size: 3rem;
    font-weight: 900;
}

.p1-final .score-val { color: var(--primary); }
.p2-final .score-val { color: var(--danger); }

.vs-text {
    font-weight: 800;
    color: rgba(255,255,255,0.2);
    font-size: 1.5rem;
}

.elo-change {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 2rem;
}

.elo-change.positive { color: var(--primary); }
.elo-change.negative { color: var(--danger); }

.result-actions {
    display: flex;
    gap: 1rem;
}

/* --- 7. LEADERBOARD SCREEN --- */
.leaderboard-container {
    width: 100%;
    max-width: 700px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.leaderboard-container h2 {
    text-align: center;
}

.table-wrapper {
    overflow-y: auto;
    flex: 1;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    position: sticky;
    top: 0;
    background: rgba(26,26,46,0.95);
}

tbody tr:hover {
    background: rgba(255,255,255,0.05);
}

/* --- 8. PROFILE SCREEN --- */
.profile-container {
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.profile-avatar {
    width: 80px;
    height: 80px;
    font-size: 2.5rem;
    background: #2a3a60;
}

.profile-title h2 {
    margin-bottom: 0.5rem;
}

.profile-badges {
    display: flex;
    gap: 0.5rem;
}

.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.badge.rank {
    background: rgba(255, 215, 0, 0.15);
    color: var(--accent);
}

.badge.elo {
    background: rgba(0, 255, 136, 0.15);
    color: var(--primary);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: rgba(0,0,0,0.2);
    padding: 1rem;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
}

.stat-card.full-width {
    grid-column: span 2;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.stat-val {
    font-size: 1.5rem;
    font-weight: 800;
}

.match-history-section h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.history-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* --- ANIMATIONS --- */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

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

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

@keyframes countdownPop {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes scorePopup {
    0% { transform: scale(1); }
    50% { transform: scale(1.5); }
    100% { transform: scale(1); }
}

@keyframes coinFlip {
    0% { transform: perspective(400px) rotateY(0deg); }
    100% { transform: perspective(400px) rotateY(360deg); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.5s ease;
}

/* Match History Items */
.match-history-item {
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.match-history-item:hover {
    background: rgba(255,255,255,0.05) !important;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .scoreboard-inner { gap: 0.25rem; }
    .hex-avatar-wrapper { width: 40px; height: 40px; }
    .hex-avatar { font-size: 1.2rem; }
    .p-name { font-size: 0.85rem; }
    .p-elo { font-size: 0.7rem; }
    #game-timer { font-size: 1.2rem; }
    .score-left, .score-right { font-size: 2rem; min-width: 40px; }
    .coin { width: 65px; height: 65px; font-size: 2rem; }
    #result-title { font-size: 2.5rem; }
    .score-val { font-size: 2.5rem; }
    .main-title { font-size: 2.5rem; }
    .menu-btn { font-size: 1rem; }
}
