/* 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;
    justify-content: center;
    align-items: center;
    color: #fff
}

.game-container {
    position: relative;
    width: 800px;
    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-icon {
    font-size: 2.5rem
}

.build-info {
    flex: 1
}

.build-info h4 {
    color: #44aaff;
    margin-bottom: 5px
}

.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%;
    }

    .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;
    }
}
