/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #06101f;
    color: #eee;
}

/* === Game Container === */
.game-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    position: relative;
}

/* === Header / HUD === */
.game-header {
    height: 40px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    background: #002855;
    color: #eee;
    font-size: 13px;
    font-weight: 600;
    z-index: 1000;
    gap: 8px;
}

.hud-left, .hud-center, .hud-right {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.hud-left { flex: 1; min-width: 0; overflow: hidden; }
.hud-center { flex-shrink: 0; }
.hud-right { flex-shrink: 0; gap: 8px; }

#hud-score { color: #fdba58; }
#hud-score.over-optimal { color: #e44730; }
#hud-total { color: #8ab4d8; }

.header-btn {
    background: none;
    border: none;
    color: #eee;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
}

/* === Hamburger Popup === */
.hamburger-popup {
    position: absolute;
    top: 40px;
    right: 8px;
    background: #ffffff;
    border: 1px solid #d0d8e0;
    border-radius: 8px;
    padding: 8px;
    z-index: 1100;
    min-width: 160px;
    box-shadow: 0 4px 16px rgba(0, 40, 85, 0.15);
}

.hamburger-popup.hidden {
    display: none;
}

/* === Map / Canvas === */
#game-map {
    flex: 1;
    min-height: 0;
    background: #ffffff;
    position: relative;
    overflow: hidden;
    touch-action: none;
}

#game-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

/* === Arrow Overlay === */
#arrow-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

.arrow-btn {
    position: absolute;
    pointer-events: auto;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid #CE000C;
    background: #CE000C;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, box-shadow 0.15s;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    box-shadow: 0 2px 8px rgba(206, 0, 12, 0.3);
}

.arrow-btn:active {
    background: #a50009;
    box-shadow: 0 2px 12px rgba(206, 0, 12, 0.5);
}

.arrow-btn.arrow-blocked {
    border-color: #CE000C;
    background: rgba(206, 0, 12, 0.3);
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    box-shadow: 0 0 12px rgba(206, 0, 12, 0.2);
    animation: danger-pulse 1.5s ease-in-out infinite;
}

@keyframes danger-pulse {
    0%, 100% { box-shadow: 0 0 12px rgba(206, 0, 12, 0.2); }
    50% { box-shadow: 0 0 20px rgba(206, 0, 12, 0.5); }
}

.arrow-btn.arrow-behind {
    width: 44px;
    height: 44px;
    opacity: 0.6;
}

.arrow-btn svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

/* === Recenter Button === */
.recenter-btn {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 15;
    padding: 8px 22px;
    background: rgba(0, 58, 116, 0.9);
    color: #ffffff;
    border: 1px solid #003a74;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    touch-action: manipulation;
    user-select: none;
}

.recenter-btn:active {
    background: rgba(0, 40, 85, 0.95);
}

.recenter-btn.hidden {
    display: none;
}

/* === Ad Banner === */
.ad-banner {
    height: 60px;
    flex-shrink: 0;
    background: #081020;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #3a5070;
    font-size: 12px;
}

/* === Overlays === */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 40, 85, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    background: #ffffff;
    border: 1px solid #d0d8e0;
    border-radius: 12px;
    padding: 32px 28px;
    text-align: center;
    max-width: 360px;
    width: 90%;
    max-height: 90vh;
    max-height: 90dvh;
    overflow-y: auto;
    color: #002855;
    box-shadow: 0 8px 32px rgba(0, 40, 85, 0.2);
}

.overlay-content h1 {
    font-size: 28px;
    margin-bottom: 8px;
    color: #003a74;
}

.overlay-content h2 {
    font-size: 22px;
    margin-bottom: 12px;
    color: #003a74;
}

/* === Game Over h2 in red === */
#overlay-gameover h2 {
    color: #CE000C;
}

/* === Buttons === */
.btn-primary {
    display: block;
    width: 100%;
    padding: 12px 20px;
    margin: 8px 0;
    background: #003a74;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-primary:hover {
    background: #002855;
}

.btn-primary:disabled {
    background: #d0d8e0;
    color: #8a9ab0;
    cursor: not-allowed;
}

.btn-secondary {
    display: block;
    width: 100%;
    padding: 10px 20px;
    margin: 8px 0;
    background: transparent;
    color: #003a74;
    border: 1px solid #003a74;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.btn-secondary:hover {
    background: #f0f4f8;
    color: #002855;
}

.btn-share {
    font-size: 13px;
    padding: 10px 20px;
}

.btn-red {
    background: #CE000C;
}

.btn-red:hover {
    background: #a50009;
}

/* === Start Page === */
.start-page {
    max-width: 360px;
}

.start-store-img {
    width: 270px;
    height: auto;
    margin: 0 auto 16px;
    display: block;
    border-radius: 8px;
    image-rendering: pixelated;
}

.start-tagline {
    color: #CE000C;
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 16px;
    line-height: 1.4;
}

.start-explanation {
    color: #3a5a7a;
    font-size: 14px;
    margin-bottom: 0;
    line-height: 1.5;
}

.start-spacer {
    height: 24px;
}

.start-scoring {
    color: #3a5a7a;
    font-size: 13px;
    margin-top: 12px;
    line-height: 1.4;
}

.start-disclaimer {
    color: #8a9ab0;
    font-size: 11px;
    margin-top: 12px;
    line-height: 1.3;
}

/* === Game Over Store Photo === */
.gameover-store-img {
    width: 200px;
    height: auto;
    margin: 0 auto 12px;
    display: block;
    border-radius: 8px;
}

.gameover-store-img.has-photo {
    border: 2px solid #CE000C;
}

/* === Game Over Stats === */
.gameover-stat {
    margin: 20px 0;
    text-align: center;
}

.gameover-stat:first-of-type {
    margin-top: 20px;
}

.gameover-stat:last-of-type {
    margin-bottom: 20px;
}

.gameover-big-num {
    display: block;
    font-size: 34px;
    font-weight: 800;
    color: #CE000C;
    line-height: 1.1;
}

.gameover-stat-label {
    display: block;
    font-size: 14px;
    color: #3a5a7a;
    font-weight: 400;
    margin-top: 2px;
}

/* === Overlay score/rating === */
.overlay-rating {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.overlay-rating.perfect { color: #CE000C; }
.overlay-rating.great { color: #003a74; }
.overlay-rating.good { color: #3a6a9a; }
.overlay-rating.completed { color: #6a8aaa; }

.overlay-score {
    color: #3a5a7a;
    font-size: 15px;
    margin-bottom: 16px;
    line-height: 1.6;
}

.overlay-rank {
    color: #003a74;
    font-size: 14px;
    margin-bottom: 16px;
    font-weight: 600;
}

/* === Victory === */
.victory-content {
    max-width: 360px;
}

.victory-subtitle {
    color: #3a5a7a;
    font-size: 15px;
    margin-bottom: 12px;
}

.total-score-big {
    font-size: 48px;
    font-weight: 800;
    color: #003a74;
    margin: 8px 0 16px;
}

/* === Spinner === */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #d0d8e0;
    border-top-color: #003a74;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 16px auto 0;
}

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

/* === Small screens === */
@media (max-height: 700px) {
    .overlay-content {
        padding: 20px 20px;
    }

    .start-store-img {
        width: 180px;
    }

    .start-tagline {
        font-size: 17px;
    }

    .start-spacer {
        height: 12px;
    }

    .gameover-store-img {
        width: 140px;
    }

    .gameover-stat {
        margin: 8px 0;
    }

    .gameover-stat:first-of-type {
        margin-top: 8px;
    }

    .gameover-stat:last-of-type {
        margin-bottom: 8px;
    }

    .gameover-big-num {
        font-size: 28px;
    }

    #overlay-gameover h2 {
        margin-bottom: 8px;
    }
}

/* === Desktop === */
@media (min-width: 768px) {
    .game-header {
        height: 50px;
        font-size: 15px;
    }

    .ad-banner {
        height: 90px;
    }

    .arrow-btn {
        width: 52px;
        height: 52px;
    }
}
