/* The hidden attribute must always win. Without this, any class that sets
   display (e.g. .backup-prompt-buttons' flex) silently overrides it — which
   showed the replay's "Return to your journey" button on normal loops. */
[hidden] { display: none !important; }

:root {
  --hud-h: 70px; /* #bottom-bar height; resize() in game.js switches it to 40px on short screens */
}

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

body {
  font-family: 'VT323', monospace;
  background: #0a0a12;
  color: #eee;
  height: 100vh;
  /* --app-h is the measured visible height (window.innerHeight), set by
     resize() in game.js. CSS viewport units — even 100dvh — can report more
     than is actually visible on iPhones (Safari landscape, home-screen mode). */
  height: var(--app-h, 100dvh);
  width: 100vw;
  display: flex;
  justify-content: center;
  /* Top, not center: the canvas is shorter than the page by the HUD bar
     below it, so centring put a gap above it and hid its bottom behind the
     bar. */
  align-items: flex-start;
  overflow: hidden;
  margin: 0;
  /* Anchor every absolutely-positioned overlay (#bottom-bar, the touch
     buttons, modals) to the body, which is sized to the *visible* area
     (--app-h). Without this they anchor to the initial containing block,
     which on iPhone Safari is the full screen height — so with the address
     bar showing (it never hides here, since the page doesn't scroll) the
     bottom bar sat partly behind Safari's toolbar in landscape. */
  position: relative;
}

#game-canvas {
  image-rendering: pixelated;
  width: 100vw;
  height: calc(100vh - 70px);
  height: calc(var(--app-h, 100dvh) - var(--hud-h));
  display: block;
  touch-action: none;
}

#modal {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: var(--hud-h);
  background: rgba(0, 0, 0, 0.80);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  pointer-events: auto;
}

#modal.show {
  display: flex;
}

.modal-box {
  position: relative;
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 27px,
      rgba(120, 80, 10, 0.07) 27px,
      rgba(120, 80, 10, 0.07) 28px
    ),
    radial-gradient(ellipse at 30% 20%, rgba(255,255,240,0.25) 0%, transparent 60%),
    linear-gradient(160deg, #f5e9cc 0%, #eedcaa 45%, #f0e2b8 70%, #e6d098 100%);
  border: 2px solid #8b6420;
  border-radius: 2px;
  padding: 1.1rem 1.25rem 1.5rem;
  max-width: 500px;
  width: 90%;
  /* Never taller than the space above the HUD bar: an unusually long
     question scrolls inside the box rather than running off-screen. */
  max-height: calc(100% - 12px);
  overflow-y: auto;
  box-shadow:
    0 0 0 1px #c49a38,
    0 0 0 5px #6b4810,
    0 0 0 6px #c49a38,
    0 16px 60px rgba(0, 0, 0, 0.8),
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    inset 0 0 80px rgba(120, 80, 10, 0.1);
  pointer-events: auto;
}

/* Inner ruled border */
.modal-box::before {
  content: '';
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(139, 100, 20, 0.30);
  pointer-events: none;
}

/* Bottom decorative divider */
.modal-box::after {
  content: '— ✦ —';
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(139, 100, 20, 0.55);
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  pointer-events: none;
  font-family: serif;
}

.modal-title {
  font-family: 'Silkscreen', cursive;
  font-size: 0.95rem;
  color: #3a1a05;
  margin-bottom: 0.6rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid rgba(139, 100, 20, 0.35);
  letter-spacing: 0.04em;
}

.modal-code {
  background: rgba(100, 60, 10, 0.10);
  padding: 0.6rem 0.8rem;
  border-radius: 1px;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  color: #1a0a00;
  margin-bottom: 0.75rem;
  border-left: 3px solid #8b6420;
  white-space: pre-wrap;
  line-height: 1.45;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.08);
}

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  pointer-events: auto;
  position: relative;
  z-index: 2000;
}

.choice-btn {
  background: linear-gradient(180deg, #f8f1dd 0%, #eddebb 100%);
  border: 1.5px solid #9a7428;
  padding: 0.45rem 0.6rem;
  border-radius: 2px;
  font-family: 'VT323', monospace;
  font-size: 1.05rem;
  color: #2a1205;
  cursor: pointer;
  transition: all 0.12s;
  pointer-events: auto;
  z-index: 2000;
  position: relative;
  box-shadow: 0 1px 3px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.55);
  text-align: left;
}

.choice-btn:hover:not(:disabled) {
  background: linear-gradient(180deg, #ffe9a8 0%, #f0d268 100%);
  border-color: #6a4800;
  box-shadow: 0 2px 6px rgba(0,0,0,0.22), inset 0 1px 0 rgba(255,255,255,0.6);
}

.choice-btn:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.choice-btn.correct {
  background: linear-gradient(180deg, #d4f0c4 0%, #a8d888 100%);
  border-color: #2a7a20;
  color: #0a3005;
  box-shadow: 0 1px 4px rgba(40,120,20,0.25);
}

.choice-btn.wrong {
  background: linear-gradient(180deg, #f0c4b4 0%, #d89070 100%);
  border-color: #8a2010;
  color: #3a0808;
  box-shadow: 0 1px 4px rgba(150,30,10,0.25);
}

.feedback {
  text-align: center;
  margin-top: 0.5rem;
  font-size: 1rem;
  min-height: 1.4rem;
  color: #2a1205;
  font-family: 'VT323', monospace;
  font-size: 1.1rem;
}

.feedback.correct {
  color: #1a5a10;
}

.feedback.wrong {
  color: #7a1a05;
}

/* Phones on their side (body.short-landscape, set in resize()): code on the
   left, answers stacked on the right, so the box grows sideways instead of
   running off the bottom of a short screen. */
body.short-landscape .modal-box {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  grid-template-areas:
    "title    title"
    "code     choices"
    "feedback feedback";
  column-gap: 0.9rem;
  align-items: start;
  max-width: 820px;
  width: 94%;
  padding: 0.8rem 1rem 1.3rem;
}
body.short-landscape .modal-title    { grid-area: title; font-size: 0.85rem; margin-bottom: 0.5rem; }
body.short-landscape .modal-code     { grid-area: code; margin-bottom: 0; font-size: 0.8rem; line-height: 1.35; padding: 0.5rem 0.7rem; }
body.short-landscape .choices        { grid-area: choices; grid-template-columns: 1fr; gap: 0.35rem; }
body.short-landscape .choice-btn     { padding: 0.3rem 0.55rem; font-size: 1rem; }
body.short-landscape .feedback       { grid-area: feedback; margin-top: 0.35rem; min-height: 1.2rem; }
/* The decorative "— ✦ —" is pinned to the box's bottom edge, which drifts
   over the code once a long question makes the box scroll. */
body.short-landscape .modal-box::after { display: none; }

#clue-box {
  position: absolute;
  bottom: 150px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  border: 2px solid #ffd700;
  border-radius: 8px;
  padding: 0.8rem 1.2rem;
  display: none;
  text-align: center;
  z-index: 1000;
}

#search-box {
  position: absolute;
  bottom: 150px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  border: 2px solid #00ced1;
  border-radius: 8px;
  padding: 0.8rem;
  display: none;
  text-align: center;
  z-index: 1000;
}

#clue-box.show {
  display: block;
}

#clue-box h3 {
  font-family: 'Silkscreen', cursive;
  color: #ffd700;
  margin-bottom: 0.3rem;
}

#search-box.show {
  display: block;
}

#search-result {
  font-size: 1.4rem;
  margin: 0.5rem 0;
}

/* Same look as #message-box, with a column of choices instead of Continue */
#choice-box {
  position: absolute;
  top: calc((100% - var(--hud-h)) / 2);
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(400px, 92%);
  max-height: calc(100% - var(--hud-h) - 16px);
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.95);
  border: 3px solid #ffd700;
  border-radius: 10px;
  padding: 1.2rem 1.4rem;
  text-align: center;
  display: none;
  z-index: 160;
}
#choice-box.show { display: block; }
#choice-box h2 {
  font-family: 'Silkscreen', cursive;
  color: #ffd700;
  font-size: 1.2rem;
  margin-bottom: 0.6rem;
}
#choice-box p {
  font-size: 1.1rem;
  line-height: 1.3;
  margin-bottom: 0.9rem;
  white-space: pre-line;
}
.choice-box-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.choice-box-buttons .choice-btn { text-align: center; font-size: 1.15rem; }
.choice-box-buttons .choice-btn.secondary { background: #4a4a6a; color: #eee; }
body.short-landscape #choice-box { width: min(560px, 94%); padding: 0.8rem 1.2rem; }
body.short-landscape #choice-box p { font-size: 1rem; margin-bottom: 0.5rem; }
body.short-landscape .choice-box-buttons { gap: 0.3rem; }

/* Shown only during a Reliquary replay, beside the help button */
#replay-end-btn {
  position: absolute;
  top: 13px;
  left: 54px;
  z-index: 100;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  background: rgba(20, 14, 32, 0.9);
  border: 1.5px solid #a67ce0;
  color: #e0c8ff;
  font-family: 'VT323', monospace;
  font-size: 1.05rem;
  cursor: pointer;
}
#replay-end-btn[hidden] { display: none; }

#message-box {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.95);
  border: 3px solid #ffd700;
  border-radius: 10px;
  padding: 1.5rem;
  text-align: center;
  display: none;
  z-index: 150;
}

#message-box.show {
  display: block;
}

#message-box h2 {
  font-family: 'Silkscreen', cursive;
  color: #ffd700;
  font-size: 1.4rem;
  margin-bottom: 0.8rem;
}

#message-box p {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  white-space: pre-line; /* keep the line breaks in multi-line messages (e.g. the end-of-game summary) */
}

#backup-prompt {
  position: absolute;
  top: calc((100% - var(--hud-h)) / 2); /* centred in the space above the HUD bar */
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(380px, 92%);
  max-height: calc(100% - var(--hud-h) - 16px);
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.95);
  border: 3px solid #ffd700;
  border-radius: 10px;
  padding: 1.5rem;
  text-align: center;
  display: none;
  z-index: 150;
}

#backup-prompt.show {
  display: block;
}

#backup-prompt h2 {
  font-family: 'Silkscreen', cursive;
  color: #ffd700;
  font-size: 1.3rem;
  margin-bottom: 0.8rem;
}

#backup-prompt p {
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

/* This loop's stars, and what earned them / what the missing ones need */
.loop-stars {
  font-size: 2.4rem;
  line-height: 1;
  color: #ffd700;
  letter-spacing: 0.15em;
  text-shadow: 0 0 12px rgba(255, 215, 0, 0.55);
  margin-bottom: 0.6rem;
}

.loop-checklist {
  list-style: none;
  text-align: left;
  font-size: 1.05rem;
  line-height: 1.3;
  margin: 0 0 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.loop-checklist .earned { color: #f0d890; }
.loop-checklist .missed { color: #9a9ab0; }
.loop-checklist .new-best { color: #ffd700; text-align: center; margin-top: 0.2rem; }
.loop-checklist .hint { color: #c8a8f0; font-size: 0.95em; margin-top: 0.3rem; }

/* Keep the buttons reachable even if the box has to scroll on a tiny screen */
.backup-prompt-buttons {
  position: sticky;
  bottom: -1.5rem; /* sits flush with the box's bottom padding */
  padding: 0.5rem 0;
  background: rgba(0, 0, 0, 0.95);
}

/* Landscape phones: wider and tighter, so the checklist lines don't wrap
   and the buttons fit without scrolling. */
body.short-landscape #backup-prompt { width: min(620px, 94%); padding: 0.8rem 1.2rem; }
body.short-landscape #backup-prompt h2 { font-size: 1rem; margin-bottom: 0.3rem; }
body.short-landscape .loop-stars { font-size: 1.7rem; margin-bottom: 0.3rem; }
body.short-landscape .loop-checklist { font-size: 0.95rem; gap: 0.1rem; margin-bottom: 0.4rem; }
body.short-landscape #backup-prompt p { font-size: 0.95rem; margin-bottom: 0.4rem; }
body.short-landscape .backup-prompt-buttons { bottom: -0.8rem; padding: 0.3rem 0; }
/* No room for the backup explainer here; "Download Backup" speaks for itself */
body.short-landscape #backup-text { display: none; }

.help-star { color: #c89a10; }

.backup-prompt-buttons {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
}

.backup-prompt-buttons .choice-btn {
  width: auto;
  padding: 0.5rem 1rem;
}

#controls {
  position: absolute;
  bottom: calc(var(--hud-h) + 8px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.15rem;
  color: #e0c060;
  background: rgba(0, 0, 0, 0.55);
  padding: 0.28rem 0.8rem;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
}

@media (max-width: 540px) {
  #controls { display: none; }
}

/* ── Touch controls ─────────────────────────────────────────────────────
   Movement is a floating pad (see initTouchControls() in game.js): drag
   anywhere on the canvas. The two action buttons float bottom-right, over
   the floor tiles just above #bottom-bar, and glow (.ready) when they would
   do something. */

#touch-pad,
#touch-actions {
  display: none;
}

#touch-pad {
  position: absolute;       /* relative to body, like everything else — see body */
  left: 56px;               /* resting spot: bottom-left, over the floor */
  top: calc(100% - var(--hud-h) - 48px); /* 100% = body = visible height (--app-h) */
  width: 64px;              /* 2 × PAD_RADIUS */
  height: 64px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid rgba(230, 208, 152, 0.55);
  background: radial-gradient(circle, rgba(245, 233, 204, 0.10) 0%, rgba(245, 233, 204, 0.04) 70%);
  opacity: 0.45;
  pointer-events: none;
  z-index: 115;
  transition: opacity 0.12s;
}

#touch-pad.active {
  opacity: 1;
  transition: none;
}

.touch-pad-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.65rem;
  color: rgba(245, 233, 204, 0.8);
}
.touch-pad-arrow.left  { left: 4px; }
.touch-pad-arrow.right { right: 4px; }

.touch-pad-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 32px;
  height: 32px;
  margin: -16px 0 0 -16px; /* centred via margins so JS can set a plain translateX */
  border-radius: 50%;
  background: linear-gradient(160deg, #f5e9cc 0%, #e6d098 100%);
  border: 1.5px solid #8b6420;
  box-shadow: 0 0 0 1px #c49a38, 0 2px 8px rgba(0, 0, 0, 0.5);
}

#touch-actions {
  position: absolute;
  right: 12px;
  bottom: calc(var(--hud-h) + 12px); /* just above #bottom-bar */
  gap: 12px;
  align-items: flex-end;
  flex-direction: row-reverse;
  z-index: 120;
}

.touch-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(160deg, #f5e9cc 0%, #e6d098 100%);
  border: 1.5px solid #8b6420;
  color: #3a1a05;
  font-size: 1.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 0 0 1px #c49a38,
    0 2px 8px rgba(0, 0, 0, 0.5);
  opacity: 0.6;
  transition: opacity 0.15s, transform 0.1s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

/* Lit up when pressing it would do something (near a wizard, the dragon,
   an unlocked gate, or a Reliquary door). */
.touch-btn.ready {
  opacity: 1;
  box-shadow:
    0 0 0 1px #c49a38,
    0 0 14px 3px rgba(255, 215, 0, 0.65),
    0 2px 8px rgba(0, 0, 0, 0.5);
  animation: touch-ready-pulse 1.4s ease-in-out infinite;
}

@keyframes touch-ready-pulse {
  50% { box-shadow: 0 0 0 1px #c49a38, 0 0 22px 6px rgba(255, 215, 0, 0.8), 0 2px 8px rgba(0, 0, 0, 0.5); }
}

@media (prefers-reduced-motion: reduce) {
  .touch-btn.ready { animation: none; }
}

.touch-btn.pressed {
  opacity: 1;
  transform: scale(0.92);
}

.touch-btn-talk {
  width: 62px;
  height: 62px;
  font-size: 1.6rem;
}

/* Narrow phones (~320-399px): slightly smaller, still ≥ 48px targets */
@media (hover: none) and (pointer: coarse) and (max-width: 399px) {
  #touch-actions { right: 8px; gap: 10px; }
  .touch-btn { width: 50px; height: 50px; font-size: 1.2rem; }
  .touch-btn-talk { width: 56px; height: 56px; font-size: 1.45rem; }
  #touch-pad { left: 50px; }
}

@media (hover: none) and (pointer: coarse) {
  #touch-pad, #touch-actions { display: flex; }
  #game-canvas { touch-action: none; }
  #controls { display: none; }
}

#bottom-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--hud-h);
  background: linear-gradient(180deg,
    rgba(18, 14, 32, 0.97) 0%,
    rgba(10, 8, 20, 0.99) 100%);
  border-top: 2px solid #6a4a00;
  border-top-color: transparent;
  background-clip: padding-box;
  box-shadow:
    0 -1px 0 rgba(200, 150, 30, 0.55),
    0 -3px 0 rgba(80, 50, 0, 0.8),
    0 -4px 0 rgba(200, 150, 30, 0.25),
    0 -8px 24px rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.2rem;
  padding: 0 1.5rem;
}

.bar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 60px;
}

.bar-section.floor-section {
  flex-direction: row;
  gap: 0.4rem;
  min-width: 0;
  flex-shrink: 1;
  overflow: hidden;
}

.floor-section .bar-value {
  max-width: none;
}

.floor-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1;
}

/* VT323, not Silkscreen: Silkscreen's "&" reads as "$". */
.floor-subject {
  font-family: 'VT323', monospace;
  font-size: 1.1rem;
  color: #c8a848;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-icon {
  width: 1.5rem;
  height: 1.5rem;
  display: inline-block;
}

.bar-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

.bar-label {
  font-family: 'Silkscreen', cursive;
  font-size: 0.65rem;
  color: #c8a848;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.bar-value {
  font-family: 'VT323', monospace;
  font-size: 1.6rem;
  color: #f0c040;
  text-shadow: 0 0 8px rgba(240, 180, 40, 0.4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.bar-divider {
  width: 1px;
  height: 36px;
  background: linear-gradient(180deg,
    transparent,
    rgba(160, 110, 20, 0.5) 30%,
    rgba(200, 150, 30, 0.6) 50%,
    rgba(160, 110, 20, 0.5) 70%,
    transparent);
  flex-shrink: 0;
}

@media (max-width: 600px) {
  .bar-divider { display: none; }
  #bottom-bar  { gap: 0.6rem; padding: 0 0.8rem; }
  .bar-section { min-width: 44px; }
  .bar-value   { font-size: 1.05rem; }
  #floor-num   { display: none; }
  .floor-section .bar-icon { display: none; }
  .floor-section .bar-value { font-size: 0.95rem; }
  /* The narrow bar can't fit a long subject on one line — let it wrap. */
  .floor-subject {
    font-size: 0.85rem;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
}

/* Compact HUD for short screens (see HUD_H_COMPACT in game.js): one row,
   each icon beside its value, labels dropped. */
body.hud-compact #bottom-bar { gap: 1rem; padding: 0 0.8rem; }
body.hud-compact .bar-section { flex-direction: row; gap: 0.3rem; min-width: 0; }
body.hud-compact .bar-label { display: none; }
body.hud-compact .bar-icon { width: 1.2rem; height: 1.2rem; }
body.hud-compact .bar-value { font-size: 1.3rem; }
body.hud-compact .bar-divider { height: 22px; }
body.hud-compact .floor-text { flex-direction: row; align-items: baseline; gap: 0.6rem; }
body.hud-compact .floor-subject { font-size: 1rem; display: block; white-space: nowrap; }

#clue-panel {
  position: absolute;
  top: 10px;
  right: 10px;
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 18px,
      rgba(120, 80, 10, 0.07) 18px,
      rgba(120, 80, 10, 0.07) 19px
    ),
    linear-gradient(160deg, #f5e9cc 0%, #eedcaa 50%, #e8d098 100%);
  border: 1.5px solid #8b6420;
  border-radius: 2px;
  padding: 0.5rem 0.7rem 0.65rem;
  min-width: 170px;
  max-width: 220px;
  z-index: 100;
  box-shadow:
    0 0 0 1px #c49a38,
    0 0 0 3px #6b4810,
    0 0 0 4px #c49a38,
    0 4px 18px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    inset 0 0 30px rgba(120, 80, 10, 0.08);
}

#clue-panel::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(139, 100, 20, 0.28);
  pointer-events: none;
}

.clue-panel-title {
  font-family: 'Silkscreen', cursive;
  font-size: 0.62rem;
  color: #3a1a05;
  text-transform: uppercase;
  margin-bottom: 0.3rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid rgba(139, 100, 20, 0.35);
  letter-spacing: 0.05em;
}

#start-screen {
  position: absolute;
  inset: 0;
  background: rgba(5, 3, 15, 0.93);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 3000;
}

#start-screen.hidden {
  display: none;
}

.start-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.start-tower {
  width: 3.5rem;
  height: 3.5rem;
  filter: drop-shadow(0 0 18px rgba(180, 140, 255, 0.55));
}

.start-tower svg {
  width: 100%;
  height: 100%;
  display: block;
}

.start-title {
  font-family: 'Silkscreen', cursive;
  font-size: 2.2rem;
  color: #ffd700;
  letter-spacing: 0.08em;
  text-shadow: 0 0 20px rgba(255, 215, 0, 0.45);
}

.start-subtitle {
  font-family: 'VT323', monospace;
  font-size: 1.3rem;
  color: #9a8ab0;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}

#start-save-info {
  font-family: 'VT323', monospace;
  font-size: 1.1rem;
  color: #c8b87a;
  background: rgba(255, 215, 0, 0.07);
  border: 1px solid rgba(255, 215, 0, 0.2);
  border-radius: 4px;
  padding: 0.4rem 1rem;
  text-align: center;
  min-height: 1.8rem;
}
/* No save yet (first visit): no box at all, rather than an empty one */
#start-save-info:empty {
  display: none;
}

.start-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 200px;
  margin-top: 0.5rem;
}

.start-btn {
  font-size: 1.1rem !important;
  text-align: center !important;
  padding: 0.6rem 1rem !important;
}

#clue-panel-lines {
  font-family: 'VT323', monospace;
  font-size: 1rem;
  color: #2a1205;
  line-height: 1.55;
}

#help-btn {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(160deg, #f5e9cc 0%, #e6d098 100%);
  border: 1.5px solid #8b6420;
  color: #3a1a05;
  font-family: 'Silkscreen', cursive;
  font-size: 1.05rem;
  cursor: pointer;
  z-index: 100;
  box-shadow:
    0 0 0 1px #c49a38,
    0 2px 8px rgba(0, 0, 0, 0.5);
  transition: transform 0.12s, box-shadow 0.12s;
}

#help-btn:hover {
  transform: scale(1.08);
  box-shadow:
    0 0 0 1px #c49a38,
    0 0 10px rgba(255, 215, 0, 0.5),
    0 2px 8px rgba(0, 0, 0, 0.5);
}

#help-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: var(--hud-h);
  background: rgba(0, 0, 0, 0.80);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 2500;
  pointer-events: auto;
}

#help-overlay.show {
  display: flex;
}

.help-box {
  position: relative;
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 27px,
      rgba(120, 80, 10, 0.07) 27px,
      rgba(120, 80, 10, 0.07) 28px
    ),
    radial-gradient(ellipse at 30% 20%, rgba(255,255,240,0.25) 0%, transparent 60%),
    linear-gradient(160deg, #f5e9cc 0%, #eedcaa 45%, #f0e2b8 70%, #e6d098 100%);
  border: 2px solid #8b6420;
  border-radius: 2px;
  padding: 1.6rem 1.8rem;
  max-width: 480px;
  width: 90%;
  max-height: 85%; /* relative to #help-overlay's own box, which is shorter than the full viewport (bottom: HUD bar reserved) — 85vh was measured against the wrong box and could overflow above y:0 on short/landscape screens */
  display: flex;
  flex-direction: column;
  box-shadow:
    0 0 0 1px #c49a38,
    0 0 0 5px #6b4810,
    0 0 0 6px #c49a38,
    0 16px 60px rgba(0, 0, 0, 0.8),
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    inset 0 0 80px rgba(120, 80, 10, 0.1);
}

.help-scroll {
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

#help-close {
  position: absolute;
  top: 0.7rem;
  right: 0.7rem;
  background: none;
  border: none;
  color: rgba(58, 26, 5, 0.55);
  font-family: 'VT323', monospace;
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem 0.4rem;
}

#help-close:hover {
  color: #3a1a05;
}

.help-title {
  font-family: 'Silkscreen', cursive;
  font-size: 1.1rem;
  color: #3a1a05;
  margin-bottom: 0.6rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(139, 100, 20, 0.35);
  letter-spacing: 0.04em;
}

.help-goal {
  font-family: 'VT323', monospace;
  font-size: 1.05rem;
  color: #2a1205;
  line-height: 1.5;
  margin-bottom: 1.1rem;
}

.help-items {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 1.3rem;
}

.help-item {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
}

.help-icon {
  display: inline-block;
  flex-shrink: 0;
  width: 1.8rem;
  height: 1.8rem;
}

.help-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

.icon-inline {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
}

.icon-inline svg {
  width: 100%;
  height: 100%;
  display: block;
}

.help-item strong {
  font-family: 'Silkscreen', cursive;
  font-size: 0.78rem;
  color: #6b4810;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.help-item p {
  font-family: 'VT323', monospace;
  font-size: 0.98rem;
  color: #2a1205;
  line-height: 1.42;
  margin-top: 0.15rem;
}

/* Controls: one list per input type — keys on desktop, touch on phones */
.help-controls {
  margin-bottom: 1.1rem;
  padding: 0.6rem 0.8rem;
  background: rgba(100, 60, 10, 0.08);
  border-left: 3px solid #8b6420;
}
.help-controls strong {
  display: block;
  font-family: 'Silkscreen', cursive;
  font-size: 0.78rem;
  color: #6b4810;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}
.help-controls ul {
  list-style: none;
  font-family: 'VT323', monospace;
  font-size: 1rem;
  color: #2a1205;
  line-height: 1.45;
}
.help-controls kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 0.3em;
  border: 1px solid #8b6420;
  border-radius: 3px;
  background: rgba(255, 250, 235, 0.7);
  font-family: 'VT323', monospace;
  text-align: center;
  line-height: 1.2;
}
.controls-touch { display: none; }
@media (hover: none) and (pointer: coarse) {
  .controls-keys  { display: none; }
  .controls-touch { display: block; }
}

.help-glyph {
  font-size: 1.45rem;
  line-height: 1.8rem;
  text-align: center;
}
.help-note-extra { margin-top: 0.5rem; }

/* Landscape phones: wider and tighter, so more of the primer shows at once */
body.short-landscape .help-box { max-width: min(760px, 94%); max-height: 94%; padding: 0.7rem 1.2rem 0.8rem; }
body.short-landscape .help-title { font-size: 0.9rem; margin-bottom: 0.35rem; padding-bottom: 0.3rem; }
body.short-landscape .help-goal { line-height: 1.35; margin-bottom: 0.6rem; }
body.short-landscape .help-items { gap: 0.55rem; margin-bottom: 0.8rem; }
body.short-landscape .help-item p,
body.short-landscape .help-note p { line-height: 1.3; }
body.short-landscape #help-gotit { margin-top: 0.4rem; padding-top: 0.3rem; padding-bottom: 0.3rem; }

.help-note {
  border-top: 1px solid rgba(139, 100, 20, 0.35);
  padding-top: 0.9rem;
  margin-bottom: 1.1rem;
}

.help-note strong {
  display: block;
  font-family: 'Silkscreen', cursive;
  font-size: 0.78rem;
  color: #6b4810;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}

.help-note p {
  font-family: 'VT323', monospace;
  font-size: 0.98rem;
  color: #2a1205;
  line-height: 1.42;
}

#help-gotit {
  display: block;
  width: 100%;
  text-align: center;
  flex-shrink: 0;
  margin-top: 1rem;
}