body {
  margin: 0;
  overflow: hidden;
  background: #222;
}
canvas {
  display: block;
  margin: 0 auto;
  background: transparent;
}

/* Ensure the main game canvas stays beneath the intro overlay */
#game {
  position: relative;
  z-index: 0;
}
.hidden {
  display: none;
}
/* Make menu panels scale like the canvas */
#menu,
#levelSelect,
#settings,
#controls,
#controllerControls,
#credits,
#waveSelect,
#freeSelect,
#pauseMenu {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  
  background: rgba(0, 0, 0, 0.75);
  padding: 2.5%;
  border-radius: 1em;

  text-align: center;
  color: white;
  font-family: Arial, sans-serif;

  /* Responsive sizing */
  width: 90vw;       /* never wider than the viewport */
  max-width: 800px;  /* same as your canvas max width */
  height: auto;      /* scale height automatically */
  box-sizing: border-box;
}

/* Make buttons scale nicely on smaller screens */
#menu button,
#levelSelect button,
#settings button,
#credits button,
#controllerControls button,
#controls button,
#waveSelect button,
#freeSelect button,
#pauseMenu button {
  display: block;
  margin: 2% auto;
  padding: 1% 3%;
  font-size: 1.5vw;      /* scales with screen width */
  cursor: pointer;

  background: #444;
  color: white;
  border: 1px solid #888;
  border-radius: 6px;
}

/* Optional: make buttons slightly bigger on tiny screens */
@media (max-width: 500px) {
  #menu button,
  #levelSelect button,
  #credits button,
  #settings button,
  #controllerControls button,
  #waveSelect button,
  #controls button,
  #pauseMenu button {
    font-size: 16px;
    padding: 8px 16px;
  }
}

canvas {
  border: 1px solid black;
  display: block;
  margin: 0 auto;
}

#game {
  display: none;
}
.hidden {
  display: none;
}

/* Hide any menu when needed */
.hidden {
  display: none;
}

/* All menu panels share this styling */
#menu,
#levelSelect,
#settings,
#controls,
#credits,
#freeSelect,
#waveSelect,
#pauseMenu {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

  background: rgba(0, 0, 0, 0.75);
  padding: 25px 40px;
  border-radius: 10px;

  text-align: center;       /* center the text */
  color: white;             /* white text */
  font-family: Arial, sans-serif;
}

#controllerControls{
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

  background: rgba(255, 255, 255, 0.75);
  padding: 25px 40px;
  border-radius: 10px;

  text-align: center;       /* center the text */
  color: rgb(0, 0, 0);             /* white text */
  font-family: Arial, sans-serif;
}

/* Style menu buttons */
#menu button,
#levelSelect button,
#settings button,
#controls button,
#freeSelect button,
#credits button,
#waveSelect button,
#pauseMenu button {
  display: block;
  margin: 10px auto;
  padding: 10px 20px;
  font-size: 18px;
  cursor: pointer;

  background: #444;
  color: white;
  border: 1px solid #888;
  border-radius: 6px;
}

#controllerControls button{
  display: block;
  margin: 10px auto;
  padding: 10px 20px;
  font-size: 18px;
  cursor: pointer;

  background: #444;
  color: rgb(0, 0, 0);
  border: 1px solid #b5b5b5;
  border-radius: 6px;
}

#menu button:hover,
#levelSelect button:hover,
#settings button:hover,
#controllerControls button:hover,
#controls button:hover,
#pauseMenu button:hover {
  background: #666;
}

#touchControls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

/* Enable interaction only on buttons */
#touchControls button {
  pointer-events: auto;
  font-size: 22px;
  padding: 16px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.6);
  color: white;
}

.left-controls {
  position: fixed;
  left: 10px;
  bottom: 20px;
  display: flex;
  gap: 12px;
}

.right-controls {
  position: fixed;
  right: 10px;
  bottom: 20px;
  display: flex;
  gap: 12px;
}

.utility-controls {
  position: fixed;
  right: 10px;
  top: 70px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#btnPause {
  position: fixed;
  top: 10px;
  left: 10px;
}

#btnRestart {
  position: fixed;
  top: 10px;
  right: 10px;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #808080;
  touch-action: none;
}

canvas {
  display: block;
  margin: auto;

  /* IMPORTANT */
  width: auto;
  height: auto;

  max-width: 100vw;
  max-height: 100vh;

}

body {
  display: flex;
  justify-content: center;
  align-items: center;
}

#touchControls button {
  font-size: 24px;
  width: 60px;
  height: 60px;
  border-radius: 10px;
  border: none;
  background: #000000;
  transition: background 0.1s, transform 0.1s;
}

#touchControls button:active,
#touchControls button.pressed {
  background: #ff0; /* highlight color */
  transform: scale(0.9); /* slight press effect */
}

#game-wrapper {
  width: fit-content;
  height: fit-content;
  margin: auto;
}

/* default */
#game-wrapper {
  transform-origin: top left;
  transform: scale(1);
}

/* Intro / Load screen */
#intro-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Use percent-encoded space to avoid loader issues */
  background-image: url('Assets/Tiles/Cobblestone%20BG.png'), url('Assets/Tiles/Cobblestone BG.png');
  background-repeat: repeat !important;
  background-size: 256px 256px !important; /* control tile density */
  background-position: center center !important;
  background-color: #070609 !important; /* fallback tint */
  color: #fff;
  z-index: 99999 !important;
}

/* dark tint above the background image for dungeon mood */
#intro-screen::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(6,6,8,0.6), rgba(12,10,20,0.7));
  mix-blend-mode: multiply;
  pointer-events: none;
  z-index: 1;
}

/* Inventory & Shop UI */
.inventory-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2,2,6,0.6);
  z-index: 10000;
}
.inventory-overlay.hidden { display: none; }

.inventory-inner {
  width: min(920px, 94vw);
  max-width: 940px;
  background: linear-gradient(180deg, #0b0610, #0f0816);
  border: 1px solid rgba(255,255,255,0.04);
  padding: 18px;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.02);
  color: #f3e9d6;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 14px;
  align-items: start;
  font-family: Arial, Helvetica, sans-serif;
}

/* Stylized theme enhancements */
.inventory-inner {
  background-image: linear-gradient(180deg, rgba(255,240,200,0.03), rgba(10,8,6,0.35)),
                    radial-gradient(circle at 10% 10%, rgba(255,220,140,0.02), transparent 8%);
  border: 1px solid rgba(255,210,120,0.06);
  backdrop-filter: blur(6px) saturate(1.05);
  transform: translateY(-8px);
  animation: invEntrance 260ms cubic-bezier(.22,.9,.32,1) forwards;
}

@keyframes invEntrance {
  from { opacity: 0; transform: translateY(-20px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.inventory-header h2 { text-shadow: 0 1px 0 rgba(0,0,0,0.6); }
.inventory-header .gold { background: linear-gradient(90deg,#ffd86b,#ffb84d); padding:6px 10px; border-radius:8px; color:#2b1b00; font-weight:700; box-shadow: inset 0 -2px 0 rgba(0,0,0,0.08); }

.inv-slot {
  position: relative;
  overflow: hidden;
  border-image: linear-gradient(90deg,#ffd86b,#ffb84d) 1 round;
}
.inv-slot::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(0,0,0,0.06));
  pointer-events: none;
}
.inv-slot.empty { 
  opacity: 0.4; 
  border: 1px dashed rgba(255,255,255,0.15); 
  background: rgba(0,0,0,0.3);
}
.inv-slot.empty::before {
  content: '∙';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 24px;
  color: rgba(255,255,255,0.1);
}

.shop-row { align-items:center; }
.shop-row .shop-item { display:flex; align-items:center; gap:8px; }
.shop-row .shop-item::before { content: ''; display:inline-block; width:30px; height:30px; background: linear-gradient(180deg,#fff,#ccc); border-radius:6px; box-shadow: inset 0 -2px 0 rgba(0,0,0,0.12); }

.shop-row button { transition: transform 120ms ease, box-shadow 120ms ease; }
.shop-row button:hover { transform: translateY(-3px); box-shadow: 0 8px 18px rgba(0,0,0,0.5); }

.inventory-inner > button { background: linear-gradient(180deg,#3a3a3a,#222); border: 1px solid rgba(255,255,255,0.04); box-shadow: 0 6px 18px rgba(0,0,0,0.5); }

/* Decorative corner icons */
.inventory-inner::before, .inventory-inner::after {
  content: '';
  position: absolute;
  width: 64px; height: 64px;
  background: radial-gradient(circle at 30% 30%, rgba(255,200,80,0.06), transparent 30%);
  pointer-events: none;
  border-radius: 8px;
}
.inventory-inner::before { left: 12px; top: 12px; }
.inventory-inner::after  { right: 12px; bottom: 12px; }

/* subtle retro pixel frame */
.inventory-inner { box-shadow: 0 10px 30px rgba(0,0,0,0.6), 0 0 0 2px rgba(0,0,0,0.12) inset; border-radius: 10px; position: relative; }


.inventory-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:6px; }
.inventory-header h2 { margin:0; font-size:18px; color:#ffd86b; letter-spacing:0.6px; }
.inventory-header .gold { font-size:13px; color:#ffffff; opacity:0.95; }

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  background: rgba(255,255,255,0.02);
  padding: 8px;
  border-radius: 8px;
  min-height: 240px;
}

.inv-slot {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.04);
  height: 56px;
  display:flex;
  align-items:center;
  justify-content:center;
  color:#fff;
  font-size:12px;
  border-radius:6px;
  cursor: default;
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.inv-slot:hover { transform: translateY(-4px); box-shadow: 0 6px 20px rgba(0,0,0,0.5); }

.shop-box { background: rgba(255,255,255,0.02); border-radius:8px; padding:10px; border:1px solid rgba(255,255,255,0.03); }
.shop-list { display:flex; flex-direction:column; gap:8px; max-height:420px; overflow:auto; padding-right:4px; }
.shop-row { display:flex; justify-content:space-between; align-items:center; gap:8px; padding:8px; background: rgba(0,0,0,0.18); border-radius:6px; }
.shop-row .shop-item { color:#ffd86b; font-weight:600; }
.shop-row .shop-price { color:#fff; opacity:0.95; margin-right:8px; }
.shop-row button { 
  padding:6px 12px; 
  background: linear-gradient(180deg, #4caf50, #388e3c);
  color:#fff; 
  border:none; 
  border-radius:6px; 
  cursor:pointer;
  font-weight: 600;
  font-size: 13px;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.shop-row button:hover {
  background: linear-gradient(180deg, #66bb6a, #4caf50);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.4);
}
.shop-row button:disabled { 
  background: linear-gradient(180deg, #666, #555);
  opacity:0.6; 
  cursor:not-allowed;
}.shop-row button:disabled { background:#666; opacity:0.6; cursor:not-allowed; }

.inventory-inner > button { 
  margin-top:12px; 
  padding:10px 14px; 
  border-radius:8px; 
  background: linear-gradient(180deg, #3a3a3a, #222); 
  color:#fff; 
  border:1px solid #555; 
  cursor:pointer;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  transition: background 0.2s, transform 0.1s;
}
.inventory-inner > button:hover {
  background: linear-gradient(180deg, #4a4a4a, #333);
  transform: translateY(-2px);
}

@media (max-width: 900px) {
  .inventory-inner { grid-template-columns: 1fr; }
  .inventory-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 480px) {
  .inventory-grid { grid-template-columns: repeat(3, 1fr); }
  .inventory-inner { padding: 12px; }
  .inv-slot { height:48px; font-size:11px; }
}

/* small scrollbar for shop list */
.shop-list::-webkit-scrollbar { width:8px; }
.shop-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 6px; }
#inventory-ui { z-index: 10000; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
#invGrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; min-height: 240px; }
#shopList { max-height: 420px; overflow: auto; }

/* Explicitly separate inventory and shop into two panel boxes */
#inventory-ui .inventory-inner {
  display: block;
}

#inventory-ui .inventory-columns {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 14px;
  align-items: start;
}

#inventory-ui .inventory-panel {
  background: rgba(255,255,255,0.02);
  border-radius: 8px;
  padding: 10px;
  border: 1px solid rgba(255,255,255,0.03);
}

#inventory-ui .inventory-panel h3 {
  margin: 0 0 10px 0;
  color: #ffd86b;
}

#inventory-ui .shop-tip {
  margin: 0 0 10px 0;
  font-size: 12px;
  opacity: 0.85;
}

#inventory-ui .inv-slot {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  padding: 4px;
}

#inventory-ui .inv-slot-label {
  text-align: center;
  line-height: 1.2;
}

#inventory-ui .inv-use-btn {
  font-size: 11px;
  padding: 3px 8px;
  border: none;
  border-radius: 5px;
  color: #fff;
  background: linear-gradient(180deg, #607d8b, #455a64);
  cursor: pointer;
}

#inventory-ui .inv-use-btn:hover {
  background: linear-gradient(180deg, #78909c, #546e7a);
}

#inventory-ui .inventory-inner > button {
  width: 100%;
}

#shop-ui .shop-inner {
  width: min(520px, 92vw);
}

#shop-ui .shop-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

#shop-ui .shop-start-wave-btn {
  background: linear-gradient(180deg, #c03030, #8f2020);
  border: 1px solid #ff7777;
  color: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 700;
}

#shop-ui .shop-start-wave-btn:hover {
  background: linear-gradient(180deg, #d83a3a, #a32525);
}

@media (max-width: 900px) {
  #inventory-ui .inventory-columns {
    grid-template-columns: 1fr;
  }
}

#intro-screen .intro-content {
  text-align: center;
  max-width: 520px;
  padding: 28px 36px;
  border-radius: 12px;
  background: rgba(0,0,0,0.4);
  box-shadow: 0 8px 30px rgba(0,0,0,0.6);
  position: relative;
  overflow: hidden;
}

#intro-screen h1 {
  margin: 0 0 8px 0;
  font-size: 36px;
  letter-spacing: 1px;
}

.intro-progress {
  width: 100%;
  height: 10px;
  background: rgba(255,255,255,0.08);
  border-radius: 8px;
  margin: 14px 0 8px 0;
  overflow: hidden;
}

.intro-progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #ffd64d, #ff6b6b);
  transition: width 0.1s linear;
}

.intro-hint {
  margin-top: 8px;
  font-size: 13px;
  opacity: 0.9;
  color: #e7e7e7;
}

/* Cinematic credits + laugh */
.intro-credits {
  margin-bottom: 10px;
}
.credit-line {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 400ms ease, transform 400ms ease;
  font-size: 18px;
  color: #ffd86b;
}
.credit-big { font-size: 30px; font-weight:700; color:#fff; }
.credit-small { font-size: 14px; color:#f0e0b8; }
.credit-line.visible { opacity: 1; transform: translateY(0); }

.intro-laugh {
  font-size: 20px;
  color: #ffde59;
  margin-bottom: 8px;
  opacity: 0;
  transform: translateY(-4px) scale(0.98);
  transition: opacity 300ms ease, transform 300ms ease;
}
.intro-laugh.visible { opacity: 1; transform: translateY(0) scale(1); }

/* Small cinematic fade out when hiding */
#intro-screen.fadeout { animation: introFadeOut 420ms forwards; }
@keyframes introFadeOut { to { opacity: 0; visibility: hidden; } }

/* Keep existing hidden utility working for the intro */
.hidden { display: none; }

/* Intro sprites */
/* full-screen background sprites */
.intro-bg {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}
.intro-bg img {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(1.2);
  width: auto;
  height: 120%;
  object-fit: cover;
  opacity: 0.14;
  filter: saturate(1.05) contrast(0.98) blur(0.6px);
  transition: transform 900ms cubic-bezier(.22,.9,.32,1), opacity 800ms ease;
}
.intro-bg img.player {
  transform: translate(-45%, -50%) scale(1.6);
  opacity: 0.18;
}
.intro-bg img.snail {
  transform: translate(45%, -48%) scale(1.35);
  opacity: 0.16;
}
.intro-bg img.animate { transform: translate(-50%, -50%) scale(1.05); opacity: 0.34; filter: none; }
@keyframes intro-bob-player { 0% { transform: translateY(0); } 50% { transform: translateY(-8px); } 100% { transform: translateY(0); } }
@keyframes intro-bob-snail { 0% { transform: translateY(0); } 50% { transform: translateY(-4px); } 100% { transform: translateY(0); } }

/* subtle animated light beams for dungeon vibe */
.intro-content::before {
  content: '';
  position: absolute;
  inset: -20% -10% -20% -10%;
  background: linear-gradient(120deg, rgba(255,200,80,0.02), rgba(255,120,80,0.02));
  mix-blend-mode: overlay;
  pointer-events: none;
  opacity: 0.9;
  transform: translateY(-6%);
  animation: intro-light-pulse 3200ms ease-in-out infinite;
}
@keyframes intro-light-pulse {
  0% { filter: hue-rotate(0deg) saturate(0.9); opacity: 0.85; }
  50% { filter: hue-rotate(8deg) saturate(1.2); opacity: 1; }
  100% { filter: hue-rotate(0deg) saturate(0.9); opacity: 0.85; }
}

/* Canvas for particle effects (behind UI but above background) */
#intro-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

/* Ensure the content sits above canvas */
.intro-content { z-index: 3; }

/* Pixel-art mode */
.pixelated canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

body::after {
  content: "";
  pointer-events: none;
  position: fixed;
  inset: 0;
  opacity: 0;
  z-index: 999;

  background:
    repeating-linear-gradient(
      to bottom,
      rgba(255,255,255,0.03) 0px,
      rgba(255,255,255,0.03) 1px,
      rgba(0,0,0,0.04) 2px,
      rgba(0,0,0,0.04) 3px
    );

  mix-blend-mode: overlay;
}

/* CRT ON */

.crt::after {
  opacity: 1;
}
.crt canvas {
  animation: crtFlicker 0.15s infinite alternate;
}

@keyframes crtFlicker {
  from { filter: brightness(1) contrast(1); }
  to   { filter: brightness(1.03) contrast(1.05); }
}

body::before {
  content: "";
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 998;
  opacity: 0;

  background: radial-gradient(
    ellipse at center,
    rgba(0,0,0,0) 55%,
    rgba(0,0,0,0.25) 85%,
    rgba(0,0,0,0.45) 100%
  );
}

.crt::before {
  opacity: 1;
}

.crt canvas {
  filter:
    contrast(1.05)
    brightness(1.03)
    saturate(1.1);
}

.crt canvas {
  box-shadow:
    -2px 0 rgba(255,0,0,0.08),
     2px 0 rgba(0,255,255,0.08);
}

/* VHS tracking band */


body::selection {
  background: transparent;
}

/* Tracking bar */

/* VHS TRACKING GLITCH */
.crt.vhs::before {
  animation: vhsTrack 0.12s steps(2) infinite;
}

@keyframes vhsTrack {
  0% {
    transform: translateY(0);
    filter: none;
  }
  40% {
    transform: translateY(-2px);
  }
  60% {
    transform: translateY(1px);
  }
  100% {
    transform: translateY(0);
  }
}

.crt.vhs canvas {
  animation: vhsTear 0.12s steps(2) infinite;
}

@keyframes vhsTear {
  0% {
    clip-path: inset(0 0 0 0);
  }
  50% {
    clip-path: inset(30% 0 35% 0);
    transform: translateX(-3px);
  }
  100% {
    clip-path: inset(0 0 0 0);
    transform: translateX(0);
  }
}

.crt.vhs canvas {
  box-shadow:
    -2px 0 rgba(255,0,0,0.2),
     2px 0 rgba(0,255,255,0.2);
}
/* Update the right-controls to handle the joystick as a child */
.right-controls {
  position: fixed;
  right: 10px;
  bottom: 20px;
  display: flex;
  align-items: flex-end; /* Align bottom of joystick with bottom of buttons */
  gap: 15px;
  flex-direction: row-reverse; /* Puts joystick to the LEFT of the buttons */
}

#potatoJoystickArea {
  pointer-events: auto;
  z-index: 11; /* Slightly higher than standard buttons */
  margin-bottom: 5px; /* Tiny adjustment to center with circular buttons */
}

button, canvas {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body.high-contrast canvas {
  filter: contrast(1.5) saturate(0);
}
body.high-contrast {
  background: #000;
  color: #fff;
}
body.high-contrast button {
  background: #000;
  color: #fff;
  border: 2px solid #fff;
}

#settings,
#keybindsMenu {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #0d0d14;
  border: 1px solid #3a2f5e;
  border-radius: 12px;
  padding: 24px 28px;
  width: min(520px, 92vw);
  max-height: 80vh;
  overflow-y: auto;
  z-index: 100;
  scrollbar-width: thin;
  scrollbar-color: #3a2f5e #0d0d14;
}

#settings h2,
#keybindsMenu h2 {
  color: #f0d060;
  font-size: 22px;
  font-family: monospace;
  text-align: center;
  margin: 0 0 20px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

#keybindsMenu {
  width: min(620px, 92vw);
}

.settings-action-btn {
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid #5a4878;
  border-radius: 8px;
  background: rgba(122, 86, 190, 0.14);
  color: #fff;
  font-family: monospace;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s, border-color 0.15s;
}

.settings-action-btn:hover {
  background: rgba(122, 86, 190, 0.24);
  border-color: #9b5fe4;
  transform: translateY(-1px);
}

.keybinds-help {
  margin: -6px 0 16px;
  color: #c8c0e8;
  font-family: monospace;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
}

.keybind-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.keybind-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(90, 72, 120, 0.75);
  background: rgba(26, 20, 40, 0.75);
}

.keybind-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.keybind-label {
  color: #f0f0ff;
  font-family: monospace;
  font-size: 13px;
}

.keybind-hint {
  color: #9e94c0;
  font-family: monospace;
  font-size: 11px;
}

.keybind-button {
  min-width: 120px;
  padding: 10px 12px;
  border: 1px solid #5a4878;
  border-radius: 8px;
  background: #1a1428;
  color: #f0d060;
  font-family: monospace;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.keybind-button:hover {
  background: #2a1f4a;
  border-color: #9b5fe4;
  transform: translateY(-1px);
}

.keybind-button.capturing {
  background: #4d2c7a;
  border-color: #f0d060;
  color: #fff;
}

.keybinds-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 18px;
}

#settings h3 {
  color: #a080d0;
  font-size: 11px;
  font-family: monospace;
  text-transform: uppercase;
  letter-spacing: 3px;
  margin: 20px 0 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid #2a1f4a;
}

#settings label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: 6px;
  font-family: monospace;
  font-size: 13px;
  color: #c8c0e8;
  cursor: pointer;
  transition: background 0.15s;
}

#settings label:hover {
  background: rgba(160, 128, 208, 0.1);
  color: #fff;
}

/* Checkbox styling */
#settings input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid #5a4878;
  border-radius: 4px;
  background: #1a1428;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: border-color 0.15s, background 0.15s;
}

#settings input[type="checkbox"]:checked {
  background: #7b2fd4;
  border-color: #9b5fe4;
}

#settings input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

/* Range slider */
#settings input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 130px;
  height: 4px;
  background: #2a1f4a;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

#settings input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #7b2fd4;
  border: 2px solid #d46de8;
  cursor: pointer;
}

#settings input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #7b2fd4;
  border: 2px solid #d46de8;
  cursor: pointer;
}

/* Back button */
#settings .back-btn,
#keybindsMenu .back-btn {
  display: block;
  width: 100%;
  margin-top: 20px;
  padding: 10px;
  background: transparent;
  border: 1px solid #5a4878;
  border-radius: 8px;
  color: #c8c0e8;
  font-family: monospace;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

#settings .back-btn:hover,
#keybindsMenu .back-btn:hover {
  background: #5a4878;
  color: #fff;
}

/* Scrollbar for webkit */
#settings::-webkit-scrollbar {
  width: 6px;
}
#settings::-webkit-scrollbar-track {
  background: #0d0d14;
}
#settings::-webkit-scrollbar-thumb {
  background: #3a2f5e;
  border-radius: 3px;
}

#settings span[id^="label"] {
  color: #f0d060;
  font-family: monospace;
  font-size: 12px;
  min-width: 38px;
  text-align: right;
}
#credits {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(480px, 90vw);
  background: #0d0d14;
  border: 1px solid #3a2f5e;
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  z-index: 100;
}

.credits-outer {
  height: 380px;
  overflow: hidden;
  position: relative;
  padding: 0 28px;
}

/* Fade top and bottom edges */
.credits-outer::before,
.credits-outer::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 60px;
  z-index: 2;
  pointer-events: none;
}
.credits-outer::before {
  top: 0;
  background: linear-gradient(to bottom, #0d0d14, transparent);
}
.credits-outer::after {
  bottom: 0;
  background: linear-gradient(to top, #0d0d14, transparent);
}

.credits-scroll {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-top: 380px; /* start off-screen */
  animation: creditsScroll 22s linear infinite;
}

.credits-scroll:hover {
  animation-play-state: paused; /* pause on hover */
}

@keyframes creditsScroll {
  from { transform: translateY(0); }
  to   { transform: translateY(-100%); }
}

.credits-logo {
  font-family: monospace;
  font-size: 36px;
  font-weight: bold;
  color: #f0d060;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.credits-tagline {
  font-family: monospace;
  font-size: 12px;
  color: #7a6a9a;
  letter-spacing: 2px;
  margin-bottom: 4px;
}

.credits-role {
  font-family: monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 3px;
  color: #a080d0;
  margin-bottom: 6px;
}

.credits-name {
  font-family: monospace;
  font-size: 18px;
  color: #e8e0f8;
  margin-bottom: 4px;
}

.credits-spacer {
  height: 40px;
}

#credits .back-btn {
  display: block;
  width: calc(100% - 56px);
  margin: 0 28px 20px;
  padding: 10px;
  background: transparent;
  border: 1px solid #5a4878;
  border-radius: 8px;
  color: #c8c0e8;
  font-family: monospace;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

#credits .back-btn:hover {
  background: #5a4878;
  color: #fff;
}

#touchControls button {
  padding: 0;
  background: transparent;
  border: none;
  line-height: 0; /* removes gap below inline img */
}

#touchControls button img {
  display: block;
  image-rendering: pixelated; /* keeps pixel art crisp */
}
/* ── NAME INPUT ROW ── */
.name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
  font-family: monospace;
  font-size: 13px;
  color: #c8c0e8;
}

.name-row input {
  background: #1a1428;
  border: 1px solid #5a4878;
  border-radius: 6px;
  color: #fff;
  font-family: monospace;
  font-size: 14px;
  padding: 6px 10px;
  width: 160px;
  outline: none;
}

.name-row input:focus {
  border-color: #a080d0;
}

/* ── MULTIPLAYER LOBBY ── */
#multiplayerLobby {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #0d0d14;
  border: 1px solid #3a2f5e;
  border-radius: 12px;
  padding: 28px 36px;
  width: min(480px, 92vw);
  text-align: center;
  color: #e8e0f8;
  font-family: monospace;
  z-index: 100;
}

#multiplayerLobby h2 {
  color: #f0d060;
  font-size: 20px;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin: 0 0 20px;
}

.lobby-section {
  margin-bottom: 16px;
}

.lobby-big-btn {
  display: block;
  width: 100%;
  padding: 12px;
  background: #1a1428;
  border: 1px solid #5a4878;
  border-radius: 8px;
  color: #e8e0f8;
  font-family: monospace;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.lobby-big-btn:hover {
  background: #2a1f4a;
  border-color: #a080d0;
}

.lobby-join-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.room-code-input {
  background: #1a1428;
  border: 1px solid #5a4878;
  border-radius: 6px;
  color: #f0d060;
  font-family: monospace;
  font-size: 22px;
  font-weight: bold;
  letter-spacing: 6px;
  text-align: center;
  text-transform: uppercase;
  padding: 8px 12px;
  width: 120px;
  outline: none;
}

.room-code-input:focus {
  border-color: #a080d0;
}

#multiplayerLobby button:not(.lobby-big-btn):not(.back-btn) {
  padding: 10px 20px;
  background: #2a1f4a;
  border: 1px solid #5a4878;
  border-radius: 6px;
  color: #e8e0f8;
  font-family: monospace;
  font-size: 14px;
  cursor: pointer;
}

#multiplayerLobby button:hover {
  background: #3a2f5e;
}

.lobby-room-code {
  font-size: 13px;
  color: #a080d0;
  margin-bottom: 10px;
  letter-spacing: 1px;
}

.lobby-room-code span {
  color: #f0d060;
  font-size: 20px;
  font-weight: bold;
  letter-spacing: 6px;
  margin-left: 6px;
}

.lobby-player-list {
  background: rgba(0,0,0,0.3);
  border: 1px solid #2a1f4a;
  border-radius: 8px;
  padding: 10px;
  min-height: 80px;
  margin-bottom: 12px;
  text-align: left;
}

.lobby-player-entry {
  padding: 5px 8px;
  font-size: 13px;
  color: #c8c0e8;
  display: flex;
  align-items: center;
  gap: 8px;
}

.lobby-player-entry.is-host::after {
  content: "HOST";
  font-size: 10px;
  color: #f0d060;
  border: 1px solid #f0d060;
  border-radius: 3px;
  padding: 1px 4px;
}

.lobby-status {
  font-size: 12px;
  color: #7a6a9a;
  margin-top: 8px;
  letter-spacing: 1px;
}

#multiplayerLobby .back-btn {
  display: block;
  width: 100%;
  margin-top: 20px;
  padding: 10px;
  background: transparent;
  border: 1px solid #5a4878;
  border-radius: 8px;
  color: #c8c0e8;
  font-family: monospace;
  font-size: 13px;
  cursor: pointer;
}

#multiplayerLobby .back-btn:hover {
  background: #5a4878;
  color: #fff;
}

/* Dungeon atmospheric vignette overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(
    circle at center,
    transparent 0%,
    transparent 40%,
    rgba(5, 5, 15, 0.3) 80%,
    rgba(0, 0, 10, 0.6) 100%
  );
  pointer-events: none;
  z-index: 1;
  mix-blend-mode: multiply;
}

/* Subtle animated grain texture */
@keyframes grain {
  0%, 100% { opacity: 0.03; }
  50% { opacity: 0.06; }
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200"><filter id="noise"><feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="4"/></filter><rect width="100%" height="100%" filter="url(%23noise)" opacity="0.4"/></svg>');
  opacity: 0.05;
  pointer-events: none;
  animation: grain 2s infinite;
  z-index: 1;
  mix-blend-mode: overlay;
}

/* Make canvas slightly darker for dungeon feel */
#game {
  filter: brightness(0.98) contrast(1.02); /* Very subtle */
}

/* Glow effect on menu panels for mystical feel */
#menu, #levelSelect, #settings, #keybindsMenu, #pauseMenu,
#controls, #credits, #waveSelect, #freeSelect {
  box-shadow: 
    0 0 40px rgba(80, 60, 120, 0.3),
    inset 0 0 20px rgba(100, 80, 150, 0.1);
  border: 1px solid rgba(120, 100, 180, 0.3);
}