/*
 * style.css — Bouncing Bugs
 * ==========================
 * Handles all visual styling:
 * - Full-screen canvas setup
 * - HUD (heads-up display) positioning
 * - Overlay screens (start, question, game-over)
 * - Math question buttons and feedback
 *
 * Teaching Note: The game itself is drawn on <canvas>, but UI elements
 * like menus and buttons use regular HTML/CSS — this is a common pattern
 * in web games because DOM elements are easier to style and make accessible.
 */

/* ===================== RESET & BASE ===================== */

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

body {
    overflow: hidden;               /* No scrollbars — the canvas IS the page */
    background: #1a1a2e;           /* Dark background in case canvas doesn't cover */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* ===================== GAME CANVAS ===================== */

#gameCanvas {
    display: block;                 /* Removes inline spacing beneath canvas */
    width: 100vw;                  /* Fill the entire viewport */
    height: 100vh;
    background: #16213e;           /* Dark blue — visible before first frame draws */
}

/* ===================== HUD (Heads-Up Display) ===================== */
/* Positioned at the top of the screen, always visible during gameplay */

#hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 12px 24px;
    font-size: 20px;
    font-weight: bold;
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
    pointer-events: none;          /* Clicks pass through to canvas */
    z-index: 10;
}

/* Make hearts tappable for the H-key cheat on mobile */
.hud-lives {
    pointer-events: auto;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

/* Home button in HUD */
.hud-home {
    pointer-events: auto;
    background: none;
    border: none;
    font-size: 26px;
    color: #fff;
    cursor: pointer;
    padding: 0 8px 0 0;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    opacity: 0.6;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
}

.hud-home:hover {
    opacity: 1;
}

/* ===================== MOBILE TOUCH CONTROLS ===================== */

#mobileControls {
    display: none;                 /* Hidden by default; shown via JS on touch devices */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 15;
    pointer-events: none;          /* Container doesn't block canvas */
    padding: 0 16px 24px;
}

.mobile-btn {
    pointer-events: auto;          /* Buttons themselves are tappable */
    position: fixed;
    bottom: 24px;
    width: 80px;
    height: 80px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 36px;
    font-weight: bold;
    border-radius: 50%;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.mobile-btn:active {
    background: rgba(255, 255, 255, 0.35);
    transform: scale(0.92);
}

.mobile-left {
    left: 24px;
}

.mobile-right {
    right: 24px;
}

/* ===================== OVERLAY SCREENS ===================== */
/* Start, Question, and Game Over screens share this base style */

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: rgba(0, 0, 0, 0.7); /* Semi-transparent dark backdrop */
    z-index: 20;
}

.overlay-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 40px 50px;
    border-radius: 20px;
    text-align: center;
    color: #fff;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    max-width: 500px;
    width: 90%;
    margin: 24px auto;
    animation: popIn 0.3s ease-out;
}

/* Simple pop-in animation when overlays appear */
@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.overlay-content h1 {
    font-size: 42px;
    margin-bottom: 16px;
}

.overlay-content h2 {
    font-size: 32px;
    margin-bottom: 20px;
}

.overlay-content p {
    font-size: 18px;
    margin-bottom: 10px;
    line-height: 1.4;
}

/* ===================== CONTROLS INFO ===================== */

.controls-info {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 16px;
    margin: 16px 0;
}

.controls-info p {
    margin-bottom: 6px;
    font-size: 16px;
}

kbd {
    background: rgba(255, 255, 255, 0.25);
    border-radius: 5px;
    padding: 3px 8px;
    font-family: monospace;
    font-size: 14px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

/* ===================== START / RESTART BUTTON ===================== */

.big-btn {
    display: inline-block;
    margin-top: 18px;
    padding: 14px 44px;
    font-size: 24px;
    font-weight: bold;
    color: #fff;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.15s, background 0.15s;
}

.big-btn:hover {
    transform: scale(1.08);
    background: rgba(255, 255, 255, 0.35);
}

.big-btn:active {
    transform: scale(0.96);
}

/* ===================== "or press SPACE" PROMPT ===================== */

.prompt {
    font-size: 14px !important;
    margin-top: 10px !important;
    opacity: 0.7;
    animation: pulse 1.5s ease-in-out infinite;
}

/* Hide keyboard prompts on touch devices */
@media (pointer: coarse) {
    .prompt { display: none; }
}

.version-label {
    font-size: 12px !important;
    opacity: 0.4;
    margin-top: 16px !important;
}

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

/* ===================== MATH QUESTION ===================== */

.question-box {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}

.question-text {
    font-size: 36px !important;
    font-weight: bold;
    margin: 20px 0 !important;
    padding: 16px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
}

.answer-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin: 20px 0;
}

.answer-btn {
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    border: none;
    padding: 14px 32px;
    font-size: 24px;
    font-weight: bold;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.15s, background 0.15s;
    min-width: 80px;
}

.answer-btn:hover {
    transform: scale(1.1);
    background: #fff;
}

.answer-btn:focus {
    outline: 3px solid #fff;
    outline-offset: 2px;
}

.answer-btn.correct {
    background: #4ade80;
    color: #fff;
    transform: scale(1.1);
}

.answer-btn.wrong {
    background: #f87171;
    color: #fff;
}

/* Feedback message shown after answering */
.feedback {
    font-size: 22px !important;
    font-weight: bold;
    min-height: 30px;
}

/* High score display */
.high-score {
    font-size: 18px !important;
    color: #ffd700;
    margin-top: 12px !important;
    min-height: 24px;
}

/* Saved progress info */
.saved-progress {
    font-size: 14px !important;
    opacity: 0.8;
    margin-top: 6px !important;
}

/* Age selector */
.age-selector {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 12px 16px;
    margin: 14px 0;
}

.age-selector label {
    font-size: 16px;
    font-weight: bold;
    display: block;
    margin-bottom: 8px;
}

.age-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
}

.age-btn {
    width: 36px;
    height: 36px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 20px;
    font-weight: bold;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.1s, background 0.1s;
    line-height: 1;
}

.age-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: scale(1.1);
}

.age-display {
    font-size: 32px;
    font-weight: bold;
    min-width: 48px;
    text-align: center;
}

.age-hint {
    font-size: 12px !important;
    opacity: 0.7;
    margin-top: 6px !important;
    margin-bottom: 0 !important;
}

/* ===================== LEADERBOARD ===================== */

.leaderboard {
    margin: 10px 0;
    max-height: 220px;
    overflow-y: auto;
}

.leaderboard table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.leaderboard th {
    font-size: 12px;
    text-transform: uppercase;
    opacity: 0.7;
    padding: 4px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    text-align: left;
}

.leaderboard td {
    padding: 5px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.leaderboard tr.highlight {
    background: rgba(255, 215, 0, 0.2);
}

.leaderboard .rank {
    width: 28px;
    text-align: center;
}

.leaderboard .score-col {
    text-align: right;
    font-weight: bold;
}

.leaderboard .date-col {
    text-align: right;
    opacity: 0.7;
    font-size: 12px;
}

/* ===================== NAME ENTRY ===================== */

.name-entry-box {
    background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
}

.name-input {
    display: block;
    width: 200px;
    margin: 12px auto;
    padding: 10px 14px;
    font-size: 22px;
    font-weight: bold;
    text-align: center;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    outline: none;
}

.name-input:focus {
    border-color: #fff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.4);
}
