/* Cannibals of the Forest - Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box
}

body {
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background: linear-gradient(180deg, #0a0a0f, #1a1a2e, #0f0f1a);
    min-height: 100vh;
    min-height: 100dvh;
    overscroll-behavior: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff
}

.game-container {
    position: relative;
    flex-shrink: 0;
    width: min(800px, 100%);
    height: 600px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 0 50px rgba(139, 0, 0, 0.4), inset 0 0 80px rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(139, 0, 0, 0.3);
    touch-action: none
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.4s
}

.screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none
}

#main-menu,
#highscores-screen,
#gameover-screen {
    background: linear-gradient(180deg, #1a0a0a, #2a1a1a, #0a0505)
}

.screen-content {
    text-align: center;
    padding: 40px
}

.game-title {
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 10px;
    background: linear-gradient(180deg, #ff4444, #cc0000);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 20px rgba(255, 0, 0, 0.5));
    animation: titlePulse 2s infinite
}

@keyframes titlePulse {

    0%,
    100% {
        filter: drop-shadow(0 0 20px rgba(255, 0, 0, 0.5));
        transform: scale(1)
    }

    50% {
        filter: drop-shadow(0 0 40px rgba(255, 0, 0, 0.8));
        transform: scale(1.02)
    }
}

.game-subtitle {
    font-size: 1.4rem;
    color: #aa6666;
    margin-bottom: 40px
}

.difficulty-picker {
    width: min(100%, 540px);
    margin: -20px auto 24px;
    padding: 14px;
    border: 1px solid rgba(150, 220, 150, 0.28);
    border-radius: 14px;
    background: rgba(4, 18, 10, 0.76);
}

.difficulty-picker legend {
    padding: 0 8px;
    color: #b9f6b9;
    font-weight: 700;
}

.difficulty-options {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
}

.difficulty-btn {
    min-height: 42px;
    padding: 8px 5px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.05);
    color: #d7e8d7;
    cursor: pointer;
}

.difficulty-btn:hover,
.difficulty-btn.active {
    border-color: #65d865;
    background: rgba(57, 160, 57, 0.24);
    color: #fff;
    box-shadow: 0 0 0 2px rgba(101, 216, 101, 0.12);
}

.difficulty-btn--danger.active {
    border-color: #ff5f5f;
    background: rgba(180, 28, 28, 0.3);
}

.difficulty-description {
    min-height: 1.4em;
    margin: 10px 0 0;
    color: #a9b9a9;
    font-size: 0.82rem;
}

.store-link {
    display: inline-block;
    margin-top: 14px;
    padding: 10px 16px;
    border: 1px solid rgba(255, 215, 0, .45);
    border-radius: 8px;
    background: rgba(255, 215, 0, .08);
    color: #ffd700;
    text-decoration: none;
    font-weight: 700;
}

.portal-perks-info {
    margin-top: 8px;
    color: #9caf9c;
    font-size: .78rem;
}

.hud-difficulty {
    min-width: 112px;
}

.screen-title {
    font-size: 2.5rem;
    margin-bottom: 30px;
    color: #ff6666
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center
}

.btn {
    padding: 16px 45px;
    font-size: 1.2rem;
    font-weight: 700;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 2px;
    min-width: 250px
}

.btn.hidden {
    display: none
}

.btn-primary {
    background: linear-gradient(180deg, #cc0000, #990000);
    color: #fff;
    box-shadow: 0 5px 0 #660000;
    border: 2px solid #ff3333
}

.btn-primary:hover {
    transform: translateY(-2px)
}

.btn-primary:active {
    transform: translateY(3px)
}

.btn-primary.disabled,
.btn-primary:disabled {
    background: linear-gradient(180deg, #555, #444);
    border-color: #666;
    box-shadow: 0 5px 0 #333;
    cursor: not-allowed;
    opacity: 0.7
}

.btn-secondary {
    background: linear-gradient(180deg, #4a4a5a, #3a3a4a);
    color: #fff;
    box-shadow: 0 5px 0 #2a2a3a;
    border: 2px solid #5a5a6a
}

.btn-secondary:hover {
    transform: translateY(-2px)
}

.btn-danger {
    background: linear-gradient(180deg, #8b0000, #5a0000);
    color: #ffaaaa;
    box-shadow: 0 5px 0 #3a0000;
    border: 2px solid #aa3333
}

.btn-danger:hover {
    transform: translateY(-2px)
}

.btn-small {
    padding: 10px 20px;
    font-size: 0.9rem;
    min-width: auto
}

.highscores-box {
    background: rgba(0, 0, 0, 0.5);
    padding: 25px 40px;
    border-radius: 16px;
    margin-bottom: 30px;
    border: 2px solid rgba(139, 0, 0, 0.3);
    min-width: 350px;
    max-height: 350px;
    overflow-y: auto
}

.highscores-list {
    list-style: none
}

.highscores-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid rgba(139, 0, 0, 0.2);
    font-size: 1rem;
    gap: 15px
}

.highscores-list li:last-child {
    border-bottom: none
}

.highscores-list li.no-scores {
    justify-content: center;
    color: #666;
    font-style: italic
}

.score-rank {
    color: #ffaa00;
    font-weight: 700;
    min-width: 40px
}

.score-details {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    flex: 1
}

.score-value {
    color: #ff4444;
    font-weight: 700;
    font-size: 1.1rem
}

.score-info {
    color: #888;
    font-size: 0.85rem
}

#game-screen {
    background: #0a0a0a
}

#game-canvas {
    display: block
}

.pause-button,
.build-button {
    position: absolute;
    width: 45px;
    height: 45px;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    font-size: 1.3rem;
    cursor: pointer;
    z-index: 20;
    display: flex;
    justify-content: center;
    align-items: center
}

.pause-button {
    top: 10px;
    right: 10px
}

.build-button {
    top: 10px;
    right: 65px
}

.pause-button:hover,
.build-button:hover {
    background: rgba(50, 50, 50, 0.9);
    transform: scale(1.1)
}

#hud {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    background: rgba(0, 0, 0, 0.8);
    padding: 10px 20px;
    border-radius: 30px;
    z-index: 10;
    border: 1px solid rgba(139, 0, 0, 0.4)
}

.hud-item {
    display: flex;
    align-items: center;
    gap: 6px
}

.hud-label {
    font-size: 1rem
}

#score,
#wave,
#health-text,
#crystals {
    font-size: 1.1rem;
    font-weight: 700;
    color: #ff6666;
    min-width: 30px
}

#crystals {
    color: #44aaff
}

.crystal-counter {
    border-left: 1px solid rgba(255, 255, 255, 0.2);
    padding-left: 15px
}

.health-bar {
    gap: 8px
}

.bar-container {
    width: 100px;
    height: 14px;
    background: #2a1a1a;
    border-radius: 7px;
    overflow: hidden;
    border: 2px solid #4a2a2a
}

.bar-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, #ff4444, #cc0000);
    border-radius: 5px;
    transition: width 0.3s
}

.sleep-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    opacity: 0;
    pointer-events: none;
    z-index: 50;
    transition: opacity 0.5s
}

.sleep-overlay.active {
    pointer-events: all
}

.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    transition: opacity 0.3s
}

.modal.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none
}

.modal-content {
    background: linear-gradient(180deg, #2a1a1a, #1a0a0a);
    padding: 30px 40px;
    border-radius: 20px;
    border: 2px solid rgba(139, 0, 0, 0.5);
    text-align: center;
    max-width: 90%;
    max-height: 90%;
    overflow-y: auto
}

.modal-title {
    font-size: 1.8rem;
    margin-bottom: 20px;
    color: #ff6666
}

.rules-content,
.build-content {
    text-align: left;
    max-width: 450px
}

.rules-box {
    background: rgba(0, 0, 0, 0.4);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 20px
}

.rules-box h3 {
    color: #ff8888;
    margin: 12px 0 8px;
    font-size: 1rem
}

.rules-box h3:first-child {
    margin-top: 0
}

.rules-box p,
.rules-box li {
    color: #ccaaaa;
    line-height: 1.5;
    font-size: 0.9rem
}

.rules-box ul {
    list-style: none;
    padding-left: 0
}

.rules-box li {
    padding: 4px 0 4px 15px;
    position: relative
}

.rules-box li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: #ff6666
}

.key-inline {
    display: inline-block;
    background: #3a2a2a;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-weight: bold;
    color: #ffaaaa;
    border: 1px solid #5a3a3a;
    font-size: 0.85rem
}

.monster-name {
    font-weight: 700
}

.monster-name.zombie {
    color: #6a9c6a
}

.monster-name.bug {
    color: #8a6a5a
}

.build-list {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 400px;
    overflow-y: auto
}

.build-item {
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(0, 0, 0, 0.4);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid rgba(68, 170, 255, 0.3)
}

.build-item.hidden {
    display: none
}

.build-item--weapon {
    border-color: rgba(255, 216, 74, 0.34)
}

#bug-weapon-item {
    border-color: rgba(102, 231, 255, 0.38)
}

.build-icon {
    font-size: 2.5rem
}

.build-info {
    flex: 1
}

.build-info h4 {
    color: #44aaff;
    margin-bottom: 5px
}

.build-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 5px
}

.build-title-row h4 {
    margin-bottom: 0
}

.weapon-level {
    flex: 0 0 auto;
    padding: 3px 7px;
    border: 1px solid rgba(255, 216, 74, 0.35);
    border-radius: 999px;
    color: #ffd84a;
    background: rgba(255, 216, 74, 0.08);
    font-size: 0.7rem;
    font-weight: 700
}

.weapon-level--bug {
    border-color: rgba(102, 231, 255, 0.4);
    color: #66e7ff;
    background: rgba(102, 231, 255, 0.08)
}

.build-cost--bug {
    color: #66e7ff
}

.build-info p {
    color: #aaa;
    font-size: 0.85rem;
    margin-bottom: 8px
}

.build-cost {
    display: flex;
    align-items: center;
    gap: 5px;
    color: #44aaff;
    font-weight: bold
}

.luck-info {
    color: #aaa;
    font-size: 0.85rem;
    line-height: 1.5;
    padding: 8px 0
}

.luck-info strong {
    color: #44ff88
}

.gameover-title {
    font-size: 3rem;
    margin-bottom: 25px;
    color: #ff0000;
    text-shadow: 0 0 20px rgba(255, 0, 0, 0.8);
    animation: gameoverFlash 0.5s infinite alternate
}

@keyframes gameoverFlash {
    from {
        text-shadow: 0 0 20px rgba(255, 0, 0, 0.8)
    }

    to {
        text-shadow: 0 0 30px rgba(255, 0, 0, 1), 0 0 60px rgba(255, 0, 0, 0.7)
    }
}

.result-box {
    background: rgba(30, 10, 10, 0.8);
    padding: 25px 40px;
    border-radius: 16px;
    margin-bottom: 30px;
    border: 2px solid rgba(139, 0, 0, 0.4)
}

.result-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(139, 0, 0, 0.2)
}

.result-row:last-child {
    border-bottom: none
}

.result-label {
    font-size: 1rem;
    color: #aa6666
}

.result-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: #ff4444;
    min-width: 50px;
    text-align: right
}

/* ============================================
   MOBILE / TOUCH CONTROLS
   ============================================ */

/* Prevent scroll and zoom during gameplay */
html,
body {
    overscroll-behavior: none;
}

body.touch-active {
    touch-action: none;
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Canvas touch behavior */
#game-canvas {
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Touch Controls Container */
.touch-controls {
    display: none;
    /* Hidden on desktop by default */
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 30;
}

/* Show on touch devices */
.touch-controls.active {
    display: block;
}

/* ----------------------------------------
   VIRTUAL JOYSTICK (Left side)
   ---------------------------------------- */
.joystick-zone {
    position: absolute;
    left: 10px;
    bottom: 20px;
    width: 140px;
    height: 140px;
    pointer-events: auto;
    touch-action: none;
}

.joystick-base {
    position: relative;
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.joystick-thumb {
    width: 50px;
    height: 50px;
    background: rgba(255, 100, 100, 0.6);
    border: 2px solid rgba(255, 150, 150, 0.8);
    border-radius: 50%;
    transition: transform 0.05s ease-out;
    box-shadow: 0 0 15px rgba(255, 100, 100, 0.4);
}

.joystick-thumb.active {
    background: rgba(255, 100, 100, 0.9);
    box-shadow: 0 0 25px rgba(255, 100, 100, 0.7);
}

/* ----------------------------------------
   ACTION BUTTONS (Right side)
   ---------------------------------------- */
.action-buttons {
    position: absolute;
    right: 10px;
    bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: auto;
}

.touch-btn {
    width: 64px;
    height: 64px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 16px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    transition: all 0.1s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.touch-btn__icon {
    font-size: 1.6rem;
    line-height: 1;
}

.touch-btn__label {
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.7);
}

/* Button states */
.touch-btn:active,
.touch-btn.pressed {
    transform: scale(0.92);
    background: rgba(255, 255, 255, 0.15);
}

/* Attack button - red accent */
.touch-btn--attack {
    border-color: rgba(255, 100, 100, 0.5);
    box-shadow: 0 0 10px rgba(255, 50, 50, 0.3);
}

.touch-btn--attack:active,
.touch-btn--attack.pressed {
    background: rgba(255, 50, 50, 0.3);
    border-color: rgba(255, 100, 100, 0.8);
}

/* Dash button - blue accent */
.touch-btn--dash {
    border-color: rgba(100, 150, 255, 0.5);
    box-shadow: 0 0 10px rgba(50, 100, 255, 0.3);
}

.touch-btn--dash:active,
.touch-btn--dash.pressed {
    background: rgba(50, 100, 255, 0.3);
    border-color: rgba(100, 150, 255, 0.8);
}

/* Shoot button - yellow accent */
.touch-btn--shoot {
    border-color: rgba(255, 200, 50, 0.5);
    box-shadow: 0 0 10px rgba(255, 180, 0, 0.3);
}

.touch-btn--shoot:active,
.touch-btn--shoot.pressed {
    background: rgba(255, 180, 0, 0.3);
    border-color: rgba(255, 200, 50, 0.8);
}

/* Interact button - green accent */
.touch-btn--interact {
    border-color: rgba(100, 255, 150, 0.5);
    box-shadow: 0 0 10px rgba(50, 200, 100, 0.3);
}

.touch-btn--interact:active,
.touch-btn--interact.pressed {
    background: rgba(50, 200, 100, 0.3);
    border-color: rgba(100, 255, 150, 0.8);
}

/* Hidden button (for pistol before purchase) */
.touch-btn--hidden {
    display: none;
}

.touch-btn--hidden.visible {
    display: flex;
}

/* ============================================
   RESPONSIVE / MOBILE LAYOUT
   ============================================ */

/* Mobile: adapt game container and canvas */
@media (max-width: 900px),
(hover: none) and (pointer: coarse) {
    body {
        align-items: flex-start;
        padding: 0;
        min-height: 100dvh;
    }

    .game-container {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
        border: none;
    }

    #game-canvas {
        width: 100% !important;
        height: 100% !important;
        object-fit: contain;
        touch-action: none;
    }

    /* Show touch controls */
    .touch-controls {
        display: block;
    }

    /* Adjust HUD for mobile */
    #hud {
        padding: 6px 12px;
        gap: 12px;
        font-size: 0.85rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .hud-label {
        font-size: 0.9rem;
    }

    #score,
    #wave,
    #health-text,
    #crystals {
        font-size: 0.95rem;
        min-width: 20px;
    }

    .bar-container {
        width: 70px;
        height: 12px;
    }

    /* Adjust pause/build buttons position */
    .pause-button,
    .build-button {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
    }

    .pause-button {
        top: 8px;
        right: 8px;
    }

    .build-button {
        top: 8px;
        right: 55px;
    }

    /* Menu adaptations */
    .screen-content {
        padding: 20px;
        width: 100%;
        max-height: 100%;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .game-title {
        font-size: 1.8rem;
        line-height: 1.2;
    }

    .game-subtitle {
        font-size: 1rem;
        margin-bottom: 25px;
    }

    .difficulty-picker {
        margin: -12px auto 14px;
        padding: 10px;
    }

    .difficulty-options {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .btn {
        padding: 14px 30px;
        font-size: 1rem;
        min-width: 200px;
    }

    .modal-content {
        padding: 20px;
        max-width: 95%;
    }

    .build-content {
        width: calc(100% - 16px);
        padding: 18px 14px;
    }

    .build-list {
        max-height: min(58dvh, 470px);
        padding-right: 3px;
    }

    .build-item {
        display: grid;
        grid-template-columns: 38px minmax(0, 1fr);
        align-items: start;
        gap: 10px;
        padding: 12px;
    }

    .build-icon {
        width: 38px;
        font-size: 1.8rem;
        text-align: center;
    }

    .build-info {
        min-width: 0;
    }

    .build-title-row {
        align-items: flex-start;
        flex-wrap: wrap;
        gap: 5px 8px;
    }

    .build-item > .btn {
        width: 100%;
        min-width: 0;
        grid-column: 1 / -1;
        padding: 10px 14px;
    }

    .modal-title {
        font-size: 1.4rem;
    }

    .rules-box {
        padding: 10px;
        font-size: 0.85rem;
    }

    .rules-box h3 {
        font-size: 0.9rem;
    }

    /* Smaller action buttons on very small screens */
    @media (max-height: 600px) {
        .touch-btn {
            width: 56px;
            height: 56px;
        }

        .touch-btn__icon {
            font-size: 1.3rem;
        }

        .touch-btn__label {
            display: none;
        }

        .joystick-zone {
            width: 110px;
            height: 110px;
        }

        .joystick-base {
            width: 100px;
            height: 100px;
        }

        .joystick-thumb {
            width: 42px;
            height: 42px;
        }
    }
}

/* Landscape specific adjustments */
@media (max-height: 500px) and (orientation: landscape) {
    .action-buttons {
        flex-direction: row;
        flex-wrap: wrap;
        width: 140px;
        justify-content: flex-end;
    }

    .touch-btn {
        width: 52px;
        height: 52px;
    }

    .touch-btn__label {
        display: none;
    }

    .joystick-zone {
        bottom: 10px;
        left: 10px;
    }

    .joystick-base {
        width: 90px;
        height: 90px;
    }

    .joystick-thumb {
        width: 38px;
        height: 38px;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .touch-btn {
        transition: none;
    }

    .joystick-thumb {
        transition: none;
    }
}
/* Shared three-language selector inside the game menu. */
.game-language-switch {
    align-self: center;
    min-width: 94px;
    margin: 0 auto 12px;
    padding: 8px 12px;
    color: #fff;
    background: rgba(8, 18, 32, .9);
    border: 1px solid rgba(126, 240, 196, .55);
    border-radius: 10px;
    font: 700 14px/1 system-ui, sans-serif;
}

/* Mobile finishing layer: notches, compact HUD and scroll-safe menus. */
@media (max-width: 900px),
(hover: none) and (pointer: coarse) {
    .game-container,
    .screen,
    .screen-content,
    .modal,
    .modal-content { min-width: 0; max-width: 100%; }

    .screen-content {
        padding-top: max(18px, env(safe-area-inset-top, 0px));
        padding-right: max(16px, env(safe-area-inset-right, 0px));
        padding-bottom: max(18px, env(safe-area-inset-bottom, 0px));
        padding-left: max(16px, env(safe-area-inset-left, 0px));
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    .menu-buttons,
    .highscores-box,
    .result-box { width: 100%; min-width: 0; max-width: 100%; }

    .btn {
        width: 100%;
        min-width: 0;
        min-height: 48px;
        padding: 12px 16px;
        letter-spacing: 0.08em;
        touch-action: manipulation;
    }

    .game-language-switch {
        min-height: 44px;
        font-size: 16px;
        touch-action: manipulation;
    }

    .safe-exit-btn { min-height: 44px; touch-action: manipulation; }

    .highscores-box,
    .result-box {
        padding: 16px;
        margin-bottom: 18px;
    }

    #hud {
        top: max(8px, env(safe-area-inset-top, 0px));
        right: max(108px, calc(98px + env(safe-area-inset-right, 0px)));
        left: max(8px, env(safe-area-inset-left, 0px));
        width: auto;
        min-width: 0;
        transform: none;
        justify-content: flex-start;
        gap: 4px 8px;
        padding: 6px 8px;
        border-radius: 12px;
    }

    #hud .hud-item { min-width: 0; gap: 4px; }
    #hud .hud-difficulty { min-width: 0; max-width: 100%; }
    #difficulty-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    #hud .crystal-counter { padding-left: 8px; }

    .pause-button,
    .build-button {
        top: max(8px, env(safe-area-inset-top, 0px));
        width: 44px;
        height: 44px;
        touch-action: manipulation;
    }

    .pause-button { right: max(8px, env(safe-area-inset-right, 0px)); }
    .build-button { right: max(58px, calc(52px + env(safe-area-inset-right, 0px))); }

    .modal {
        padding-top: max(10px, env(safe-area-inset-top, 0px));
        padding-right: max(10px, env(safe-area-inset-right, 0px));
        padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
        padding-left: max(10px, env(safe-area-inset-left, 0px));
    }

    .modal-content {
        width: min(100%, 520px);
        max-height: calc(100dvh - 20px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        padding: 18px 14px;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    .joystick-zone {
        left: max(10px, env(safe-area-inset-left, 0px));
        bottom: max(14px, env(safe-area-inset-bottom, 0px));
    }

    .action-buttons {
        right: max(10px, env(safe-area-inset-right, 0px));
        bottom: max(14px, env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 430px) {
    .difficulty-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .difficulty-btn { min-height: 44px; }
    .game-title { font-size: clamp(1.55rem, 8.5vw, 2rem); overflow-wrap: anywhere; }
    .screen-title { margin-bottom: 18px; font-size: 1.8rem; }
    .modal-title { margin-bottom: 14px; font-size: 1.3rem; }

    #hud {
        right: max(104px, calc(94px + env(safe-area-inset-right, 0px)));
        font-size: 0.76rem;
    }

    #hud .health-bar .hud-label { display: none; }
    .bar-container { width: 54px; }
}

@media (max-height: 500px) and (orientation: landscape) {
    .screen-content { padding-block: max(8px, env(safe-area-inset-top, 0px)); }
    .game-title { margin-bottom: 4px; font-size: 1.45rem; }
    .game-subtitle { margin-bottom: 10px; }
    .difficulty-picker { margin: 0 auto 8px; padding: 8px; }
    .menu-buttons { gap: 7px; }
    .menu-buttons .btn { min-height: 44px; padding-block: 8px; }
}

/* Expedition interface: readable status outside the canvas, on every display. */
body { background: radial-gradient(ellipse at 50% 20%, #173b32, #080f16 72%); }
body:has(#game-screen:not(.hidden)) #safe-exit-btn { display: none; }
button, a { -webkit-tap-highlight-color: transparent; }
.game-container { border-color: #345c4d; box-shadow: 0 24px 90px #0009; }
#main-menu, #highscores-screen, #gameover-screen {
    background: radial-gradient(ellipse at 85% 0%, #285e493d, transparent 65%), linear-gradient(150deg, #152c25, #101920 70%);
}
.screen-content { width: 100%; max-height: 100%; overflow-y: auto; padding: 24px 32px; touch-action: pan-y; }
.game-title { color: #e3efc9; background: none; -webkit-text-fill-color: currentColor; font-size: clamp(1.8rem, 4vw, 2.6rem); animation: none; filter: none; }
.game-subtitle { color: #b5cebe; font-size: 1rem; margin-bottom: 10px; }
.expedition-intro { max-width: 550px; margin: 0 auto 18px; color: #a8c0b6; font-size: .88rem; line-height: 1.55; }
.difficulty-picker { margin: 0 auto 18px; }
#main-menu .menu-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 540px; margin: auto; gap: 10px; }
#main-menu .menu-buttons .btn { min-width: 0; width: 100%; padding: 12px; font-size: .92rem; letter-spacing: .04em; min-height: 48px; }
.btn-primary { background: #266a50; border-color: #82cfa3; box-shadow: 0 3px 0 #0b3b28; }
.btn-primary:hover { background: #347f61; color: #fff; }
.btn-secondary:hover { color: #fff; }
.btn, .difficulty-btn, .store-link { -webkit-text-fill-color: currentColor; }
button:focus-visible, a:focus-visible, select:focus-visible { outline: 3px solid #eadd9e; outline-offset: 3px; }
#game-canvas:focus-visible { outline: 2px solid #96cfb3; outline-offset: -2px; }
.survival-panel { position: absolute; top: 70px; left: 14px; right: 14px; z-index: 12; padding: 12px 14px; border: 1px solid #749d7d66; border-radius: 14px; background: #10271feb; color: #d8e8db; font-size: .8rem; pointer-events: none; }
.survival-heading, .survival-stats, .survival-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.survival-heading strong { color: #f3e8b9; font-size: .94rem; }
#forest-time { font-variant-numeric: tabular-nums; color: #c0dbc7; }
#day-meter { display: block; width: 100%; height: 5px; margin: 9px 0; accent-color: #d3bd78; border: 0; border-radius: 5px; overflow: hidden; }
#day-meter::-webkit-progress-bar { background: #ffffff1a; }
#day-meter::-webkit-progress-value { background: #d3bd78; }
.forest-map { height: 4px; background: #a5ceb32b; margin: 13px 8px; position: relative; border-radius: 4px; }
.forest-map span { position: absolute; top: 50%; transform: translate(-50%, -50%); }
#map-player { color: #a4edc6; font-size: 13px; text-shadow: 0 0 6px #abffd3; }
.map-camp { left: 93%; color: #eed894; font-size: 22px; background: #122b22; }
.survival-footer { font-size: .73rem; color: #adc6b6; }
#camp-action { pointer-events: auto; padding: 8px 12px; min-height: 36px; border-radius: 8px; background: #376a52; border: 1px solid #b6d69f; color: #fff; font: inherit; font-weight: 700; cursor: pointer; }
#camp-action:disabled { color: #c0cabc; border-color: #6d8472; background: #24382b; cursor: default; }
#camp-action:not(:disabled):hover { background: #528460; color: #fff; }
.touch-btn:disabled { opacity: .55; filter: saturate(.4); }
.forest-message { position: absolute; z-index: 35; top: 245px; left: 20px; right: 20px; padding: 12px; color: #ffe8af; background: #33230bf0; border: 1px solid #c2a363; border-radius: 10px; text-align: center; }
.forest-message[hidden] { display: none; }
.forest-controls, .save-status { margin: 12px 0; color: #c0d3c7; font-size: .85rem; line-height: 1.6; }
#sleep-overlay { transition: opacity .6s ease; }
#new-run-dialog { margin: auto; width: min(520px, calc(100% - 28px)); max-height: calc(100dvh - 28px); padding: 24px; border: 1px solid #7eaa8d; border-radius: 18px; color: #e9f1e9; background: #142a23; }
#new-run-dialog::backdrop { background: #050e0bc9; }
#new-run-dialog p { margin: 16px 0; line-height: 1.6; color: #c8d8c9; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.dialog-actions .btn { flex: 1; min-width: 160px; font-size: .85rem; padding: 12px; letter-spacing: .04em; }
@media (max-width: 600px) {
    .screen-content { padding: 22px 16px; }
    .expedition-intro { font-size: .82rem; }
    .survival-panel { top: max(92px, calc(82px + env(safe-area-inset-top, 0px))); left: 8px; right: 8px; padding: 10px; }
    .survival-heading strong { font-size: .85rem; }
    .survival-panel { font-size: .72rem; }
    .survival-footer { flex-wrap: nowrap; }
    #forest-zone { max-width: 65%; }
    #camp-action { min-height: 44px; flex-shrink: 0; }
    .forest-message { top: 280px; font-size: .8rem; }
}
@media (max-height: 500px) and (orientation: landscape) {
    .survival-panel { top: 66px; padding: 7px 10px; }
    .survival-footer, .forest-map { display: none; }
    #day-meter { margin: 5px 0; }
    .forest-message { top: 160px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Compact battle information, without flashing low-health effects. */
.forest-alerts{display:flex;justify-content:space-between;gap:6px 14px;flex-wrap:wrap;font-size:.74rem;margin:5px 0 8px}
#forest-danger[data-level="clear"]{color:#b5d6ba}#forest-danger[data-level="near"]{color:#ffe3a1}#forest-danger[data-level="critical"]{color:#ffb9b2;font-weight:700}
#forest-kills{color:#dce8d3;white-space:nowrap}
#forest-boss[hidden]{display:none}#forest-boss{padding:6px 0}#forest-boss label{color:#ffcfba;font-weight:700}#forest-boss-health{display:block;width:100%;height:7px;margin-top:5px;accent-color:#ec826e}
.forest-map #map-enemies{inset:0;transform:none;height:100%;width:100%}
#map-enemies i{position:absolute;top:50%;width:5px;height:7px;background:#ffb49c;border:1px solid #4c2925;transform:translate(-50%,-50%);border-radius:2px}
#map-enemies i.is-boss{width:9px;height:9px;background:#ff6f70;transform:translate(-50%,-50%) rotate(45deg)}#map-enemies i[hidden]{display:none}
#map-player,.map-camp{z-index:2}
@media(max-height:500px) and (orientation:landscape){.forest-alerts{margin:2px 0;font-size:.65rem}#forest-boss{padding:2px 0}}
