:root {
    --panel-radius: 18px;
    --btn-green: #4CAF50;
    --btn-green-light: #66BB6A;
    --btn-green-dark: #2E7D32;
    --text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #0f0f23;
    font-family: 'Arial Rounded MT Bold', 'Nunito', Arial, Helvetica, sans-serif;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

#gameWrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
}

#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

.hidden {
    display: none !important;
}

/* ========== HUD ========== */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
    z-index: 10;
}

#scoreDisplay {
    font-size: 48px;
    font-weight: bold;
    color: white;
    text-shadow: var(--text-shadow);
    line-height: 1;
}

#hudButtons {
    display: flex;
    gap: 8px;
    pointer-events: all;
}

.hud-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.35);
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.hud-btn:hover {
    background: rgba(0, 0, 0, 0.5);
}

.hud-btn:active {
    transform: scale(0.9);
}

/* ========== OVERLAYS ========== */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
    background: rgba(0, 0, 0, 0.3);
}

.panel {
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--panel-radius);
    padding: 28px 48px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 80%;
    min-width: 280px;
    animation: panelIn 0.3s ease-out;
    position: relative;
}

.menu-fullscreen-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.08);
    color: #666;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s ease, background 0.1s ease;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.menu-fullscreen-btn:hover {
    background: rgba(0, 0, 0, 0.14);
}

.menu-fullscreen-btn:active {
    transform: scale(0.88);
}

.theme-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 18px;
}

.theme-arrow {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(180deg, #66BB6A, #4CAF50);
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 0 #2E7D32;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.theme-arrow:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 0 #2E7D32;
}

.theme-arrow:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #2E7D32;
}

.theme-name {
    font-size: 15px;
    font-weight: bold;
    color: #555;
    letter-spacing: 1px;
    min-width: 76px;
    text-transform: uppercase;
}

@keyframes panelIn {
    from {
        opacity: 0;
        transform: scale(0.85) translateY(15px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ========== START SCREEN ========== */
.game-title {
    font-size: 42px;
    color: #FF9800;
    text-shadow: 2px 2px 0 #E65100, 3px 3px 0 rgba(0, 0, 0, 0.1);
    margin-bottom: 14px;
    letter-spacing: 4px;
}

.subtitle {
    font-size: 15px;
    color: #555;
    margin-bottom: 6px;
    font-weight: bold;
    letter-spacing: 1px;
}

.hint {
    font-size: 12px;
    color: #999;
    margin-bottom: 20px;
    margin-top: 20px;
}

.best-display {
    margin-top: 12px;
    font-size: 14px;
    color: #888;
    font-weight: bold;
}

/* ========== BUTTONS ========== */
.game-btn {
    display: inline-block;
    padding: 14px 52px;
    font-size: 22px;
    font-weight: bold;
    color: white;
    background: linear-gradient(180deg, var(--btn-green-light), var(--btn-green));
    border: none;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 5px 0 var(--btn-green-dark), 0 7px 18px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.game-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 7px 0 var(--btn-green-dark), 0 9px 22px rgba(0, 0, 0, 0.25);
}

.game-btn:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 var(--btn-green-dark), 0 3px 10px rgba(0, 0, 0, 0.2);
}

/* ========== GAME OVER ========== */
.gameover-title {
    font-size: 36px;
    color: #f44336;
    text-shadow: 2px 2px 0 #c62828;
    margin-bottom: 18px;
    letter-spacing: 2px;
}

.score-section {
    margin: 6px 0;
}

.score-label {
    font-size: 13px;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 3px;
    font-weight: bold;
}

.score-value {
    font-size: 42px;
    font-weight: bold;
    color: #333;
    line-height: 1.2;
}

.new-best {
    font-size: 20px;
    color: #FF9800;
    font-weight: bold;
    margin: 8px 0;
    animation: newBestPulse 0.6s ease-in-out infinite;
}

.new-best.hidden {
    display: none;
}

@keyframes newBestPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* ========== SECONDARY BUTTON ========== */
.btn-secondary {
    background: linear-gradient(180deg, #78909C, #607D8B);
    box-shadow: 0 5px 0 #455A64, 0 7px 18px rgba(0, 0, 0, 0.2);
    margin-top: 10px;
}

.btn-secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 7px 0 #455A64, 0 9px 22px rgba(0, 0, 0, 0.25);
}

.btn-secondary:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 #455A64, 0 3px 10px rgba(0, 0, 0, 0.2);
}

/* ========== PAUSE ========== */
.pause-title {
    font-size: 36px;
    color: #333;
    margin-bottom: 22px;
    letter-spacing: 2px;
}

/* ========== LANDSCAPE TWEAKS ========== */
@media (orientation: landscape) and (max-height: 500px) {
    .panel {
        padding: 16px 36px;
    }
    .game-title {
        font-size: 32px;
        margin-bottom: 8px;
    }
    .subtitle {
        font-size: 12px;
    }
    .hint {
        font-size: 11px;
        margin-bottom: 12px;
    }
    .game-btn {
        padding: 10px 40px;
        font-size: 18px;
    }
    .gameover-title,
    .pause-title {
        font-size: 28px;
        margin-bottom: 12px;
    }
    .score-value {
        font-size: 34px;
    }
    .score-section {
        margin: 3px 0;
    }
    .theme-selector {
        margin-top: 12px;
        gap: 10px;
    }
    .theme-arrow {
        width: 30px;
        height: 30px;
    }
    .theme-name {
        font-size: 13px;
    }
}

@media (orientation: landscape) and (max-height: 400px) {
    .panel {
        padding: 12px 28px;
    }
    .game-title {
        font-size: 26px;
    }
    .game-btn {
        padding: 8px 32px;
        font-size: 16px;
    }
    .score-value {
        font-size: 28px;
    }
    .new-best {
        font-size: 16px;
    }
    .menu-fullscreen-btn {
        width: 30px;
        height: 30px;
        top: 8px;
        right: 8px;
    }
}

/* The game world is laid out by JS:
   - portrait / small screens -> vertical world (fills screen)
   - landscape / big screens  -> horizontal world (fills screen) */

/* ========== SMALL SCREENS ========== */
@media (max-width: 480px) and (orientation: portrait) {
    .panel {
        padding: 20px 28px;
        min-width: unset;
        width: min(86vw, 340px);
    }
    .game-title {
        font-size: 30px;
    }
    .game-btn {
        padding: 12px 44px;
        font-size: 20px;
    }
    .menu-fullscreen-btn {
        width: 30px;
        height: 30px;
        top: 8px;
        right: 8px;
        font-size: 13px;
    }
    .theme-selector {
        margin-top: 14px;
        gap: 10px;
    }
    .theme-arrow {
        width: 30px;
        height: 30px;
    }
    .theme-name {
        font-size: 13px;
    }
}

/* Small screens: keep HUD compact and inside notched displays */
@media (max-width: 600px), (max-height: 520px) {
    #hud {
        padding: calc(10px + env(safe-area-inset-top, 0px)) calc(14px + env(safe-area-inset-right, 0px));
    }
    #scoreDisplay {
        font-size: 34px;
    }
}

/* ========== WIDE SCREENS (desktop) ========== */
@media (min-width: 1200px) and (orientation: landscape) {
    #gameWrapper {
        border-radius: 12px;
        box-shadow: 0 0 80px rgba(0, 0, 0, 0.6);
    }
}
