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

body {
  overflow: hidden;
  background: #000;
  font-family: 'Courier New', monospace;
}

/* overflow:hidden does NOT stop Chrome Android pull-to-refresh, and it
   propagates to the viewport from the ROOT element — so html must be included. */
html, body {
  overscroll-behavior: none;
}

canvas#game {
  display: block;
  width: 100vw;
  height: 100vh;
}

/* ---- Loading screen ---- */
#loading {
  position: fixed;
  inset: 0;
  background: #080810;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #e8d8a0;
  z-index: 30;
  font-size: 18px;
}

#load-bar {
  width: 300px;
  height: 4px;
  background: #222;
  margin-top: 14px;
  border-radius: 2px;
}

#load-fill {
  height: 100%;
  width: 0%;
  background: #e8d8a0;
  border-radius: 2px;
  transition: width 0.2s;
}

/* ---- Menu / blocker overlay ---- */
#blocker {
  position: fixed;
  inset: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-left: 5vw;
  z-index: 20;
}

#blocker[data-mode="game"] {
  cursor: pointer;
  justify-content: center;
  padding-left: 0;
}

#menu-panel {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 18px;
  padding: 44px 48px 36px;
  background: rgba(8, 8, 16, 0.65);
  border: 1px solid rgba(232, 216, 160, 0.08);
  border-radius: 8px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: transform 0.12s ease-out;
}

#menu-title {
  display: flex;
  flex-direction: column;
  font-size: 48px;
  font-weight: bold;
  color: #e8d8a0;
  letter-spacing: 10px;
  line-height: 1.05;
  text-shadow:
    0 0 60px rgba(232, 216, 160, 0.25),
    0 0 20px rgba(232, 216, 160, 0.12),
    0 2px 4px rgba(0, 0, 0, 0.9);
  margin: 0;
}

#menu-subtitle {
  font-size: 12px;
  color: #887755;
  letter-spacing: 6px;
  text-transform: uppercase;
  margin-top: -10px;
}

/* ---- Key hints (right side) ---- */
#menu-keys {
  position: fixed;
  right: 5vw;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 24px 28px;
  background: rgba(8, 8, 16, 0.45);
  border: 1px solid rgba(232, 216, 160, 0.06);
  border-radius: 6px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.control-item {
  color: rgba(200, 200, 200, 0.5);
  font-size: 11px;
  white-space: nowrap;
}

.control-item .key {
  display: inline-block;
  color: rgba(232, 216, 160, 0.7);
  background: rgba(232, 216, 160, 0.06);
  border: 1px solid rgba(232, 216, 160, 0.12);
  padding: 3px 8px;
  border-radius: 3px;
  margin-right: 4px;
  font-size: 10px;
  font-family: 'Courier New', monospace;
}

#daynight-toggle,
#snow-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: rgba(200, 200, 200, 0.45);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

#daynight-toggle input[type="checkbox"],
#snow-toggle input[type="checkbox"] {
  width: 13px;
  height: 13px;
  cursor: pointer;
  accent-color: #e8d8a0;
}

#gfx-toggles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 18px;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid rgba(232, 216, 160, 0.12);
}

.gfx-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: rgba(200, 200, 200, 0.45);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.gfx-toggle input[type="checkbox"] {
  width: 13px;
  height: 13px;
  cursor: pointer;
  accent-color: #e8d8a0;
}

#menu-play {
  margin-top: 8px;
  padding: 10px 40px;
  background: rgba(232, 216, 160, 0.1);
  border: 1px solid rgba(232, 216, 160, 0.25);
  border-radius: 4px;
  color: #e8d8a0;
  font-size: 14px;
  font-family: 'Courier New', monospace;
  letter-spacing: 4px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s ease;
}

#menu-play:hover {
  background: rgba(232, 216, 160, 0.18);
  border-color: rgba(232, 216, 160, 0.45);
  text-shadow: 0 0 12px rgba(232, 216, 160, 0.3);
}

#menu-play:active {
  background: rgba(232, 216, 160, 0.25);
  transform: scale(0.97);
}

/* ---- Menu loading bar (full-width overlay) ---- */
#menu-loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #080810;
  z-index: 100;
  pointer-events: auto;
  transition: opacity 0.8s ease;
}

#menu-load-text {
  color: #e8d8a0;
  font-size: 16px;
  letter-spacing: 5px;
  text-transform: uppercase;
  margin-bottom: 24px;
  text-shadow: 0 2px 10px rgba(232, 216, 160, 0.2);
  font-weight: bold;
}

#menu-load-bar {
  width: 400px;
  height: 6px;
  background: rgba(232, 216, 160, 0.05);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid rgba(232, 216, 160, 0.1);
}

#menu-load-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #c0a878, #e8d8a0);
  transform: scaleX(0);
  transform-origin: left;
  will-change: transform;
  transition: transform 0.4s ease-out;
  box-shadow: 0 0 15px rgba(232, 216, 160, 0.4);
}

/* ---- Pause overlay ---- */
#menu-pause {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.6);
  padding: 30px 50px;
  border-radius: 8px;
  backdrop-filter: blur(4px);
}

#pause-text {
  color: #e8d8a0;
  font-size: 18px;
  letter-spacing: 4px;
  text-transform: uppercase;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

#pause-hint {
  color: rgba(200, 200, 200, 0.5);
  font-size: 11px;
  letter-spacing: 2px;
}

/* ---- HUD ---- */
#crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255, 255, 255, 0.6);
  font-size: 20px;
  pointer-events: none;
  z-index: 5;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
  display: none;
}

#hud-top-left {
  position: fixed;
  top: 12px;
  left: 12px;
  color: #ddd;
  font-size: 13px;
  z-index: 5;
  pointer-events: none;
  display: none;
  line-height: 1.6;
}

#interact-hint {
  position: fixed;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  color: #e8d8a0;
  font-size: 42px;
  font-weight: bold;
  z-index: 5;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.55);
  padding: 8px 20px;
  border-radius: 4px;
  white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

#npc-speech {
  position: fixed;
  left: 0;
  top: 0;
  transform: translate(-50%, -120%);
  color: #fff;
  font-size: 16px;
  z-index: 6;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.7);
  padding: 8px 16px;
  border-radius: 8px;
  max-width: 300px;
  text-align: center;
  word-wrap: break-word;
}

#underwater-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 40, 120, 0.35);
  pointer-events: none;
  z-index: 1;
  display: none;
}

#sleep-ui {
  position: fixed;
  inset: 0;
  background: rgba(4, 4, 12, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 55;
  display: flex;
  align-items: center;
  justify-content: center;
}

#sleep-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  background: rgba(12, 12, 24, 0.75);
  border: 1px solid rgba(232, 216, 160, 0.2);
  border-radius: 12px;
  padding: 40px 50px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
}

#sleep-panel h3 {
  font-size: 24px;
  color: #e8d8a0;
  letter-spacing: 6px;
  text-transform: uppercase;
  margin: 0;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
}

#sleep-amount-lbl {
  font-size: 16px;
  color: rgba(232, 216, 160, 0.7);
  letter-spacing: 2px;
}

#sleep-slider {
  width: 250px;
  cursor: pointer;
  accent-color: #e8d8a0;
}

#sleep-buttons {
  display: flex;
  gap: 16px;
  width: 100%;
}

#sleep-buttons button {
  flex: 1;
  padding: 12px 0;
  background: rgba(232, 216, 160, 0.1);
  border: 1px solid rgba(232, 216, 160, 0.25);
  border-radius: 6px;
  color: #e8d8a0;
  font-size: 14px;
  font-family: 'Courier New', monospace;
  letter-spacing: 3px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s ease;
}

#sleep-buttons button:hover {
  background: rgba(232, 216, 160, 0.2);
  border-color: rgba(232, 216, 160, 0.5);
}

#sleep-btn-confirm {
  background: rgba(232, 216, 160, 0.2) !important;
  border-color: rgba(232, 216, 160, 0.5) !important;
  font-weight: bold;
}

#sleep-btn-confirm:hover {
  background: rgba(232, 216, 160, 0.3) !important;
  border-color: rgba(232, 216, 160, 0.8) !important;
  text-shadow: 0 0 10px rgba(232, 216, 160, 0.5);
}

#hud-bottom {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.5);
  font-size: 11px;
  z-index: 5;
  pointer-events: none;
  display: none;
}

/* ---- Hotbar ---- */
#hotbar {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  flex-direction: row;
  gap: 4px;
  z-index: 5;
  pointer-events: none;
}

.hotbar-slot {
  width: 52px;
  height: 52px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.4);
  border-radius: 4px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hotbar-slot .slot-icon {
  font-size: 24px;
  line-height: 1;
  font-family: 'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', sans-serif;
  color: #c0a878;
}

.hotbar-slot .slot-icon-svg {
  display: block;
}

.hotbar-slot.selected {
  border-color: rgba(232, 216, 160, 0.7);
  background: rgba(232, 216, 160, 0.15);
  box-shadow: 0 0 8px rgba(232, 216, 160, 0.3);
}

.hotbar-slot.dragging {
  opacity: 0.5;
  border-color: rgba(232, 216, 160, 0.9);
}

#hotbar.alt-active .hotbar-slot {
  border-color: rgba(232, 216, 160, 0.6);
  animation: hotbar-pulse 1.2s ease-in-out infinite;
}

@keyframes hotbar-pulse {

  0%,
  100% {
    box-shadow: 0 0 6px rgba(232, 216, 160, 0.3);
  }

  50% {
    box-shadow: 0 0 16px rgba(232, 216, 160, 0.7);
  }
}

.hotbar-slot.drag-target {
  border-color: rgba(100, 200, 255, 0.8);
  background: rgba(100, 200, 255, 0.2);
  box-shadow: 0 0 10px rgba(100, 200, 255, 0.4);
}

#alt-cursor {
  position: fixed;
  width: 20px;
  height: 20px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 99;
  display: none;
  border: 2px solid rgba(232, 216, 160, 0.9);
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(232, 216, 160, 0.4);
}

/* Simulated cursor for pause screen (same style as ALT cursor) */
#sim-cursor {
  position: fixed;
  width: 20px;
  height: 20px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 1000;
  display: none;
  border: 2px solid rgba(232, 216, 160, 0.9);
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(232, 216, 160, 0.4);
}

#drag-placeholder {
  position: fixed;
  transform: translate(-50%, -50%);
  font-size: 32px;
  font-family: 'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', sans-serif;
  opacity: 0.7;
  pointer-events: none;
  z-index: 100;
  filter: drop-shadow(0 0 6px rgba(232, 216, 160, 0.5));
  display: none;
}

.hotbar-slot .slot-label {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 9px;
  color: rgba(255, 255, 255, 0.3);
  font-family: 'Courier New', monospace;
}

.hotbar-slot .slot-count {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 11px;
  color: #e8d8a0;
  font-family: 'Courier New', monospace;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* ---- Minimap ---- */
#minimap-wrap {
  position: fixed;
  top: 12px;
  right: 12px;
  display: none;
  z-index: 5;
  pointer-events: none;
}

#minimap {
  width: 160px;
  height: 160px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.4);
}

/* ---- Help overlay ---- */
#help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 4, 12, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  animation: helpFadeIn 0.25s ease-out;
}

@keyframes helpFadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

#help-panel {
  width: min(900px, 88vw);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: rgba(12, 12, 24, 0.7);
  border: 1px solid rgba(232, 216, 160, 0.12);
  border-radius: 10px;
  overflow: hidden;
}

#help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px 16px;
  border-bottom: 1px solid rgba(232, 216, 160, 0.08);
}

#help-title {
  font-size: 22px;
  font-weight: bold;
  color: #e8d8a0;
  letter-spacing: 8px;
  margin: 0;
  text-shadow:
    0 0 40px rgba(232, 216, 160, 0.2),
    0 1px 3px rgba(0, 0, 0, 0.9);
}

#help-close,
#help-close-mobile {
  font-size: 10px;
  color: rgba(200, 200, 200, 0.35);
  letter-spacing: 2px;
  text-transform: uppercase;
  background: rgba(232, 216, 160, 0.05);
  border: 1px solid rgba(232, 216, 160, 0.1);
  padding: 4px 12px;
  border-radius: 3px;
}

/* Desktop/mobile help toggle */
.help-mobile {
  display: none;
}

.help-desktop {
  display: block;
}

/* Help tabs */
#help-tabs {
  display: flex;
  gap: 4px;
}

.help-tab {
  background: rgba(232, 216, 160, 0.05);
  border: 1px solid rgba(232, 216, 160, 0.1);
  color: rgba(200, 200, 200, 0.4);
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 5px 14px;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.help-tab:hover {
  background: rgba(232, 216, 160, 0.1);
  color: rgba(200, 200, 200, 0.6);
}

.help-tab.active {
  background: rgba(232, 216, 160, 0.12);
  border-color: rgba(232, 216, 160, 0.25);
  color: #e8d8a0;
}

.help-tab-content {
  padding: 20px 28px 24px;
  overflow-y: auto;
  display: none;
  flex-direction: column;
  gap: 24px;
}

.help-tab-content.active {
  display: flex;
}

.help-tab-content::-webkit-scrollbar {
  width: 6px;
}

.help-tab-content::-webkit-scrollbar-track {
  background: transparent;
}

.help-tab-content::-webkit-scrollbar-thumb {
  background: rgba(232, 216, 160, 0.15);
  border-radius: 3px;
}

.help-section-title {
  font-size: 12px;
  color: #e8d8a0;
  letter-spacing: 5px;
  text-transform: uppercase;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.help-icon {
  font-size: 16px;
  filter: grayscale(0.3);
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.help-card {
  background: rgba(232, 216, 160, 0.03);
  border: 1px solid rgba(232, 216, 160, 0.07);
  border-radius: 6px;
  padding: 14px 16px 12px;
  transition: border-color 0.2s, background 0.2s;
}

.help-card:hover {
  background: rgba(232, 216, 160, 0.06);
  border-color: rgba(232, 216, 160, 0.18);
}

.help-card-head {
  font-size: 13px;
  color: #e8d8a0;
  font-weight: bold;
  margin-bottom: 6px;
  letter-spacing: 1px;
}

.help-card-body {
  font-size: 11px;
  color: rgba(200, 200, 200, 0.55);
  line-height: 1.55;
}

.help-card-body b {
  color: rgba(232, 216, 160, 0.75);
  font-weight: normal;
  background: rgba(232, 216, 160, 0.06);
  border: 1px solid rgba(232, 216, 160, 0.1);
  padding: 1px 5px;
  border-radius: 2px;
  font-size: 10px;
  font-family: 'Courier New', monospace;
}

/* ---- Touch controls (mobile) ---- */
#touch-controls {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

#touch-joystick {
  position: fixed;
  width: 120px;
  height: 120px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.2);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#joystick-knob {
  position: absolute;
  width: 50px;
  height: 50px;
  background: rgba(255, 255, 255, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#touch-top-buttons {
  position: fixed;
  top: 12px;
  left: 12px;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

#touch-top-buttons button {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.7);
  font-family: 'Courier New', monospace;
  font-size: 14px;
  font-weight: bold;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

#touch-top-buttons button:active {
  background: rgba(232, 216, 160, 0.25);
  border-color: rgba(232, 216, 160, 0.5);
}

#touch-buttons {
  position: fixed;
  bottom: 110px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}

#touch-buttons button {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.25);
  color: rgba(255, 255, 255, 0.8);
  font-family: 'Courier New', monospace;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 1px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

#touch-buttons button:active {
  background: rgba(232, 216, 160, 0.3);
  border-color: rgba(232, 216, 160, 0.6);
}

/* ---- Touch long-press progress ---- */
#touch-progress {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80px;
  height: 80px;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 15;
  pointer-events: none;
}

#touch-progress svg {
  position: absolute;
  inset: 0;
}

#progress-arc {
  transition: stroke-dashoffset 0.05s linear;
}

#progress-label {
  position: relative;
  z-index: 1;
  color: #e8d8a0;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 1px;
  text-transform: uppercase;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

/* ---- Mobile-specific overrides ---- */
@media (hover: none) and (pointer: coarse) {
  body {
    touch-action: none;
  }

  /* The guide's scroller can never beat an ancestor `none`: WebKit intersects
     touch-action across the WHOLE ancestor chain (none ∩ pan-y = none), which
     is why setting pan-y on .help-tab-content alone did nothing on iOS. So
     relax body, but ONLY while the guide is open — index.html's viewport meta
     has no user-scalable=no, making this rule the sole pinch-zoom and
     double-tap-zoom guard during play. pan-y (not auto) keeps zoom dead even
     while the guide is up. Do NOT try `body > *:not(#help-overlay)`: a
     multi-touch gesture resolves touch-action at the lowest common ancestor of
     its touch points, which for two thumbs on different children is body —
     that variant silently re-enables pinch-zoom mid-game. */
  body.help-open {
    touch-action: pan-y;
  }

  /* Hide desktop-only UI */
  #menu-keys {
    display: none !important;
  }

  #hud-bottom {
    display: none !important;
  }

  #crosshair {
    display: none !important;
  }

  /* Center menu panel on mobile */
  #blocker {
    padding-left: 0;
    justify-content: center;
    align-items: center;
    padding: 16px;
  }

  /* Menu panel — tighter on mobile */
  #menu-panel {
    padding: 24px 28px 20px;
    gap: 14px;
    align-items: stretch;
    max-width: 340px;
    width: 100%;
  }

  #menu-title {
    font-size: 32px;
    letter-spacing: 6px;
    align-self: flex-start;
  }

  #menu-subtitle {
    font-size: 10px;
    letter-spacing: 4px;
  }

  /* Bigger tap targets */
  #menu-play {
    padding: 14px 24px;
    font-size: 14px;
    min-height: 48px;
    width: 100%;
    text-align: center;
    margin-top: 4px;
  }

  #daynight-toggle,
  #snow-toggle {
    font-size: 14px;
    gap: 10px;
    padding: 6px 0;
  }

  #daynight-toggle input[type="checkbox"],
  #snow-toggle input[type="checkbox"] {
    width: 20px;
    height: 20px;
    min-width: 20px;
  }

  /* Pause screen — mobile text */
  #menu-pause {
    padding: 24px 28px;
    max-width: 300px;
    width: 90vw;
  }

  #pause-text {
    font-size: 16px;
    letter-spacing: 3px;
  }

  #pause-hint {
    font-size: 11px;
  }

  /* Interact hint — smaller on mobile */
  #interact-hint {
    font-size: 24px;
    padding: 6px 14px;
  }

  /* Minimap — shrink on mobile */
  #minimap-wrap {
    top: 8px;
    right: 8px;
  }

  #minimap {
    width: 100px;
    height: 100px;
    border-width: 1px;
  }

  /* Hotbar — enable touch, position above touch buttons */
  #hotbar {
    pointer-events: auto;
    bottom: 16px;
    gap: 3px;
  }

  .hotbar-slot {
    width: 46px;
    height: 46px;
  }

  .hotbar-slot .slot-icon {
    font-size: 20px;
  }

  .hotbar-slot .slot-label {
    font-size: 8px;
  }

  .hotbar-slot .slot-count {
    font-size: 10px;
  }

  /* HUD top-left — smaller */
  #hud-top-left {
    font-size: 11px;
    top: 58px;
    left: 8px;
  }

  /* Swap desktop/mobile help content */
  .help-desktop {
    display: none !important;
  }

  .help-mobile {
    display: inline-flex !important;
  }

  /* On mobile, default to Touch tab instead of Controls */
  .help-tab-content[data-tab="controls"] {
    display: none;
  }

  .help-tab[data-tab="controls"] {
    display: none !important;
  }

  /* Help overlay — full screen on mobile */
  #help-overlay {
    padding: 0;
  }

  #help-panel {
    width: 100%;
    max-height: 100vh;
    height: 100%;
    border-radius: 0;
    border: none;
  }

  #help-header {
    padding: 14px 16px 12px;
    /* Push the tabs and the close button into one right-hand cluster (the
       margin-left:auto below eats the free space, so space-between has none
       left to spread), leaving this gap between the tab group and the X. */
    gap: 12px;
  }

  #help-tabs {
    margin-left: auto;
    flex: 0 0 auto;
  }

  #help-title {
    font-size: 16px;
    letter-spacing: 4px;
  }

  #help-close {
    font-size: 9px;
    padding: 4px 10px;
  }

  /* Generous square tap target. flex-shrink:0 is load-bearing: the header is a
     flex row and on a ~360-390px viewport the title + tabs + X overflow it, so
     a shrinkable item gets compressed horizontally and the "square" renders as
     a narrow rectangle. An explicit width does NOT prevent that — only
     flex-shrink:0 does. The title absorbs the shortfall instead (it wraps). */
  #help-close-mobile {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    padding: 0;
    font-family: inherit;
    font-size: 17px;
    line-height: 1;
    letter-spacing: 0;
    border-color: rgba(232, 216, 160, 0.25);
    color: rgba(232, 216, 160, 0.7);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  /* Let the title give up the space instead */
  #help-title {
    min-width: 0;
  }

  /* Match the tabs' height exactly so the cluster lines up. inline-flex rather
     than the button default so the label stays centred at a fixed height. */
  .help-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    padding: 0 14px;
  }

  /* The scrollable body of each tab. Was targeting #help-content /
     #help-content-mobile — neither ID has ever existed in index.html, so this
     block was dead and mobile padding/scroll never applied. */
  .help-tab-content {
    padding: 12px 16px 20px;
    gap: 16px;
    touch-action: pan-y;
    overscroll-behavior: contain;
  }

  .help-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .help-section-title {
    font-size: 11px;
    letter-spacing: 3px;
  }

  .help-card {
    padding: 10px 12px;
  }

  .help-card-head {
    font-size: 12px;
  }

  .help-card-body {
    font-size: 11px;
    line-height: 1.45;
  }

  /* NPC speech — constrain */
  #npc-speech {
    max-width: 240px;
    font-size: 14px;
  }

  /* Loading screen */
  #loading {
    font-size: 14px;
  }

  #load-bar {
    width: 260px;
  }

  #menu-load-text {
    font-size: 10px;
  }
}

/* Extra-small screens (phones in portrait) */
@media (max-width: 400px) {
  #menu-panel {
    padding: 18px 20px 16px;
    max-width: 100%;
  }

  #menu-title {
    font-size: 26px;
    letter-spacing: 4px;
  }

  .hotbar-slot {
    width: 42px;
    height: 42px;
  }
}