/* ==========================================================================
   1. FONTS & VARIABLES
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@600;700;800&family=Outfit:wght@400;500;600;700;800&display=swap');

:root {
    --telegram-blue: #0088cc;
    --telegram-blue-dark: #006ba3;
    --telegram-blue-light: #40a7e3;
    --telegram-bg: #17212b;
    --telegram-secondary: #242f3d;

    --blue-team: #2196f3;
    --red-team: #e53935;

    --success: #2ecc71;
    --danger: #e74c3c;
    --warning: #f39c12;

    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;

    --text-primary: #212121;
    --text-secondary: #757575;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    --board-max-width: 1280px;
    --board-max-height: 520px;
    --board-gap: clamp(10px, 1.6vw, 20px);

    --title-size: clamp(18px, 2.2vw, 30px);
    --panel-title-size: clamp(14px, 1.4vw, 16px);
    --problem-size: clamp(24px, 3.5vh, 38px);
    --input-size: clamp(16px, 2.4vh, 26px);
    --key-size: clamp(18px, 2.6vh, 24px);
}

/* ==========================================================================
   2. BASE & TYPOGRAPHY
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #f0f3f7;
    color: var(--text-primary);
    height: 100svh;
    overflow: hidden;
    display: grid;
    grid-template-rows: auto 1fr auto;
    align-items: stretch;
    user-select: none;
    -webkit-user-select: none;
}

/* Apple-Tier Typography: Outfit for UI, Nunito for Numbers */
.game-header h1, .start-modal h2, .setup-step h3, .team-header, .score-item span {
    letter-spacing: 0.3px;
    font-weight: 700;
}

.problem-display, .answer-input, .key-btn, .score-badge, .score-value, 
.timer-display, .splash-title, .stat-item span {
    font-family: 'Inter', sans-serif;
    font-weight: 700;
}

#backgroundMusic { display: none; }

/* ==========================================================================
   3. HEADER, FOOTER & CONTROLS
   ========================================================================== */
.game-header, .game-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 10px 20px;
    background: var(--bg-secondary);
    position: relative;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
    gap: 10px;
}

.header-left, .header-right, .footer-left, .footer-right { flex: 1; display: flex; align-items: center; }
.header-left, .footer-left { justify-content: flex-start; }
.header-right, .footer-right { justify-content: flex-end; }
.header-center, .footer-center { flex: 2; display: flex; justify-content: center; text-align: center; }

.game-header h1 {
    font-size: var(--title-size);
    background: linear-gradient(135deg, var(--telegram-blue), var(--telegram-blue-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.game-footer p { font-size: clamp(12px, 1.4vh, 14px); }
.game-footer a { color: var(--telegram-blue); font-weight: 600; text-decoration: none; }

/* Buttons & Icons */
/* Buttons & Icons */
.home-btn, .lang-toggle, .view-controls, .icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 40px; /* Locks every button to the exact same height */
    border-radius: 14px; /* Uniform modern curve for all buttons */
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: var(--bg-secondary);
    box-shadow: var(--shadow-md);
    color: var(--telegram-blue-dark);
    cursor: pointer;
    transition: var(--transition);
}

/* Give text-based buttons padding */
.home-btn, .lang-toggle {
    padding: 0 14px;
    gap: 8px;
    font-weight: 800;
}

/* Make icon-only buttons perfect squares */
.icon-btn {
    width: 40px; 
}

/* Style the zoom controls container and inside buttons */
.view-controls {
    padding: 0 6px;
    gap: 2px;
}

/* Make the inner buttons slightly smaller */
.view-btn {
    width: 30px; 
    height: 30px; 
    border: none; 
    border-radius: 8px; 
    cursor: pointer; 
    background: transparent; 
    color: var(--telegram-blue-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

/* Scale the plus/minus icons down to match the header text */
.view-btn i { 
    font-size: 14px; 
}

/* Add a subtle hover effect ONLY to the individual + and - buttons */
.view-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    transform: scale(1.1);
}
.view-btn:active { 
    transform: scale(0.95); 
}

/* Scale the center magnifying glass down to match */
.zoom-icon-anchor {
    font-size: 14px;
    color: var(--telegram-blue-dark);
    margin: 0 4px;
    opacity: 0.6;
    pointer-events: none;
}

.home-btn:hover, .lang-toggle:hover, .icon-btn:hover { 
    transform: translateY(-2px); 
    box-shadow: var(--shadow-lg); 
}

/* Language Dropdown */
.language-selector { position: relative; z-index: 100; }
.lang-flag { width: 28px; height: 20px; border-radius: 6px; overflow: hidden; display: block; }
.lang-flag img { width: 100%; height: 100%; object-fit: cover; }
.lang-menu {
    position: absolute; right: 0; top: calc(100% + 5px); min-width: 160px;
    background: var(--bg-secondary); border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 14px; padding: 6px; box-shadow: var(--shadow-md);
    display: grid; gap: 6px; opacity: 0; pointer-events: none;
    transform: translateY(-6px); transition: var(--transition);
}
.language-selector.open .lang-menu { opacity: 1; pointer-events: auto; transform: translateY(0); }
.lang-menu .lang-btn {
    width: 100%; background: var(--bg-primary); border-radius: 10px; padding: 8px 10px;
    cursor: pointer; display: flex; align-items: center; gap: 8px;
    font-size: 13px; font-weight: 700; border: 1px solid transparent; color: var(--text-primary);
}
.lang-menu .lang-btn img { width: 24px; height: 18px; border-radius: 5px; }
.lang-menu .lang-btn.active { border-color: var(--telegram-blue); background: rgba(0, 136, 204, 0.12); color: var(--telegram-blue-dark); }

/* View & Social Controls */
.view-btn { width: 34px; height: 34px; border: none; border-radius: 10px; cursor: pointer; background: #f2f5f9; color: var(--telegram-blue-dark); }
.view-label { min-width: 54px; text-align: center; font-weight: 800; font-size: 13px; color: var(--telegram-blue-dark); }
.social-links { display: flex; justify-content: center; gap: 14px; }
.social-link { width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,0.92); border: 1px solid rgba(0,0,0,0.08); display: grid; place-items: center; color: var(--telegram-blue); transition: var(--transition); }
.social-link:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

/* ==========================================================================
   4. SPLASH LOADER
   ========================================================================== */
.splash-loader {
    position: fixed; inset: 0; z-index: 9999;
    background: radial-gradient(circle at center, var(--telegram-bg), #0a0f14);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: #fff; transition: opacity 0.6s ease-in-out;
}
.splash-title {
    font-size: clamp(24px, 5vw, 42px); margin-bottom: 30px;
    background: linear-gradient(135deg, var(--telegram-blue-light), var(--telegram-blue));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    animation: popIn 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.loader-pulse { font-size: 48px; color: var(--telegram-blue); margin-bottom: 20px; animation: heartbeat 1.2s infinite; }
.loading-bar-container { width: 250px; height: 8px; background: rgba(255, 255, 255, 0.1); border-radius: 10px; overflow: hidden; margin-bottom: 10px; }
.loading-bar { width: 0%; height: 100%; background: var(--telegram-blue); border-radius: 10px; animation: loadProgress 1.5s ease-out forwards; }
.loading-text { font-size: 14px; font-weight: 700; color: rgba(255, 255, 255, 0.6); letter-spacing: 2px; text-transform: uppercase; animation: blink 1.5s infinite; }

/* ==========================================================================
   5. SETUP MENUS & MODALS
   ========================================================================== */
.modal-overlay {
    position: fixed; inset: 0; z-index: 999;
    background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
}
.start-modal {
    background: rgba(255, 255, 255, 0.96); backdrop-filter: blur(15px);
    border: 2px solid rgba(255, 255, 255, 0.5); box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    border-radius: 24px; padding: 40px 30px; width: min(720px, 92vw); max-height: min(86svh, 680px);
    overflow: hidden; animation: slideUp 0.35s ease;
}
.start-modal h2 { font-size: clamp(28px, 4vw, 36px); text-transform: uppercase; color: var(--telegram-blue); text-align: center; margin-bottom: 30px; }
.setup-step h3 { font-size: 20px; color: var(--text-primary); text-align: center; margin-bottom: 10px; }
.setup-hint { text-align: center; color: var(--text-secondary); font-size: 13px; margin-bottom: 14px; }

.setup-steps { position: relative; min-height: 260px; display: flex; flex-direction: column; }
.setup-step { opacity: 0; transform: translateX(16px); pointer-events: none; transition: all 0.25s ease; display: none; }
.setup-step.active { opacity: 1; transform: translateX(0); pointer-events: auto; display: block; }

/* Setup Buttons (High Contrast Chunky UI) */
.operation-buttons { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.difficulty-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; width: 100%; }

.operation-btn, .difficulty-btn, .chunky-toggle-btn {
    background: #ffffff; border: 2px solid #cbd5e1; border-bottom-width: 6px;
    border-radius: 16px; cursor: pointer; transition: all 0.15s ease;
}
.operation-btn { padding: 14px 12px; display: flex; align-items: center; gap: 12px; }
.difficulty-btn { padding: 16px 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }

.operation-btn:active, .difficulty-btn:active, .chunky-toggle-btn:active { border-bottom-width: 3px; transform: translateY(3px); }

/* Active Glow States */
.operation-btn.active, .difficulty-btn.active, .chunky-toggle-btn.active {
    background: #f0f9ff; border-color: var(--telegram-blue);
}

/* Icon Circles */
.op-symbol, .difficulty-btn i, .chunky-toggle-btn i {
    background: #e2e8f0; color: #475569; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    width: 48px; height: 48px; min-width: 48px; min-height: 48px; flex-shrink: 0;
}
.op-symbol { font-size: 24px; }
.difficulty-btn i, .chunky-toggle-btn i { font-size: 20px; margin-bottom: 8px; }

.operation-btn.active .op-symbol, .difficulty-btn.active i, .chunky-toggle-btn.active i {
    background: var(--telegram-blue); color: #ffffff;
}
.op-text, .difficulty-btn span { color: #1e293b; font-weight: 800; font-size: 14px; }

/* Side-by-Side Teams (Step 3) */
.mode-selector-chunky { display: flex; gap: 12px; margin-bottom: 24px; }
.chunky-toggle-btn { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 16px 8px; font-weight: 800; color: #1e293b; }

.team-setup-side-by-side { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; }
.team-card {
    flex: 1; display: flex; flex-direction: column; background: #ffffff; border: 2px solid #cbd5e1;
    border-bottom-width: 6px; border-radius: 16px; overflow: hidden; transition: all 0.2s ease;
}
.team-card:focus-within { border-color: var(--telegram-blue); transform: translateY(-2px); }
.team-header { display: flex; justify-content: center; align-items: center; gap: 6px; padding: 8px 4px; color: #ffffff; font-size: 13px; text-transform: uppercase; }
.blue-team-card .team-header { background: var(--blue-team); }
.red-team-card .team-header { background: var(--red-team); }
.team-card input { width: 100%; border: none; background: transparent; padding: 12px 6px; text-align: center; font-size: 16px; font-weight: 800; color: #1e293b; outline: none; }
.vs-badge-circle { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; background: #e2e8f0; color: #475569; font-weight: 900; font-size: 14px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 4px 6px rgba(0,0,0,0.05); }

/* Setup Nav Buttons */
.setup-nav { display: flex; gap: 12px; justify-content: center; margin-top: 18px; }
.primary-btn, .secondary-btn {
    padding: 12px 16px; font-size: 16px; font-weight: 800; border-radius: var(--radius-md);
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
    transition: var(--transition); border: none; box-shadow: var(--shadow-md);
}
.primary-btn { color: #fff; background: linear-gradient(135deg, var(--telegram-blue), var(--telegram-blue-dark)); }
.secondary-btn { color: var(--text-primary); background: #fff; border: 2px solid rgba(0,0,0,0.08); }
.primary-btn:hover, .secondary-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.primary-btn:active, .secondary-btn:active { transform: translateY(0); box-shadow: var(--shadow-sm); }
.nav-btn { min-width: 180px; }

/* Countdown Overlay */
.countdown-overlay {
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.82); display: none; align-items: center; justify-content: center;
    z-index: 998; font-size: clamp(56px, 10vw, 90px); font-weight: 900; color: #fff; text-shadow: 0 0 22px rgba(0, 136, 204, 0.9);
}
.countdown-overlay.go { color: var(--success); }

/* ==========================================================================
   6. MAIN GAME BOARD & KEYPAD
   ========================================================================== */
.game-shell { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; padding: 0 clamp(10px, 1.8vw, 18px); overflow: hidden; }
.game-stage { --game-scale: 1; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; transform: scale(var(--game-scale)); }
.game-board {
    width: var(--board-max-width); height: var(--board-max-height); display: grid; gap: var(--board-gap);
    grid-template-columns: 0.92fr 1.7fr 0.92fr; grid-template-areas: 'left arena right';
}

.panel-left { grid-area: left; border-top: 4px solid var(--blue-team); }
.panel-right { grid-area: right; border-top: 4px solid var(--red-team); }
.arena-container { grid-area: arena; background: var(--bg-secondary); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 12px; display: flex; flex-direction: column; }

.calculator-panel { background: var(--bg-secondary); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden; }
.panel-header { padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; font-size: var(--panel-title-size); }
.panel-left .panel-header { background: linear-gradient(135deg, var(--blue-team), #1976d2); color: #fff; }
.panel-right .panel-header { background: linear-gradient(135deg, var(--red-team), #c62828); color: #fff; }
.panel-header h3 { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Badges */
.score-badge { background: #fff; color: var(--telegram-blue); padding: 4px 10px; border-radius: 18px; font-size: clamp(16px, 2.2vh, 20px); min-width: 36px; text-align: center; }
.streak-badge { background: linear-gradient(135deg, var(--warning), #d35400); color: #fff; padding: 4px 8px; border-radius: 14px; font-size: clamp(12px, 1.8vh, 16px); display: inline-flex; align-items: center; gap: 4px; box-shadow: var(--shadow-sm); animation: pulseStreak 1.2s infinite; }

/* Problem & Inputs */
.problem-display { padding: 10px; text-align: center; font-size: var(--problem-size); min-height: 52px; display: flex; align-items: center; justify-content: center; }
.panel-left .problem-display { background: #e3f2fd; color: var(--blue-team); }
.panel-right .problem-display { background: #ffebee; color: var(--red-team); }


.answer-input { width: calc(100% - 28px); margin: 8px 14px 10px; padding: 8px 10px; font-size: var(--input-size); letter-spacing: 2px; text-align: center; border-radius: 12px; border: 2px solid #e0e0e0; transition: var(--transition); }
.answer-input:focus { outline: none; border-color: var(--telegram-blue); box-shadow: 0 0 0 3px rgba(0, 136, 204, 0.15); }

/* Input Colors */
.answer-input.correct { background: #d4edda; border-color: var(--success); }
.answer-input.incorrect { background: #f8d7da; border-color: var(--danger); animation: shakeInput 0.4s; }

/* Keypad */
/* Chunky 3D Keypad Buttons */
.keypad { flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(4, 1fr); gap: 8px; padding: 12px; background: var(--bg-primary); }

.key-btn { 
    border: 2px solid #cbd5e1; 
    border-bottom-width: 6px; 
    border-radius: 12px; 
    cursor: pointer; 
    background: #ffffff; 
    color: #1e293b;
    font-size: var(--key-size); 
    font-weight: 900;
    transition: all 0.05s linear; /* Ultra-snappy response for that physical click feel */
}

/* The actual "press down" effect */
.key-btn:active { 
    border-bottom-width: 2px; 
    transform: translateY(4px); 
}

/* Keep disabled buttons pressed down so they look visibly inactive */
.key-btn:disabled { 
    opacity: 0.6; 
    cursor: not-allowed; 
    border-bottom-width: 2px; 
    transform: translateY(4px); 
}

/* Special Action Buttons */
/* Vibrant Amber Clear Button */
.key-clear { 
    background: #f59e0b; 
    color: #ffffff; 
    border-color: #d97706; 
}

/* Dark Mode Fix */
body.dark-theme .key-clear { 
    background: #d97706; 
    border-color: #b45309; 
    color: #ffffff; 
}

/* Vibrant Green Submit Button */
.key-submit { 
    background: #22c55e; /* Bright, playful green */
    color: #ffffff; 
    border-color: #16a34a; /* Deeper green for the 3D edge */
}
/* AI Locked Overlay */
.locked-mode .keypad { position: relative; overflow: hidden; }
.locked-mode .keypad::after {
    content: "\f023"; font-family: "Font Awesome 6 Free"; font-weight: 900;
    position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
    font-size: 56px; background: rgba(255, 255, 255, 0.4); backdrop-filter: blur(3px); color: rgba(0, 0, 0, 0.4); cursor: not-allowed;
}

/* ==========================================================================
   7. ARENA & VIDEO
   ========================================================================== */
/* Modern Apple-Style Floating Scoreboard */
/* Full-Width Floating Scoreboard */
.arena-scoreboard { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    background: #ffffff; 
    border-radius: 20px; 
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06); 
    padding: 10px 20px; 
    margin-bottom: 12px; 
    width: 100%; /* Stretches across the entire arena width */
    border: 1px solid rgba(0, 0, 0, 0.04);
}

/* Push Team A to the far left */
.score-item.left-side { 
    flex: 1; /* Takes up equal space on the left */
    display: flex; 
    align-items: center; 
    justify-content: flex-start; /* Pins content to the left edge */
    gap: 12px; 
}

/* Push Team B to the far right */
.score-item.right-side { 
    flex: 1; /* Takes up equal space on the right */
    display: flex; 
    align-items: center; 
    justify-content: flex-end; /* Pins content to the right edge */
    gap: 12px; 
}

/* Ensure the timer stays perfectly centered */
.timer-display { 
    flex: 0 1 auto;
    display: flex; 
    align-items: center; 
    gap: 8px; 
    background: #f1f5f9; 
    padding: 8px 16px; 
    border-radius: 16px; 
    font-size: 18px; 
    font-family: 'Nunito', sans-serif;
    font-weight: 800; 
    color: #334155; 
    letter-spacing: 1px;
}

.team-name {
    font-size: 14px;
    font-weight: 800;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90px;
}

/* Vibrant Score Badges */
.score-value { 
    font-size: 20px; 
    font-family: 'Nunito', sans-serif;
    font-weight: 900; 
    width: 42px; 
    height: 42px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    border-radius: 14px; 
    color: #ffffff; 
}

#leftCorrectCount { 
    background: var(--blue-team); 
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.35); 
}

#rightCorrectCount { 
    background: var(--red-team); 
    box-shadow: 0 4px 12px rgba(229, 57, 53, 0.35); 
}

/* Central Timer Bubble */
.timer-display { 
    display: flex; 
    align-items: center; 
    gap: 8px; 
    background: #f1f5f9; 
    padding: 8px 16px; 
    border-radius: 16px; 
    font-size: 18px; 
    font-family: 'Nunito', sans-serif;
    font-weight: 800; 
    color: #334155; 
    letter-spacing: 1px;
}


.arena { position: relative; flex: 1; width: 100%; background: #ffffff; border-radius: 14px; margin-top: 12px; display: flex; align-items: center; justify-content: center; overflow: hidden; box-shadow: 0 3px 12px rgba(0,0,0,0.12); }
.center-line { position: absolute; left: 48%; top: 0; bottom: 0; width: 2px; background: repeating-linear-gradient(to bottom, #333 0, #333 8px, transparent 8px, transparent 16px); transform: translateX(-50%); z-index: 2; opacity: 0.7; }

.rope-container { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 92%; transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1); z-index: 1; }
.rope-container video { width: 100%; height: auto; display: block; }
#win-video, .win-video-wrap { position: absolute; left: 50%; top: 15%; transform: translate(-50%, -50%); width: 92%; z-index: 3; pointer-events: none; }
.win-video { position: absolute; inset: 0; width: 100%; }

/* Block Browser Video Popups (Opera Shield) */
.rope-container video, .win-video-wrap video { pointer-events: none; user-select: none; }
.rope-container::after, .win-video-wrap::after { content: ""; position: absolute; inset: 0; z-index: 90; background: rgba(255, 255, 255, 0); cursor: default; }

/* ==========================================================================
   8. WINNER SCREEN (APPLE ARCADE STYLE)
   ========================================================================== */
.winner-overlay {
    position: absolute; inset: 0; z-index: 99999 !important; /* Overrides AI keypads */
    background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(8px);
    display: none; align-items: center; justify-content: center;
}
.winner-content {
    background: rgba(255, 255, 255, 0.98); border: 2px solid #cbd5e1; border-bottom-width: 8px;
    border-radius: 28px; padding: 40px 30px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,0.25);
    max-width: 420px; width: 90%; animation: popIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.trophy-animation { font-size: 64px; color: #f59e0b; margin-bottom: 16px; filter: drop-shadow(0 4px 6px rgba(245,158,11,0.3)); animation: heartbeat 1.5s infinite; }
.winner-title { font-size: 32px; font-weight: 900; color: #1e293b; margin-bottom: 4px; text-transform: uppercase; }
.winner-message { font-size: 16px; font-weight: 800; color: #64748b; margin-bottom: 24px; letter-spacing: 1px; }

.winner-stats { display: flex; gap: 12px; margin-bottom: 30px; }
.stat-item { flex: 1; background: #f8fafc; border: 2px solid #e2e8f0; border-bottom-width: 4px; border-radius: 16px; padding: 16px 10px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stat-item i { font-size: 20px; color: var(--telegram-blue); margin-bottom: 4px; }
.stat-item span { font-size: 32px; color: #1e293b; line-height: 1; }
.stat-item small { font-size: 11px; color: #64748b; text-transform: uppercase; }

.winner-content .primary-btn { width: 100%; padding: 16px; font-size: 18px; border-bottom-width: 6px; border-radius: 16px; }
.winner-content .primary-btn:active { border-bottom-width: 2px; transform: translateY(4px); }

/* ==========================================================================
   9. DARK MODE THEME
   ========================================================================== */
body.dark-theme {
    --bg-primary: #17212b;      
    --bg-secondary: #242f3d;    
    --text-primary: #f5f5f5;
    --text-secondary: #aab8c2;
    background-color: #0e1621;
}

body.dark-theme .secondary-btn, 
body.dark-theme .icon-btn, 
body.dark-theme .lang-toggle, 
body.dark-theme .home-btn,
body.dark-theme .view-controls,
body.dark-theme .view-btn { 
    background: var(--bg-secondary); 
    color: var(--text-primary); 
    border-color: rgba(255,255,255,0.1); 
}

body.dark-theme .arena-scoreboard { background: var(--bg-secondary); border-color: rgba(255,255,255,0.05); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); }
body.dark-theme .timer-display { background: var(--bg-primary); color: #e2e8f0; }
body.dark-theme .team-name { color: #94a3b8; }
body.dark-theme .arena { background: #ffffff; }

body.dark-theme .keypad, body.dark-theme .operation-btn, 
body.dark-theme .difficulty-btn, body.dark-theme .team-box { background: var(--bg-primary); }

/* Dark Mode Chunky Keypad */
body.dark-theme .key-btn { 
    background: #1e293b; 
    color: #f8fafc; 
    border-color: #334155; 
}



body.dark-theme .key-submit { 
    background: #16a34a; 
    border-color: #15803d; 
    color: #ffffff; 
}
body.dark-theme .key-clear { 
    background: #d97706; 
    border-color: #b45309; 
    color: #ffffff; 
}

body.dark-theme .secondary-btn, body.dark-theme .icon-btn, 
body.dark-theme .lang-toggle, body.dark-theme .home-btn { background: var(--bg-secondary); color: var(--text-primary); border-color: rgba(255,255,255,0.1); }

body.dark-theme .answer-input { background: var(--bg-primary); color: var(--text-primary); border-color: var(--bg-primary); }
body.dark-theme .answer-input.correct { background: rgba(46, 204, 113, 0.15); border-color: var(--success); color: var(--success); }
body.dark-theme .answer-input.incorrect { background: rgba(231, 76, 60, 0.15); border-color: var(--danger); color: var(--danger); }

body.dark-theme .start-modal { background: rgba(23, 33, 43, 0.85); border: 2px solid rgba(255,255,255,0.1); box-shadow: 0 20px 50px rgba(0,0,0,0.6); }
body.dark-theme .operation-btn, body.dark-theme .difficulty-btn, 
body.dark-theme .chunky-toggle-btn, body.dark-theme .team-card { background: #1e293b; border-color: #334155; }
body.dark-theme .op-symbol, body.dark-theme .difficulty-btn i, body.dark-theme .chunky-toggle-btn i { background: #0f172a; color: #cbd5e1; }
body.dark-theme .op-text, body.dark-theme .setup-step h3, body.dark-theme .difficulty-btn span, body.dark-theme .chunky-toggle-btn span, body.dark-theme .team-card input { color: #f8fafc; }
body.dark-theme .operation-btn.active, body.dark-theme .difficulty-btn.active, body.dark-theme .chunky-toggle-btn.active { background: rgba(56, 189, 248, 0.1); border-color: #38bdf8; }
body.dark-theme .operation-btn.active .op-symbol, body.dark-theme .difficulty-btn.active i, body.dark-theme .chunky-toggle-btn.active i { background: #38bdf8; color: #0f172a; }
body.dark-theme .vs-badge-circle { background: #0f172a; color: #cbd5e1; }

body.dark-theme .winner-content { background: #0f172a; border-color: #334155; box-shadow: 0 20px 50px rgba(0,0,0,0.7); }
body.dark-theme .winner-title, body.dark-theme .stat-item span { color: #f8fafc; }
body.dark-theme .winner-message, body.dark-theme .stat-item small { color: #94a3b8; }
body.dark-theme .stat-item { background: #1e293b; border-color: #334155; }
body.dark-theme .locked-mode .keypad::after { background: rgba(23, 33, 43, 0.6); color: rgba(255, 255, 255, 0.2); }

/* ==========================================================================
   10. ANIMATIONS & EFFECTS
   ========================================================================== */
@keyframes slideUp { from { opacity: 0; transform: translateY(40px) scale(var(--modal-scale)); } to { opacity: 1; transform: translateY(0) scale(var(--modal-scale)); } }
@keyframes shakeInput { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes pulseStreak { 0% { box-shadow: 0 0 0 0 rgba(243, 156, 18, 0.7); } 70% { box-shadow: 0 0 0 8px rgba(243, 156, 18, 0); } 100% { box-shadow: 0 0 0 0 rgba(243, 156, 18, 0); } }
@keyframes popIn { 0% { opacity: 0; transform: scale(0.8); } 100% { opacity: 1; transform: scale(1); } }
@keyframes heartbeat { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }
@keyframes loadProgress { 0% { width: 0%; } 40% { width: 60%; } 80% { width: 85%; } 100% { width: 100%; } }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes confettiFall { to { transform: translateY(110vh) rotate(360deg); opacity: 0; } }

.confetti { position: absolute; width: 8px; height: 8px; border-radius: 50%; animation: confettiFall 3s linear; pointer-events: none; z-index: 6; }
.operation-btn.shake { animation: shakeInput 0.35s; }

/* ==========================================================================
   11. RESPONSIVE DESIGN (MEDIA QUERIES) & RTL
   ========================================================================== */
/* RTL Logic */
html, body { max-width: 100vw; overflow-x: hidden; }
html[dir="rtl"] .lang-menu { right: auto; left: 0; }

@media (max-width: 820px) {
    :root { --board-max-height: 100%; }
    .game-board { grid-template-columns: 1fr 1fr; grid-template-rows: 0.82fr 1.18fr; grid-template-areas: 'arena arena' 'left right'; }
    .calculator-panel { height: 100%; }
    .keypad { align-content: stretch; grid-auto-rows: minmax(0, 1fr); gap: clamp(8px, 1.6vw, 10px); }
}


@media (max-width: 768px) {
    /* 1. Hide Footer completely to maximize game space */
    .game-footer { display: none !important; }
    
    /* 2. Show the Gear Icon */
    #settingsToggleBtn { display: inline-flex !important; }

    /* 3. Transform the controls group into a dropdown menu */
    .header-controls-group {
        position: absolute;
        top: calc(100% + 10px);
        right: 20px;
        background: var(--bg-secondary);
        border: 1px solid rgba(0, 0, 0, 0.08);
        border-radius: 16px;
        padding: 12px;
        box-shadow: var(--shadow-lg);
        
        /* Stack them vertically */
        flex-direction: column !important;
        align-items: flex-end !important;
        gap: 12px !important;
        z-index: 1000;
        
        /* Hidden by default on mobile */
        opacity: 0;
        pointer-events: none;
        transform: translateY(-10px);
        transition: var(--transition);
    }

    /* Active class to show the menu */
    .header-controls-group.show {
        opacity: 1;
        pointer-events: auto;
        transform: translateY(0);
    }
}

/* Dark mode support for the dropdown panel */
body.dark-theme .header-controls-group {
    background: var(--bg-secondary);
    border-color: rgba(255,255,255,0.1);
}

@media (max-width: 600px) {
    #viewControls { display: none; } /* Hides zoom on small screens to prevent overlap */
}




@media (max-width: 480px) {
    .game-header { padding: 10px 5px; }
    .game-header h1 { font-size: clamp(14px, 4vw, 18px); }
    .game-footer p { display: none; }
    .lang-flag { width: 24px; height: 18px; }
    .lang-code { font-size: 11px; }
    .lang-menu { min-width: 140px; }
    .setup-steps { min-height: 280px; }
}

@media (max-height: 820px) {
    .modal-content { max-height: min(88svh, 660px); }
    .start-modal { padding: 18px 16px; }
    .start-modal h2 { margin-bottom: 12px; }
    .setup-steps { min-height: 240px; }
}

@media (max-height: 620px) {
    .modal-content { overflow: auto; }
}

@media (hover: none) and (pointer: coarse) {
    .key-btn:hover, .primary-btn:hover, .secondary-btn:hover, .difficulty-btn:hover, .operation-btn:hover { transform: none; box-shadow: none; }
    .key-btn:active, .primary-btn:active, .secondary-btn:active { transform: scale(0.98); }
}


.zoom-icon-anchor {
    font-size: 16px;
    color: var(--telegram-blue-dark);
    margin: 0 4px;
    opacity: 0.7; /* Makes it look like a label rather than a clickable button */
    pointer-events: none; /* Prevents it from interfering with clicks */
}

body.dark-theme .zoom-icon-anchor {
    color: var(--text-primary);
}


body.dark-theme .view-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}


.slim-buttons-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

/* Layout for the row */
.slim-buttons-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

/* The Main Button Card */
.slim-btn {
    display: flex;
    align-items: center;
    justify-content: flex-start; /* Pushes content to the left (or right in Arabic) */
    gap: 12px;
    padding: 12px;
    background: #ffffff;
    border: 2px solid #cbd5e1;
    border-bottom-width: 4px;
    border-radius: 14px;
    cursor: pointer;
    text-align: start; /* Ensures text aligns correctly based on language */
    transition: all 0.15s ease;
}

.slim-btn:active {
    border-bottom-width: 2px;
    transform: translateY(2px);
}

.slim-btn.active {
    background: #f0f9ff;
    border-color: var(--telegram-blue);
}

/* The Icon Circle */
.slim-btn i {
    background: #e2e8f0;
    color: #475569;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    font-size: 16px;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.slim-btn.active i {
    background: var(--telegram-blue);
    color: #ffffff;
}

/* The Stacked Text Wrapper */
.btn-text-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* The Large Title */
.btn-title {
    font-size: 16px;
    font-weight: 900;
    color: #1e293b;
    line-height: 1.1;
}

.slim-btn.active .btn-title {
    color: var(--telegram-blue);
}

/* The Smaller Description */
.btn-desc {
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
    line-height: 1.2;
}


body.dark-theme .slim-btn {
    background: #1e293b;
    border-color: #334155;
}

body.dark-theme .slim-btn.active {
    background: rgba(56, 189, 248, 0.1);
    border-color: #38bdf8;
}

body.dark-theme .btn-title { color: #f8fafc; }
body.dark-theme .btn-desc { color: #94a3b8; }

body.dark-theme .slim-btn i {
    background: #0f172a;
    color: #cbd5e1;
}

body.dark-theme .slim-btn.active i {
    background: #38bdf8;
    color: #0f172a;
}



/* Layout Grids for New Screens */
.slim-buttons-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 2x2 Grid for Math */
    gap: 12px;
}

.slim-buttons-col {
    display: flex;
    flex-direction: column; /* Stacked List for Modes */
    gap: 12px;
}

/* =====================================
   NEW NAVIGATION BUTTONS
   ===================================== */
.setup-navigation {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 24px;
}

.nav-slim-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    border: none;
    border-bottom: 4px solid rgba(0,0,0,0.2);
    transition: all 0.15s ease;
    flex: 1; /* Makes "Back" and "Next" take equal space */
    color: #ffffff;
}

.nav-slim-btn:active {
    transform: translateY(2px);
    border-bottom-width: 2px;
}

/* Gray for Back */
.btn-secondary { background: #94a3b8; }
.btn-secondary:hover { background: #64748b; }

/* Telegram Blue for Next */
.btn-primary { background: var(--telegram-blue); }
.btn-primary:hover { background: var(--telegram-blue-dark); }

/* Green for Start Game */
.btn-success { background: var(--success); }
.btn-success:hover { background: #27ae60; }

/* Automatically flip arrows in Arabic (RTL) */
html[dir="rtl"] .nav-slim-btn.btn-primary i,
html[dir="rtl"] .nav-slim-btn.btn-secondary i {
    transform: scaleX(-1);
}


/* ==========================================================================
   MOBILE-ONLY TWEAKS (Under 600px) - UNIFIED LAYOUT
   ========================================================================== */
@media (max-width: 600px) {
    /* 1. MAGIC FIX FOR BLANK SPACE: Vertically center all screens */
    .setup-steps {
        display: flex;
        flex-direction: column;
        min-height: 280px; 
    }

    .setup-step.active {
        display: flex !important;
        flex-direction: column;
        justify-content: center; /* Distributes blank space evenly top and bottom */
        flex: 1;
        width: 100%;
    }

    /* 2. PAGE 2 (Difficulty/Time) - Side-by-Side Columns */
    .setup-step[data-step="1"].active {
        flex-direction: row; 
        align-items: center; 
        gap: 12px;
    }

    .difficulty-selector, .length-selector {
        flex: 1;
        width: 50%;
        margin: 0 !important;
    }

    .setup-step[data-step="1"] h3 {
        font-size: 13px; /* Slightly smaller to prevent text wrapping */
        margin-bottom: 12px !important;
        text-align: center;
    }

    .slim-buttons-row {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    /* 3. PAGE 1 & 3 (Math & Modes) - Match the 2-Column Grid Look */
    .setup-step[data-step="0"] .slim-buttons-grid,
    .setup-step[data-step="2"] .slim-buttons-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    /* 4. PAGE 3 (Teams) - Tighter Spacing */
    .teams-setup {
        margin-top: 16px !important;
    }
    
    .team-setup-side-by-side {
        gap: 8px;
    }
    
    .team-card input {
        padding: 10px 4px;
        font-size: 14px;
    }

    /* 5. UNIFORM BUTTON SIZING FOR ALL SCREENS */
    .slim-btn {
        padding: 10px 8px;
        gap: 8px;
    }

    .btn-title { font-size: 13px; }
    .btn-desc { font-size: 10px; line-height: 1.1; }

    .slim-btn i {
        width: 32px;
        height: 32px;
        min-width: 32px;
        font-size: 14px;
    }
}
