/* Reset and Base Styles */
:root {
    --bg-start: #f6f8ff;
    --bg-end: #ffffff;
    --accent-1: #667eea;
    --accent-2: #764ba2;
    --muted: #6b7280;
    --card-bg: #e9eef6; /* stronger, slightly darker cool card */
    --glass: rgba(246,247,250,0.95);
    --success: #8BC34A;
    --danger: #ff6b6b;
    --gold: #ffd700;
    --max-width: 1100px;

    /* Colors used by canvas and UI elements */
    --text-primary: #1f2937;
    --text-muted: #6b7280;
    --text-on-surface: #0b1220;
    --canvas-sky-start: #87CEEB;
    --canvas-sky-end: #E0F6FF;
    --cloud-color: rgba(255, 255, 255, 0.7);
    --ground-color: #8BC34A;
    --surface-bg: rgba(250,251,253,0.98);
    --basket-top: #d4a574;
    --basket-bottom: #8b5a2b;
    /* Overlay and UI helpers */
    --overlay-top: rgba(2,6,23,0.6);
    --overlay-bottom: rgba(2,6,23,0.5);
    --input-bg: rgba(244,245,248,0.92);
    --ad-bg: linear-gradient(135deg, rgba(0, 102, 204, 0.3) 0%, rgba(0, 51, 102, 0.5) 100%);
    --ad-text-color: #fff;
}

/* Dark mode overrides */
body.dark {
    --bg-start: #0b1220;
    --bg-end: #071025;
    --accent-1: #4f46e5;
    --accent-2: #9b63e6;
    --muted: #9aa3b2;
    --card-bg: #0f1724;
    --glass: rgba(8,10,14,0.6);
    --text-primary: #e6eef8;
    --text-muted: #9aa3b2;
    --text-on-surface: #f8fafc;
    --canvas-sky-start: #081028;
    --canvas-sky-end: #06101a;
    --cloud-color: rgba(255,255,255,0.06);
    --ground-color: #1f6b2e;
    --surface-bg: rgba(12,14,18,0.8);
    --basket-top: #b8874a;
    --basket-bottom: #5a3f2a;
    --overlay-top: rgba(0,0,0,0.6);
    --overlay-bottom: rgba(0,0,0,0.5);
    --input-bg: rgba(20,22,28,0.6);
    --ad-bg: linear-gradient(135deg, rgba(28, 64, 96, 0.25) 0%, rgba(12, 30, 48, 0.4) 100%);
    --ad-text-color: #e6eef8;
} 

/* Settings toggles container (holds theme and music toggles) */
.settings-toggles-container {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

/* Theme toggle styles */
.theme-toggle-container,
.music-toggle-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-label {
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 600;
}

.theme-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.theme-switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--glass);
    transition: 0.2s;
    border-radius: 26px;
} 

.theme-switch .slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.2s;
    border-radius: 50%;
}

.theme-switch input:checked + .slider {
    background-color: var(--accent-1);
}

.theme-switch input:checked + .slider:before {
    transform: translateX(22px);
}

/* Canvas background uses CSS variables so it adapts to theme */
#gameCanvas {
    display: block;
    width: 100%;
    height: auto; /* preserve aspect ratio and avoid cropping */
    background: linear-gradient(to bottom, var(--canvas-sky-start) 0%, var(--canvas-sky-end) 100%);
    touch-action: none;
    border-radius: 8px;
    box-shadow: 0 8px 30px rgba(12,18,26,0.12) inset, 0 10px 30px rgba(12,18,26,0.08);
}

/* Make the screen content respect the surface/background variables */
.screen-content {
    text-align: center;
    color: var(--text-on-surface);
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
    width: min(420px, 94%);
    background: var(--surface-bg);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(12,18,26,0.12);
} 

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--accent-1) 0%, var(--accent-2) 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 18px;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-size: clamp(14px, 1.6vw, 16px);
    transition: background 0.25s ease, color 0.25s ease;
}

/* Smooth theme transitions for core UI elements */
.game-container,
.screen-content,
.canvas-wrapper,
.info-panel,
.controls-info,
.game-btn {
    transition: background 0.25s ease, color 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

/* Explicit dark-mode surface overrides to ensure some components that had
   earlier hard-coded backgrounds switch correctly when the theme is toggled */
body.dark .info-panel,
body.dark .screen-content,
body.dark .canvas-wrapper,
body.dark .controls-info,
body.dark .ad-container {
    background: var(--surface-bg) !important;
    color: var(--text-on-surface) !important;
}

.game-container {
    background: var(--card-bg);
    border-radius: 18px;
    box-shadow: 0 10px 40px rgba(12, 18, 26, 0.12);
    padding: clamp(10px, 2vw, 20px);
    max-width: var(--max-width);
    width: 100%;
    max-height: calc(100vh - 36px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
 

/* Header */
header {
    text-align: center;
    margin-bottom: 20px;
}

header h1 {
    color: var(--accent-2);
    font-size: clamp(1.25rem, 3vw, 2.2rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    text-shadow: none;
    margin-bottom: 4px;
} 

/* Info Panel */
.info-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 8px;
    background: var(--surface-bg);
    border-radius: 12px;
    padding: 10px;
    margin-bottom: 6px;
    align-items: center;
}  

.info-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 4px 6px;
}

.info-item .label {
    font-size: 0.8rem;
    color: var(--muted);
}

.info-item .value {
    font-size: clamp(1rem, 2.2vw, 1.4rem);
    font-weight: 700;
    color: var(--accent-2);
} 

.info-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 100px;
}

.info-item .label {
    font-size: 0.9rem;
    color: var(--muted);
    margin-bottom: 5px;
}

.info-item .value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--accent-2);
}

@media (max-width: 480px) {
    .info-item .value {
        font-size: 1.1rem;
    }
    header h1 {
        font-size: 1.1rem;
    }
}

/* Canvas Wrapper */
.canvas-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--surface-bg);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 8px;
    touch-action: none; /* Prevent browser handling of touch */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    padding: 8px;
    width: 100%;
    max-width: 800px; /* keeps canvas from growing too wide on large screens */
    margin-left: auto;
    margin-right: auto;
    aspect-ratio: 4 / 3; /* preserve game aspect ratio */
} 

/* Canvas Wrapper */
.canvas-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--surface-bg);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 8px;
    touch-action: none; /* Prevent browser handling of touch */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    padding: 8px;
    width: 100%;
    max-width: 800px; /* keeps canvas from growing too wide on large screens */
    margin-left: auto;
    margin-right: auto;
    aspect-ratio: 4 / 3; /* preserve game aspect ratio */
} 

#gameCanvas {
    display: block;
    width: 100%;
    height: auto; /* preserve aspect ratio and avoid cropping */
    background: linear-gradient(to bottom, var(--canvas-sky-start) 0%, var(--canvas-sky-end) 100%);
    touch-action: none;
    border-radius: 8px;
    box-shadow: 0 8px 30px rgba(12,18,26,0.12) inset, 0 10px 30px rgba(12,18,26,0.08);
} 
 

/* Screens (Start/Game Over) */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    z-index: 10;
    background: linear-gradient(180deg, var(--overlay-top), var(--overlay-bottom));
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    overflow: hidden;
}

/* On small screens, allow the overlay to scroll and align its content to the top */
@media (max-width: 480px) {
    .screen {
        align-items: flex-start;
        padding-top: 20px;
        overflow: auto;
    }

    .screen-content {
        max-height: calc(100vh - 80px);
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        width: min(420px, 96%);
        margin: 0 auto;
    }
} 

.screen.hidden {
    display: none;
}

.screen-content {
    text-align: center;
    color: var(--text-on-surface);
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
    width: min(420px, 94%);
    background: var(--surface-bg);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(12,18,26,0.12);
} 

.screen-content h2 {
    font-size: clamp(1.1rem, 2.6vw, 1.45rem);
    margin: 0;
    color: var(--accent-2);
    font-weight: 700;
}

.screen-content p {
    font-size: clamp(0.85rem, 1.8vw, 0.95rem);
    margin: 0;
}


.tap-hint {
    font-size: 1rem !important;
    margin-top: 5px !important;
    animation: pulse 1.5s infinite;
}

#newHighScore {
    color: var(--gold);
    font-size: 0.75rem;
    font-weight: bold;
    margin: 0;
    animation: pulse 1s infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.game-btn {
    background: linear-gradient(135deg, var(--accent-1) 0%, var(--accent-2) 100%);
    color: white;
    border: none;
    padding: 12px 20px;
    font-size: clamp(14px, 2.2vw, 16px);
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    margin: 0;
    font-weight: 600;
    box-shadow: 0 6px 18px rgba(118,75,162,0.18);
    min-width: 140px;
}

.game-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 22px rgba(118,75,162,0.22);
}

.game-btn:active {
    transform: translateY(0);
}

/* Secondary button style */
.game-btn.secondary {
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
    box-shadow: 0 6px 18px rgba(108,117,125,0.18);
}

.game-btn.secondary:hover {
    box-shadow: 0 10px 22px rgba(108,117,125,0.22);
}

/* Back button */
.game-btn.back-btn {
    margin-top: 15px;
    font-size: 0.9rem;
    padding: 10px 18px;
    min-width: 100px;
}

/* Button group for game over screen */
.button-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    margin-top: 10px;
}

@media (min-width: 400px) {
    .button-group {
        flex-direction: row;
        justify-content: center;
    }
}

/* Divider with "or" text */
.divider {
    display: flex;
    align-items: center;
    margin: 15px 0;
    width: 100%;
    max-width: 300px;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(118,75,162,0.2);
}

.divider span {
    padding: 0 15px;
    color: var(--muted);
    font-size: 0.9rem;
}

/* Welcome text */
.welcome-text {
    margin-bottom: 15px;
    font-size: 0.95rem;
    color: var(--muted);
}

/* Account status message */
.account-status {
    font-size: 0.9rem;
    margin-top: 8px;
    padding: 8px 16px;
    border-radius: 8px;
    background: rgba(118,75,162,0.1);
    color: var(--text-primary);
}

.account-status.success {
    background: rgba(40, 167, 69, 0.15);
    color: #28a745;
}

.account-status.error {
    background: rgba(220, 53, 69, 0.15);
    color: var(--danger);
}

.account-status.hidden {
    display: none;
}


/* Name Input */
.name-input-container {
    margin: 12px 0;
    width: 100%;
}

.name-input-container label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.95rem;
    color: var(--muted);
}

.name-input-container input {
    padding: 14px 20px;
    font-size: clamp(15px, 2.4vw, 18px);
    border: 1px solid rgba(118,75,162,0.12);
    border-radius: 999px;
    width: 100%;
    max-width: 360px;
    text-align: center;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--input-bg);
    color: var(--text-on-surface);
} 

.name-input-container input:focus {
    border-color: var(--accent-1);
    box-shadow: 0 6px 20px rgba(102,126,234,0.12);
}


.name-error {
    color: var(--danger);
    font-size: 0.95rem;
    margin-top: 10px;
    font-weight: bold;
}

.name-error.hidden {
    display: none;
}

/* Leaderboard */
.leaderboard-container {
    margin: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 1;
    min-height: 0;
    overflow-x: auto; /* allow the table to be scrolled horizontally on tiny screens */
    -webkit-overflow-scrolling: touch;
}

.leaderboard-table {
    width: 100%;
    min-width: 280px; /* keep readable column widths */
} 

.leaderboard-container h3 {
    margin: 0 0 6px 0;
    color: var(--gold);
    font-size: 0.85rem;
    font-weight: 700;
}

.leaderboard-table {
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
    border-collapse: collapse;
    background: rgba(0,0,0,0.04);
    border-radius: 8px;
    overflow: hidden;
}

.leaderboard-table th,
.leaderboard-table td {
    padding: 6px 8px;
    text-align: center;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    font-size: 0.9rem;
    line-height: 1.2;
}

.leaderboard-table th {
    background: rgba(118, 75, 162, 0.12);
    color: var(--text-primary);
    font-weight: 700;
}

.leaderboard-table td {
    color: var(--text-primary);
}

.leaderboard-table tr:last-child td {
    border-bottom: none;
}

.leaderboard-table tr.highlight {
    background: rgba(255, 215, 0, 0.12);
    font-weight: 700;
}

.leaderboard-table tr.current-score {
    background: rgba(255, 215, 0, 0.25);
    font-weight: 800;
}
.leaderboard-table tr:nth-child(1) td:first-child::before {
    content: '🥇 ';
}

.leaderboard-table tr:nth-child(2) td:first-child::before {
    content: '🥈 ';
}

.leaderboard-table tr:nth-child(3) td:first-child::before {
    content: '🥉 ';
} 

/* Advertisement Section */
.ad-container {
    margin: 0;
    padding: 3px 6px;
    background: var(--ad-bg);
    border-radius: 5px;
    border: 1px solid rgba(0, 153, 255, 0.25);
    width: 100%;
    max-width: 260px;
    flex-shrink: 0;
}

.ad-text {
    font-size: 0.55rem;
    color: var(--ad-text-color);
    margin: 0;
    font-weight: bold;
}

.ad-subtext {
    font-size: 0.5rem;
    color: #cce5ff;
    margin: 1px 0;
}

.ad-subtext strong {
    color: #00d4ff;
}

.store-buttons {
    display: flex;
    justify-content: center;
    gap: 5px;
    flex-wrap: wrap;
}

.store-btn {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px 6px;
    border-radius: 3px;
    text-decoration: none;
    font-weight: bold;
    font-size: 0.5rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

.store-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.store-btn.app-store {
    background: linear-gradient(135deg, #1a1a1a 0%, #333 100%);
    color: var(--ad-text-color);
}

.store-btn.play-store {
    background: linear-gradient(135deg, #01875f 0%, #34a853 100%);
    color: var(--ad-text-color);
}

.store-icon {
    font-size: 1.2rem;
}

.store-label {
    white-space: nowrap;
}

/* Controls Info */
.controls-info {
    text-align: center;
    color: var(--muted);
    font-size: 1rem;
    margin-bottom: 10px;
}

/* Control hints - show appropriate hint based on device */
.mobile-controls,
.mobile-hint {
    display: none;
}

.desktop-controls,
.desktop-hint {
    display: block;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 8px;
        align-items: flex-start;
    }

    header h1 {
        font-size: clamp(1.1rem, 4vw, 1.6rem);
    }

    .game-container {
        padding: 12px;
        border-radius: 12px;
    }

    .info-panel {
        padding: 8px;
        gap: 6px;
    }

    .info-item .value {
        font-size: 1.05rem;
    }

    .info-item .label {
        font-size: 0.75rem;
    }

    /* Show mobile hints, hide desktop hints */
    .mobile-controls,
    .mobile-hint {
        display: block;
    }

    .desktop-controls,
    .desktop-hint {
        display: none;
    }

    .controls-info {
        text-align: center;
        font-size: 0.85rem;
        padding: 8px;
        background: var(--surface-bg);
        border-radius: 8px;
        margin-top: 8px;
    }

    .canvas-wrapper {
        margin-bottom: 8px;
        padding: 8px;
    }

    .game-btn {
        width: 100%;
        min-width: 0;
        padding: 12px;
    }
} 

@media (max-width: 480px) {
    body {
        padding: 0;
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }

    .game-container {
        padding: 8px;
        border-radius: 6px;
        min-height: 100vh;
        min-height: -webkit-fill-available;
        display: flex;
        flex-direction: column;
        max-height: 100vh; /* allow scrolling inside the container */
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: env(safe-area-inset-bottom);
    }

    header {
        margin-bottom: 6px;
        flex-shrink: 0;
    }

    header h1 {
        font-size: clamp(1rem, 4vw, 1.1rem);
    }

    .info-panel {
        padding: 6px;
        margin-bottom: 6px;
        flex-shrink: 0;
    }

    .info-item .label {
        font-size: 0.6rem;
    }

    .info-item .value {
        font-size: 0.95rem;
    }

    .canvas-wrapper {
        flex: 1;
        min-height: 0;
        margin-bottom: 6px;
        display: flex;
        justify-content: center;
        align-items: center;
        background: var(--surface-bg);
        border-radius: 8px;
        padding: 6px;
        /* reduce side paddings to preserve vertical space */
    }

    /* Keep canvas width responsive but preserve aspect ratio to avoid stretching */
    #gameCanvas {
        display: block;
        width: 100% !important;
        height: auto !important;
        max-width: 100%;
        max-height: 62vh; /* tighter cap for small screens so overlay fits */
    }

    .controls-info {
        flex-shrink: 0;
        padding: 6px;
        font-size: 0.75rem;
    }

    /* Overlay / start/game-over content: shrink to fit without scroll */
    .screen-content {
        width: min(420px, 94%);
        padding: 12px;
        gap: 8px;
        max-height: calc(100vh - 40px);
        overflow: visible; /* allow parent to handle scrolling if necessary */
    }

    .screen-content h2 {
        font-size: 1.15rem;
        margin-bottom: 2px;
    }

    /* Compact leaderboard on small screens */
    .leaderboard-container {
        width: 100%;
        padding: 0 4px;
    }

    .leaderboard-table th,
    .leaderboard-table td {
        padding: 4px 6px;
        font-size: 0.85rem;
    }

    /* Show only top 5 on mobile so it fits without scrolling */
    .leaderboard-table tbody tr:nth-child(n+6) {
        display: none;
    }

    /* Hide the ad on very small screens to avoid vertical overflow */
    .ad-container {
        display: none;
    }

    .game-btn {
        padding: 10px;
        font-size: 1rem;
        min-width: 120px;
    }
}


/* Landscape mode on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    body {
        padding: 5px;
    }

    .game-container {
        padding: 10px;
    }

    header {
        margin-bottom: 5px;
    }

    header h1 {
        font-size: 1.2rem;
    }

    .info-panel {
        padding: 5px;
        margin-bottom: 5px;
    }

    .controls-info {
        display: none;
    }
}
