html, body {
    overscroll-beavior: contain;
    touch-action: pan-x pan-y;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Allow selection / callout inside form controls and editable elements */
input, textarea, select, [contenteditable="true"] {
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
}

/* Footer styling inside modal */
.menu-footer {
    margin-top: 16px; /* increased from 8px to give more separation from the action row */
    font-size: 11px;
    color: #cfcfcf;
    text-align: center;
}

.menu-footer a {
    color: #d7b56d; /* softer warm-gold that pairs well with dark backgrounds */
    text-decoration: none;
    border-bottom: 1px dotted rgba(215,181,109,0.18);
    transition: color 160ms ease, border-color 160ms ease;
}
.menu-footer a:hover,
.menu-footer a:focus {
    color: #f0d08a;
    border-color: rgba(240,208,138,0.45);
    outline: none;
}

body {
    margin: 0;
    font-family: 'Space Mono', monospace;
    min-height: 100vh;
    background-color: #2c3e50;
    color: #ecf0f1;
    overflow: hidden; /* Prevent scrollbars */
}

body::after {
    display: none;
}

@font-face {
    font-family: 'Press Start 2P';
    src: url('./PressStart2P-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* Enforce the font globally */
.use-pressstart, .use-pressstart * { font-family: 'Press Start 2P', monospace !important; }

/* Day / Night variables and application (20s cycle) */
:root {
    --day-sat: 1;
    --day-bright: 1;
}
/* Apply smooth filter transitions to the in-game world and minimap */
#game-world, #minimap {
    transition: filter 400ms linear;
    filter: saturate(var(--day-sat)) brightness(var(--day-bright));
}

#game-world {
    position: absolute;
    top: 0;
    left: 0;
    will-change: transform;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    touch-action: none; /* Prevent browser gestures from intercepting game touches (fixes iOS touch drop) */
}

h1 {
    margin-bottom: 20px;
}

#grid-container {
    border: none;
    box-shadow: none;
    /* Will be positioned by JS for camera */
    position: absolute; 
    /* The grid layout will be set dynamically by JS */
    display: grid;
    background-color: #1a5147; /* Dark green to hide seams */
}

.grid-tile {
    width: 40px;
    height: 40px;
    background-size: cover;
}

.grid-tile-rotated {
    transform: rotate(180deg);
}

.grid-tile-flipped-x {
    transform: scaleX(-1);
}

@keyframes highlight-animation {
    0%, 100% { background-image: url(./Highlight.png); }
    25%, 75% { background-image: url(./Highlight1.png); }
    50% { background-image: url(./Highlight2.png); }
}

#tile-highlighter {
    position: absolute;
    width: 40px;
    height: 40px;
    display: none; /* Initially hidden */
    pointer-events: none; /* To not interfere with other mouse events */
    z-index: 0;
    animation: highlight-animation 0.8s infinite steps(1, end);
    background-size: contain;
    background-repeat: no-repeat;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#tile-highlighter::before,
#tile-highlighter::after {
    display: none;
}

/* Top-left and bottom-right corners */
#tile-highlighter::before {
    top: 0;
    left: 0;
    border-width: 2px 0 0 2px; /* Top and left borders */
    border-bottom-right-radius: 4px; /* Optional: adds a slight curve */
}

/* Top-right and bottom-left corners */
#tile-highlighter::after {
    bottom: 0;
    right: 0;
    border-width: 0 2px 2px 0; /* Bottom and right borders */
    border-top-left-radius: 4px; /* Optional: adds a slight curve */
}

@keyframes plant-sway {
  0% { transform: rotate(-1.25deg); }
  50% { transform: rotate(1.25deg); }
  100% { transform: rotate(-1.25deg); }
}

.tree, .cactus, .log-item {
    will-change: transform, opacity;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.tree {
    position: absolute;
    width: 48px;
    height: 69px;
    background-image: url("./Tree.png");
    background-size: contain;
    background-position: bottom;
    background-repeat: no-repeat;
    pointer-events: none;
    z-index: 1; /* Default, will be updated by JS */
    transition: opacity 0.15s ease-out;
    transform-origin: bottom center;
    animation: plant-sway 3.2s ease-in-out infinite;
}

.tree.falling {
    opacity: 0;
}

.cactus {
    position: absolute;
    width: 48px;
    height: 48px;
    background-image: url("./Cactus.png");
    background-size: contain;
    background-position: bottom;
    background-repeat: no-repeat;
    pointer-events: none;
    z-index: 1; /* Default, will be updated by JS */
    transform-origin: bottom center;
    animation: plant-sway 4s ease-in-out infinite;
}

.log-item, .cactus-piece {
    position: absolute;
    background-size: contain;
    background-repeat: no-repeat;
    pointer-events: none;
    z-index: 1; /* Handled by JS */
}

.log-item {
    width: 40px;
    height: 25px;
    background-image: url("./LogTexture.png");
}

.cactus-piece {
    width: 30px;
    height: 30px;
    background-image: url("./cactusPiece.png");
}

/* NEW: Apple drop styling to ensure the dropped apple is visible and crisp */
.apple-item {
    position: absolute;
    width: 18px;
    height: 18px;
    background-image: url("./Apple.png");
    background-size: contain;
    background-repeat: no-repeat;
    pointer-events: none;
    z-index: 1;
    image-rendering: pixelated;
}

.rock-piece {
    position: absolute;
    width: 18px; /* scaled to ~60% */
    height: 18px; /* scaled to ~60% */
    background-size: contain;
    background-repeat: no-repeat;
    pointer-events: none;
    z-index: 1;
}

.tumbleweed {
    position: absolute;
    width: 40px;
    height: 40px;
    background-image: url("./TumbWeed.png");
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    pointer-events: none;
    z-index: 1; /* Default, will be updated by JS */
    transform-origin: center;
    will-change: transform, opacity;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* NEW: Enemy styling */
.enemy {
    width: 40px; /* Same as player */
    height: 40px; /* Same as player */
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;

    position: absolute; /* Positioned within the game-world */
    z-index: 10; /* Initial z-index, will be updated by script */
    will-change: transform, z-index, top, left;
}

#player {
    width: 40px;
    height: 40px;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;

    position: absolute; /* Positioned within the game-world */
    z-index: 10; /* Initial z-index, will be updated by script */
    will-change: transform, z-index, top, left;
}

#interaction-prompt {
    position: absolute;
    width: 32px;
    height: 32px;
    background-image: url(./E.png);
    background-size: contain;
    background-repeat: no-repeat;
    display: none; /* Initially hidden */
    pointer-events: none;
    z-index: 100; /* Above everything */
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#object-container {
    /* This container is no longer used for trees/cacti */
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
}

#virtual-object-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

#fps-counter {
    position: fixed;
    top: 10px;
    left: 10px;
    background-color: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 5px 10px;
    font-family: 'Space Mono', monospace;
    font-size: 14px;
    z-index: 1000;
    text-shadow: 1px 1px 0 #000;
    display: none; /* Hidden per user request */
}

#minimap {
    position: fixed;
    top: 10px;
    right: 10px;
    width: 120px;
    height: 120px;
    border: 2px solid #ecf0f1;
    background-color: #1a5147;
    z-index: 1001;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    outline: none;
    user-select: none;
}

#minimap-modal { position: fixed; inset: 0; display: none; z-index: 300000; }
#minimap-modal.open { display: block; }
#minimap-modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.65); }

#minimap-modal-content {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 90vw; height: 90vh; max-width: 1000px; max-height: 1000px;
  background: #111; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,0.8);
  overflow: hidden;
}

#minimap-close-btn {
  position: absolute; top: 8px; right: 8px; z-index: 1;
  background: rgba(255,255,255,0.1); color: #000; border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px; padding: 6px 10px; cursor: pointer; font-family: 'Space Mono', monospace;
}

#minimap-full {
  display: block; width: 100%; height: 100%;
  image-rendering: pixelated; image-rendering: crisp-edges;
  -webkit-tap-highlight-color: rgba(0,0,0,0); touch-action: none; outline: none;
}

#light-layer {
  position: absolute;
  top: 0; left: 0;
  width: 0; height: 0;
  pointer-events: none;
  z-index: 999; /* above world */
}
.campfire-light {
  position: absolute;
  width: 420px; height: 420px;
  border-radius: 50%;
  pointer-events: none;
  mix-blend-mode: screen;
  background: radial-gradient(closest-side,
    rgba(255,210,140,0.60) 0%,
    rgba(255,180,90,0.45) 32%,
    rgba(255,150,70,0.25) 56%,
    rgba(255,120,50,0.10) 78%,
    rgba(255,100,20,0.00) 100%);
  opacity: var(--campfire-glow);
  filter: saturate(1.6) brightness(1.55);
  transition: opacity 220ms linear;
  /* crisp on pixel art */
  image-rendering: pixelated;
}

@keyframes campfire-flicker {
  0%, 100% { background-image: url(./Campfire1.png); }
  33% { background-image: url(./Campfire2.png); }
  66% { background-image: url(./Campfire3.png); }
}
.campfire {
  background-size: contain;
  background-repeat: no-repeat;
  background-position: bottom;
  image-rendering: pixelated;
}

#hotbar-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 1002; /* Above minimap */
    padding: 8px;
    background-color: transparent;
    border-radius: 12px;
    border: none;
    /* NEW: respond to day/night cycle like the game world */
    transition: filter 400ms linear;
    filter: saturate(var(--day-sat)) brightness(var(--day-bright));
    align-items: center; /* added to vertically center backpack with hotbar slots */
}

/* Ensure individual slots also transition smoothly */
.hotbar-slot {
    transition: filter 400ms linear;
    filter: saturate(var(--day-sat)) brightness(var(--day-bright));
    order: 0;
}

.hotbar-slot {
    width: 64px;
    height: 64px;
    background-image: url(./Hotbar.png);
    background-size: cover;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    font-family: 'Space Mono', monospace;
    color: white;
    text-shadow: 2px 2px 0 #000;
}

.hotbar-slot.selected {
    background-image: url(./Highlight.png); /* Or another highlight image */
    background-size: 100% 100%;
}

.hotbar-slot.selected-hotbar {
    outline: 3px solid rgba(100,180,255,0.95);
    box-shadow: 0 6px 12px rgba(0,0,0,0.5) inset;
}

.hotbar-item {
    width: 50px; /* Smaller than slot */
    height: 50px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.item-count {
    position: absolute;
    bottom: 2px;
    right: 5px;
    font-size: 14px;
}

/* Backpack button (right-side) */
#backpack-btn {
    order: 1;
    position: relative;
    margin-left: 8px;
    width: 52px;
    height: 52px;
    background-image: url(./Backpack.png);
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    z-index: 1003;
    box-shadow: 0 4px 10px rgba(0,0,0,0.6);
}

#touch-controls {
    display: none; /* JS will enable it on touch devices */
    position: absolute; /* Positioned relative to the hotbar-container */
    bottom: 100%; /* Sit directly above the hotbar */
    left: 50%;
    transform: translateX(-50%);
    width: 360px; /* Provide room for joystick & action button */
    height: 140px;
    pointer-events: all;
    z-index: 2000;
    margin-bottom: 12px; /* small gap between hotbar and controls */
}

#joystick-container {
    position: absolute;
    bottom: 10px;
    left: 12px;
    width: 120px;
    height: 120px;
    background-color: rgba(128, 128, 128, 0.18);
    border-radius: 50%;
    pointer-events: all;
    user-select: none;
}

#joystick-nub {
    position: absolute;
    width: 48px;
    height: 48px;
    background-color: rgba(128, 128, 128, 0.6);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

#action-button-container {
    position: absolute;
    bottom: 18px;
    right: 12px;
    pointer-events: all;
}

#action-button {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background-color: rgba(128, 128, 128, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.7);
    color: white;
    font-family: 'Space Mono', monospace;
    font-size: 20px;
    background-image: url(./E.png);
    background-size: 36px 36px;
    background-repeat: no-repeat;
    background-position: center;
    user-select: none;
    padding: 0;
}

#spawn-tumbleweed-btn {
    position: fixed;
    top: 60px; /* Below FPS counter */
    left: 10px;
    z-index: 1001;
    display: none; /* Initially hidden */
    padding: 8px 12px;
    font-family: 'Space Mono', monospace;
    font-size: 12px;
    background-color: rgba(0, 0, 0, 0.7);
    color: #fff;
    border: 2px solid #ecf0f1;
    cursor: pointer;
    text-shadow: 1px 1px 0 #000;
}

#spawn-tumbleweed-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

#menu-btn {
    position: fixed;
    top: 5px; /* moved up 5px */
    left: 10px;
    z-index: 500000; /* ensure above all other layers */
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    padding: 6px;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(0,0,0,0); /* mobile: remove tap highlight */
}

.hamburger-lines { display: inline-block; width: 100%; height: 100%; position: relative; }
.hamburger-lines span { 
    display: block; 
    position: absolute; 
    height: 3px; 
    width: 100%; 
    background: #000; 
    left: 0; 
    border-radius: 2px; 
    pointer-events: none; 
}

/* Position the three hamburger lines vertically (top, middle, bottom) */
.hamburger-lines span:nth-child(1) { top: 6px; }
.hamburger-lines span:nth-child(2) { top: 18px; }
.hamburger-lines span:nth-child(3) { top: 30px; }

/* Modal overlay & content */
#menu-modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; display: none; z-index: 400000; }
#menu-modal.open { display: block; }
#menu-modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.45); }

#menu-modal .modal-content {
    position: absolute;
    top: 60px; /* appear below top area aligned with minimap */
    left: 50%;
    transform: translateX(-50%);
    min-width: 220px;
    background: #111;
    color: #fff;
    border-radius: 8px;
    padding: 14px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.7);
    font-family: 'Space Mono', monospace;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: stretch;
    text-align: center;
}
.modal-action {
    display: block;
    width: 100%;
    margin: 8px 0;
    padding: 8px 12px;
    background: rgba(255,255,255,0.06);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.08);
    cursor: pointer;
    border-radius: 6px;
    font-family: 'Space Mono', monospace;
    font-size: 12px;
}

#menu-modal .modal-content h3 {
    font-size: 12px;
    margin: 6px 0 10px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

#menu-modal .modal-content .menu-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 8px;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.menu-label-wrapper {
    display: block;
    padding-top: 2px;
    padding-bottom: 2px;
}

.menu-label {
    margin: 0;
    font-size: 12px; /* keep it subtle so it doesn't compete with the app title */
    font-weight: 600;
    color: #e6e6e6;
    letter-spacing: 0.6px;
}

/* Small visual spacer between the label and the buttons */
.menu-separator {
    height: 8px;
    width: 100%;
}

/* Group actions to control spacing independently from other content */
.menu-actions {
    display: flex;
    flex-direction: column;
    gap: 12px; /* increased from 8px to add more space between option rows (e.g., Ambiente) and the action row */
    align-items: stretch;
}

.menu-actions label.modal-action {
    width: 200px;
    align-self: center;
}

/* New: put the modal bottom actions (Volver / Salir) on one row */
.modal-action-row {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    margin-top: 12px; /* added spacing to push 'Volver / Salir' further from the options above */
}
.modal-action-row .modal-action {
    margin: 0;
    flex: 1;
    min-width: 0; /* allow buttons to shrink nicely */
}

/* New: visually differentiate the 'Enemies' toggle label and give the checkbox an accent color */
.modal-action-enemies {
    background: rgba(255,165,0,0.08); /* subtle orange tint */
    border-color: rgba(255,165,0,0.16);
}

#enemies-toggle {
    accent-color: #ff8c00; /* accent the checkbox on supported browsers */
}

/* New: Cabin interaction modal */
#cabin-interaction-modal {
    position: fixed;
    inset: 0;
    display: none;
    z-index: 500000; /* Higher than menu modal */
    align-items: center;
    justify-content: center;
}

#cabin-interaction-modal.open {
    display: flex !important;
}

.cabin-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.cabin-modal-content {
    position: relative;
    min-width: 280px;
    max-width: 90%;
    background: #2c1810;
    color: #f0e6d2;
    border: 3px solid #8b4513;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.8);
    font-family: 'Space Mono', monospace;
    text-align: center;
    z-index: 500001;
}

.cabin-modal-content h3 {
    font-size: 18px;
    margin: 0 0 15px;
    color: #d4af37;
    text-shadow: 2px 2px 0 #000;
}

.cabin-modal-content p {
    font-size: 14px;
    margin: 0 0 20px;
    line-height: 1.5;
}

.cabin-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cabin-action {
    padding: 12px 20px;
    border: 2px solid #8b4513;
    border-radius: 6px;
    background: #654321;
    color: #f0e6d2;
    cursor: pointer;
    font-family: 'Space Mono', monospace;
    font-size: 14px;
    transition: all 0.1s ease-out;
}

.cabin-action:hover {
    background: #8b5a2b;
    border-color: #a0522d;
    box-shadow: 2px 2px 0 #5d4037;
}

.cabin-action.cabin-destroy {
    background: #8b2635;
    border-color: #a0394a;
}

.cabin-action.cabin-destroy:hover {
    background: #a0394a;
    border-color: #b74c5f;
}

/* Ensure the hotspot is invisible but clickable and doesn't interfere with accessibility outlines */
#cabin-hotspot {
    outline: none;
}

#intro-screen {
    position: fixed; inset: 0;
    background: #000;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    z-index: 100000;
    gap: 16px;
    text-align: center;
}
#intro-hero { width: 120px; height: 120px; image-rendering: pixelated; }
#intro-title { margin: 0; font-family: 'Space Mono', monospace; font-size: 20px; color: #fff; }

/* Improved styles for intro buttons */
#intro-screen button {
    padding: 12px 24px;
    border-radius: 8px;
    border: 2px solid #555;
    background: #333;
    color: #eee;
    cursor: pointer;
    font-family: 'Space Mono', monospace;
    font-size: 16px;
    text-shadow: 2px 2px 0 #000;
    box-shadow: 4px 4px 0 #111;
    transition: all 0.1s ease-out;
    margin: 8px 0;
}

#intro-screen button:hover:not(:disabled) {
    background: #444;
    border-color: #777;
    box-shadow: 2px 2px 0 #111;
    transform: translate(2px, 2px);
}

#intro-screen button:active:not(:disabled) {
    background: #222;
    border-color: #444;
    box-shadow: 0 0 0 #b71c1c;
    transform: translate(4px, 4px);
}

#intro-screen button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    filter: grayscale(1);
}

#intro-screen[aria-hidden="true"] { display: none; }

/* New: Confirmation Modal Styling */
#confirmation-modal {
    position: fixed;
    inset: 0;
    display: none; /* Hidden by default */
    z-index: 300000; /* Ensure it's above the intro screen */
}

#confirmation-modal.open {
    display: flex;
    align-items: center;
    justify-content: center;
}

#confirmation-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
}

#confirmation-modal .modal-content {
    position: relative; /* important for z-index */
    top: auto; /* override menu modal specific top */
    left: auto; /* override menu modal specific left */
    transform: none; /* override menu modal specific transform */
    min-width: 280px;
    max-width: 90%;
    max-height: 85vh; /* Added max-height to prevent overflow */
    background: #222;
    color: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.9);
    font-family: 'Space Mono', monospace;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: stretch;
    z-index: 300001; /* Above overlay */
}

/* New: Help Modal Styling */
#help-modal {
    position: fixed;
    inset: 0;
    display: none;
    z-index: 450000; /* Above menu modal */
}
#help-modal.open {
    display: flex;
    align-items: center;
    justify-content: center;
}
#help-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}
#help-modal .modal-content {
    position: relative;
    top: auto;
    left: auto;
    transform: none;
    min-width: 280px;
    max-width: 450px;
    max-height: 85vh; /* Added max-height to prevent overflow */
    background: #221e1c;
    color: #e0e0e0;
    border: 4px solid #4a2a0c;
    border-radius: 4px;
    padding: 24px;
    box-shadow: 0 0 0 4px #2b1806, 0 10px 40px rgba(0,0,0,0.8);
    font-family: 'Space Mono', monospace;
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: stretch;
    z-index: 450001;
}
#help-modal h3 {
    font-size: 18px;
    margin: 0 0 15px;
    text-align: center;
    color: #f1c40f;
    text-shadow: 2px 2px 0 #000;
    letter-spacing: 1px;
}
#help-content {
    font-size: 12px;
    line-height: 1.7;
    text-align: center;
    overflow-y: auto; /* Make this section scrollable */
    flex-shrink: 1; /* Ensure it shrinks to fit within the modal's max-height */
    padding-right: 10px; /* Add space for the scrollbar */
}
#help-content hr {
    border: none;
    height: 3px;
    background-image: linear-gradient(to right, 
      transparent, 
      rgba(139, 69, 19, 0.6) 20%, 
      rgba(139, 69, 19, 0.6) 80%, 
      transparent);
    margin: 18px 0;
}
#help-content ul {
    padding-left: 0;
    margin: 10px 0 0;
    list-style-type: none;
}
#help-content li {
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
}
/* New: styles for inline icons in the help text */
#help-content .help-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    image-rendering: pixelated;
}
#help-content strong {
    color: #f1c40f; /* A highlight color */
}

#help-modal .confirm-actions .modal-action {
    background: #3498db;
    border-color: #2980b9;
    box-shadow: 2px 2px 0 #1f618d;
}

#help-modal .confirm-actions .modal-action:hover:not(:disabled) {
    background: #5dade2;
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0 #1f618d;
}

#confirmation-modal .modal-content h3 {
    font-size: 16px;
    margin: 0 0 10px;
    color: #fff;
}

#confirmation-modal .modal-content p {
    font-size: 12px;
    margin: 0;
    line-height: 1.5;
    color: #ccc;
}

.confirm-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 15px;
}

.confirm-actions .modal-action {
    width: 100%; /* Take full width of modal-content */
    padding: 10px 15px;
    font-size: 14px;
    background: #4CAF50; /* Green for confirm */
    border-color: #388E3C;
    box-shadow: 2px 2px 0 #28602B;
    transition: all 0.1s ease-out;
}

.confirm-actions .modal-action:first-child {
    background: #f44336; /* Red for destructive action */
    border-color: #d32f2f;
    box-shadow: 2px 2px 0 #9f1f1f;
}

.confirm-actions .modal-action:first-child:hover:not(:disabled) {
    background: #e57373;
    border-color: #d32f2f;
    box-shadow: 1px 1px 0 #9f1f1f;
    transform: translate(1px, 1px);
}

.confirm-actions .modal-action:first-child:active:not(:disabled) {
    background: #d32f2f;
    border-color: #b71c1c;
    box-shadow: 0 0 0 #b71c1c;
    transform: translate(2px, 2px);
}

.confirm-actions .modal-action:hover:not(:disabled) {
    background: #66BB6A;
    border-color: #4CAF50;
    box-shadow: 1px 1px 0 #28602B;
    transform: translate(1px, 1px);
}

.confirm-actions .modal-action:active:not(:disabled) {
    background: #388E3C;
    border-color: #1B5E20;
    box-shadow: 0 0 0 #1B5E20;
    transform: translate(2px, 2px);
}

.menu-version { margin-top: 4px; font-size: 10px; color: #9aa3ab; }

#day-counter{
    position: fixed;
    top: 12px;
    left: auto; /* positioned by JS so it can sit between menu and minimap */
    transform: none;
    z-index: 10050;
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 3px 8px; /* reduced vertical padding so content sits slightly higher */
    border-radius: 8px;
    background: rgba(0,0,0,0.22); /* lighter (less dark) than before */
    color: #fff;
    font-family: 'Space Mono', monospace;
    font-size: 12px;
    pointer-events: auto;
    /* Apply same day/night filter as the game world so the counter is covered/dimmed at night */
    filter: saturate(var(--day-sat)) brightness(var(--day-bright));
    transition: filter 400ms linear, background 300ms linear, color 300ms linear, left 200ms ease;
}
.day-icon{ font-size:13px; line-height:1; display:inline-block; width:18px; text-align:center; transform: translateY(-4px); }
.day-icon.day{ color: #FFD54F; } /* sun color */
.day-icon.night{ color: #CFE8FF; } /* moon color */
.day-count{ font-size:12px; font-weight:600; letter-spacing:0.4px; }
/* Slightly darker background during night for contrast */
#day-counter.night { background: rgba(0,0,0,0.6); color: #e6eef6; }

#hearts-container {
    position: fixed;
    bottom: 96px; /* sits above hotbar */
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    z-index: 1003;
    /* Ensure hearts respond to day/night overlay like the rest of the UI */
    filter: saturate(var(--day-sat)) brightness(var(--day-bright));
    transition: filter 400ms linear;
}

#hearts-container .heart {
    width: 22px; height: 22px;
    background-size: contain; background-repeat: no-repeat;
}

/* Backpack grid */
.backpack-grid {
  display: grid; grid-template-columns: repeat(3, 64px); gap: 18px; padding: 6px;
}
.backpack-slot {
  width: 64px; height: 64px; background-image: url(./Hotbar.png); background-size: cover;
  position: relative; display: flex; align-items: center; justify-content: center;
}
.backpack-slot.selected { outline: 3px solid rgba(100,180,255,0.95); box-shadow: 0 6px 12px rgba(0,0,0,0.5) inset; }
.backpack-slot.hotbar-active-target { box-shadow: 0 0 0 2px rgba(255,255,255,0.2) inset; }

.backpack-item { width: 50px; height: 50px; background-size: contain; background-repeat: no-repeat; background-position: center; }
.backpack-count { position: absolute; bottom: 2px; right: 5px; font-size: 14px; text-shadow: 2px 2px 0 #000; }

/* Crafting options */
.craft-options { display: flex; gap: 10px; padding: 6px; justify-content: center; }
.craft-btn {
  width: 56px; height: 56px; background-size: contain; background-repeat: no-repeat; background-position: center;
  border: 1px solid rgba(255,255,255,0.15); border-radius: 6px; background-color: rgba(255,255,255,0.06); cursor: pointer;
}
.craft-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.craft-btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(0.3);
}

#backpack-modal { position: fixed; inset: 0; display: none; z-index: 2100; }
#backpack-modal.open { display: flex; align-items: center; justify-content: center; }
#backpack-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.45); }
#backpack-content { position: relative; background: #111; color: #fff; border-radius: 8px; padding: 12px; box-shadow: 0 8px 30px rgba(0,0,0,0.7); }

#craft-modal { position: fixed; inset: 0; display: none; z-index: 2200; }
#craft-modal.open { display: flex; align-items: center; justify-content: center; }
#craft-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.45); }
#craft-modal .modal-content { position: relative; background: #111; color: #fff; border-radius: 8px; padding: 14px; box-shadow: 0 8px 30px rgba(0,0,0,0.7); }

body.map-open #day-counter { display: none !important; }

/* Responsive adjustments for smaller screens */
@media (max-width: 480px) {
    /* Stack modal action buttons vertically on mobile */
    .modal-action-row {
        flex-direction: column;
    }

    /* Stack help content list items vertically for better readability */
    #help-content li {
        flex-direction: column;
        align-items: center; /* Align to the start of the column */
        text-align: center;
    }

    /* Adjust confirmation modal for very narrow screens */
    #confirmation-modal .modal-content {
        padding: 15px;
        min-width: 260px;
    }
}