/* ========================================
   π∞ - The Infinite Pi Challenge
   Cosmic Theme Stylesheet
   ======================================== */

:root {
    /* Cosmic Color Palette */
    --void: #050510;
    --deep-space: #0a0a1a;
    --nebula: #1a1a3a;
    --stardust: #2d2d5a;
    
    /* Accent Colors */
    --nova: #00f5d4;
    --supernova: #00bbf9;
    --pulsar: #9b5de5;
    --solar-flare: #f15bb5;
    --comet: #fee440;
    
    /* Text */
    --starlight: #ffffff;
    --moonlight: #b8c5d6;
    --twilight: #6b7a8f;
    
    /* Functional */
    --success: #00f5a0;
    --error: #ff5757;
    --warning: #ffbe0b;
    
    /* Sizes */
    --header-height: 60px;
    --footer-height: 60px;
    
    /* Typography */
    --font-display: 'Orbitron', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation; /* Prevent double-tap zoom on buttons */
}

html {
    zoom: 0.8; /* Make 80% zoom the new 100% */
}

html, body {
    min-height: 100%;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
}

body {
    font-family: var(--font-mono);
    background: var(--deep-space);
    color: var(--starlight);
    line-height: 1.6;
    position: relative;
    overflow: hidden;
}

/* ========================================
   Animated Star Background
   ======================================== */

/* Stars background - outside/body background (STATIC - white stars) */
.stars {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    background: 
        radial-gradient(2px 2px at 20px 30px, var(--starlight), transparent),
        radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.8), transparent),
        radial-gradient(1px 1px at 90px 40px, var(--starlight), transparent),
        radial-gradient(2px 2px at 160px 120px, rgba(255,255,255,0.9), transparent),
        radial-gradient(1px 1px at 230px 80px, var(--starlight), transparent),
        radial-gradient(2px 2px at 300px 150px, rgba(255,255,255,0.7), transparent),
        radial-gradient(1px 1px at 350px 200px, var(--starlight), transparent),
        radial-gradient(2px 2px at 400px 50px, rgba(255,255,255,0.8), transparent);
    background-repeat: repeat;
    background-size: 400px 300px;
    opacity: 0.4;
    /* No animation - static stars */
}

/* Twinkling background - inside game container (ANIMATED - colored stars) */
.twinkling {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    background: 
        radial-gradient(2px 2px at 50px 100px, var(--nova), transparent),
        radial-gradient(1px 1px at 150px 200px, var(--supernova), transparent),
        radial-gradient(2px 2px at 250px 50px, var(--pulsar), transparent),
        radial-gradient(1px 1px at 350px 250px, var(--solar-flare), transparent),
        radial-gradient(2px 2px at 100px 300px, var(--nova), transparent),
        radial-gradient(1px 1px at 200px 150px, var(--supernova), transparent),
        radial-gradient(2px 2px at 300px 350px, var(--pulsar), transparent),
        radial-gradient(1px 1px at 50px 250px, var(--solar-flare), transparent);
    background-repeat: repeat;
    background-size: 400px 400px;
    animation: twinkle 3s ease-in-out infinite;
    opacity: 0.8;
}

@keyframes twinkle {
    0%, 100% { 
        opacity: 0.8;
    }
    50% { 
        opacity: 0.2;
    }
}

/* ========================================
   App Container
   ======================================== */

.app-container {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 500px;
    width: 100%;
    margin: 0 auto;
    background: linear-gradient(180deg, var(--void) 0%, var(--deep-space) 50%, var(--nebula) 100%);
    box-shadow: 0 0 100px rgba(0, 245, 212, 0.1);
    padding-bottom: 160px; /* Space for footer (60px) + gap + ad (32px) */
    z-index: 1;
    overflow-x: hidden;
}

/* ========================================
   Header
   ======================================== */

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    height: var(--header-height);
    background: rgba(5, 5, 16, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 10;
    position: relative;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 900;
}

.pi-symbol {
    background: linear-gradient(135deg, var(--nova), var(--supernova));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 30px rgba(0, 245, 212, 0.5);
}

.infinity {
    color: var(--pulsar);
    font-size: 20px;
    animation: pulse 2s ease-in-out infinite;
}

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

.lives-display {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(255, 87, 87, 0.15);
    border: 1px solid rgba(255, 87, 87, 0.3);
    border-radius: 20px;
}

.lives-icon {
    color: var(--error);
    font-size: 18px;
    animation: heartbeat 1.5s ease-in-out infinite;
}

@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    15% { transform: scale(1.15); }
    30% { transform: scale(1); }
    45% { transform: scale(1.1); }
}

.lives-count {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 18px;
    min-width: 20px;
    text-align: center;
}

.buy-lives-btn {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: var(--nova);
    color: var(--void);
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.buy-lives-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 15px var(--nova);
}

.music-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: var(--nebula);
    color: var(--moonlight);
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.music-btn:hover {
    background: var(--stardust);
    transform: scale(1.1);
}

.music-btn.muted {
    opacity: 0.5;
}

/* ========================================
   Game Container & Screens
   ======================================== */

.game-container {
    flex: 1;
    height: calc(100vh - var(--header-height) - 32px); /* Extended even more - only account for ad height */
    min-height: calc(100vh - var(--header-height) - 32px);
    position: relative;
    overflow: visible; /* Allow content to extend into space below */
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    padding: 15px 20px 5px; /* Further reduced padding to maximize usable area */
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.4s ease;
    overflow-y: visible; /* Allow content to extend beyond bounds for numpad */
    overflow-x: hidden;
    min-height: 100%; /* Allow content to extend beyond 100% if needed */
    box-sizing: border-box;
}

.screen.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* ========================================
   Start Screen
   ======================================== */

#startScreen {
    justify-content: center;
    align-items: center;
    text-align: center;
    padding-bottom: 30px; /* Reduced padding - footer/ad are outside game-container */
}

.title {
    font-family: var(--font-display);
    font-size: 32px;
    font-weight: 400;
    line-height: 1.3;
    margin-bottom: 10px;
    color: var(--moonlight);
}

.title .highlight {
    display: block;
    font-size: 38px;
    font-weight: 900;
    background: linear-gradient(135deg, var(--nova), var(--supernova), var(--pulsar));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--twilight);
    font-size: 16px;
    margin-bottom: 40px;
}

.stats-preview {
    display: flex;
    gap: 40px;
    margin-bottom: 40px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-value {
    font-family: var(--font-display);
    font-size: 36px;
    font-weight: 700;
    color: var(--nova);
    text-shadow: 0 0 20px rgba(0, 245, 212, 0.5);
}

.stat-label {
    font-size: 12px;
    color: var(--twilight);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.hint {
    margin-top: 30px;
    font-size: 13px;
    color: var(--twilight);
}

/* ========================================
   Buttons
   ======================================== */

.btn {
    position: relative;
    padding: 24px 40px; /* Increased vertical padding for better centering */
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: linear-gradient(135deg, var(--nova), var(--supernova));
    color: var(--void);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 40px rgba(0, 245, 212, 0.4);
}

.btn-glow {
    animation: glow 2s ease-in-out infinite;
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 20px rgba(0, 245, 212, 0.4); }
    50% { box-shadow: 0 0 40px rgba(0, 245, 212, 0.6), 0 0 60px rgba(0, 187, 249, 0.3); }
}

.btn-secondary {
    background: transparent;
    color: var(--moonlight);
    border: 1px solid var(--stardust);
}

.btn-secondary:hover {
    background: var(--stardust);
    border-color: var(--pulsar);
}

.btn-accent {
    background: linear-gradient(135deg, var(--solar-flare), var(--pulsar));
    color: var(--starlight);
}

.btn-cost {
    display: block;
    font-size: 11px;
    font-weight: 400;
    opacity: 0.8;
    margin-bottom: 4px;
}

/* ========================================
   Game Screen
   ======================================== */

#gameScreen {
    padding: 10px 20px 0; /* Minimal padding to maximize usable area */
}

.home-btn {
    padding: 8px 14px;
    border: none;
    border-radius: 16px;
    background: var(--nebula);
    color: var(--moonlight);
    font-family: var(--font-mono);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.home-btn:hover {
    background: var(--stardust);
    color: var(--nova);
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 10px;
}

.digit-counter, .timer, .mistakes {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 60px; /* Prevent layout shift */
}

.counter-label, .timer-label, .mistakes-label {
    font-size: 10px;
    color: var(--twilight);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.counter-value {
    font-family: var(--font-display);
    font-size: 32px;
    font-weight: 900;
    color: var(--nova);
    text-shadow: 0 0 20px rgba(0, 245, 212, 0.5);
    min-width: 50px; /* Prevent layout shift */
    text-align: center;
}

#highestCounter {
    color: var(--supernova);
    text-shadow: 0 0 20px rgba(0, 187, 249, 0.5);
    min-width: 50px; /* Prevent layout shift */
    text-align: center;
}

.timer-value {
    font-family: var(--font-mono); /* Use monospace for consistent width */
    font-size: 20px;
    font-weight: 700;
    color: var(--supernova);
    min-width: 60px; /* Fixed width to prevent layout shift */
    text-align: center;
}

.mistakes-value {
    display: flex;
    gap: 4px;
    font-size: 20px;
}

.strike {
    color: var(--stardust);
    transition: all 0.3s;
}

.strike.active {
    color: var(--error);
    text-shadow: 0 0 10px var(--error);
    animation: strikeShake 0.5s ease;
}

@keyframes strikeShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Pi Display */
.pi-display {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--stardust);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    min-height: 120px;
    max-height: 180px;
    overflow-y: auto;
}

.pi-prefix {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 700;
    color: var(--pulsar);
    margin-bottom: 10px;
}

.digits-container {
    font-family: var(--font-mono);
    font-size: 22px;
    line-height: 1.8;
    word-break: break-all;
    color: var(--moonlight);
}

.digit {
    display: inline;
    transition: all 0.2s;
}

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

.digit.wrong {
    color: var(--error);
    animation: wrongDigit 0.3s ease;
}

@keyframes wrongDigit {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

.digit.new {
    animation: newDigit 0.3s ease;
}

@keyframes newDigit {
    0% { transform: scale(1.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.cursor {
    display: inline-block;
    width: 2px;
    height: 24px;
    background: var(--nova);
    vertical-align: middle;
    margin-left: 2px;
}

.cursor.blink {
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Current Input Display */
.current-input-display {
    text-align: center;
    margin-bottom: 20px;
}


/* Reduce top margin of game controls when classic mode is active */
.layout-classic.active ~ .game-controls {
    margin-top: 10px;
}

.prompt {
    font-size: 14px;
    color: var(--twilight);
    margin-right: 10px;
}

.current-digit {
    font-family: var(--font-display);
    font-size: 36px;
    font-weight: 900;
    color: var(--comet);
    text-shadow: 0 0 20px rgba(254, 228, 64, 0.5);
}

/* Numpad */
.game-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin: 20px auto 30px;
    max-width: 400px;
}

.control-btn {
    flex: 1;
    padding: 15px 30px;
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 700;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
    min-width: 120px;
}

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

.control-btn:active {
    transform: scale(0.95);
}

.control-btn.btn-stop {
    background: linear-gradient(180deg, rgba(255, 87, 87, 0.3) 0%, rgba(255, 87, 87, 0.5) 100%);
    color: var(--error);
    border: 2px solid rgba(255, 87, 87, 0.5);
}

.control-btn.btn-stop:hover {
    background: linear-gradient(180deg, rgba(255, 87, 87, 0.5) 0%, rgba(255, 87, 87, 0.7) 100%);
    box-shadow: 0 4px 15px rgba(255, 87, 87, 0.4);
}

.control-btn.btn-done {
    background: linear-gradient(180deg, rgba(0, 245, 160, 0.3) 0%, rgba(0, 245, 160, 0.5) 100%);
    color: var(--success);
    border: 2px solid rgba(0, 245, 160, 0.5);
}

.control-btn.btn-done:hover {
    background: linear-gradient(180deg, rgba(0, 245, 160, 0.5) 0%, rgba(0, 245, 160, 0.7) 100%);
    box-shadow: 0 4px 15px rgba(0, 245, 160, 0.4);
}

/* ========================================
   Game Over Screen
   ======================================== */

#gameOverScreen {
    justify-content: center;
    align-items: center;
}

.game-over-content {
    text-align: center;
    width: 100%;
}

.game-over-title {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 30px;
    color: var(--moonlight);
}

.game-over-title.new-record {
    background: linear-gradient(135deg, var(--comet), var(--solar-flare));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: celebration 0.5s ease infinite alternate;
}

@keyframes celebration {
    0% { transform: scale(1); }
    100% { transform: scale(1.05); }
}

.final-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-bottom: 30px;
}

.final-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.final-stat.main .final-stat-value {
    font-size: 64px;
    color: var(--nova);
    text-shadow: 0 0 30px rgba(0, 245, 212, 0.6);
}

.final-stat-value {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 700;
    color: var(--supernova);
}

.final-stat-label {
    font-size: 12px;
    color: var(--twilight);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.achievements {
    margin-bottom: 30px;
}

.achievement {
    display: inline-block;
    padding: 8px 16px;
    margin: 4px;
    background: linear-gradient(135deg, rgba(254, 228, 64, 0.2), rgba(241, 91, 181, 0.2));
    border: 1px solid var(--comet);
    border-radius: 20px;
    font-size: 14px;
    color: var(--comet);
    animation: achievementPop 0.5s ease;
}

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

.game-over-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

.no-lives-warning {
    display: none;
    margin-top: 20px;
    padding: 20px;
    background: rgba(255, 87, 87, 0.1);
    border: 1px solid rgba(255, 87, 87, 0.3);
    border-radius: 12px;
}

.no-lives-warning p {
    color: var(--error);
    margin-bottom: 15px;
}

.no-lives-warning.visible {
    display: block;
}

/* ========================================
   Leaderboard Screen
   ======================================== */

#leaderboardScreen {
    padding: 0 20px !important; /* No vertical padding to maximize list space */
    display: flex;
    flex-direction: column;
    height: 100%; /* Ensure full height */
    min-height: 100%; /* Ensure minimum height */
}

.leaderboard-header {
    display: flex;
    align-items: center;
    gap: 10px; /* Good gap size */
    margin: 0; /* No margins to maximize list space */
    padding: 0; /* No padding to maximize list space */
    flex-shrink: 0; /* Don't shrink header */
    min-height: 0; /* Allow to be as small as content */
}

.leaderboard-header h2 {
    font-family: var(--font-display);
    font-size: 20px; /* Restored to good size */
    font-weight: 700;
    line-height: 1.2; /* Normal line height */
    margin: 0; /* Remove any default margins */
    padding: 0; /* Remove any padding */
}

.back-btn {
    width: 32px; /* Restored to good size */
    height: 32px; /* Restored to good size */
    border: none;
    border-radius: 8px;
    background: var(--nebula);
    color: var(--moonlight);
    font-size: 16px; /* Restored to good size */
    cursor: pointer;
    transition: all 0.2s;
    padding: 0; /* Remove any padding */
    margin: 0; /* Remove any margins */
}

.back-btn:hover {
    background: var(--stardust);
}

.leaderboard-tabs {
    display: flex;
    gap: 8px; /* Good gap size */
    margin: 0; /* No margins to maximize list space */
    padding: 0; /* No padding to maximize list space */
    flex-shrink: 0; /* Don't shrink tabs */
    min-height: 0; /* Allow to be as small as content */
}

.tab {
    flex: 1;
    padding: 8px; /* Restored to good size */
    font-family: var(--font-mono);
    font-size: 12px; /* Restored to good size */
    line-height: 1.2; /* Normal line height */
    border: none;
    border-radius: 8px;
    background: var(--nebula);
    color: var(--twilight);
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.tab[data-tab="speed"] {
    padding-left: 8px;
}

.tab.active {
    background: linear-gradient(135deg, var(--nova), var(--supernova));
    color: var(--void);
}

.leaderboard-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow flex item to shrink */
    height: 100%; /* Use full available height */
}

.leaderboard-panel {
    display: none;
    flex-direction: column;
    flex: 1; /* Fill available content space */
    min-height: 0; /* Allow flex item to shrink */
    overflow: hidden;
    height: 100%; /* Use full content height */
}

.leaderboard-panel.active {
    display: flex;
}

.training-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.training-tab {
    flex: 1;
    padding: 12px;
    font-family: var(--font-mono);
    font-size: 13px;
    border: none;
    border-radius: 8px;
    background: var(--nebula);
    color: var(--twilight);
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.training-tab:hover {
    background: var(--stardust);
}

.training-tab.active {
    background: linear-gradient(135deg, var(--nova), var(--supernova));
    color: var(--void);
}

.training-content {
    flex: 1;
    overflow: hidden;
}

.training-panel {
    display: none;
    flex-direction: column;
    height: 100%;
}

.training-panel.active {
    display: flex;
}

.speed-filter {
    display: flex;
    align-items: center;
    gap: 8px; /* Good gap size */
    margin: 0; /* No margins to maximize list space */
    padding: 0; /* No padding to maximize list space */
    flex-shrink: 0; /* Don't shrink filter */
    min-height: 0; /* Allow to be as small as content */
}

.speed-filter label {
    color: var(--twilight);
    font-size: 12px; /* Restored to good size */
    line-height: 1.2; /* Normal line height */
}

.speed-filter select {
    padding: 6px 10px; /* Restored to good size */
    font-family: var(--font-mono);
    font-size: 12px; /* Restored to good size */
    line-height: 1.2; /* Normal line height */
    background: var(--nebula);
    color: var(--starlight);
    border: 1px solid var(--stardust);
    border-radius: 6px;
    cursor: pointer;
}

.leaderboard-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0; /* Allow flex item to shrink */
    height: 100%; /* Use full panel height */
}

.speed-group-header {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    color: var(--nova);
    padding: 15px 15px 8px 15px;
    margin-top: 20px;
    border-bottom: 1px solid rgba(0, 245, 212, 0.2);
}

.speed-group-header:first-child {
    margin-top: 0;
}

.leaderboard-entry {
    display: flex;
    align-items: center;
    gap: 8px; /* Even smaller gap to maximize space */
    padding: 6px 10px; /* Even smaller padding to maximize space */
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px; /* Smaller radius */
    margin-bottom: 3px; /* Even smaller margin to fit more entries */
    transition: all 0.2s;
}

.leaderboard-entry:hover {
    background: rgba(0, 0, 0, 0.3);
}

.leaderboard-entry.highlight {
    background: linear-gradient(135deg, rgba(0, 245, 212, 0.1), rgba(155, 93, 229, 0.1));
    border: 1px solid var(--nova);
}

.entry-rank {
    font-family: var(--font-display);
    font-size: 16px; /* Reduced font size to save space */
    font-weight: 700;
    width: 30px; /* Reduced width to save space */
    text-align: center;
}

.entry-rank.odd { color: #fee440; } /* Yellow for odd numbers */
.entry-rank.even { color: #ffffff; } /* White for even numbers */

.entry-rank.gold { color: #ffd700; }
.entry-rank.silver { color: #c0c0c0; }
.entry-rank.bronze { color: #cd7f32; }

.entry-info {
    flex: 1;
}

.entry-name {
    font-weight: 700;
    color: var(--starlight);
    font-size: 14px; /* Slightly reduced font size */
    line-height: 1.3; /* Tighter line height */
}

.entry-date {
    font-size: 10px; /* Slightly reduced font size */
    color: var(--twilight);
    line-height: 1.2; /* Tighter line height */
}

.entry-score {
    font-family: var(--font-display);
    font-size: 16px; /* Reduced font size to save space */
    font-weight: 700;
    color: var(--nova);
}

.entry-time {
    font-family: var(--font-display);
    font-size: 14px; /* Reduced font size to save space */
    font-weight: 700;
    color: var(--supernova);
}

.empty-leaderboard {
    text-align: center;
    padding: 40px;
    color: var(--twilight);
}

/* ========================================
   Modal
   ======================================== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(5, 5, 16, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 100;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: linear-gradient(180deg, var(--nebula) 0%, var(--deep-space) 100%);
    border: 1px solid var(--stardust);
    border-radius: 20px;
    padding: 30px;
    width: 100%;
    max-width: 350px;
    text-align: center;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: var(--stardust);
    color: var(--moonlight);
    font-size: 20px;
    cursor: pointer;
}

.modal h2 {
    font-family: var(--font-display);
    font-size: 22px;
    margin-bottom: 20px;
}

.modal p {
    color: var(--twilight);
    margin-bottom: 20px;
}

.modal input {
    width: 100%;
    padding: 15px;
    font-family: var(--font-mono);
    font-size: 16px;
    background: var(--void);
    border: 1px solid var(--stardust);
    border-radius: 8px;
    color: var(--starlight);
    text-align: center;
    margin-bottom: 20px;
}

.modal input:focus {
    outline: none;
    border-color: var(--nova);
    box-shadow: 0 0 20px rgba(0, 245, 212, 0.2);
}

.modal-actions {
    display: flex;
    gap: 10px;
}

.modal-actions .btn {
    flex: 1;
    padding: 12px;
}

/* Shop Modal */
.shop-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.shop-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--stardust);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.shop-item:hover {
    background: rgba(0, 0, 0, 0.5);
    border-color: var(--nova);
}

.shop-item.popular {
    border-color: var(--comet);
    background: linear-gradient(135deg, rgba(254, 228, 64, 0.1), rgba(241, 91, 181, 0.1));
}

.shop-item-badge {
    position: absolute;
    top: -8px;
    right: 15px;
    padding: 4px 10px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    background: var(--comet);
    color: var(--void);
    border-radius: 10px;
}

.shop-item-icon {
    font-size: 28px;
}

.shop-item-info {
    flex: 1;
    text-align: left;
}

.shop-item-amount {
    display: block;
    font-weight: 700;
    color: var(--starlight);
}

.shop-item-price {
    font-size: 14px;
    color: var(--nova);
}

.shop-note {
    font-size: 12px;
    color: var(--twilight);
}

/* ========================================
   Footer
   ======================================== */

.footer {
    position: fixed;
    bottom: 100px; /* Position well above ad (ad is 32px tall) */
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 500px;
    display: flex;
    gap: 10px;
    padding: 10px 20px;
    height: var(--footer-height);
    background: rgba(5, 5, 16, 0.8);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 1002; /* Above the ad */
    box-sizing: border-box;
}

.footer-btn {
    flex: 1;
    padding: 10px;
    font-family: var(--font-mono);
    font-size: 13px;
    border: none;
    border-radius: 8px;
    background: var(--nebula);
    color: var(--moonlight);
    cursor: pointer;
    transition: all 0.2s;
}

.footer-btn:hover {
    background: var(--stardust);
}

/* ========================================
   Banner Ad
   ======================================== */

.banner-ad {
    position: fixed;
    bottom: 0; /* At the very bottom */
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 500px;
    height: 32px;
    max-height: 32px;
    background: rgba(10, 10, 26, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    box-sizing: border-box;
}

.banner-ad-content {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.banner-ad-label {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 8px;
    color: var(--twilight);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 2px 4px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 2px;
}

.banner-ad-placeholder {
    width: 100%;
    height: 100%;
    max-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(0, 245, 212, 0.1), rgba(155, 93, 229, 0.1));
    border: 1px solid rgba(0, 245, 212, 0.2);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    overflow: hidden;
}

.banner-ad-placeholder:hover {
    background: linear-gradient(135deg, rgba(0, 245, 212, 0.15), rgba(155, 93, 229, 0.15));
    border-color: rgba(0, 245, 212, 0.3);
}

.banner-ad-text {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--moonlight);
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Ensure banner ad is always visible, even over modals */
.modal {
    z-index: 100;
}

.banner-ad {
    z-index: 1001;
}

/* Constrain AdSense ads to container size */
.banner-ad .adsbygoogle {
    max-height: 32px !important;
    overflow: hidden !important;
    display: block !important;
}

/* ========================================
   Scrollbar
   ======================================== */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--stardust);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--pulsar);
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 400px) {
    .title {
        font-size: 26px;
    }
    
    .title .highlight {
        font-size: 32px;
    }
    
    .game-controls {
        gap: 10px;
        padding: 0 10px;
    }
    
    .control-btn {
        font-size: 16px;
        padding: 12px 20px;
        min-width: 100px;
    }
    
    .app-container {
        max-width: 100%;
        padding-bottom: 160px;
    }
    
    .footer, .banner-ad {
        max-width: 100%;
    }
    
    .screen {
        padding: 20px 15px;
    }
}

/* Small screens and short viewports */
@media (max-height: 700px) {
    .app-container {
        padding-bottom: 140px;
    }
    
    .footer {
        bottom: 80px;
        height: 50px;
        padding: 8px 15px;
    }
    
    .banner-ad {
        height: 28px;
        max-height: 28px;
    }
    
    .screen {
        padding: 15px 20px;
    }
    
    #startScreen {
        padding-bottom: 140px;
        min-height: auto;
    }
    
    #leaderboardScreen {
        padding-bottom: 0 !important; /* Remove padding to allow list to extend to bottom */
    }
    
    .title {
        font-size: 24px;
        margin-bottom: 10px;
    }
    
    .title .highlight {
        font-size: 30px;
    }
    
    .subtitle {
        margin-bottom: 20px;
    }
    
    .stats-preview {
        margin-bottom: 20px;
    }
}

/* Very small screens */
@media (max-width: 320px), (max-height: 600px) {
    .app-container {
        padding-bottom: 120px;
    }
    
    .footer {
        bottom: 60px;
        height: 45px;
        padding: 6px 10px;
    }
    
    .footer-btn {
        font-size: 11px;
        padding: 8px;
    }
    
    .banner-ad {
        height: 28px;
        max-height: 28px;
        padding: 0 5px;
    }
    
    .header {
        height: 50px;
        padding: 0 15px;
    }
    
    .logo {
        font-size: 24px;
    }
    
    .screen {
        padding: 10px;
    }
    
    #startScreen {
        padding-bottom: 120px;
        min-height: auto;
    }
    
    #leaderboardScreen {
        padding-bottom: 0 !important; /* Remove padding to allow list to extend to bottom */
    }
    
    .title {
        font-size: 20px;
    }
    
    .title .highlight {
        font-size: 26px;
    }
    
    .btn {
        padding: 12px 30px;
        font-size: 14px;
    }
}

@media (min-height: 800px) {
    .pi-display {
        max-height: 250px;
    }
}

/* ========================================
   Animations for screen transitions
   ======================================== */

.screen-enter {
    animation: screenEnter 0.4s ease forwards;
}

@keyframes screenEnter {
    0% {
        opacity: 0;
        transform: translateY(30px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Flash effect for correct/wrong */
.flash-correct {
    animation: flashCorrect 0.3s ease;
}

@keyframes flashCorrect {
    0% { background: rgba(0, 245, 160, 0.3); }
    100% { background: transparent; }
}

.flash-wrong {
    animation: flashWrong 0.3s ease;
}

@keyframes flashWrong {
    0%, 100% { background: rgba(255, 87, 87, 0.3); }
    50% { background: rgba(255, 87, 87, 0.5); }
}

/* ========================================
   Layout Selector (Start Screen)
   ======================================== */

.layout-selector {
    margin-bottom: 30px;
    text-align: center;
}

.layout-label {
    display: block;
    font-size: 12px;
    color: var(--twilight);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 12px;
}

.layout-options {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.layout-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 16px;
    background: var(--nebula);
    border: 2px solid var(--stardust);
    border-radius: 12px;
    color: var(--moonlight);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 80px;
}

.layout-btn:hover {
    border-color: var(--pulsar);
    background: var(--stardust);
}

.layout-btn.active {
    border-color: var(--nova);
    background: linear-gradient(135deg, rgba(0, 245, 212, 0.15), rgba(155, 93, 229, 0.15));
    color: var(--starlight);
}

.layout-icon {
    font-size: 24px;
}

.layout-name {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ========================================
   Layout Displays
   ======================================== */

.layout-display {
    display: none;
}

.layout-display.active {
    display: block;
}

/* Hide training layout in classic and reveal modes */
.layout-classic.active ~ .layout-training,
.layout-reveal.active ~ .layout-training {
    display: none !important;
}

/* Ensure training grid is only visible in training mode */
.layout-training:not(.active) {
    display: none !important;
}

/* ========================================
   REVEAL LAYOUT
   ======================================== */

.layout-reveal {
    text-align: center;
}

.reveal-header {
    margin-bottom: 20px;
}

.reveal-prefix {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 700;
    color: var(--pulsar);
}

.reveal-progress {
    display: block;
    font-size: 13px;
    color: var(--twilight);
    margin-top: 5px;
}

.reveal-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 6px;
    max-width: 400px;
    margin: 0 auto 25px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    height: 130px; /* Fixed height to show exactly 3 rows */
    overflow: hidden; /* Hide overflow since we only show 3 rows */
}

.reveal-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 700;
    background: var(--stardust);
    border-radius: 6px;
    color: var(--stardust);
    transition: all 0.3s ease;
    position: relative;
}

.reveal-cell::before {
    content: '•';
    color: var(--twilight);
    font-size: 20px;
}

.reveal-cell.revealed {
    background: linear-gradient(135deg, var(--nova), var(--supernova));
    color: var(--void);
    animation: revealPop 0.4s ease;
}

.reveal-cell.revealed::before {
    content: none;
}

.reveal-cell.current {
    border: 2px solid var(--comet);
    box-shadow: 0 0 15px rgba(254, 228, 64, 0.5);
    animation: currentPulse 1s ease-in-out infinite;
}

.reveal-cell.current::before {
    content: '?';
    color: var(--comet);
    font-size: 16px;
}

.reveal-cell.wrong {
    background: var(--error);
    animation: wrongShake 0.4s ease;
}

.reveal-cell.wrong::before {
    content: '✗';
    color: var(--starlight);
}

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

@keyframes currentPulse {
    0%, 100% { box-shadow: 0 0 15px rgba(254, 228, 64, 0.5); }
    50% { box-shadow: 0 0 25px rgba(254, 228, 64, 0.8); }
}

@keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}


/* ========================================
   TRAINING LAYOUT
   ======================================== */

.layout-training {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.training-header {
    margin-bottom: 20px;
    text-align: center;
}

.training-prefix {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 700;
    color: var(--starlight);
}

.training-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 500px;
}

.training-row {
    display: flex;
    justify-content: center;
    gap: 6px;
    flex-wrap: nowrap;
}

.training-digit {
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 700;
    border-radius: 6px;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    flex-shrink: 0;
}

/* Waiting to be entered - lighter color */
.training-digit.waiting {
    background: rgba(0, 245, 212, 0.15);
    color: rgba(0, 245, 212, 0.5);
    border-color: rgba(0, 245, 212, 0.2);
}

/* Current digit to enter - highlighted */
.training-digit.current {
    background: var(--nebula);
    color: var(--comet);
    border-color: var(--comet);
    box-shadow: 0 0 20px rgba(254, 228, 64, 0.6);
    animation: trainingPulse 1s ease-in-out infinite;
    transform: scale(1.1);
}

/* Entered digit - darker color */
.training-digit.entered {
    background: rgba(0, 245, 212, 0.4);
    color: var(--nova);
    border-color: rgba(0, 245, 212, 0.6);
}

/* Wrong digit - error state */
.training-digit.wrong {
    background: var(--error);
    color: var(--starlight);
    border-color: var(--error);
    animation: wrongShake 0.4s ease;
}

@keyframes trainingPulse {
    0%, 100% { 
        box-shadow: 0 0 20px rgba(254, 228, 64, 0.6);
        transform: scale(1.1);
    }
    50% { 
        box-shadow: 0 0 30px rgba(254, 228, 64, 0.9);
        transform: scale(1.15);
    }
}

/* ========================================
   Mobile Numpad
   ======================================== */

.mobile-numpad {
    display: none; /* Hidden by default, shown on mobile */
    flex-direction: column;
    gap: 12px;
    padding: 20px;
    margin-top: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}

.mobile-numpad .numpad-row {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.mobile-numpad .numpad-btn {
    flex: 1;
    min-width: 60px;
    height: 60px;
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 700;
    border: 2px solid var(--stardust);
    border-radius: 12px;
    background: var(--nebula);
    color: var(--starlight);
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.mobile-numpad .numpad-btn:active,
.mobile-numpad .numpad-btn.pressed {
    transform: scale(0.95);
    background: var(--stardust);
    border-color: var(--nova);
    box-shadow: 0 0 20px rgba(0, 245, 212, 0.4);
}

.mobile-numpad .numpad-zero {
    max-width: 200px;
    margin: 0 auto;
}

/* Show numpad on mobile devices */
@media (max-width: 768px) {
    .mobile-numpad {
        display: flex;
    }
}

/* Touch-friendly buttons on mobile */
@media (max-width: 768px) {
    .btn, .control-btn, .footer-btn {
        min-height: 44px; /* iOS recommended touch target */
        padding: 12px 20px;
    }
    
    .layout-btn {
        min-height: 60px;
        padding: 12px 16px;
    }
    
    /* Make reveal mode more compact on mobile to fit numpad */
    .layout-reveal .reveal-header {
        margin-bottom: 10px;
    }
    
    .layout-reveal .reveal-grid {
        margin-bottom: 15px;
        padding: 10px;
    }
    
    .layout-reveal .game-controls {
        margin: 15px auto 15px;
    }
    
    .layout-reveal .mobile-numpad {
        margin-top: 10px;
        margin-bottom: 0;
        padding: 20px;
        flex-shrink: 0;
        min-height: auto;
    }
    
    /* Make numpad buttons taller in reveal mode to extend into available space */
    .layout-reveal .mobile-numpad .numpad-btn {
        height: 70px;
        min-height: 70px;
    }
    
    /* Increase gap between numpad rows in reveal mode */
    .layout-reveal .mobile-numpad .numpad-row {
        gap: 15px;
        margin-bottom: 8px;
    }
    
    .layout-reveal .mobile-numpad {
        gap: 15px;
    }
    
    .tab {
        min-height: 44px;
        padding: 12px;
    }
    
    /* Extend usable area on mobile - allow numpad to extend into space below */
    #gameScreen {
        overflow-y: visible; /* Allow numpad to extend beyond screen bounds */
        padding: 8px 15px 0; /* Minimal padding to maximize usable area */
        min-height: 100%; /* Allow content to extend beyond 100% */
    }
}

/* Extra compact spacing for very small screens in reveal mode */
@media (max-width: 768px) and (max-height: 700px) {
    .layout-reveal .reveal-header {
        margin-bottom: 8px;
    }
    
    .layout-reveal .reveal-grid {
        margin-bottom: 10px;
        padding: 8px;
    }
    
    .layout-reveal .game-controls {
        margin: 10px auto 10px;
    }
    
    .layout-reveal .mobile-numpad {
        margin-top: 8px;
        margin-bottom: 0;
        padding: 18px;
        flex-shrink: 0;
        min-height: auto;
    }
    
    /* Make numpad buttons taller on very small screens in reveal mode */
    .layout-reveal .mobile-numpad .numpad-btn {
        height: 65px;
        min-height: 65px;
    }
    
    /* Increase gap between numpad rows */
    .layout-reveal .mobile-numpad .numpad-row {
        gap: 12px;
        margin-bottom: 6px;
    }
    
    .layout-reveal .mobile-numpad {
        gap: 12px;
    }
    
    #gameScreen {
        padding: 3px 15px 0; /* Even more minimal padding to maximize usable area */
        overflow-y: visible; /* Allow numpad to extend beyond screen bounds */
        min-height: 100%; /* Allow content to extend beyond 100% */
    }
}


