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

html, body {
  height: 100%;
  width: 100%;
  background: #1a0f0a;
  color: #fff8e7;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  /* Stop pull-to-refresh / overscroll while playing */
  overscroll-behavior: none;
  touch-action: none;
  /* Fill mobile browser chrome (notch / home indicator) */
  position: fixed;
  inset: 0;
}

#game-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  /* Prefer dynamic viewport units on modern mobile browsers */
  width: 100dvw;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 20%, #3d2415 0%, #1a0f0a 70%);
  overflow: hidden;
  touch-action: none;
}

#game {
  display: block;
  /* Keep 16:9 canvas aspect; scale to fit the viewport */
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  width: min(100dvw, calc(100dvh * 16 / 9));
  height: min(100dvh, calc(100dvw * 9 / 16));
  max-width: 100%;
  max-height: 100%;
  /* Smooth scaling when the canvas is resized to fit the window */
  image-rendering: auto;
  border: 4px solid #c47a3a;
  border-radius: 8px;
  box-shadow:
    0 0 0 2px #6b3a18,
    0 20px 60px rgba(0, 0, 0, 0.55),
    0 0 80px rgba(255, 140, 40, 0.12);
  background: #87ceeb;
  /* Canvas must not steal swipe gestures for scrolling */
  touch-action: none;
}

#hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: min(960px, 96vw);
  display: flex;
  justify-content: space-between;
  padding: 0 18px;
  pointer-events: none;
  font-weight: 700;
  font-size: 18px;
  text-shadow: 0 2px 0 #3a1c0a, 0 0 8px rgba(0, 0, 0, 0.5);
  z-index: 6;
}

#hud span {
  margin-right: 18px;
}

.hud-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 4px;
}

.hud-left span:last-child {
  margin-right: 0;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.touch-pause-btn {
  display: none;
  pointer-events: auto;
  position: relative;
  z-index: 10;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 2px solid #e8a85a;
  border-radius: 10px;
  background: linear-gradient(180deg, #6b3a18 0%, #3a1c0a 100%);
  box-shadow: 0 2px 0 #5a2208, inset 0 1px 0 rgba(255, 230, 170, 0.2);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.touch-pause-bars {
  display: block;
  width: 14px;
  height: 16px;
  border-left: 4px solid #ffd27a;
  border-right: 4px solid #ffd27a;
  box-sizing: border-box;
}

.touch-pause-btn:active {
  transform: translateY(1px);
  background: linear-gradient(180deg, #8a4a20 0%, #5a2c12 100%);
}

@media (pointer: coarse), (hover: none) {
  .touch-pause-btn {
    display: inline-flex;
  }
}

body.touch-enabled .touch-pause-btn {
  display: inline-flex;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 8, 4, 0.72);
  backdrop-filter: blur(3px);
  z-index: 5;
  transition: opacity 0.25s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.panel {
  background: linear-gradient(180deg, #5c3317 0%, #3a1c0a 100%);
  border: 4px solid #e8a85a;
  border-radius: 16px;
  padding: 32px 40px;
  max-width: 520px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 220, 160, 0.25);
}

.panel h1 {
  font-size: 1.55rem;
  letter-spacing: 0.02em;
  color: #ffd27a;
  text-shadow: 0 3px 0 #6b2f0a;
  margin-bottom: 8px;
  line-height: 1.2;
}

.panel p {
  color: #f5d9b0;
  margin-bottom: 16px;
  line-height: 1.4;
}

.panel p a {
  color: #ffd27a;
  text-decoration: underline;
  word-break: break-all;
}

.panel p a:hover {
  color: #ffe8a8;
}

/* Title start screen: full-bleed start.png with only Start Game button */
.overlay.start-screen {
  background: transparent;
  backdrop-filter: none;
  align-items: flex-end;
  padding-bottom: max(28px, env(safe-area-inset-bottom, 0px) + 16px);
}

.overlay.start-screen .panel {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  max-width: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.overlay.start-screen #title,
.overlay.start-screen #subtitle,
.overlay.start-screen #hint,
.overlay.start-screen #countdown,
.overlay.start-screen #controls-list,
.overlay.start-screen #gameover-label {
  display: none !important;
}

.overlay.start-screen #start-btn {
  min-width: 200px;
  font-size: 1.2rem;
  padding: 14px 36px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55), 0 0 24px rgba(255, 160, 40, 0.35);
}

.overlay.start-screen #new-game-btn {
  display: inline-block;
}

.overlay.start-screen #new-game-btn.hidden,
.overlay.start-screen #new-game-btn[hidden] {
  display: none !important;
}

/* How-to controls step — jam-label / market stall flavor */
.overlay.controls-screen {
  background:
    radial-gradient(ellipse at 50% 20%, rgba(255, 160, 60, 0.12) 0%, transparent 55%),
    rgba(12, 6, 4, 0.62);
  backdrop-filter: blur(3px);
}

.overlay.controls-screen .panel {
  position: relative;
  max-width: 460px;
  padding: 28px 28px 24px;
  /* Teak board + warm jam glaze */
  background:
    linear-gradient(180deg, rgba(255, 210, 140, 0.12) 0%, transparent 28%),
    linear-gradient(180deg, #6b3a18 0%, #4a2410 45%, #2e1508 100%);
  border: 4px solid #e8a85a;
  border-radius: 18px;
  box-shadow:
    0 0 0 3px #6b2f0a,
    0 18px 48px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 230, 170, 0.35),
    inset 0 -8px 24px rgba(80, 30, 5, 0.35);
  overflow: hidden;
}

/* Decorative gold corner flourishes */
.overlay.controls-screen .panel::before,
.overlay.controls-screen .panel::after {
  content: "";
  position: absolute;
  width: 28px;
  height: 28px;
  border: 3px solid #ffd27a;
  opacity: 0.7;
  pointer-events: none;
}
.overlay.controls-screen .panel::before {
  top: 10px;
  left: 10px;
  border-right: none;
  border-bottom: none;
  border-radius: 6px 0 0 0;
}
.overlay.controls-screen .panel::after {
  bottom: 10px;
  right: 10px;
  border-left: none;
  border-top: none;
  border-radius: 0 0 6px 0;
}

.overlay.controls-screen #title {
  font-size: 1.45rem;
  color: #ffd27a;
  text-shadow:
    0 3px 0 #5a2208,
    0 0 18px rgba(255, 160, 40, 0.35);
  letter-spacing: 0.03em;
  margin-bottom: 4px;
}

.overlay.controls-screen #subtitle {
  color: #f0c898;
  font-size: 0.95rem;
  font-style: italic;
  margin-bottom: 14px;
  line-height: 1.35;
}

.overlay.controls-screen #controls-list {
  max-width: none;
  margin: 0 0 18px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.overlay.controls-screen #controls-list li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 0;
  padding: 10px 12px;
  text-align: left;
  background: linear-gradient(90deg, rgba(255, 180, 80, 0.1) 0%, rgba(40, 18, 6, 0.45) 100%);
  border: 1px solid rgba(232, 168, 90, 0.35);
  border-radius: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 230, 180, 0.12);
}

.overlay.controls-screen .ctrl-icon {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  line-height: 1;
  background: radial-gradient(circle at 40% 35%, #ffd27a 0%, #c47a3a 70%, #6b2f0a 100%);
  border: 2px solid #ffe8a8;
  border-radius: 50%;
  box-shadow: 0 2px 0 #5a2208, 0 0 10px rgba(255, 160, 40, 0.25);
  color: #3a1c0a;
  font-weight: 900;
}

.overlay.controls-screen .ctrl-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.overlay.controls-screen .ctrl-body strong {
  color: #ffd27a;
  font-size: 0.98rem;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 0 #3a1c0a;
}

.overlay.controls-screen .ctrl-keys {
  color: #ffe8c8;
  font-size: 0.88rem;
  line-height: 1.4;
}

.overlay.controls-screen .ctrl-tip {
  color: #e8c8a0;
  font-size: 0.82rem;
  line-height: 1.35;
  opacity: 0.95;
}

.overlay.controls-screen .ctrl-warn {
  border-color: rgba(200, 80, 60, 0.45);
  background: linear-gradient(90deg, rgba(200, 60, 40, 0.14) 0%, rgba(40, 18, 6, 0.45) 100%);
}

.overlay.controls-screen .ctrl-warn .ctrl-icon {
  background: radial-gradient(circle at 40% 35%, #ffb0a0 0%, #8a3020 75%, #3a1008 100%);
  border-color: #ffc8b0;
}

.overlay.controls-screen .ctrl-goal .ctrl-icon {
  background: radial-gradient(circle at 40% 35%, #ffe08a 0%, #d35400 65%, #6b2f0a 100%);
}

.overlay.controls-screen #start-btn {
  background: linear-gradient(180deg, #ffc85a 0%, #e07a1a 55%, #c45a10 100%);
  color: #2a1206;
  font-size: 1.12rem;
  letter-spacing: 0.02em;
  padding: 13px 34px;
  box-shadow:
    0 4px 0 #8a4510,
    0 10px 24px rgba(0, 0, 0, 0.35),
    0 0 20px rgba(255, 160, 40, 0.3);
}

.overlay.controls-screen #hint {
  color: #e8a85a;
  font-size: 0.88rem;
  margin-top: 12px;
}

.reset-scores-btn {
  display: none;
  margin: 10px auto 0;
  padding: 8px 16px;
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  color: #f0c898;
  cursor: pointer;
  border: 2px solid #c48a4a;
  border-radius: 10px;
  background: linear-gradient(180deg, #5a3014 0%, #2e1508 100%);
  box-shadow: 0 2px 0 #5a2208, inset 0 1px 0 rgba(255, 230, 170, 0.15);
}

.reset-scores-btn.hidden,
.reset-scores-btn[hidden] {
  display: none !important;
}

.overlay.controls-screen .reset-scores-btn {
  display: inline-block;
}

.overlay.controls-screen .reset-scores-btn:hover,
.overlay.controls-screen .reset-scores-btn:focus-visible {
  outline: none;
  border-color: #ffd27a;
  color: #fff8e7;
}

.overlay.start-screen .reset-scores-btn,
.overlay.pause-screen .reset-scores-btn,
.overlay.levelselect-screen .reset-scores-btn {
  display: none !important;
}

/* Kitchen Tips on short landscape (iPhone): keep portrait unchanged.
   Compact the board, allow scroll, keep Continue on screen. */
@media (orientation: landscape) and (max-height: 500px) {
  .overlay.controls-screen {
    align-items: stretch;
    justify-content: center;
    padding:
      6px
      max(12px, env(safe-area-inset-right, 0px))
      6px
      max(12px, env(safe-area-inset-left, 0px));
  }

  .overlay.controls-screen .panel {
    max-width: min(720px, 96vw);
    max-height: 100%;
    margin: 0 auto;
    padding: 12px 16px 10px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  .overlay.controls-screen #title {
    font-size: 1.12rem;
    margin-bottom: 2px;
  }

  .overlay.controls-screen #subtitle {
    font-size: 0.8rem;
    margin-bottom: 8px;
  }

  .overlay.controls-screen #controls-list {
    gap: 4px;
    margin: 0 0 8px;
  }

  .overlay.controls-screen #controls-list li {
    padding: 6px 10px;
    gap: 8px;
  }

  .overlay.controls-screen .ctrl-icon {
    flex-basis: 26px;
    width: 26px;
    height: 26px;
    font-size: 0.95rem;
  }

  .overlay.controls-screen .ctrl-body strong {
    font-size: 0.88rem;
  }

  .overlay.controls-screen .ctrl-keys,
  .overlay.controls-screen .ctrl-tip {
    font-size: 0.74rem;
  }

  /* Keyboard rows aren't useful on a phone; hide them only in landscape */
  body.touch-enabled .overlay.controls-screen .ctrl-desktop {
    display: none !important;
  }

  .overlay.controls-screen #start-btn {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin-top: 4px;
    font-size: 1rem;
    padding: 10px 28px;
    box-shadow:
      0 -14px 18px rgba(46, 21, 8, 0.92),
      0 4px 0 #8a4510,
      0 10px 24px rgba(0, 0, 0, 0.35);
  }

  .overlay.controls-screen #hint {
    font-size: 0.75rem;
    margin-top: 6px;
  }
}

.overlay.controls-screen kbd {
  background: linear-gradient(180deg, #4a2810 0%, #2a150a 100%);
  border-color: #e8a85a;
  color: #ffd27a;
  box-shadow: 0 2px 0 #1a0c04;
}

/* Cabin cutscene: see the scene; only the Continue button sits on top */
.overlay.cutscene-mode {
  background: transparent;
  backdrop-filter: none;
  align-items: flex-end;
  padding-bottom: 36px;
  pointer-events: none;
}

.overlay.cutscene-mode .panel {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  pointer-events: auto;
}

.overlay.cutscene-mode #title,
.overlay.cutscene-mode #subtitle,
.overlay.cutscene-mode #hint,
.overlay.cutscene-mode #countdown,
.overlay.cutscene-mode #controls-list,
.overlay.cutscene-mode #gameover-label,
.overlay.cutscene-mode #new-game-btn {
  display: none !important;
}

/* Boss dialogue — Tam Tam speech bubble over the frozen stage */
#boss-bubble-tail {
  display: none;
}

#boss-bubble-tail[hidden] {
  display: none !important;
}

.overlay.bossintro-mode {
  background: rgba(10, 4, 2, 0.45);
  backdrop-filter: blur(2px);
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
  pointer-events: auto;
}

.overlay.bossintro-mode .panel {
  position: absolute;
  left: 50%;
  top: 72%;
  transform: translate(-50%, -50%);
  width: min(440px, calc(100% - 28px));
  max-width: min(440px, calc(100% - 28px));
  margin: 0;
  overflow: visible;
  background: #fff6e0;
  border: 4px solid #3d6b3a;
  border-radius: 22px 16px 26px 18px / 18px 24px 16px 22px;
  box-shadow:
    3px 4px 0 rgba(61, 107, 58, 0.22),
    0 10px 22px rgba(40, 24, 8, 0.28);
  padding: 26px 22px 10px;
  text-align: center;
}

.overlay.bossintro-mode #title {
  position: absolute;
  top: -15px;
  left: 16px;
  z-index: 2;
  margin: 0;
  padding: 3px 12px 4px;
  max-width: calc(100% - 32px);
  background: #e8a317;
  color: #3a2410;
  font-size: clamp(13px, 3.4vw, 16px);
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: 0.01em;
  text-shadow: none;
  border: 3px solid #3d6b3a;
  border-radius: 9px 11px 8px 5px;
  box-shadow: 1px 2px 0 rgba(61, 107, 58, 0.28);
  transform: rotate(-1.5deg);
}

.overlay.bossintro-mode #subtitle {
  color: #3a2410;
  font-size: clamp(18px, 4.6vw, 22px);
  line-height: 1.45;
  margin: 6px 0 2px;
  min-height: 3.1em;
  text-shadow: none;
}

.overlay.bossintro-mode #controls-list,
.overlay.bossintro-mode #gameover-label,
.overlay.bossintro-mode #countdown,
.overlay.bossintro-mode #hint,
.overlay.bossintro-mode #new-game-btn,
.overlay.bossintro-mode #reset-scores-btn {
  display: none !important;
}

.overlay.bossintro-mode #start-btn {
  appearance: none;
  display: block;
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  margin: 2px auto 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: transparent;
  font-size: 0;
  line-height: 0;
  cursor: pointer;
}

.overlay.bossintro-mode #start-btn::before {
  content: "★";
  display: block;
  color: #e8a317;
  font-size: 32px;
  line-height: 48px;
  text-shadow:
    0 2px 0 #8a6414,
    0 0 8px rgba(232, 163, 23, 0.45);
  animation: boss-star-bob 0.9s ease-in-out infinite;
}

.overlay.bossintro-mode #start-btn:hover,
.overlay.bossintro-mode #start-btn:active {
  transform: none;
  background: transparent;
  box-shadow: none;
}

@keyframes boss-star-bob {
  0%,
  100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

.overlay.bossintro-mode #boss-bubble-tail {
  display: block;
  position: absolute;
  width: 26px;
  height: 18px;
  margin: 0;
  pointer-events: none;
  z-index: 2;
}

.overlay.bossintro-mode #boss-bubble-tail::before,
.overlay.bossintro-mode #boss-bubble-tail::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  border-style: solid;
  border-color: transparent;
}

.overlay.bossintro-mode #boss-bubble-tail::before {
  border-width: 18px 13px 0 13px;
  border-top-color: #3d6b3a;
}

.overlay.bossintro-mode #boss-bubble-tail::after {
  left: 3px;
  top: 0;
  border-width: 13px 10px 0 10px;
  border-top-color: #fff6e0;
}

/* Credits scroll: skip without waiting out the roll */
.credits-skip-btn {
  display: none;
  position: absolute;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
  z-index: 8;
  min-width: 96px;
  min-height: 44px;
  padding: 10px 22px;
  border: 2px solid #e8a85a;
  border-radius: 12px;
  background: linear-gradient(180deg, #6b3a18 0%, #3a1c0a 100%);
  color: #ffd27a;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 3px 0 #5a2208, 0 8px 20px rgba(0, 0, 0, 0.45);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.credits-skip-btn:not(.hidden):not([hidden]) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.credits-skip-btn:active {
  transform: translateY(1px);
  background: linear-gradient(180deg, #8a4a20 0%, #5a2c12 100%);
}

/* Credits return: dark minimal panel with Continue */
.overlay.credits-return {
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: none;
  align-items: flex-end;
  padding-bottom: 40px;
}

.overlay.credits-return .panel {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

.overlay.credits-return #title,
.overlay.credits-return #subtitle,
.overlay.credits-return #hint,
.overlay.credits-return #countdown,
.overlay.credits-return #controls-list,
.overlay.credits-return #gameover-label,
.overlay.credits-return #new-game-btn {
  display: none !important;
}

.panel.victory {
  max-width: 560px;
}

.panel.victory .hint {
  min-height: 2.6em;
  line-height: 1.45;
  color: #ffd27a;
}

#hud.hidden {
  display: none;
}

.controls {
  list-style: none;
  text-align: left;
  margin: 0 auto 20px;
  max-width: 340px;
  color: #ffe8c8;
  font-size: 0.95rem;
}

.controls li {
  margin: 8px 0;
  padding-left: 4px;
}

kbd {
  display: inline-block;
  background: #2a150a;
  border: 2px solid #c47a3a;
  border-bottom-width: 3px;
  border-radius: 5px;
  padding: 1px 7px;
  font-family: inherit;
  font-size: 0.85em;
  color: #ffd27a;
  margin: 0 2px;
}

#start-btn {
  appearance: none;
  border: none;
  background: linear-gradient(180deg, #ffb347 0%, #e07a1a 100%);
  color: #3a1c0a;
  font-weight: 800;
  font-size: 1.15rem;
  padding: 12px 36px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 0 #8a4510, 0 8px 20px rgba(0, 0, 0, 0.3);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

#start-btn:hover {
  transform: translateY(-1px);
}

#start-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #8a4510;
}

.new-game-btn {
  appearance: none;
  border: 2px solid #c47a3a;
  background: linear-gradient(180deg, #5a3018 0%, #3a1c0a 100%);
  color: #ffd27a;
  font-weight: 800;
  font-size: 0.95rem;
  padding: 9px 26px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 3px 0 #2a1408, 0 6px 16px rgba(0, 0, 0, 0.35);
  display: none;
}

.new-game-btn:hover {
  transform: translateY(-1px);
}

.new-game-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #2a1408;
}

.hint {
  margin-top: 14px;
  font-size: 0.85rem;
  color: #c9a07a;
  min-height: 1.2em;
}

.controls.hidden {
  display: none;
}

.countdown {
  margin-top: 10px;
  font-size: 1.35rem;
  font-weight: 800;
  color: #ffd27a;
  text-shadow: 0 2px 0 #6b2f0a;
  letter-spacing: 0.04em;
  min-height: 1.4em;
}

.countdown.urgent {
  color: #ff6b4a;
  animation: pulse-countdown 0.6s ease-in-out infinite alternate;
}

@keyframes pulse-countdown {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

.panel.gameover {
  border-color: #ff6b4a;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5), 0 0 30px rgba(255, 80, 40, 0.2), inset 0 1px 0 rgba(255, 220, 160, 0.25);
}

.gameover-label {
  display: block;
  width: min(260px, 72vw);
  height: auto;
  margin: 0 auto 14px;
  border-radius: 12px;
  background: #fffaf0;
  padding: 10px 12px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25), 0 0 20px rgba(255, 180, 80, 0.15);
  object-fit: contain;
}

.gameover-label[hidden] {
  display: none !important;
}

/* ── On-screen touch controls ─────────────────────────────
   Big zone pads (not tiny circles): left ~48% = move, right ~48% = jump.
   Visual glyphs sit near the bottom; the whole zone is the hit target. */
#touch-controls {
  display: none; /* shown via media query or .touch-enabled */
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  touch-action: none;
}

.touch-zone {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  /* Tall enough that thumbs don't miss while running */
  bottom: 0;
  height: min(48%, 280px);
  min-height: 160px;
}

/* Left half of the screen — slide finger L/R to switch direction */
.touch-move-zone {
  left: 0;
  width: 48%;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding:
    0 max(10px, env(safe-area-inset-left, 0px))
    max(14px, calc(env(safe-area-inset-bottom, 0px) + 10px))
    max(10px, env(safe-area-inset-left, 0px));
  box-sizing: border-box;
}

/* Right half — entire zone is jump (tap or hold) */
.touch-jump-zone {
  right: 0;
  width: 48%;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding:
    0 max(10px, env(safe-area-inset-right, 0px))
    max(14px, calc(env(safe-area-inset-bottom, 0px) + 10px))
    0;
  box-sizing: border-box;
  overflow: hidden;
}

.touch-jump-zone.is-active {
  background: none;
}

.touch-throw-zone {
  right: 118px;
  width: auto;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding:
    0 0
    max(14px, calc(env(safe-area-inset-bottom, 0px) + 10px))
    0;
  pointer-events: none;
}
.touch-throw-zone .touch-throw-pad {
  pointer-events: auto;
  width: 72px;
  height: 72px;
  min-width: 72px;
  min-height: 72px;
  font-size: 1.1rem;
}
.touch-throw-zone.is-active .touch-throw-pad {
  background: rgba(224, 122, 26, 0.78);
  border-color: rgba(255, 210, 122, 0.95);
}

.touch-zone-pad {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 3px solid rgba(255, 210, 122, 0.5);
  background: rgba(58, 28, 10, 0.5);
  color: #ffd27a;
  border-radius: 50%;
  width: 108px;
  height: 108px;
  min-width: 108px;
  min-height: 108px;
  font-weight: 800;
  font-size: 1.55rem;
  line-height: 1;
  box-shadow:
    0 4px 0 rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 220, 160, 0.18);
  transition: background 0.08s ease, transform 0.08s ease, border-color 0.08s ease,
    opacity 0.08s ease;
  pointer-events: none; /* zone handles hits; pads are visual only */
  opacity: 0.92;
}

.touch-left-pad,
.touch-right-pad {
  /* Slightly inset so L/R read as separate sides of the move zone */
  margin: 0 6px;
}

.touch-move-zone.is-left .touch-left-pad,
.touch-move-zone.is-right .touch-right-pad {
  background: rgba(224, 122, 26, 0.78);
  border-color: rgba(255, 210, 122, 0.95);
  transform: translateY(2px) scale(0.96);
  box-shadow:
    0 1px 0 rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 220, 160, 0.25);
  opacity: 1;
}

.touch-jump-pad {
  width: 118px;
  height: 118px;
  min-width: 118px;
  min-height: 118px;
  background: rgba(224, 122, 26, 0.52);
  border-color: rgba(255, 179, 71, 0.75);
  font-size: 1rem;
  letter-spacing: 0.04em;
  margin-right: max(4px, env(safe-area-inset-right, 0px));
  margin-bottom: 2px;
}

.touch-jump-zone.is-active .touch-jump-pad {
  background: rgba(255, 179, 71, 0.9);
  border-color: rgba(255, 230, 160, 0.95);
  color: #3a1c0a;
  transform: translateY(2px) scale(0.97);
  box-shadow:
    0 1px 0 rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 240, 200, 0.35);
}

.touch-icon {
  pointer-events: none;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.touch-jump-label {
  font-size: 1.05rem;
  font-weight: 900;
}

.touch-jump-sub {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.85;
  line-height: 1;
}

.touch-jump-zone.is-active .touch-jump-sub {
  opacity: 0.75;
  color: #3a1c0a;
}

/* Show touch controls on touch / coarse-pointer devices */
@media (hover: none), (pointer: coarse) {
  #touch-controls {
    display: block;
  }

  .ctrl-desktop {
    display: none;
  }

  .ctrl-mobile {
    display: list-item;
  }

  #hud {
    font-size: 15px;
    width: min(960px, 94vw);
    padding: 0 10px;
  }

  #hud span {
    margin-right: 8px;
  }

  .panel {
    padding: 22px 20px;
    max-width: min(520px, 92vw);
    margin: 0 10px;
    max-height: min(90dvh, 90vh);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Allow scrolling the menu panel if content is tall */
    touch-action: pan-y;
  }

  .panel h1 {
    font-size: 1.25rem;
  }

  .panel p {
    font-size: 0.92rem;
  }

  .controls {
    font-size: 0.88rem;
    max-width: 100%;
  }

  #start-btn {
    font-size: 1.05rem;
    padding: 14px 32px;
    /* Comfortable tap target */
    min-height: 48px;
  }

  #game {
    border-width: 2px;
    border-radius: 4px;
  }
}

/* Landscape: larger L/R pads, pulled closer together in the move zone */
@media (hover: none) and (orientation: landscape),
       (pointer: coarse) and (orientation: landscape) {
  .touch-zone {
    height: min(70%, 220px);
    min-height: 120px;
  }

  .touch-move-zone {
    /* Cluster L/R near the left-center instead of far edges */
    width: 42%;
    justify-content: center;
    gap: 10px;
    padding-left: max(8px, env(safe-area-inset-left, 0px));
    padding-right: 0;
  }

  .touch-left-pad,
  .touch-right-pad {
    width: 96px;
    height: 96px;
    min-width: 96px;
    min-height: 96px;
    margin: 0 2px;
    font-size: 1.45rem;
  }

  .touch-zone-pad {
    width: 96px;
    height: 96px;
    min-width: 96px;
    min-height: 96px;
    font-size: 1.35rem;
  }

  .touch-jump-pad {
    width: 110px;
    height: 110px;
    min-width: 110px;
    min-height: 110px;
    font-size: 0.95rem;
  }

  .touch-jump-sub {
    font-size: 0.55rem;
  }

  .touch-move-zone,
  .touch-jump-zone {
    padding-bottom: max(8px, calc(env(safe-area-inset-bottom, 0px) + 4px));
  }

  #hud {
    font-size: 13px;
    top: max(6px, env(safe-area-inset-top, 0px));
  }
}

/* Short landscape phones (extra compact height) */
@media (hover: none) and (orientation: landscape) and (max-height: 420px),
       (pointer: coarse) and (orientation: landscape) and (max-height: 420px) {
  .touch-left-pad,
  .touch-right-pad,
  .touch-zone-pad {
    width: 88px;
    height: 88px;
    min-width: 88px;
    min-height: 88px;
  }

  .touch-move-zone {
    gap: 8px;
  }
}

/* Portrait phones: taller zones + larger glyphs */
@media (hover: none) and (orientation: portrait),
       (pointer: coarse) and (orientation: portrait) {
  .touch-zone {
    height: min(42%, 320px);
    min-height: 200px;
  }

  .touch-left-pad,
  .touch-right-pad,
  .touch-zone-pad {
    width: 114px;
    height: 114px;
    min-width: 114px;
    min-height: 114px;
    font-size: 1.6rem;
  }

  .touch-jump-pad {
    width: 132px;
    height: 132px;
    min-width: 132px;
    min-height: 132px;
  }

  .touch-move-zone,
  .touch-jump-zone {
    padding-bottom: max(22px, calc(env(safe-area-inset-bottom, 0px) + 14px));
  }
}

/* Very narrow phones */
@media (max-width: 380px) {
  .touch-left-pad,
  .touch-right-pad,
  .touch-zone-pad {
    width: 96px;
    height: 96px;
    min-width: 96px;
    min-height: 96px;
  }

  .touch-jump-pad {
    width: 108px;
    height: 108px;
    min-width: 108px;
    min-height: 108px;
  }
}

/* Desktop: hide mobile-only control lines; keep keyboard hints */
.ctrl-mobile {
  display: none;
}

/* Force-show when JS detects touch (covers hybrid laptops that report fine pointer) */
body.touch-enabled #touch-controls {
  display: block;
}

body.touch-enabled .ctrl-desktop {
  display: none;
}

body.touch-enabled .ctrl-mobile {
  display: list-item;
}

/* Hide controls while menus are up so they don't block Start / Continue */
#game-wrap.menu-open #touch-controls {
  visibility: hidden;
  pointer-events: none;
}

/* Landscape + touch: elevate the playfield above a control dock.
   Pads live in the reserved strip — they no longer overlay Tam Tam. */
body.touch-landscape {
  --touch-dock: calc(128px + env(safe-area-inset-bottom, 0px));
}

body.touch-landscape #game-wrap:not(.menu-open) {
  padding-bottom: var(--touch-dock);
  justify-content: center;
  align-items: center;
}

body.touch-landscape #game-wrap:not(.menu-open) #game {
  width: min(100dvw, calc((100dvh - var(--touch-dock)) * 16 / 9));
  height: min(calc(100dvh - var(--touch-dock)), calc(100dvw * 9 / 16));
}

body.touch-landscape #game-wrap:not(.menu-open) #hud {
  /* Keep HUD pinned to the playfield, not the control dock */
  width: min(960px, 96vw);
}

body.touch-landscape #game-wrap:not(.menu-open) #touch-controls {
  position: absolute;
  inset: auto 0 0 0;
  height: var(--touch-dock);
  background:
    linear-gradient(
      180deg,
      rgba(90, 44, 16, 0.5) 0%,
      rgba(26, 15, 10, 0.94) 32%,
      #140c08 100%
    );
  border-top: 2px solid rgba(232, 168, 90, 0.45);
  box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.35);
}

body.touch-landscape #game-wrap:not(.menu-open) .touch-zone {
  height: 100%;
  min-height: 0;
}

body.touch-landscape #game-wrap:not(.menu-open) .touch-move-zone,
body.touch-landscape #game-wrap:not(.menu-open) .touch-jump-zone {
  /* Dock already has a floor — drop the tall overlay gradients */
  background: none;
  padding-top: 8px;
  padding-bottom: max(8px, calc(env(safe-area-inset-bottom, 0px) + 6px));
  align-items: center;
}

@media (max-height: 420px) {
  body.touch-landscape {
    --touch-dock: calc(108px + env(safe-area-inset-bottom, 0px));
  }

  body.touch-landscape #game-wrap:not(.menu-open) .touch-jump-pad {
    width: 96px;
    height: 96px;
    min-width: 96px;
    min-height: 96px;
  }
}

/* ── TEMP: iPhone landscape ghost pads (PHONE_LANDSCAPE_GHOST_PADS in game.js)
   Full-height 16:9, no dock. Jump stays a big right-corner zone.
   ◀ ▶ are a compact D-pad in the left corner (not a 48% split —
   that made the left hit box feel huge). Brighten on press.
   Swap the flag to restore the dock. Ask: "put the dock back" ── */
body.touch-ghost-pads #game-wrap:not(.menu-open) {
  padding-bottom: 0;
}

body.touch-ghost-pads #game-wrap:not(.menu-open) #game {
  width: min(100dvw, calc(100dvh * 16 / 9));
  height: min(100dvh, calc(100dvw * 9 / 16));
}

body.touch-ghost-pads #game-wrap:not(.menu-open) #touch-controls {
  position: absolute;
  inset: 0;
  height: auto;
  background: none;
  border: none;
  box-shadow: none;
}

body.touch-ghost-pads #game-wrap:not(.menu-open) .touch-zone {
  height: min(62%, 210px);
  min-height: 120px;
  background: none;
}

body.touch-ghost-pads #game-wrap:not(.menu-open) .touch-move-zone {
  left: 0;
  /* Hug the two pads — the old 48% strip made LEFT a quarter of the screen */
  width: max-content;
  max-width: 38%;
  justify-content: flex-start;
  align-items: flex-end;
  gap: 18px;
  padding:
    14px 26px
    max(8px, calc(env(safe-area-inset-bottom, 0px) + 4px))
    max(8px, env(safe-area-inset-left, 0px));
}

body.touch-ghost-pads #game-wrap:not(.menu-open) .touch-jump-zone {
  right: 0;
  width: 48%;
  justify-content: flex-end;
  align-items: flex-end;
  padding:
    0 max(8px, env(safe-area-inset-right, 0px))
    max(8px, calc(env(safe-area-inset-bottom, 0px) + 4px))
    0;
}

body.touch-ghost-pads #game-wrap:not(.menu-open) .touch-throw-zone {
  right: 86px;
  bottom: 78px;
  width: auto;
  padding: 0;
}
body.touch-ghost-pads #game-wrap:not(.menu-open) .touch-throw-pad {
  width: 54px;
  height: 54px;
  min-width: 54px;
  min-height: 54px;
  opacity: 0.24;
}
body.touch-ghost-pads #game-wrap:not(.menu-open) .touch-throw-zone.is-active .touch-throw-pad {
  opacity: 0.9;
}

body.touch-ghost-pads #game-wrap:not(.menu-open) .touch-zone-pad,
body.touch-ghost-pads #game-wrap:not(.menu-open) .touch-left-pad,
body.touch-ghost-pads #game-wrap:not(.menu-open) .touch-right-pad {
  width: 62px;
  height: 62px;
  min-width: 62px;
  min-height: 62px;
  margin: 0;
  font-size: 1.1rem;
  border-width: 2px;
  border-color: rgba(255, 210, 122, 0.55);
  background: rgba(58, 28, 10, 0.28);
  box-shadow: none;
  opacity: 0.24;
}

body.touch-ghost-pads #game-wrap:not(.menu-open) .touch-jump-pad {
  width: 70px;
  height: 70px;
  min-width: 70px;
  min-height: 70px;
  font-size: 0.72rem;
  margin: 0;
  border-color: rgba(255, 179, 71, 0.55);
  background: rgba(224, 122, 26, 0.28);
  opacity: 0.24;
}

body.touch-ghost-pads #game-wrap:not(.menu-open) .touch-jump-sub {
  display: none;
}

body.touch-ghost-pads #game-wrap:not(.menu-open) .touch-move-zone.is-left .touch-left-pad,
body.touch-ghost-pads #game-wrap:not(.menu-open) .touch-move-zone.is-right .touch-right-pad {
  opacity: 0.88;
  background: rgba(224, 122, 26, 0.78);
  border-color: rgba(255, 210, 122, 0.95);
  transform: translateY(1px) scale(0.96);
}

body.touch-ghost-pads #game-wrap:not(.menu-open) .touch-jump-zone.is-active .touch-jump-pad {
  opacity: 0.92;
  background: rgba(255, 179, 71, 0.9);
  border-color: rgba(255, 230, 160, 0.95);
  color: #3a1c0a;
  transform: translateY(1px) scale(0.97);
}

body.touch-ghost-pads #game-wrap:not(.menu-open) .touch-jump-zone.is-active .touch-jump-sub {
  color: #3a1c0a;
}

/* ── TEMP DEV: level select (remove with DEV_LEVEL_SELECT before go-live) ── */
.level-select {
  margin: 12px 0 4px;
  width: 100%;
}

.level-select.hidden,
.level-select[hidden] {
  display: none !important;
}

.level-select-label {
  margin: 0 0 10px !important;
  color: #ffb060 !important;
  font-size: 0.85rem !important;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.level-select-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.level-select-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 10px 9px;
  text-align: left;
  font: inherit;
  color: #fff8e7;
  cursor: pointer;
  border: 2px solid #e8a85a;
  border-radius: 10px;
  background: linear-gradient(180deg, #6b3a18 0%, #3a1c0a 100%);
  box-shadow: 0 2px 0 #5a2208, inset 0 1px 0 rgba(255, 230, 170, 0.2);
  transition: transform 0.08s ease, border-color 0.12s ease, background 0.12s ease;
}

.level-select-btn:hover,
.level-select-btn:focus-visible {
  outline: none;
  border-color: #ffd27a;
  background: linear-gradient(180deg, #8a4a20 0%, #5a2c12 100%);
  transform: translateY(-1px);
}

.level-select-btn:active {
  transform: translateY(1px);
}

.level-select-btn .ls-num {
  font-size: 0.72rem;
  font-weight: 800;
  color: #ffd27a;
  letter-spacing: 0.06em;
}

.level-select-btn .ls-name {
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.2;
  color: #fff0d8;
}

.level-select-btn.ls-credits {
  grid-column: 1 / -1;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-color: #ffd27a;
  background: linear-gradient(180deg, #8a4a20 0%, #4a2410 100%);
}

.level-select-hint {
  margin: 0 !important;
  font-size: 0.78rem !important;
  color: #e0b888 !important;
}

.level-select-hint kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid #c47a3a;
  background: rgba(0, 0, 0, 0.35);
  font-size: 0.72rem;
  color: #ffd27a;
}

.overlay.levelselect-screen .panel {
  max-width: 520px;
}

.overlay.levelselect-screen #start-btn {
  display: none;
}

@media (max-width: 520px) {
  .level-select-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ── Pause menu ── */
.pause-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 280px;
  margin: 12px auto 0;
}

.pause-menu.hidden,
.pause-menu[hidden] {
  display: none !important;
}

.pause-vol {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 10px 14px 12px;
  font: inherit;
  font-weight: 700;
  font-size: 0.88rem;
  color: #fff8e7;
  border: 2px solid #e8a85a;
  border-radius: 10px;
  background: linear-gradient(180deg, #6b3a18 0%, #3a1c0a 100%);
  box-shadow: 0 2px 0 #5a2208, inset 0 1px 0 rgba(255, 230, 170, 0.2);
}
.pause-vol span {
  letter-spacing: 0.01em;
}
.pause-vol input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: #ffd27a;
  cursor: pointer;
  touch-action: none;
}

.pause-btn {
  width: 100%;
  padding: 11px 14px;
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff8e7;
  cursor: pointer;
  border: 2px solid #e8a85a;
  border-radius: 10px;
  background: linear-gradient(180deg, #6b3a18 0%, #3a1c0a 100%);
  box-shadow: 0 2px 0 #5a2208, inset 0 1px 0 rgba(255, 230, 170, 0.2);
}

.pause-btn:hover,
.pause-btn:focus-visible,
.pause-btn.is-pad-focus {
  outline: none;
  border-color: #ffd27a;
  background: linear-gradient(180deg, #8a4a20 0%, #5a2c12 100%);
}

.pause-hint {
  margin: 4px 0 0 !important;
  font-size: 0.78rem !important;
  color: #e0b888 !important;
}

.overlay.pause-screen #controls-list,
.overlay.pause-screen #level-select,
.overlay.pause-screen #gameover-label,
.overlay.pause-screen #countdown {
  display: none !important;
}

.overlay.pause-screen #start-btn {
  display: none;
}

/* Short phone landscape: pause menu + continue/game-over must fit. */
@media (orientation: landscape) and (max-height: 500px) {
  .overlay.pause-screen {
    align-items: stretch;
    justify-content: center;
    padding:
      4px
      max(10px, env(safe-area-inset-right, 0px))
      4px
      max(10px, env(safe-area-inset-left, 0px));
  }

  .overlay.pause-screen .panel {
    max-width: min(640px, 96vw);
    max-height: 100%;
    margin: auto;
    padding: 8px 14px 10px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  .overlay.pause-screen #title {
    font-size: 1.05rem;
    margin-bottom: 2px;
  }

  .overlay.pause-screen #subtitle {
    display: none;
  }

  .pause-menu {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    max-width: none;
    width: 100%;
    margin: 8px auto 0;
  }

  .pause-vol {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 6px 10px 8px;
  }

  .pause-vol span {
    white-space: nowrap;
    font-size: 0.8rem;
  }

  .pause-vol input[type="range"] {
    flex: 1;
  }

  .pause-hint {
    grid-column: 1 / -1;
    margin: 0 !important;
    font-size: 0.68rem !important;
  }

  .pause-btn {
    padding: 8px 10px;
    font-size: 0.82rem;
  }

  /* Game over / Continue (jam label + countdown) */
  .panel.gameover {
    padding: 8px 16px 10px;
    max-width: min(560px, 94vw);
    max-height: 96dvh;
    overflow-y: auto;
  }

  .panel.gameover .gameover-label {
    width: min(140px, 34vh);
    margin-bottom: 4px;
    padding: 4px 6px;
  }

  .panel.gameover h1 {
    font-size: 1.12rem;
    margin-bottom: 4px;
  }

  .panel.gameover p {
    font-size: 0.82rem;
    margin-bottom: 8px;
  }

  .panel.gameover #start-btn {
    font-size: 0.95rem;
    padding: 8px 22px;
    min-height: 40px;
  }

  .panel.gameover .countdown {
    margin-top: 4px;
    font-size: 1.05rem;
    min-height: 1.1em;
  }
}
