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

/* Ad strip + reserved zone (flex layout + fixed UI use this so nothing draws over the banner). */
:root {
    --ad-banner-width: 728px;
    --ad-banner-height: 28px;
    --ad-slot-gap: 8px;
    --ad-reserved-height: calc(var(--ad-banner-height) + var(--ad-slot-gap) + env(safe-area-inset-bottom, 0px));
}

html {
    height: 100%;
}

body {
    font-family: 'Courier New', monospace;
    background: #1a1a1a;
    color: #e0e0e0;
    overflow: hidden;
    min-height: 100%;
    min-height: 100dvh;
}

#game-container {
    position: relative;
    width: 100%;
    max-width: 100vw;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    background: #0a0a0a;
    box-sizing: border-box;
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-top: env(safe-area-inset-top, 0px);
}

#game-stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    overflow: hidden;
}

/* Bottom ad strip + gap so flex layout never draws HUD/game under the banner */
.ad-banner-slot {
    flex: 0 0 auto;
    width: 100%;
    min-height: var(--ad-banner-height);
    height: var(--ad-banner-height);
    margin-top: var(--ad-slot-gap);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: #000;
    border-top: 1px solid #222;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    box-sizing: content-box;
}

.ad-banner-frame {
    width: 100%;
    max-width: var(--ad-banner-width);
    height: var(--ad-banner-height);
    min-height: var(--ad-banner-height);
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    border: 2px solid #222;
    box-sizing: border-box;
    overflow: hidden;
}

.ad-banner-hit {
    width: 100%;
    height: 100%;
    min-height: var(--ad-banner-height);
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
    cursor: default;
    min-width: 0;
}

.ad-banner-hit--linked {
    cursor: pointer;
}

.ad-banner-hit--linked:focus-visible {
    box-shadow: inset 0 0 0 2px #4488ff;
}

.ad-banner-img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: center;
    pointer-events: none;
    user-select: none;
    flex-shrink: 0;
}

.ad-coming-soon-toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--ad-reserved-height) + 12px);
    transform: translateX(-50%);
    z-index: 10001;
    padding: 10px 18px;
    background: rgba(20, 20, 20, 0.96);
    border: 1px solid #4488ff;
    border-radius: 4px;
    color: #e0e0e0;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    max-width: min(420px, 92vw);
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.55);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.28s ease;
}

.ad-coming-soon-toast--visible {
    opacity: 1;
}

#scene-background.hidden {
    display: none !important;
}

#loading-screen {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: #0a0a0a;
    color: #888;
}
#loading-screen.hidden {
    display: none !important;
}
#loading-screen img {
    max-width: 80%;
    max-height: 60vh;
    object-fit: contain;
}
#loading-screen p {
    margin-top: 16px;
    font-size: 14px;
}

#game-play-inner #scene-background {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    z-index: 0;
    pointer-events: none;
}

#game-canvas {
    border: none;
    background: transparent;
    cursor: crosshair;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    display: block;
    box-sizing: border-box;
    touch-action: none;
}

/* Full inner hit target: explicit w/h set in JS to match inner; pan/tap listeners attach here. */
.game-play-pointer-layer,
#game-play-pointer-layer {
    position: absolute;
    /* Fill #game-play-inner exactly (constraint box); avoids JS px vs subpixel gaps where inner would steal events */
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: auto;
    z-index: 12;
    pointer-events: auto;
    touch-action: none;
    cursor: crosshair;
    /* DEBUG: semi-transparent overlay — set background to transparent when verified on device */
    background: rgba(0, 255, 100, 0.14);
    box-sizing: border-box;
}
#game-canvas:not(.hidden) {
    display: block !important;
}

/* Three-column gameplay: sidebars | center viewport (mobile: cover-scale + pan; desktop: contain, full map) | sidebars */
#game-play-root {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    z-index: 5;
}

#game-play-root:not(.hidden) {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    max-width: 100%;
    overflow-x: hidden;
}

#game-play-root.hidden {
    display: none !important;
}

/* Outer column: no scroll. Inner .hud-sidebar-scroll is the only menu scroll region (vertical-first). */
#hud-sidebar-left,
#hud-sidebar-right {
    flex: 0 0 auto;
    width: clamp(200px, 26vw, 320px);
    min-width: 0;
    align-self: stretch;
    min-height: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: rgba(8, 8, 8, 0.96);
    border: 1px solid #333;
    box-sizing: border-box;
    z-index: 10;
}

.hud-sidebar-scroll {
    flex: 1 1 0;
    flex-grow: 1;
    flex-shrink: 1;
    flex-basis: 0;
    min-height: 0;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    overscroll-behavior-x: none;
    touch-action: auto;
}

#hud-sidebar-left {
    border-right: 2px solid #2a2a2a;
}

#hud-sidebar-right {
    border-left: 2px solid #2a2a2a;
}

#game-play-viewport {
    position: relative;
    flex: 1 1 auto;
    align-self: stretch;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #050505;
    padding: 0;
    box-sizing: border-box;
    touch-action: none;
}

/* Frame on inner (not canvas) so border box matches pointer layer 1:1 with no extra inset. */
#game-play-inner {
    position: absolute;
    left: 0;
    top: 0;
    transform-origin: 0 0;
    will-change: transform;
    box-sizing: border-box;
    outline: 2px solid #333;
    outline-offset: -2px;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.55);
}

.hud-left-top {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
    flex: 0 0 auto;
    min-width: 0;
    max-width: 100%;
    width: 100%;
}

.hud-right-top {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    flex: 0 0 auto;
    min-width: 0;
    max-width: 100%;
    width: 100%;
}

@media (max-width: 1024px) {
    #hud-sidebar-left,
    #hud-sidebar-right {
        width: clamp(96px, 26vw, 132px);
        min-width: 88px;
        max-width: 148px;
    }

    .hud-sidebar-scroll {
        padding: 4px;
        gap: 6px;
    }

    .hud-left-top {
        flex-direction: column;
        gap: 4px;
        min-width: 0;
        width: 100%;
    }

    #hud-sidebar-right .hud-right-top {
        min-width: 0;
        width: 100%;
    }

    #meters-panel {
        padding: 4px;
        font-size: 9px;
        min-width: 0;
        width: 100%;
    }

    .meter-bar {
        width: 100%;
        max-width: 100%;
    }

    .rest-btn {
        font-size: 10px;
        padding: 4px 6px;
    }

    #inventory-panel {
        padding: 0;
        padding-top: 8px;
        margin: 2px 0 0 0;
        min-width: 0;
        width: 100%;
        max-width: 100%;
    }

    #inventory-panel h3 {
        font-size: 11px;
        margin-bottom: 6px;
    }

    #inventory-grid {
        gap: 4px;
    }

    .inventory-slot {
        min-height: 48px;
        padding: 4px 3px;
    }

    .inventory-slot-inner {
        gap: 3px;
    }

    .inventory-slot-meta {
        gap: 2px;
    }

    .inventory-slot .item-emoji {
        width: 26px;
        height: 26px;
        min-width: 26px;
        font-size: 18px;
    }

    .inventory-slot-name {
        font-size: 9px;
        line-height: 1.2;
    }

    .inventory-slot .item-count {
        font-size: 8px;
        padding: 1px 4px;
    }

    .inventory-slot.empty {
        min-height: 24px;
        padding: 3px;
    }

    #day-counter {
        padding: 4px 6px;
        font-size: 10px;
    }

    #time-display {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        padding: 4px 6px;
        font-size: 9px;
    }

    #weather-display {
        margin-left: 0;
        padding-left: 0;
        border-left: none;
        flex-wrap: wrap;
    }

    #equip-panel {
        padding: 4px 6px;
        font-size: 9px;
    }

    #message-log {
        font-size: 8px;
        margin-top: 6px;
        min-width: 0;
        width: 100%;
    }

    #pause-btn {
        touch-action: manipulation;
        padding: 4px 8px;
        font-size: 10px;
    }

    #ticker-text {
        font-size: clamp(12px, 3.5vw, 20px);
    }

    .closet-back-btn {
        left: 4px;
        padding: 10px 8px;
        font-size: 12px;
    }
}

/* Closet: explicit return control for touch / small screens */
.closet-back-btn {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 35;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    color: #e0e0e0;
    background: rgba(0, 0, 0, 0.85);
    border: 2px solid #4488ff;
    border-radius: 5px;
    cursor: pointer;
    touch-action: manipulation;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}
.closet-back-btn:hover {
    background: rgba(68, 136, 255, 0.25);
}
.closet-back-btn.hidden {
    display: none !important;
}
#pause-btn {
    pointer-events: auto;
    cursor: pointer;
    position: relative;
    z-index: 20;
}

#meters-panel {
    position: relative;
    top: auto;
    left: auto;
    background: rgba(0, 0, 0, 0.7);
    padding: 10px;
    border-radius: 5px;
    border: 1px solid #444;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.meter {
    margin-bottom: 8px;
}

.meter label {
    display: block;
    font-size: 11px;
    margin-bottom: 2px;
    color: #aaa;
}

.meter-bar {
    width: 100%;
    max-width: 100%;
    height: 12px;
    background: #333;
    border: 1px solid #555;
    position: relative;
    overflow: hidden;
    --meter-pct: 0;
}
.meter-bar .meter-fill {
    width: calc(var(--meter-pct, 0) * 100%);
    min-width: 0;
    display: block;
    height: 12px;
    box-sizing: border-box;
}

.meter-fill {
    height: 12px;
    min-width: 0;
    transition: width 0.3s ease;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
}

.meter-fill.health { background: #ff4444; }
.meter-fill.hydration { background: #4488ff; }
.meter-fill.hunger { background: #ffaa44; }
.meter-fill.morale { background: #aa44ff; }
.meter-fill.hygiene { background: #44ff88; }
.meter-fill.fatigue { background: linear-gradient(to right, #2196F3, #64B5F6, #90CAF9, #BBDEFB); }
.meter-fill.bathroom { background: #8B4513; } /* Brown color for bathroom meter */
.meter-fill.bodyHeat { background: linear-gradient(to right, #4488ff, #88aaff, #44ff44, #ff8844); } /* Cool → ideal (green) → hot; 100 = heat stroke risk */
.meter-ideal { font-size: 9px; color: #888; font-weight: normal; }
.meter-bodyHeat { position: relative; }
/* Ideal range 35–65: visible green band so players see what the meter means */
.meter-bodyHeat::before {
    content: '';
    position: absolute;
    left: 35%;
    width: 30%;
    top: 0;
    bottom: 0;
    background: rgba(68, 255, 68, 0.35);
    border-left: 2px solid rgba(68, 255, 68, 0.9);
    border-right: 2px solid rgba(68, 255, 68, 0.9);
    pointer-events: none;
    z-index: 1;
}
.bodyHeat-marker {
    position: absolute;
    top: -14px;
    font-size: 9px;
    color: #6c6;
    font-weight: bold;
    pointer-events: none;
    z-index: 2;
}
.bodyHeat-marker-low { left: 35%; transform: translateX(-50%); }
.bodyHeat-marker-high { left: 65%; transform: translateX(-50%); }
.meter-fill.sickness { background: #88aa44; } /* Sickness meter: 0 = healthy, 100 = very sick */
.meter-fill.attraction { background: #ff4444; }

.meter span {
    font-size: 10px;
    color: #ccc;
    display: block;
    margin-top: 2px;
}

#sickness-indicator {
    background: #ff0000;
    color: white;
    padding: 5px 10px;
    border-radius: 3px;
    font-weight: bold;
    margin-top: 5px;
    text-align: center;
}

#sickness-indicator.hidden {
    display: none;
}

#attraction-indicator {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #444;
}

#attraction-indicator.hidden {
    display: none;
}

#day-counter {
    position: relative;
    top: auto;
    right: auto;
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 15px;
    border-radius: 5px;
    border: 1px solid #444;
    font-size: 14px;
    font-weight: bold;
    z-index: 10;
}

#time-display {
    position: relative;
    top: auto;
    right: auto;
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 15px;
    border-radius: 5px;
    border: 1px solid #444;
    font-size: 12px;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

#weather-display {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-left: 10px;
    padding-left: 10px;
    border-left: 1px solid #555;
}

#weather-icon {
    font-size: 16px;
}

#temperature-text {
    font-weight: bold;
}

#season-text {
    font-size: 10px;
    color: #aaa;
    margin-left: 5px;
}

#pause-btn {
    margin-left: 10px;
    padding: 5px 10px;
    background: #444;
    color: white;
    border: 1px solid #666;
    cursor: pointer;
    border-radius: 3px;
}

#pause-btn:hover {
    background: #555;
}

/* Rest button and dropdown: Nap / Full sleep / Wake up. */
.rest-wrap {
    position: relative;
    top: auto;
    left: auto;
    z-index: 15;
}
.rest-btn {
    margin-left: 0;
    padding: 5px 10px;
    background: #334;
    color: #ddd;
    border: 1px solid #555;
    cursor: pointer;
    border-radius: 3px;
}
.rest-btn:hover {
    background: #445;
}
.rest-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}
.rest-panel {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid #555;
    border-radius: 5px;
    z-index: 25;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.hud-sidebar-scroll .rest-panel {
    max-width: 100%;
    box-sizing: border-box;
}

.rest-panel button {
    padding: 6px 12px;
    background: #444;
    color: white;
    border: 1px solid #666;
    border-radius: 3px;
    cursor: pointer;
    white-space: normal;
    text-align: center;
    max-width: 100%;
}
.rest-panel button:hover {
    background: #555;
}

.equip-panel {
    position: relative;
    top: auto;
    right: auto;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 12px;
    border-radius: 5px;
    border: 1px solid #444;
    font-size: 11px;
    z-index: 10;
    pointer-events: auto;
}
.equip-panel label {
    display: block;
    color: #aaa;
    margin-bottom: 6px;
}
#equip-slots .equip-slot-row {
    margin: 4px 0;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.equip-slot-label { color: #aaa; min-width: 48px; }
.equip-slot-name { color: #fff; }
.equip-take-off {
    font-size: 10px;
    padding: 2px 6px;
    background: #444;
    color: #fff;
    border: 1px solid #666;
    cursor: pointer;
    border-radius: 3px;
}
.equip-take-off:hover { background: #555; }

/* Inventory is plain flow inside .hud-sidebar-scroll — one vertical scroll, no nested panel */
#inventory-panel {
    position: relative;
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    border-top: 1px solid #333;
    padding-top: 10px;
    margin-top: 4px;
    overflow-x: hidden;
    overflow-y: visible;
    box-sizing: border-box;
}

#inventory-panel h3 {
    margin: 0 0 6px 0;
    font-size: 12px;
    font-weight: bold;
    color: #ccc;
}

/* Single column: full width of sidebar scroll area */
#inventory-grid {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
    box-sizing: border-box;
}

.inventory-slot {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 52px;
    height: auto;
    box-sizing: border-box;
    border: 1px solid #555;
    background: #222;
    display: flex;
    align-items: stretch;
    justify-content: flex-start;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    padding: 5px 4px;
}

/* Label block on top, icon centered underneath */
.inventory-slot-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
    width: 100%;
    min-width: 0;
}

.inventory-slot-meta {
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 2px;
    text-align: center;
}

.inventory-slot-name {
    font-size: 10px;
    line-height: 1.25;
    color: #ddd;
    width: 100%;
    max-width: 100%;
    white-space: normal;
    word-break: normal;
    overflow-wrap: break-word;
    text-align: center;
}

.inventory-slot:hover {
    border-color: #888;
    background: #333;
}

.inventory-slot.empty {
    border-style: dashed;
    min-height: 28px;
    padding: 4px;
}

.inventory-slot.selected {
    border-color: #c9a227;
    background: rgba(201, 162, 39, 0.2);
    box-shadow: 0 0 8px rgba(201, 162, 39, 0.4);
}

.item-icon, .item-emoji {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.inventory-slot .item-emoji {
    flex: 0 0 auto;
    align-self: center;
    width: 30px;
    height: 30px;
    min-width: 30px;
    font-size: 22px;
}

.inventory-slot .item-count {
    position: static;
    align-self: center;
    font-size: 9px;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.75);
    padding: 1px 4px;
    border-radius: 2px;
    color: #fff;
}

#message-log {
    position: relative;
    bottom: auto;
    right: auto;
    margin-top: 12px;
    flex: 0 1 auto;
    min-height: 48px;
    width: 100%;
    max-width: 300px;
    max-height: 150px;
    background: #000;
    color: #fff;
    padding: 10px;
    border-radius: 5px;
    border: 1px solid #444;
    overflow-y: auto;
    font-size: 11px;
    z-index: 10;
    box-sizing: border-box;
}

#hud-sidebar-right #message-log {
    max-width: none;
    max-height: none;
    overflow-y: visible;
}

#message-content {
    display: flex;
    flex-direction: column;
    gap: 5px;
    color: #fff;
}

.message {
    padding: 3px 0;
    border-bottom: 1px solid #333;
}

.message:last-child {
    border-bottom: none;
}

#interaction-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    padding: 10px 20px;
    border-radius: 5px;
    border: 2px solid #888;
    font-size: 14px;
    z-index: 20;
    pointer-events: none;
    opacity: 0; /* Invisible: zone name not shown in middle of screen */
}

#interaction-hint.hidden {
    display: none;
}

#proximity-hand-hint {
    position: fixed;
    transform: translate(-50%, -50%);
    font-size: 24px;
    z-index: 10050;
    pointer-events: none;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.85);
    filter: drop-shadow(0 0 4px rgba(255, 230, 120, 0.8));
}

#proximity-hand-hint.hidden {
    display: none;
}

#crafting-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    padding: 20px;
    border-radius: 5px;
    border: 2px solid #888;
    z-index: 15;
}

#crafting-panel.hidden {
    display: none;
}

#crafting-slots {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.craft-slot {
    width: 60px;
    height: 60px;
    border: 2px solid #555;
    background: #222;
    display: flex;
    align-items: center;
    justify-content: center;
}

#craft-btn, #clear-craft-btn {
    padding: 8px 15px;
    margin: 5px;
    background: #444;
    color: white;
    border: 1px solid #666;
    cursor: pointer;
    border-radius: 3px;
}

#craft-btn:hover, #clear-craft-btn:hover {
    background: #555;
}

#item-examine {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.95);
    padding: 20px;
    border-radius: 5px;
    border: 2px solid #888;
    z-index: 15;
    min-width: 300px;
    max-width: 400px;
}

#item-examine.hidden {
    display: none;
}

#examine-actions {
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.action-btn {
    padding: 8px;
    background: #444;
    color: white;
    border: 1px solid #666;
    cursor: pointer;
    border-radius: 3px;
    text-align: left;
}

.action-btn:hover {
    background: #555;
}

#menu-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.95);
    padding: 30px;
    border-radius: 5px;
    border: 2px solid #888;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 200px;
    pointer-events: auto;
}

#menu-panel.hidden {
    display: none !important;
}

#menu-panel:not(.hidden) {
    display: flex !important;
}

#menu-panel button {
    padding: 10px 20px;
    background: #444;
    color: white;
    border: 1px solid #666;
    cursor: pointer;
    border-radius: 3px;
    font-size: 14px;
}

#menu-panel button:hover {
    background: #555;
}

.hidden {
    display: none;
}

/* Season Selection - only visible when .hidden is removed (ID would override .hidden otherwise) */
#season-selection {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 101;
    box-sizing: border-box;
    padding: max(8px, env(safe-area-inset-top, 0px)) max(10px, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(10px, env(safe-area-inset-left, 0px));
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
#season-selection.hidden {
    display: none;
}
#season-selection:not(.hidden) {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

#season-content {
    text-align: center;
    color: #e0e0e0;
    flex: 0 0 auto;
    width: 100%;
    max-width: min(720px, 100%);
    padding-bottom: 20px;
}

#season-content h2 {
    font-size: clamp(20px, 5vmin, 36px);
    margin-bottom: 12px;
    color: #4488ff;
}

#season-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: clamp(8px, 2vmin, 15px);
    margin: clamp(12px, 3vmin, 24px) 0;
    max-width: 600px;
    width: 100%;
}

.season-btn {
    padding: 20px;
    background: rgba(68, 136, 255, 0.2);
    color: #e0e0e0;
    border: 2px solid #4488ff;
    cursor: pointer;
    border-radius: 5px;
    font-size: 16px;
    font-weight: bold;
    transition: all 0.3s;
}

.season-btn:hover {
    background: rgba(68, 136, 255, 0.4);
    box-shadow: 0 0 20px rgba(68, 136, 255, 0.5);
    transform: scale(1.05);
}

.season-btn small {
    display: block;
    font-size: 12px;
    font-weight: normal;
    margin-top: 5px;
    color: #aaa;
}

.season-sub {
    margin-top: 16px;
    font-size: 14px;
    color: #aaa;
}

#starting-time-options {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin: 12px auto 0;
    max-width: 640px;
    width: 100%;
    padding-bottom: 8px;
}

.start-time-btn {
    padding: 12px 14px;
    min-width: 100px;
    background: rgba(40, 40, 40, 0.9);
    color: #e0e0e0;
    border: 2px solid #555;
    cursor: pointer;
    border-radius: 5px;
    font-size: 13px;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    transition: border-color 0.2s, background 0.2s;
}

.start-time-btn small {
    display: block;
    font-size: 10px;
    font-weight: normal;
    margin-top: 4px;
    color: #888;
}

.start-time-btn:hover {
    border-color: #888;
    background: rgba(60, 60, 60, 0.95);
}

.start-time-btn.selected {
    border-color: #4488ff;
    background: rgba(68, 136, 255, 0.25);
    box-shadow: 0 0 12px rgba(68, 136, 255, 0.35);
}

#cover-art-screen {
    position: absolute;
    inset: 0;
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
}
#cover-art-screen.hidden {
    display: none !important;
}
#cover-art-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Title Screen - .hidden must win over ID so hide/show works */
#title-screen {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    background: linear-gradient(180deg, #0a0a0a 0%, #1a1a1a 100%);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    box-sizing: border-box;
    padding: max(8px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
    z-index: 100;
}
#title-screen.hidden {
    display: none;
}
#title-screen:not(.hidden) {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

#title-canvas {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#title-stats {
    order: 2;
    position: relative;
    z-index: 2;
    margin-top: clamp(8px, 2vmin, 20px);
    font-size: clamp(11px, 2.5vmin, 14px);
    color: #888;
}

#death-marker-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    border: 2px solid #666;
    padding: 10px 15px;
    border-radius: 5px;
    z-index: 101;
    pointer-events: none;
    font-size: 12px;
    color: #fff;
    min-width: 200px;
}

#death-marker-tooltip div {
    margin: 3px 0;
}

#marker-name {
    font-weight: bold;
    color: #ffaa44;
    font-size: 14px;
}

#marker-date {
    color: #aaa;
}

#marker-days {
    color: #888;
}

#marker-cause {
    color: #ff4444;
    font-style: italic;
}

#title-content {
    order: 1;
    position: relative;
    z-index: 2;
    text-align: center;
    color: #e0e0e0;
    width: 100%;
    max-width: min(96vw, 720px);
    margin: 0 auto;
    margin-top: min(3vh, 24px);
    padding: 0 8px;
    box-sizing: border-box;
    flex: 0 0 auto;
}

#game-title {
    font-size: clamp(20px, min(8vw, 7vh), 56px);
    font-weight: bold;
    margin-bottom: clamp(8px, 2.5vmin, 20px);
    color: #4488ff;
    text-shadow: 0 0 20px #4488ff;
    letter-spacing: clamp(1px, 0.35vmin, 8px);
    white-space: normal;
    line-height: 1.08;
    text-align: center;
    width: 100%;
    max-width: 100%;
    overflow-wrap: break-word;
    word-break: break-word;
    box-sizing: border-box;
}

#title-tagline {
    font-size: clamp(12px, 3.2vmin, 20px);
    font-weight: bold;
    margin-bottom: clamp(16px, 4vmin, 40px);
    color: #fff;
    text-shadow: 0 1px 3px #000;
    line-height: 1.5;
}

#title-menu {
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 2vmin, 15px);
    align-items: center;
    padding-bottom: 8px;
}

@media (max-height: 520px) {
    #title-stats {
        margin-top: 8px;
        font-size: 11px;
    }

    #game-title {
        margin-bottom: 6px;
    }

    #title-tagline {
        margin-bottom: 10px;
    }

    .menu-btn {
        padding: 8px 24px;
        min-width: 160px;
        font-size: 14px;
    }
}

.menu-btn {
    padding: 12px 40px;
    background: rgba(68, 136, 255, 0.2);
    color: #e0e0e0;
    border: 2px solid #4488ff;
    cursor: pointer;
    border-radius: 5px;
    font-size: 16px;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    min-width: 200px;
    transition: all 0.3s;
}

.menu-btn:hover {
    background: #3a5aaa;
    box-shadow: 0 0 20px rgba(68, 136, 255, 0.5);
    transform: scale(1.05);
}

/* Intro Sequence — above ad strip (z-index 100) so Skip stays visible and clickable */
#intro-screen {
    position: absolute;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 120;
}

/* Skip intro: fixed above bottom ad bar so it is not covered by #ad-banner-slot */
#skip-intro-btn.skip-intro-btn {
    position: fixed;
    bottom: calc(var(--ad-reserved-height) + 16px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 10003;
    min-width: 140px;
    padding: 12px 20px;
    touch-action: manipulation;
}

#skip-intro-btn.skip-intro-btn:hover {
    transform: translateX(-50%) scale(1.05);
}

#emergency-broadcast {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    background: #000;
    position: relative;
}

/* Lower-third disaster stories during news caster (above ticker; not full-viewport marquee) */
#intro-story-caption.intro-story-caption {
    position: absolute;
    bottom: 118px;
    left: 50%;
    transform: translateX(-50%);
    width: 92%;
    max-width: 720px;
    padding: 10px 14px;
    text-align: center;
    color: #f5f5f5;
    font-size: clamp(13px, 1.65vw, 17px);
    font-weight: 600;
    line-height: 1.4;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.95);
    background: rgba(0, 0, 0, 0.55);
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    z-index: 6;
    pointer-events: none;
    box-sizing: border-box;
}

#ticker-container {
    position: absolute;
    bottom: 50px;
    width: 100%;
    height: 60px;
    background: #000;
    border-top: 2px solid #444;
    border-bottom: 2px solid #444;
    overflow: hidden;
}

#ticker-text {
    position: absolute;
    white-space: nowrap;
    color: #fff;
    font-size: 24px;
    font-weight: bold;
    line-height: 60px;
    animation: scroll-right 60s linear infinite;
}

@keyframes scroll-right {
    0% { transform: translateX(100%); }
    100% { transform: translateX(-100%); }
}

#living-room {
    width: 100%;
    height: 100%;
    background: #3a3a3a;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 24px;
}

#tv-screen {
    width: min(400px, 92vw);
    height: min(300px, 40vh);
    background: #000;
    border: 10px solid #555;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

#tv-static {
    color: #fff;
    font-size: 48px;
    font-weight: bold;
    animation: static-flicker 0.1s infinite;
}

@keyframes static-flicker {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Death Screen */
#death-screen {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 98;
    color: #e0e0e0;
}
#death-screen.hidden { display: none; }
#death-screen:not(.hidden) { display: flex; }

#death-screen h2 {
    font-size: 72px;
    color: #ff4444;
    margin-bottom: 40px;
    text-shadow: 0 0 20px #ff4444;
}

#death-name-container {
    margin: 30px 0;
}

#death-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

#death-stats {
    text-align: center;
    margin-bottom: 40px;
    font-size: 20px;
    line-height: 1.8;
}

#death-cause {
    font-size: 24px;
    color: #ffaa44;
    margin-bottom: 20px;
}

#days-survived {
    font-size: 18px;
    color: #aaa;
    margin-bottom: 20px;
}

#death-flavor {
    font-size: 18px;
    color: #888;
    font-style: italic;
    max-width: 600px;
}

/* Ending Screen */
#ending-screen {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    justify-content: center;
    align-items: center;
    z-index: 99;
    color: #e0e0e0;
}
#ending-screen.hidden { display: none; }
#ending-screen:not(.hidden) { display: flex; }

#ending-content {
    text-align: center;
    max-width: 800px;
}

#ending-text {
    font-size: 24px;
    line-height: 1.8;
    margin-bottom: 40px;
}

#ending-choice {
    display: flex;
    gap: 20px;
    justify-content: center;
}

#ending-result {
    margin-top: 40px;
}

#ending-result-text {
    font-size: 20px;
    line-height: 1.8;
    margin-bottom: 30px;
}

/* Options Menu */
#options-menu {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10001;
    color: #e0e0e0;
}
#options-menu.hidden { display: none; }
#options-menu:not(.hidden) { display: flex; }

#options-menu h2 {
    font-size: 48px;
    margin-bottom: 40px;
    color: #4488ff;
}

.option-group {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    min-width: 400px;
}

.option-group label {
    min-width: 150px;
    text-align: right;
}

.option-group input[type="range"] {
    flex: 1;
}

.option-group select {
    flex: 1;
    padding: 8px;
    background: #333;
    color: #e0e0e0;
    border: 1px solid #555;
    border-radius: 3px;
}

.option-group span {
    min-width: 50px;
    text-align: left;
}

#interaction-hint-toggle {
    width: 18px;
    height: 18px;
}

/* Achievement Notification */
#achievement-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.9);
    border: 3px solid #ffaa44;
    padding: 15px 20px;
    border-radius: 5px;
    align-items: center;
    gap: 15px;
    z-index: 200;
    animation: slideIn 0.5s ease-out;
    min-width: 300px;
}
#achievement-notification.hidden { display: none; }
#achievement-notification:not(.hidden) { display: flex; }

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.achievement-icon {
    font-size: 40px;
}

.achievement-text {
    flex: 1;
}

.achievement-title {
    font-size: 12px;
    color: #ffaa44;
    font-weight: bold;
    margin-bottom: 5px;
}

.achievement-name {
    font-size: 16px;
    color: #e0e0e0;
    font-weight: bold;
}

/* Tip Jar Menu */
#tip-jar-menu {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.95);
    padding: 30px;
    border-radius: 5px;
    border: 2px solid #888;
    z-index: 10001;
    min-width: 400px;
    text-align: center;
}

#tip-jar-menu.hidden {
    display: none;
}

#tip-categories {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 20px 0;
}

.tip-category-btn {
    padding: 10px 15px;
    background: #444;
    color: white;
    border: 1px solid #666;
    cursor: pointer;
    border-radius: 3px;
    font-size: 14px;
}

.tip-category-btn:hover {
    background: #555;
}

.tip-category-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#tip-display {
    margin: 20px 0;
    padding: 15px;
    background: rgba(68, 136, 255, 0.2);
    border: 1px solid #4488ff;
    border-radius: 3px;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#tip-display.hidden {
    display: none;
}

#tip-text {
    font-size: 14px;
    color: #e0e0e0;
    font-style: italic;
    line-height: 1.6;
}
