  :root {
    --game-font: "Funnel Display", sans-serif;
    --game-font-scale: 1;
  }

  html, body {
    margin: 0;
    padding: 0;
    background: #000;
    color: #eee;
    font-family: var(--game-font) !important;
    /* Prevent scrolling - keeps game at top of page */
    overflow: hidden;
    height: 100%;
    width: 100%;
    /* Mobile: disable pinch-to-zoom and double-tap-to-zoom */
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-text-size-adjust: 100%;
    -ms-touch-action: manipulation;
    overscroll-behavior: none;
    /* Note: Don't use position:fixed on body - causes issues on iOS Safari */
  }
  
  /* Ensure all form elements use the same font */
  button, input, select, textarea, label, option, div, span, p {
    font-family: var(--game-font) !important;
  }

@keyframes shieldHitShake {
  0%   { transform: translate(0, 0) rotate(0deg); }
  15%  { transform: translate(-10px, -6px) rotate(-2deg); }
  30%  { transform: translate(8px, 4px) rotate(2deg); }
  45%  { transform: translate(-8px, 3px) rotate(-3deg); }
  60%  { transform: translate(6px, -4px) rotate(2deg); }
  75%  { transform: translate(-4px, 2px) rotate(-1deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

.shield-hit-shake {
  animation: shieldHitShake 0.4s ease;
}

@keyframes fireHitShake {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(-5px, -5px); }
  50%  { transform: translate(5px, 5px); }
  75%  { transform: translate(-5px, -5px); }
  100% { transform: translate(0, 0); }
}

.fire-hit-shake {
  animation: fireHitShake 0.3s ease infinite;
}

@keyframes gorillaHitShake {
  0%   { transform: translate(0, 0); }
  10%  { transform: translate(-8px, -6px); }
  20%  { transform: translate(8px, 4px); }
  30%  { transform: translate(-6px, 6px); }
  40%  { transform: translate(6px, -4px); }
  50%  { transform: translate(-8px, -2px); }
  60%  { transform: translate(8px, 6px); }
  70%  { transform: translate(-4px, -6px); }
  80%  { transform: translate(6px, 2px); }
  90%  { transform: translate(-2px, 4px); }
  100% { transform: translate(0, 0); }
}

.gorilla-hit-shake {
  animation: gorillaHitShake 0.35s ease;
}

@keyframes shieldDrainShake {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(-5px, -3px); }
  50%  { transform: translate(5px, 3px); }
  75%  { transform: translate(-3px, 2px); }
  100% { transform: translate(0, 0); }
}

.shield-drain-shake {
  animation: shieldDrainShake 0.3s ease infinite;
  will-change: transform;
}

@keyframes monsterShiver {
  0%   { transform: translate(0, 0) rotate(0deg); }
  10%  { transform: translate(-2px, -1px) rotate(-0.5deg); }
  20%  { transform: translate(2px, 1px) rotate(0.5deg); }
  30%  { transform: translate(-1px, 1px) rotate(-0.3deg); }
  40%  { transform: translate(1px, -1px) rotate(0.3deg); }
  50%  { transform: translate(-2px, 0px) rotate(-0.5deg); }
  60%  { transform: translate(2px, 1px) rotate(0.5deg); }
  70%  { transform: translate(-1px, -1px) rotate(-0.3deg); }
  80%  { transform: translate(1px, 1px) rotate(0.3deg); }
  90%  { transform: translate(-1px, 0px) rotate(-0.2deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

.monster-shiver {
  animation: monsterShiver 0.1s ease infinite;
  will-change: transform;
}

@keyframes shimmerMove {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes playerBlink {
  0%   { opacity: 1; }
  50%  { opacity: 0; }
  100% { opacity: 1; }
}

.player-blink {
  animation: playerBlink 0.4s linear infinite;
  /* When opacity is 0, the player icon becomes transparent, revealing the base tile below */
}




  #game-root {
    display: flex;
    justify-content: center;
    padding: 20px 0;
  }

  #frame-container {
    position: relative;
    width: 2400px;
    height: 1200px;
    /* Scale will be applied dynamically via JavaScript */
    transform-origin: top center;
    /* Hidden until JS applies the correct scale to prevent a brief magnified flash on load */
    visibility: hidden;
  }

  #game-frame {
    position: relative;
    width: 2400px;
    height: 1200px;
    background-size: cover;
    background-position: center;
  }

  /* 3D viewport positioned inside the frame */
  #viewport {
    position: absolute;
    left: 100px;
    top: 100px;
    width: 1000px;
    height: 1000px;
    background: #000;
    overflow: hidden;
    /* GPU acceleration for iOS/iPad - prevents image flicker */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-perspective: 1000;
    perspective: 1000;
    /* Hint to browser to keep this layer composited */
    will-change: transform;
    /* CSS Containment - tells browser that layout/paint inside viewport doesn't affect outside.
       This significantly helps Safari by limiting the scope of style/layout recalculations. */
    contain: layout style paint;
    /* Disable iOS text selection/highlighting */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
  
  /* Fullscreen toggle button - bottom right of viewport */
  #fullscreen-toggle {
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 3px;
    cursor: pointer;
    z-index: 95;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s, transform 0.2s;
  }
  
  #fullscreen-toggle:hover {
    background: rgba(0, 0, 0, 0.9);
    border-color: rgba(255, 255, 255, 1);
    transform: scale(1.1);
  }
  
  #fullscreen-toggle svg {
    width: 22px;
    height: 22px;
    fill: rgba(255, 255, 255, 0.9);
  }
  
  #fullscreen-toggle:hover svg {
    fill: rgba(255, 255, 255, 1);
  }
  
  /* Fullscreen mode class - applied via JavaScript */
  #frame-container.fullscreen-mode {
    /* Keep original dimensions - scaling is done via transform */
    width: 2400px !important;
    height: 1200px !important;
    /* Center in viewport */
    position: fixed !important;
    left: 50% !important;
    top: 50% !important;
    /* Transform origin for proper scaling from center */
    transform-origin: center center !important;
    /* Scale is applied inline via JavaScript */
    z-index: 9999 !important;
  }
  
  /* Black background overlay when in fullscreen */
  #fullscreen-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #000;
    z-index: 9998;
  }
  
  #fullscreen-backdrop.visible {
    display: block;
  }

  /* Hotspot controls for touch/click interaction */
  .hotspot {
    position: absolute;
    width: 50px;  /* Doubled for HD frame touch accessibility */
    height: 50px; /* Doubled for HD frame touch accessibility */
    cursor: pointer;
    z-index: 100;
    background: transparent; /* Keep invisible like original */
    border: none; /* Keep invisible like original */
    padding: 0;
    margin: 0;
  }
  
  .hotspot:hover {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 30%;
  }
  
  /* Custom tooltip for hotspots - appears on hover */
  .hotspot[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: #FFD700;
    padding: 4px 8px;
    border-radius: 4px;
    font-family: var(--game-font);
    font-size: calc(15px * var(--game-font-scale));
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease-in-out;
    z-index: 200;
    border: 1px solid #FFD700;
  }
  
  .hotspot[data-tooltip]:hover::after {
    opacity: 1;
  }
  
  /* Position tooltip below for hotspots near top of screen (radar) */
  .hotspot.tooltip-below[data-tooltip]::after {
    bottom: auto;
    top: 100%;
    margin-top: 5px;
  }
  
  /* Position tooltip to the left for hotspots near right edge (logoff, level-select) */
  .hotspot.tooltip-left[data-tooltip]::after {
    bottom: auto;
    top: 50%;
    left: auto;
    right: 100%;
    transform: translateY(-50%);
    margin-right: 5px;
  }
  
  .hotspot-flash {
    position: absolute;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0.5) 40%, rgba(255, 255, 255, 0) 70%);
    pointer-events: none;
    z-index: 101;
    animation: hotspot-pulse 0.3s ease-out forwards;
  }
  
  @keyframes hotspot-pulse {
    0% { transform: scale(0.5); opacity: 1; }
    100% { transform: scale(2); opacity: 0; }
  }
  
  /* Phase 4 Step 3: Glowing seed word animation for first-time objective claims */
  @keyframes seedGlow {
    0%   { text-shadow: 0 0 10px rgba(0,255,136,0.4), 0 0 20px rgba(0,255,136,0.2); }
    50%  { text-shadow: 0 0 25px rgba(0,255,136,0.9), 0 0 40px rgba(0,255,136,0.4); }
    100% { text-shadow: 0 0 10px rgba(0,255,136,0.4), 0 0 20px rgba(0,255,136,0.2); }
  }
  
  .seed-word-glow {
    animation: seedGlow 1.6s ease-in-out infinite;
  }
  
  /* Level select dialog styling */
  .level-select-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(180deg, #2a1a0a 0%, #1a0f05 100%);
    border: 3px solid #8b6914;
    border-radius: 8px;
    padding: 20px;
    z-index: 10001;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
    min-width: 280px;
    font-family: var(--game-font);
    color: #ffd700;
  }
  
  .level-select-dialog h3 {
    margin: 0 0 15px 0;
    text-align: center;
    font-size: calc(18px * var(--game-font-scale));
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
  }
  
  .level-select-dialog select {
    width: 100%;
    padding: 8px;
    margin-bottom: 15px;
    background: #1a0f05;
    border: 2px solid #8b6914;
    color: #ffd700;
    font-family: var(--game-font);
    font-size: calc(14px * var(--game-font-scale));
    cursor: pointer;
  }
  
  .level-select-dialog select option {
    font-family: var(--game-font);
    background: #1a0f05;
    color: #ffd700;
  }
  
  .level-select-dialog .dialog-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
  }
  
  .level-select-dialog button {
    padding: 8px 20px;
    background: linear-gradient(180deg, #8b6914 0%, #5a4510 100%);
    border: 2px solid #ffd700;
    color: #ffd700;
    font-family: var(--game-font);
    font-size: calc(14px * var(--game-font-scale));
    cursor: pointer;
    border-radius: 4px;
  }
  
  .level-select-dialog button:hover {
    background: linear-gradient(180deg, #a87b1a 0%, #6b5012 100%);
  }
  
  /* Confirmation dialog styling (Log off, Reset map, etc.) - doubled size for iPad */
  .confirm-dialog-box {
    background: linear-gradient(180deg, #2a1a0a 0%, #1a0f05 100%);
    border: 6px solid #8b6914;
    border-radius: 16px;
    padding: 30px;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.8);
    min-width: 300px;
    font-family: var(--game-font);
    color: #ffd700;
    text-align: center;
  }
  
  .confirm-dialog-box p {
    margin: 0 0 30px 0;
    font-size: calc(24px * var(--game-font-scale));
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
  }
  
  .confirm-dialog-box .dialog-buttons {
    display: flex;
    gap: 20px;
    justify-content: center;
  }
  
  .confirm-dialog-box button {
    padding: 20px 40px;
    background: linear-gradient(180deg, #8b6914 0%, #5a4510 100%);
    border: 4px solid #ffd700;
    color: #ffd700;
    font-family: var(--game-font);
    font-size: calc(24px * var(--game-font-scale));
    cursor: pointer;
    border-radius: 8px;
  }
  
  .confirm-dialog-box button:hover {
    background: linear-gradient(180deg, #a87b1a 0%, #6b5012 100%);
  }
  
  /* Merchant shop buy button styling */
  .merchant-buy-btn {
    position: absolute;
    background: linear-gradient(180deg, #1a3d1a 0%, #0d1f0d 100%);
    border: 1px solid rgba(219, 216, 60, 0.88);
    color: rgb(255, 252, 68);
    font-family: var(--game-font);
    font-size: calc(23px * var(--game-font-scale));
    padding: 2px 4px;
    cursor: pointer;
    border-radius: 3px;
    text-align: center;
    white-space: nowrap;
    z-index: 10001;
    text-shadow: 0 0 2px rgb(249, 255, 68);
    box-shadow: 0 0 2px rgba(222, 206, 59, 0.786);
  }
  
  .merchant-buy-btn:hover {
    background: linear-gradient(180deg, #2a5d2a 0%, #1a3f1a 100%);
    border-color: #6c6;
    color: #6f6;
  }
  
  .merchant-buy-btn.purchased {
    background: linear-gradient(180deg, #333 0%, #222 100%);
    border-color: #888;
    color: #aaa;
    cursor: default;
    text-shadow: none;
    box-shadow: none;
  }
  
  .merchant-buy-btn.repair {
    background: linear-gradient(180deg, #3d2a1a 0%, #2a1f0d 100%);
    border: 1px solid rgba(255, 180, 60, 0.88);
    color: rgb(255, 200, 100);
    text-shadow: 0 0 2px rgb(255, 180, 68);
    box-shadow: 0 0 2px rgba(255, 180, 59, 0.786);
  }
  
  .merchant-buy-btn.repair:hover {
    background: linear-gradient(180deg, #5d3a2a 0%, #3a2f1a 100%);
    border-color: #fc6;
    color: #ff6;
  }

  /* Skill upgrade buttons on Level-Up Overlay */
  .skill-btn {
    position: absolute;
    font-family: var(--game-font);
    font-size: calc(18px * var(--game-font-scale));
    padding: 2px 6px;
    cursor: pointer;
    border-radius: 3px;
    text-align: center;
    white-space: nowrap;
    z-index: 10;
  }

  .skill-btn.affordable {
    background: linear-gradient(180deg, #1a3d1a 0%, #0d1f0d 100%);
    border: 1px solid rgba(0, 220, 0, 0.88);
    color: rgb(0, 255, 0);
    text-shadow: 0 0 2px rgb(0, 255, 0);
    box-shadow: 0 0 2px rgba(0, 220, 0, 0.5);
  }

  .skill-btn.affordable:hover {
    background: linear-gradient(180deg, #2a5d2a 0%, #1a3f1a 100%);
    border-color: #0f0;
    color: #6f6;
  }

  .skill-btn.locked {
    background: linear-gradient(180deg, #3d2a1a 0%, #2a1f0d 100%);
    border: 1px solid rgba(255, 165, 0, 0.88);
    color: rgb(255, 165, 0);
    text-shadow: 0 0 2px rgb(255, 165, 0);
    box-shadow: 0 0 2px rgba(255, 165, 0, 0.5);
  }

  .skill-btn.locked:hover {
    background: linear-gradient(180deg, #5d3a2a 0%, #3a2f1a 100%);
    border-color: #fc6;
    color: #fd0;
  }

  .skill-btn.active {
    background: linear-gradient(180deg, #3d3a1a 0%, #2a2a0d 100%);
    border: 1px solid rgba(255, 225, 84, 0.88);
    color: rgb(255, 225, 84);
    text-shadow: 0 0 2px rgb(255, 225, 84);
    box-shadow: 0 0 2px rgba(255, 225, 84, 0.5);
    cursor: pointer;
  }

  .skill-btn.active:hover {
    background: linear-gradient(180deg, #5d4a2a 0%, #3a3a1a 100%);
    border-color: #ffe970;
    color: #fff080;
  }

  /* Name prompt dialog styling */
  .name-prompt-box {
    background: linear-gradient(180deg, #2a1a0a 0%, #1a0f05 100%);
    border: 3px solid #8b6914;
    border-radius: 8px;
    padding: 36px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
    min-width: 630px;
    max-width: 780px;
    font-family: var(--game-font);
    color: #ffd700;
  }
  
  .name-prompt-box h3 {
    margin: 0 0 27px 0;
    text-align: center;
    font-size: calc(33px * var(--game-font-scale));
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
  }
  
  .name-prompt-box .info-text {
    margin-bottom: 27px;
    line-height: 1.6;
    font-size: 22.5px;
    color: #cca000;
  }
  
  .name-prompt-box label {
    display: block;
    margin-bottom: 12px;
    font-weight: 500;
    font-size: calc(24px * var(--game-font-scale));
  }
  
  .name-prompt-box input {
    width: 100%;
    box-sizing: border-box;
    padding: 15px;
    margin-bottom: 12px;
    background: #1a0f05;
    color: #ffd700;
    border: 2px solid #8b6914;
    border-radius: 4px;
    font-family: var(--game-font);
    font-size: calc(24px * var(--game-font-scale));
  }
  
  .name-prompt-box .error-msg {
    color: #ff6666;
    font-size: calc(21px * var(--game-font-scale));
    margin-bottom: 18px;
    min-height: 27px;
  }
  
  .name-prompt-box button {
    padding: 15px 36px;
    background: linear-gradient(180deg, #8b6914 0%, #5a4510 100%);
    border: 2px solid #ffd700;
    color: #ffd700;
    font-family: var(--game-font);
    font-size: calc(24px * var(--game-font-scale));
    cursor: pointer;
    border-radius: 4px;
  }
  
  .name-prompt-box button:hover {
    background: linear-gradient(180deg, #a87b1a 0%, #6b5012 100%);
  }
  
  .level-select-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10000;
  }

/* WIN OVERLAY — displayed when the level is completed */
/* Note: win-overlay and lose-overlay are children of viewport, so positioned relative to viewport */
#win-overlay, #lose-overlay {
  position: absolute;
  left: 0;        /* Positioned relative to viewport (which is at 100px, 100px) */
  top: 0;          /* Positioned relative to viewport (which is at 100px, 100px) */
  width: 1000px;  /* Same as viewport */
  height: 1000px; /* Same as viewport */
  background-size: cover;
  background-position: center;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.4s ease;
}

/* RAISER WALL FALLING OVERLAY — displayed when player is under falling raiser wall */
/* Note: raiser-wall-falling-overlay is a child of viewport, so positioned relative to viewport */
#raiser-wall-falling-overlay {
  position: absolute;
  left: 0;        /* Positioned relative to viewport (which is at 100px, 100px) */
  top: 0;          /* Positioned relative to viewport (which is at 100px, 100px) */
  width: 1000px;  /* Same as viewport */
  height: 1000px; /* Same as viewport */
  background-size: cover;
  background-position: center;
  z-index: 201;   /* Above win/lose overlays but below UI elements */
  pointer-events: none; /* Allow clicks to pass through */
}

/* PAUSED OVERLAY — displayed when game is paused */
/* Note: paused-overlay is a sibling of viewport, so positioned relative to game-frame */
#paused-overlay {
  position: absolute;
  left: 100px;    /* Updated for HD frame viewport position */
  top: 100px;     /* Updated for HD frame viewport position */
  width: 1000px;  /* Same as viewport (doubled for HD) */
  height: 1000px; /* Same as viewport (doubled for HD) */
  background-size: cover;
  background-position: center;
  z-index: 200;
  pointer-events: none; /* Allow clicks to pass through to viewport */
  opacity: 0;
  transition: opacity 0.4s ease;
}

/* READY OVERLAY — displayed when game is ready to start (after loading) */
#ready-overlay {
  position: absolute;
  left: 100px;    /* Updated for HD frame viewport position */
  top: 100px;     /* Updated for HD frame viewport position */
  width: 1000px;  /* Same as viewport (doubled for HD) */
  height: 1000px; /* Same as viewport (doubled for HD) */
  background-size: cover;
  background-position: center;
  z-index: 200;
  display: none; /* Hidden by default */
  pointer-events: none; /* Allow clicks to pass through to viewport */
  opacity: 0;
  transition: opacity 0.4s ease;
}

/* LOSE OVERLAY — displayed when the player is killed by Sickle */

/* LOADING OVERLAY — displayed while preloading assets */
/* Positioned in the same area as the viewport, appears immediately */
#loading-overlay {
  position: absolute;
  left: 100px;    /* Updated for HD frame viewport position */
  top: 100px;     /* Updated for HD frame viewport position */
  width: 1000px;  /* Same as viewport (doubled for HD) */
  height: 1000px; /* Same as viewport (doubled for HD) */
  background: rgba(0, 0, 0, 0.9);
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: calc(32px * var(--game-font-scale)); /* Doubled for HD frame */
  z-index: 300;
}

/* PAUSED OVERLAY — displayed when game is paused */

/* Overlay that darkens the edges */
#vignette-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    circle at center,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.85) 100%
  );
  opacity: 0.5;
  z-index: 95; /* Overlay Vignette */
  transition: opacity 0.3s ease;
}

/* Subtle red vignette when Sickle is 2 tiles away */
#proximity-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    circle at center,
    rgba(255, 0, 0, 0.02) 0%,
    rgba(255, 0, 0, 0.35) 100%
  );
  opacity: 0.9;
  z-index: 97; /* Proximity Vignette */
  transition: opacity 0.3s ease-out;
}


/* Strong red damage vignette (0–1 tile away / damage events) */
#damage-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    circle at center,
    rgba(255, 0, 0, 0.10) 0%,
    rgba(255, 0, 0, 0.6) 100%
  );
  opacity: 0.9;
  z-index: 98; /* Damage Vignette */
  transition: opacity 0.3s ease-out;
}

/* Flash animation helper */
.damage-flash {
  opacity: 1 !important;
}

/* Purple teleporter vignette overlay */
#teleport-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: rgba(128, 0, 255, 0.85);
  opacity: 0;
  z-index: 99; /* Above damage vignette */
  transition: opacity 0.15s ease-in-out;
}

#teleport-vignette.teleport-active {
  opacity: 1;
}

/* Blue shield charge vignette overlay */
#shield-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: rgba(0, 100, 255, 0.4);
  opacity: 0;
  z-index: 99;
  transition: opacity 0.4s ease-in-out;
}

#shield-vignette.vignette-active {
  opacity: 1;
}

/* Green energy recharge vignette overlay */
#energy-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: rgba(0, 200, 50, 0.4);
  opacity: 0;
  z-index: 99;
  transition: opacity 0.4s ease-in-out;
}

#energy-vignette.vignette-active {
  opacity: 1;
}

/* Boss encounter red reverse vignette - 30% red center fading to transparent at edges */
#boss-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    circle at center,
    rgba(255, 0, 0, 0.30) 0%,
    rgba(255, 0, 0, 0.15) 40%,
    rgba(255, 0, 0, 0) 80%
  );
  opacity: 0;
  z-index: 94; /* Below main vignette (95), above monster layers */
  transition: opacity 0.4s ease;
}

/* Dark zone overlay — blacks out viewport when player is near/inside a dark zone */
#dark-zone-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: black;
  opacity: 0;
  z-index: 93;
  transition: opacity 0.4s ease;
}

/* Flashlight overlay — radial gradient that lights center, dark at edges */
#flashlight-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 93;
  transition: opacity 0.3s ease;
}

/* Boss name and HP text overlay - centered in viewport */
#boss-info-overlay {
  position: absolute;
  top: 6%;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  pointer-events: none;
  z-index: 96; /* Above vignettes, below damage vignette */
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  text-shadow: 2px 2px 6px rgba(0, 0, 0, 0.9), 0 0 12px rgba(0, 0, 0, 0.7);
}

#boss-info-overlay .boss-name {
  display: block;
  color: #FFD700;
  font-family: var(--game-font);
  font-size: calc(30px * var(--game-font-scale));
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  white-space: nowrap;
}

#boss-info-overlay .boss-hp {
  display: block;
  color: #FF2222;
  font-family: var(--game-font);
  font-size: calc(30px * var(--game-font-scale));
  font-weight: 600;
  margin-top: 2px;
}


  .layer-tile {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    /* GPU acceleration for smooth rendering - especially on iOS/iPad.
       Firefox override below removes these for non-flipping elements to avoid compositor layer limits. */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    -webkit-perspective: 1000;
    perspective: 1000;
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
    /* CSS Containment - limits scope of style/layout/paint to this element.
       Helps Safari significantly by preventing layout thrashing. */
    contain: layout style paint;
  }

  /* GPU-promoted class - kept for elements that specifically need GPU acceleration.
     On Firefox, only elements with this class get GPU promotion (added via JS). */
  .gpu-promoted {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    -webkit-perspective: 1000;
    perspective: 1000;
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
  }

/* Sickle overlay inside the viewport */
#sickle-layer,
#sickle-layer-d0,
#sickle-layer-d1,
#sickle-layer-d2,
#sickle-layer-d3 {
  pointer-events: none;
}

/* CCTV overlay inside the viewport */
#cctv-layer-d0,
#cctv-layer-d1,
#cctv-layer-d2,
#cctv-layer-d3 {
  pointer-events: none;
}

/* Fire overlay inside the viewport */
#fire-layer-d1,
#fire-layer-d2,
#fire-layer-d3,
#fire-side-layer-left,
#fire-side-layer-right {
  pointer-events: none;
}

/* GOLD overlay inside the viewport */
#gold-layer,
#gold-layer-d1,
#gold-layer-d2,
#gold-layer-d3 {
  pointer-events: none;
}

  .floor-tile,
  .roof-tile,
  .side-wall,
  .front-wall {
    transform-origin: 50% 50%;
  }

  .hidden {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    /* Tell browser to skip rendering entirely - improves performance */
    content-visibility: hidden;
  }

  /* Minimap title / message area - above minimap */
  #minimap-title-area {
    position: absolute;
    left: 1325px;   /* Updated for HD frame minimap position */
    top: 30px;      /* Aligned with player EXP area */
    width: 1000px;  /* Same as minimap (doubled for HD) */
    height: 40px;   /* Same height as player EXP area */
    color: #ffe154;
    font-size: calc(28px * var(--game-font-scale)); /* Doubled for HD frame */
    text-align: left;
    font-weight: 600;
    font-family: Arial, Helvetica, sans-serif;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    line-height: 1.2;
    overflow: visible; /* Ensure text is not clipped */
    z-index: 10; /* Ensure it's above other elements */
  }
  
  /* Floor title (hidden when showing messages) */
  #floor-title {
    color: #ffe154;
    font-weight: 600;
    font-family: var(--game-font);
  }
  
  /* Message display in title area */
  #title-message {
    color: #ffe154;
    display: none;
  }
  
  #title-message.status-atmosphere {
    text-shadow: 0 0 8px rgba(255, 225, 84, 0.8), 0 0 16px rgba(255, 225, 84, 0.6);
    animation: atmosphereGlow 2s ease-in-out 3 forwards;
  }
  
  #title-message.status-statue {
    text-shadow: 0 0 8px rgba(255, 225, 84, 0.8), 0 0 16px rgba(255, 225, 84, 0.6);
    animation: atmosphereGlow 2s ease-in-out 3 forwards;
  }
  
  #title-message.status-priority {
    font-weight: 600;
    animation: priorityFlash 0.25s linear infinite alternate;
  }
  
  /* Player EXP area - above viewport */
  #player-score-area {
    position: absolute;
    left: 100px;   /* Doubled for HD frame */
    top: 28px;     /* Doubled for HD frame */
    width: 890px;  /* Doubled for HD frame */
    height: 40px;  /* Doubled for HD frame */
    color: #ffe154;
    font-size: calc(24px * var(--game-font-scale)); /* Doubled for HD frame */
    font-weight: 600;
    font-family: var(--game-font);
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    line-height: 1.2;
    white-space: pre;
    z-index: 101;
  }
  
  /* Keycard count display */
  #keycard-count {
    position: absolute;
    left: 27px;    /* Doubled for HD frame + 1px adjustment */
    top: 545px;    /* Adjusted for SquareSpace positioning */
    color: #000;
    font-size: calc(28px * var(--game-font-scale)); /* Doubled for HD frame */
    font-weight: 700; /* Bolder for SquareSpace */
  }
  
  /* Blueprint count display */
  #blueprint-count {
    position: absolute;
    left: 27px;    /* Doubled for HD frame + 1px adjustment */
    top: 630px;    /* Adjusted for SquareSpace positioning */
    color: #000;
    font-size: calc(28px * var(--game-font-scale)); /* Doubled for HD frame */
    font-weight: 700; /* Bolder for SquareSpace */
  }

  /* Minimap area inside frame */
  #minimap {
    position: absolute;
    left: 1300px;
    top: 100px;
    width: 1000px;
    height: 1000px;
    display: flex;
    flex-direction: column;
  }

  .mini-row {
    display: flex;
    flex: 1 1 auto;
  }

  .mini-cell {
    flex: 1 1 auto;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
  pointer-events: none; /* Allow clicks to pass through when needed */
  }

  /* Status-permanent removed - info now shown in dedicated areas */
  #status-permanent {
    display: none;
  }

  /* Status-temporary removed - messages now shown in minimap title area */
  #status-temporary {
    display: none;
  }

  @keyframes atmosphereGlow {
    0%   { opacity: 0;   text-shadow: 0 0 4px rgba(255,225,84,0.4); }
    50%  { opacity: 1;   text-shadow: 0 0 10px rgba(255,225,84,0.9); }
    100% { opacity: 0;   text-shadow: 0 0 4px rgba(255,225,84,0.4); }
  }

  @keyframes priorityFlash {
    from { opacity: 1;   text-shadow: 0 0 10px rgba(255,225,84,0.9); }
    to   { opacity: 0.5; text-shadow: 0 0 2px rgba(255,225,84,0.2); }
  }

  @keyframes hp-bar-flash {
    0%, 100% { 
      opacity: 1; 
    }
    50% { 
      opacity: 0.1; 
    }
  }

  /* HUD + controls row under frame (hidden by default, shown for developer accounts via JS) */
  #controls-row {
    margin-top: 6px;
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    color: #ccc;
    font-size: calc(24px * var(--game-font-scale)); /* Doubled for HD frame */
  }

  .control-group {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .control-group label {
    font-size: calc(12px * var(--game-font-scale));
  }

  .control-group select,
  .control-group button,
  .control-group input[type="checkbox"] {
    background: #222;
    color: #eee;
    border: 1px solid #555;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: calc(11px * var(--game-font-scale));
    cursor: pointer;
  }

  .control-group button:hover {
    background: #333;
  }

  .control-group input[type="checkbox"] {
    width: auto;
    padding: 0;
  }

  #hud {
    flex: 1 1 auto;
    text-align: right;
  }


  #level-controls-panel select,
  #level-controls-panel button {
    background: #222;
    color: #eee;
    border: 1px solid #555;
    padding: 3px 6px;
    border-radius: 3px;
    font-size: calc(10px * var(--game-font-scale));
    cursor: pointer;
    text-align: left;
  }

  #pause-toggle {
    position: absolute;
    top: 520px;
    left: 659px;
    background: #222;
    color: #eee;
    border: 1px solid #555;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: calc(10px * var(--game-font-scale));
    cursor: pointer;
  }

  #pause-toggle:hover {
    background: #333;
  }

  #floor-toggle {
    position: absolute;
    top: 520px;
    left: 744px;
    background: #222;
    color: #eee;
    border: 1px solid #555;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: calc(10px * var(--game-font-scale));
    cursor: pointer;
    display: none; /* Hidden on levels 1-2 */
  }

  #floor-toggle:hover {
    background: #333;
  }

  #music-toggle {
    position: absolute;
    top: 520px;
    left: 830px;
    background: #222;
    color: #eee;
    border: 1px solid #555;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: calc(10px * var(--game-font-scale));
    cursor: pointer;
  }

  #music-toggle:hover {
    background: #333;
  }

  #leaderboard-toggle {
    position: absolute;
    top: 520px;
    left: 910px;
    background: #222;
    color: #eee;
    border: 1px solid #555;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: calc(10px * var(--game-font-scale));
    cursor: pointer;
  }

  #leaderboard-toggle:hover {
    background: #333;
  }

  #leaderboard {
    position: absolute;
    left: 1300px;   /* Updated for HD frame minimap position */
    top: 100px;     /* Updated for HD frame minimap position */
    width: 1000px;  /* Same as minimap (doubled for HD) */
    height: 1000px; /* Same as minimap (doubled for HD) */
    background: rgba(0, 0, 0, 0.9);
    color: #eee;
    font-size: calc(40px * var(--game-font-scale)); /* Doubled again for better readability */
    padding: 8px;    /* Doubled for HD frame */
    box-sizing: border-box;
    overflow-y: auto;
  }
  
  #leaderboard table {
    line-height: 1.2;
  }
  
  #leaderboard table tr {
    line-height: 1.2;
  }
  
  #leaderboard table td,
  #leaderboard table th {
    padding: 2px 4px;
    line-height: 1.4;
  }

  /* Monster ghost transition overlay (fades out at old position) */
  .monster-ghost {
    position: absolute;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    pointer-events: none;
    /* z-index set inline from the original monster element so ghosts
       respect the same depth layering as real sprites (walls occlude them). */
    opacity: 1;
    transition: opacity 180ms ease-out, transform 180ms ease-out;
  }
  .monster-ghost.fading {
    opacity: 0;
  }

  /* Monster fade-in at new position after movement */
  .monster-fade-in {
    opacity: 0 !important;
    transition: opacity 180ms ease-in !important;
  }
  .monster-fade-in.visible {
    opacity: 1 !important;
  }

  /* Responsive scaling for smaller screens */
  /* Responsive scaling handled by JavaScript applyInitialFrameScale() function */
  /* Media queries removed to avoid conflicts with dynamic scaling */
