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

html, body {
  height: 100%;
  height: 100dvh;
  background:
    radial-gradient(ellipse 90% 70% at 50% 18%, #243044 0%, #121820 42%, #08090d 100%);
  color: #e8e0c8;
  font-family: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

#game-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 100vw;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Stage matches canvas size so overlays sit crisply on top */
#stage {
  position: relative;
  width: min(96vw, 960px);
  max-height: min(85vh, 85dvh);
  aspect-ratio: 512 / 480;
  border: 3px solid #c4a050;
  border-radius: 8px;
  box-shadow:
    0 0 0 2px #3a2810,
    0 0 0 7px #120c08,
    0 0 0 8px #8b6914,
    0 18px 48px rgba(0, 0, 0, 0.62),
    0 0 70px rgba(212, 168, 75, 0.08);
  background: #000;
  overflow: hidden;
  flex-shrink: 0;
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  /* Crisp-but-detailed: painted sprites read better with slight smoothing */
  image-rendering: auto;
  image-rendering: -webkit-optimize-contrast;
  background: #000;
  touch-action: none;
  vertical-align: top;
}

#hint {
  font-size: 12px;
  opacity: 0.78;
  text-align: center;
  letter-spacing: 0.04em;
  padding: 6px 16px;
  max-width: 42rem;
  color: #d8cbb0;
}

/* —— HTML menu overlays (retina-sharp) —— */
#ui-overlays {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.ui-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 6% 5% 4%;
  text-align: center;
  pointer-events: none;
}

.ui-screen[hidden] {
  display: none !important;
}

.ui-screen--dim {
  background: rgba(8, 6, 4, 0.55);
  justify-content: center;
  padding: 8%;
}

.ui-title-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
  gap: 0.2em;
  /* Soft veil so text stays readable over pixel scene */
  background: linear-gradient(
    180deg,
    rgba(6, 4, 2, 0.55) 0%,
    rgba(6, 4, 2, 0.25) 42%,
    rgba(6, 4, 2, 0.15) 70%,
    rgba(6, 4, 2, 0.72) 100%
  );
  border-radius: 10px;
  padding: 4% 4% 3%;
  pointer-events: none;
}

.ui-flourish {
  color: #d4a84b;
  font-size: clamp(10px, 3.2vw, 18px);
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  margin-bottom: 0.1em;
}

.ui-title-name {
  font-size: clamp(22px, 7.2vw, 42px);
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.05;
  color: #f0d078;
  text-shadow:
    0 1px 0 #5a3a10,
    0 2px 8px rgba(0, 0, 0, 0.85),
    0 0 24px rgba(212, 168, 75, 0.35);
}

.ui-title-sub {
  font-size: clamp(16px, 5.2vw, 30px);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #fff8e8;
  line-height: 1.1;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.9);
}

.ui-rule {
  width: min(52%, 220px);
  height: 2px;
  margin: 0.35em auto 0.15em;
  background: linear-gradient(90deg, transparent, #d4a84b, transparent);
  border: 0;
}

.ui-level {
  font-size: clamp(11px, 3.4vw, 16px);
  font-weight: 600;
  letter-spacing: 0.06em;
  color: #f0e6d0;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}

.ui-card {
  margin-top: 0.55em;
  padding: 0.65em 0.9em;
  width: min(92%, 340px);
  background: rgba(10, 8, 6, 0.82);
  border: 1px solid rgba(212, 168, 75, 0.45);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}

.ui-card p {
  font-size: clamp(11px, 3.2vw, 15px);
  line-height: 1.35;
  color: #f5efe0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75);
}

.ui-card p + p {
  margin-top: 0.2em;
}

.ui-muted {
  color: #c8b898 !important;
  font-size: clamp(10px, 2.8vw, 13px) !important;
  margin-top: 0.35em !important;
}

.ui-start-btn {
  pointer-events: auto;
  appearance: none;
  -webkit-appearance: none;
  margin-top: 0.75em;
  padding: 0.55em 1.6em;
  min-height: 44px;
  min-width: 140px;
  font: inherit;
  font-size: clamp(14px, 4vw, 18px);
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #1a1208;
  background: linear-gradient(180deg, #f0d078 0%, #d4a84b 55%, #b88830 100%);
  border: 2px solid #fff0c0;
  border-radius: 12px;
  box-shadow:
    0 4px 0 #6a4810,
    0 8px 20px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#ui-title.ui-screen {
  justify-content: space-between;
  padding: 3% 4% 2%;
}

#ui-title .ui-start-btn {
  flex-shrink: 0;
  margin-top: 0.4em;
  margin-bottom: 0.15em;
  position: relative;
  z-index: 5;
}

#ui-title .ui-footer {
  display: none;
}

#ui-title .ui-portrait {
  width: 72px;
  height: 72px;
  margin: 0.2em 0 0.15em;
}

#ui-title .ui-card {
  margin-top: 0.25em;
  padding: 0.4em 0.7em;
}

#ui-title .ui-title-name {
  font-family: Cinzel, "Palatino Linotype", Palatino, serif;
  font-size: clamp(22px, 6.4vw, 36px);
}

#ui-title .ui-title-sub {
  font-family: Cinzel, "Palatino Linotype", Palatino, serif;
  font-size: clamp(14px, 4.4vw, 24px);
}

.ui-start-btn:active,
.ui-start-btn.is-active {
  transform: translateY(2px);
  box-shadow:
    0 2px 0 #6a4810,
    0 4px 12px rgba(0, 0, 0, 0.4);
}

.ui-start-btn--compact {
  min-width: 120px;
  min-height: 40px;
  padding: 0.45em 1.2em;
  font-size: clamp(13px, 3.6vw, 16px);
  margin-top: 0.9em;
}

.ui-prompt {
  margin-top: 0.45em;
  font-size: clamp(10px, 2.8vw, 13px);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #ffd878;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}

.ui-prompt.is-dim {
  opacity: 0.25;
}

.ui-footer {
  margin-top: 0.55em;
  font-size: clamp(9px, 2.5vw, 12px);
  color: #e8dcc0;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  opacity: 0.9;
}

.ui-panel {
  pointer-events: none;
  width: min(88%, 360px);
  padding: 1.1em 1.2em 1.2em;
  background: rgba(12, 8, 6, 0.92);
  border: 1px solid rgba(212, 168, 75, 0.55);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35em;
}

.ui-panel--wide {
  pointer-events: none;
}

.ui-panel .ui-start-btn {
  pointer-events: auto;
}

.ui-heading {
  font-size: clamp(20px, 6vw, 32px);
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #fff8e8;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.85);
}

.ui-heading--gold {
  color: #f0d078;
}

.ui-heading--danger {
  color: #e86868;
}

.ui-body {
  font-size: clamp(12px, 3.4vw, 16px);
  color: #f0e6d0;
  line-height: 1.35;
}

.ui-score {
  font-size: clamp(12px, 3.4vw, 16px);
  font-weight: 700;
  color: #ffd878;
  letter-spacing: 0.04em;
  margin-top: 0.25em;
}

/* Title screen: allow tapping the scene (not only the button) to start */
#ui-title:not([hidden]) {
  pointer-events: auto;
}

#ui-title .ui-title-inner {
  pointer-events: none;
}

#ui-title .ui-start-btn {
  pointer-events: auto;
}

#ui-win:not([hidden]),
#ui-lose:not([hidden]),
#ui-clear:not([hidden]) {
  pointer-events: auto;
}

.ui-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.55em 0.65em;
  margin-top: 0.75em;
  width: 100%;
  pointer-events: none;
}

.ui-actions .ui-start-btn {
  margin-top: 0;
  pointer-events: auto;
}

.ui-share-btn {
  pointer-events: auto;
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-height: 40px;
  min-width: 120px;
  padding: 0.45em 1.1em;
  font: inherit;
  font-size: clamp(12px, 3.4vw, 15px);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  color: #f0e6d0;
  background: rgba(20, 16, 12, 0.85);
  border: 2px solid rgba(212, 168, 75, 0.75);
  border-radius: 12px;
  box-shadow: 0 4px 0 #3a2a14, 0 6px 16px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.ui-share-btn:active,
.ui-share-btn.is-active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #3a2a14, 0 3px 10px rgba(0, 0, 0, 0.35);
  background: rgba(40, 32, 22, 0.95);
}

.ui-panel .ui-share-btn {
  pointer-events: auto;
}

/* —— Virtual controls (hidden by default; shown via .touch-ui) —— */
#touch-controls {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(96vw, 640px);
  pointer-events: none;
}

html.touch-ui #touch-controls,
body.touch-ui #touch-controls {
  display: flex;
  /* Mid-screen: under the stage with modest gap, not pinned to the bottom */
  margin-top: clamp(12px, 4dvh, 28px);
  margin-bottom: max(12px, env(safe-area-inset-bottom));
  padding-top: 4px;
  padding-bottom: 4px;
}

html.touch-ui #hint,
body.touch-ui #hint {
  display: none;
}

html.touch-ui #game-wrap,
body.touch-ui #game-wrap {
  height: 100dvh;
  min-height: 100dvh;
  justify-content: flex-start;
  gap: 0;
}

html.touch-ui #stage,
body.touch-ui #stage {
  /* Larger playfield; controls sit about halfway down the phone */
  width: min(98vw, calc(66dvh * 512 / 480), 860px);
  max-height: 66dvh;
  margin-top: 8px;
}

html.touch-ui body,
body.touch-ui {
  justify-content: flex-start;
  padding-top: 0;
}

.touch-start {
  pointer-events: auto;
  min-width: 140px;
  min-height: 48px;
  padding: 10px 28px;
  font-size: 16px;
  letter-spacing: 2px;
  font-weight: bold;
  border-radius: 12px;
  margin-top: 2px;
}

.touch-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  width: 100%;
  gap: 16px;
  padding: 0 4px 4px;
  pointer-events: none;
}

.touch-cluster {
  display: flex;
  gap: 12px;
  pointer-events: auto;
  align-items: flex-end;
}

/* Circular virtual stick / D-pad (left thumb) */
.touch-stick {
  position: relative;
  width: 132px;
  height: 132px;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.touch-stick-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(212, 168, 75, 0.7);
  background:
    radial-gradient(circle at 50% 50%, rgba(40, 32, 22, 0.35) 0%, rgba(12, 10, 8, 0.72) 70%),
    rgba(16, 12, 10, 0.55);
  box-shadow:
    inset 0 0 18px rgba(0, 0, 0, 0.45),
    0 6px 16px rgba(0, 0, 0, 0.4);
}

.touch-stick-cross {
  position: absolute;
  background: rgba(212, 168, 75, 0.22);
  border-radius: 3px;
  pointer-events: none;
}

.touch-stick-cross--h {
  left: 18%;
  right: 18%;
  top: 50%;
  height: 18px;
  transform: translateY(-50%);
}

.touch-stick-cross--v {
  top: 18%;
  bottom: 18%;
  left: 50%;
  width: 18px;
  transform: translateX(-50%);
}

.touch-stick-hint {
  position: absolute;
  font-size: 11px;
  line-height: 1;
  color: rgba(240, 230, 208, 0.55);
  pointer-events: none;
  font-weight: 700;
}

.touch-stick-hint--u { top: 10px; left: 50%; transform: translateX(-50%); }
.touch-stick-hint--d { bottom: 10px; left: 50%; transform: translateX(-50%); }
.touch-stick-hint--l { left: 12px; top: 50%; transform: translateY(-50%); }
.touch-stick-hint--r { right: 12px; top: 50%; transform: translateY(-50%); }

.touch-stick.dir-up .touch-stick-hint--u,
.touch-stick.dir-down .touch-stick-hint--d,
.touch-stick.dir-left .touch-stick-hint--l,
.touch-stick.dir-right .touch-stick-hint--r {
  color: #ffd878;
  text-shadow: 0 0 8px rgba(255, 216, 120, 0.55);
}

.touch-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: 0;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(240, 208, 120, 0.85);
  background: linear-gradient(160deg, rgba(80, 64, 40, 0.95) 0%, rgba(28, 22, 14, 0.95) 100%);
  box-shadow:
    0 3px 10px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 240, 200, 0.25);
  pointer-events: none;
  will-change: transform;
}

.touch-stick.is-active .touch-stick-base {
  border-color: #d4a84b;
  box-shadow:
    inset 0 0 18px rgba(0, 0, 0, 0.45),
    0 0 14px rgba(212, 168, 75, 0.35),
    0 6px 16px rgba(0, 0, 0, 0.4);
}

.touch-stick.is-active .touch-stick-knob {
  background: linear-gradient(160deg, rgba(212, 168, 75, 0.85) 0%, rgba(90, 64, 28, 0.95) 100%);
  border-color: #ffe08a;
}

.touch-btn {
  pointer-events: auto;
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid rgba(212, 168, 75, 0.65);
  background: rgba(20, 16, 12, 0.55);
  color: #f0e6d0;
  font-family: inherit;
  font-size: 22px;
  font-weight: bold;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.touch-btn.is-active,
.touch-btn:active {
  background: rgba(212, 168, 75, 0.45);
  border-color: #d4a84b;
  transform: scale(0.96);
}

.touch-jump,
.touch-attack {
  width: 88px;
  height: 88px;
  font-size: 28px;
  font-weight: 800;
}

.touch-jump {
  background: rgba(64, 160, 96, 0.4);
  border-color: rgba(64, 160, 96, 0.75);
}

.touch-attack {
  background: rgba(192, 64, 64, 0.4);
  border-color: rgba(192, 64, 64, 0.75);
}

.touch-start {
  border-radius: 14px;
  background: rgba(212, 168, 75, 0.35);
  width: auto;
  height: auto;
}

@media (orientation: landscape) and (max-height: 500px) {
  html.touch-ui #stage,
  body.touch-ui #stage {
    width: min(74vw, calc(64dvh * 512 / 480));
    max-height: 64dvh;
  }

  html.touch-ui #touch-controls,
  body.touch-ui #touch-controls {
    margin-top: clamp(8px, 3dvh, 20px);
    margin-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .touch-stick {
    width: 104px;
    height: 104px;
  }

  .touch-stick-knob {
    width: 42px;
    height: 42px;
  }

  .touch-btn {
    width: 52px;
    height: 52px;
    font-size: 18px;
  }

  .touch-jump,
  .touch-attack {
    width: 72px;
    height: 72px;
    font-size: 24px;
  }

  .touch-start {
    min-height: 40px;
    padding: 6px 20px;
    font-size: 14px;
  }

  .touch-bar {
    gap: 8px;
  }

  .ui-title-name {
    font-size: clamp(16px, 4.5vh, 28px);
  }

  .ui-title-sub {
    font-size: clamp(12px, 3.5vh, 20px);
  }

  .ui-card {
    padding: 0.4em 0.7em;
  }

  .ui-start-btn {
    min-height: 36px;
    padding: 0.35em 1.1em;
    margin-top: 0.4em;
  }
}

@media (max-width: 480px) {
  #hint { font-size: 10px; padding: 0 8px; }

  .touch-stick {
    width: 140px;
    height: 140px;
  }

  .touch-stick-knob {
    width: 58px;
    height: 58px;
  }

  .touch-btn {
    width: 70px;
    height: 70px;
  }

  .touch-jump,
  .touch-attack {
    width: 96px;
    height: 96px;
    font-size: 30px;
  }
}

.ui-portrait {
  display: block;
  width: 72px;
  height: 72px;
  margin: 0.35rem auto 0.5rem;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 2px solid #d4a84b;
  border-radius: 6px;
  background: #0a0806;
  box-shadow: 0 0 12px rgba(212, 168, 75, 0.35);
}

/* Always-on mute, bottom-left of the playfield */
.mute-btn {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 6;
  pointer-events: auto;
  min-width: 44px;
  height: 32px;
  padding: 0 10px;
  border: 2px solid #d4a84b;
  background: rgba(12, 10, 8, 0.82);
  color: #f0e6c8;
  font: 700 13px/1 system-ui, -apple-system, sans-serif;
  letter-spacing: 0.06em;
  border-radius: 4px;
  cursor: pointer;
  touch-action: manipulation;
}
.mute-btn.is-muted {
  color: #8a8070;
  border-color: #6a5a40;
  text-decoration: line-through;
}
.mute-btn:active {
  transform: translateY(1px);
}


/* —— Release polish —— */
.ui-title-name,
.ui-title-sub,
.ui-heading {
  font-family: Cinzel, "Palatino Linotype", Palatino, serif;
}

.ui-title-inner {
  background: linear-gradient(
    180deg,
    rgba(8, 6, 4, 0.62) 0%,
    rgba(8, 6, 4, 0.18) 40%,
    rgba(8, 6, 4, 0.12) 68%,
    rgba(8, 6, 4, 0.7) 100%
  );
}

.ui-portrait {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: 3px solid #d4a84b;
  box-shadow:
    0 0 0 2px #3a2810,
    0 0 18px rgba(212, 168, 75, 0.4);
  image-rendering: auto;
}

.ui-panel {
  backdrop-filter: blur(6px);
  border: 1px solid rgba(232, 196, 110, 0.65);
  box-shadow:
    0 10px 36px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 240, 200, 0.08);
}

.ui-start-btn {
  font-family: Cinzel, "Palatino Linotype", Palatino, serif;
}

.mute-btn {
  border-radius: 999px;
  min-width: 40px;
  height: 36px;
  letter-spacing: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.touch-btn {
  flex-direction: column;
  gap: 2px;
  line-height: 1;
}

.touch-btn span {
  font-size: 1.05em;
}

.touch-btn small {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.8;
}

.touch-jump,
.touch-attack {
  box-shadow:
    0 6px 16px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

/* —— Full-screen landscape arcade —— */
html, body, #game-wrap {
  width: 100%;
  max-width: 100%;
}

#game-wrap {
  height: 100%;
  height: 100dvh;
  gap: 0;
  padding: 0;
  justify-content: center;
}

#stage {
  width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  max-width: 100vw;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #050508;
}

#game {
  width: min(100vw, calc(100dvh * 1080 / 480));
  height: min(100dvh, calc(100vw * 480 / 1080));
  object-fit: fill;
  background: #050508;
}

#hint {
  display: none;
}

html.touch-ui #game-wrap,
body.touch-ui #game-wrap {
  height: 100dvh;
  min-height: 100dvh;
  justify-content: stretch;
}

html.touch-ui #stage,
body.touch-ui #stage {
  width: 100vw;
  max-height: 100dvh;
  height: 100dvh;
  margin-top: 0;
}

html.touch-ui #touch-controls,
body.touch-ui #touch-controls {
  display: block;
  position: absolute;
  inset: 0;
  width: auto;
  margin: 0;
  padding: 0;
  pointer-events: none;
  z-index: 5;
}

html.touch-ui .touch-bar,
body.touch-ui .touch-bar {
  position: absolute;
  inset: 0;
  width: auto;
  padding:
    env(safe-area-inset-top, 8px)
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  align-items: flex-end;
  justify-content: space-between;
}

#stage > .mute-btn {
  left: auto;
  right: max(8px, env(safe-area-inset-right));
  bottom: auto;
  top: max(8px, env(safe-area-inset-top));
}

#rotate-gate[hidden] {
  display: none;
}
#rotate-gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 2rem;
  text-align: center;
  background: rgba(6, 4, 2, 0.92);
  color: #f0e6d0;
  font-family: Cinzel, "Palatino Linotype", Palatino, serif;
  font-size: clamp(18px, 5vw, 28px);
  font-weight: 700;
}

#rotate-gate .rotate-icon {
  font-size: 2.4em;
  color: #d4a84b;
  animation: rotate-wiggle 1.6s ease-in-out infinite;
}

@keyframes rotate-wiggle {
  0%, 100% { transform: rotate(-18deg); }
  50% { transform: rotate(22deg); }
}

@media (orientation: portrait) and (pointer: coarse) and (max-width: 600px) {
  html:not(.gate-dismissed) #rotate-gate {
    display: flex !important;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  html.touch-ui #stage,
  body.touch-ui #stage {
    width: 100vw;
    max-height: 100dvh;
    height: 100dvh;
  }

  .touch-stick {
    width: 112px;
    height: 112px;
  }

  .touch-jump,
  .touch-attack {
    width: 76px;
    height: 76px;
  }
}


/* Title: always-visible Begin, compact landscape */
#ui-title.ui-screen {
  justify-content: center;
  padding: 10px 16px 88px;
  overflow: hidden;
}

#ui-title .ui-title-inner {
  overflow: visible;
  max-height: none;
  background: none;
  padding: 0;
  gap: 0.15em;
}

#ui-title .ui-start-btn {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 12;
  margin: 0;
  min-height: 48px;
  min-width: 180px;
}

#ui-title .ui-start-btn:active,
#ui-title .ui-start-btn.is-active {
  transform: translateX(-50%) translateY(2px);
}

.ui-install {
  display: none;
  position: absolute;
  left: 50%;
  bottom: max(72px, calc(env(safe-area-inset-bottom) + 56px));
  transform: translateX(-50%);
  width: min(90%, 420px);
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: #d8cbb0;
  text-shadow: 0 1px 3px #000;
  pointer-events: none;
}



@media (orientation: landscape) and (max-height: 500px) {
  #ui-title .ui-card,
  #ui-title .ui-flourish,
  #ui-title .ui-rule,
  #ui-title .ui-level,
  #ui-title .ui-prompt {
    display: none;
  }
  #ui-title .ui-portrait {
    width: 44px;
    height: 44px;
    margin: 0 0 0.2em;
  }
  #ui-title .ui-title-name {
    font-size: clamp(18px, 5.5vh, 28px);
  }
  #ui-title .ui-title-sub {
    font-size: clamp(12px, 4vh, 18px);
  }
  .ui-panel {
    max-height: 78dvh;
    overflow: auto;
    padding: 0.7em 1em;
  }
  .ui-heading {
    font-size: clamp(16px, 4.5vh, 24px);
  }
}

@media (display-mode: standalone), (display-mode: fullscreen) {
  .ui-install { display: none !important; }
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
  pointer-events: none;
  background: linear-gradient(180deg, rgba(12, 8, 6, 0.88) 0%, rgba(12, 8, 6, 0.35) 70%, transparent 100%);
  font-family: Cinzel, "Palatino Linotype", Palatino, serif;
  color: #f0e6d0;
}
#hud[hidden] {
  display: flex !important;
  background: none;
}
#hud[hidden] .hud-hearts,
#hud[hidden] .hud-chapter,
#hud[hidden] .hud-score {
  visibility: hidden;
}
#hud[hidden] .mute-btn { pointer-events: auto; }

.hud-hearts { display: flex; gap: 4px; min-width: 7.5rem; }
.hud-heart { color: #e04040; font-size: 20px; line-height: 1; text-shadow: 0 1px 2px #000; }
.hud-heart.is-empty { color: #4a3028; }
.hud-chapter { font-weight: 700; letter-spacing: 0.12em; color: #f0d078; font-size: 15px; padding-top: 2px; }
.hud-end {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: auto;
}
.hud-score { font-weight: 700; letter-spacing: 0.08em; font-size: 15px; min-width: 5.5rem; text-align: right; }
#hud .mute-btn {
  position: static;
  left: auto;
  right: auto;
  top: auto;
  bottom: auto;
}

/* —— Round 1: save/continue, pause menu, chapter cards, tips —— */
#ui-title .ui-title-actions {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 12;
  display: flex;
  gap: 14px;
  align-items: stretch;
  justify-content: center;
  pointer-events: none;
}
#ui-title .ui-title-actions .ui-start-btn {
  position: static;
  transform: none;
  left: auto;
  bottom: auto;
  margin: 0;
  min-width: 160px;
  pointer-events: auto;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
}
#ui-title .ui-title-actions .ui-start-btn[hidden] { display: none; }
#ui-title .ui-title-actions .ui-start-btn:active,
#ui-title .ui-title-actions .ui-start-btn.is-active { transform: translateY(2px); }
.ui-start-btn small {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: none;
  font-weight: 700;
  opacity: 0.85;
}
/* Secondary look for Begin when Continue is offered */
#ui-title .ui-continue-btn:not([hidden]) + .ui-start-btn {
  color: #f0e6d0;
  background: rgba(20, 16, 12, 0.88);
  border-color: rgba(212, 168, 75, 0.8);
  box-shadow: 0 4px 0 #3a2a14, 0 8px 20px rgba(0, 0, 0, 0.45);
}
.ui-start-btn.is-selected,
.ui-menu-btn.is-selected {
  outline: 3px solid #fff4c8;
  outline-offset: 3px;
}
.ui-best {
  position: absolute;
  left: max(14px, env(safe-area-inset-left));
  top: max(10px, env(safe-area-inset-top));
  margin: 0;
  font: 700 13px/1 Cinzel, "Palatino Linotype", Palatino, serif;
  letter-spacing: 0.08em;
  color: #f0d078;
  text-shadow: 0 1px 3px #000;
  pointer-events: none;
}
.ui-best[hidden] { display: none; }

/* HUD: mute + pause side by side under the score */
.hud-btns { display: flex; gap: 6px; pointer-events: auto; }
.pause-btn {
  pointer-events: auto;
  min-width: 40px;
  height: 36px;
  padding: 0 10px;
  border: 2px solid #d4a84b;
  background: rgba(12, 10, 8, 0.82);
  color: #f0e6c8;
  font: 800 13px/1 system-ui, -apple-system, sans-serif;
  letter-spacing: 0.08em;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.pause-btn:active { transform: translateY(1px); }
#hud[hidden] .pause-btn,
#hud.is-paused .pause-btn { visibility: hidden; }

/* Pause menu */
#ui-pause:not([hidden]) { pointer-events: auto; }
.ui-pause-panel { pointer-events: auto; width: min(88%, 320px); }
.ui-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-top: 0.5em;
}
.ui-menu-btn {
  appearance: none;
  -webkit-appearance: none;
  pointer-events: auto;
  min-height: 42px;
  padding: 0.4em 1em;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #f0e6d0;
  background: rgba(30, 22, 14, 0.95);
  border: 2px solid rgba(212, 168, 75, 0.7);
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.ui-menu-btn:first-child {
  color: #1a1208;
  background: linear-gradient(180deg, #f0d078 0%, #d4a84b 55%, #b88830 100%);
  border-color: #fff0c0;
}
.ui-menu-btn:active,
.ui-menu-btn.is-active { transform: translateY(2px); }
.ui-menu-hint {
  margin-top: 0.4em;
  font-size: 11px;
  color: #b8a888;
  letter-spacing: 0.04em;
}
html.touch-ui .ui-menu-hint,
body.touch-ui .ui-menu-hint { display: none; }

/* Chapter intro card */
#ui-intro {
  justify-content: center;
  pointer-events: auto;
  background: radial-gradient(ellipse at center, rgba(8, 6, 4, 0.62) 0%, rgba(8, 6, 4, 0.9) 75%);
  cursor: pointer;
}
.ui-intro-card {
  max-width: min(90%, 560px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3em;
  pointer-events: none;
}
.ui-intro-num {
  margin: 0;
  font: 700 13px/1.2 "Source Sans 3", system-ui, sans-serif;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: #d4a84b;
}
.ui-intro-title {
  margin: 0.1em 0 0;
  font-family: Cinzel, "Palatino Linotype", Palatino, serif;
  font-size: clamp(26px, 6.5vw, 46px);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff4d8;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.9);
}
.ui-intro-story {
  margin: 0.2em 0 0;
  font-size: clamp(14px, 3.4vw, 19px);
  line-height: 1.4;
  color: #f0e6d0;
  text-shadow: 0 1px 4px #000;
}
.ui-intro-year {
  margin: 0.35em 0 0;
  font: italic 600 clamp(12px, 2.8vw, 15px)/1.2 Cinzel, "Palatino Linotype", Palatino, serif;
  letter-spacing: 0.1em;
  color: #f0d078;
}
.ui-intro-skip {
  position: absolute;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(240, 230, 208, 0.55);
  pointer-events: none;
}
#ui-intro.is-anim .ui-intro-num { animation: pq-rise 0.7s ease-out both; }
#ui-intro.is-anim .ui-intro-title { animation: pq-rise 0.8s 0.15s ease-out both; }
#ui-intro.is-anim .ui-rule { animation: pq-fade 0.8s 0.35s ease-out both; }
#ui-intro.is-anim .ui-intro-story { animation: pq-rise 0.8s 0.45s ease-out both; }
#ui-intro.is-anim .ui-intro-year { animation: pq-rise 0.8s 0.7s ease-out both; }
#ui-intro.is-anim .ui-intro-skip { animation: pq-fade 0.6s 1.2s ease-out both; }
@keyframes pq-rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes pq-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  #ui-intro.is-anim * { animation-duration: 0.01s !important; animation-delay: 0s !important; }
}

/* One-line first-run tips */
.ui-tip {
  position: absolute;
  left: 50%;
  top: calc(max(8px, env(safe-area-inset-top)) + 9%);
  transform: translate(-50%, -6px);
  z-index: 5;
  max-width: min(86%, 520px);
  padding: 6px 14px;
  font: 700 14px/1.25 "Source Sans 3", system-ui, sans-serif;
  letter-spacing: 0.02em;
  color: #fff4d8;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: rgba(12, 8, 6, 0.55);
  border: 1px solid rgba(212, 168, 75, 0.45);
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.ui-tip.is-shown {
  opacity: 0.92;
  transform: translate(-50%, 0);
}
.ui-tip.is-shown.is-faded { opacity: 0.3; }
@media (orientation: landscape) and (max-height: 500px) {
  .ui-tip { font-size: 12px; max-width: min(52%, 460px); white-space: normal; }
  .ui-intro-story { font-size: 14px; }
  .ui-menu { gap: 6px; }
  .ui-menu-btn { min-height: 36px; font-size: 13px; }
  #ui-title .ui-title-actions .ui-start-btn { min-width: 140px; min-height: 44px; }
}

/* Muted state reads as a word, not a glyph */
.mute-btn.is-muted { text-decoration: none; color: #b8a888; }

/* —— Round 2: credits roll —— */
#ui-win.ui-credits {
  justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 4% max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(10, 8, 6, 0.35) 0%, rgba(10, 8, 6, 0.15) 40%, rgba(10, 8, 6, 0.7) 100%);
}
.ui-credits-view {
  position: relative;
  flex: 1 1 auto;
  width: min(92%, 620px);
  overflow: hidden;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 12%, #000 85%, transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0%, #000 12%, #000 85%, transparent 100%);
}
.ui-credits-roll {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  text-align: center;
  color: #f0e6d0;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.95);
  font-size: clamp(13px, 2.6vw, 16px);
  line-height: 1.5;
}
.ui-credits-roll.is-rolling {
  animation: pq-credits 46s linear 0.6s both;
}
@keyframes pq-credits {
  from { transform: translateY(var(--pq-roll-from, 60vh)); }
  to { transform: translateY(-100%); }
}
.ui-credits-roll p { margin: 0.15em 0; }
.ui-credits-roll h3 {
  margin: 1.4em 0 0.4em;
  font: 700 clamp(14px, 3vw, 18px)/1.2 Cinzel, "Palatino Linotype", Palatino, serif;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #d4a84b;
}
.ui-credits-head {
  margin: 0.2em 0 0.1em;
  font: 800 clamp(24px, 5.6vw, 38px)/1.15 Cinzel, "Palatino Linotype", Palatino, serif;
  color: #fff4d8;
}
.ui-credits-sub {
  font-family: Cinzel, "Palatino Linotype", Palatino, serif;
  font-style: italic;
  color: #f0d078;
  letter-spacing: 0.08em;
}
.ui-credits-line { margin: 1em 0 !important; font-size: 1.06em; }
.ui-credits-note { color: #c8b898; font-size: 0.9em; margin-bottom: 0.5em !important; }
.ui-credits-roll b { color: #fff4d8; font-weight: 700; }
.ui-credits-foot {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2em;
  pointer-events: auto;
}
.ui-credits-score {
  margin: 0;
  font: 700 clamp(13px, 2.8vw, 16px)/1.2 "Source Sans 3", system-ui, sans-serif;
  color: #ffd878;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 3px #000;
}
.ui-credits-foot .ui-actions { margin-top: 0.4em; }
.ui-credits-foot .ui-start-btn { margin-top: 0; }
@media (prefers-reduced-motion: reduce) {
  .ui-credits-roll.is-rolling { animation: none; position: static; }
  .ui-credits-view { overflow-y: auto; pointer-events: auto; }
}

/* —— Round 2: iPhone install hint sits at the top, off the grass —— */
.ui-install {
  top: max(10px, env(safe-area-inset-top));
  bottom: auto !important;
  width: auto;
  max-width: min(60%, 420px);
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(12, 8, 6, 0.72);
  border: 1px solid rgba(212, 168, 75, 0.45);
  font-size: 11px;
  white-space: nowrap;
}

/* —— Round 3: options, chapter select, results, toast —— */
#ui-title .ui-title-actions .ui-chapters-btn {
  color: #f0e6d0;
  background: rgba(20, 16, 12, 0.88);
  border-color: rgba(212, 168, 75, 0.8);
  box-shadow: 0 4px 0 #3a2a14, 0 8px 20px rgba(0, 0, 0, 0.45);
  min-width: 130px;
}
.ui-title-options {
  position: absolute;
  left: 50%;
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 66px);
  transform: translateX(-50%);
  z-index: 12;
  display: flex;
  gap: 8px;
  pointer-events: none;
  white-space: nowrap;
}
.ui-opt-btn {
  appearance: none;
  -webkit-appearance: none;
  pointer-events: auto;
  padding: 5px 12px;
  font: 700 12px/1.1 "Source Sans 3", system-ui, sans-serif;
  letter-spacing: 0.05em;
  color: #f0e6d0;
  background: rgba(12, 8, 6, 0.72);
  border: 1px solid rgba(212, 168, 75, 0.55);
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.ui-opt-btn.is-on { color: #ffe39a; border-color: #f0d078; }
.ui-opt-btn.is-selected { outline: 2px solid #fff4c8; outline-offset: 2px; }
.ui-opt-btn:active { transform: translateY(1px); }

/* Chapter select */
#ui-chapters:not([hidden]) { pointer-events: auto; }
.ui-chapters-panel { pointer-events: auto; width: min(94%, 780px); }
.ui-chapter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  margin: 0.5em 0 0.3em;
}
.ui-chapter-card {
  appearance: none;
  -webkit-appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 6px;
  min-height: 86px;
  font: inherit;
  color: #f0e6d0;
  background: rgba(30, 22, 14, 0.95);
  border: 2px solid rgba(212, 168, 75, 0.7);
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.ui-chapter-card:active { transform: translateY(2px); }
.ui-chapter-card.is-selected { outline: 3px solid #fff4c8; outline-offset: 2px; }
.ui-chapter-card.is-locked { opacity: 0.45; cursor: default; border-style: dashed; }
.ui-chapter-num { font: 800 20px/1 Cinzel, "Palatino Linotype", Palatino, serif; color: #d4a84b; }
.ui-chapter-name { font-weight: 800; font-size: 13px; line-height: 1.15; }
.ui-chapter-stars { color: #ffd34a; font-size: 17px; letter-spacing: 0.08em; text-shadow: 0 1px 2px #000; }
.ui-chapter-pages { font-size: 11px; color: #c8b898; }

/* Results card */
.ui-stars { display: flex; gap: 10px; justify-content: center; margin: 0.1em 0 0.2em; }
.ui-star {
  font-size: clamp(30px, 6vw, 44px);
  line-height: 1;
  color: rgba(255, 255, 255, 0.16);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7);
  transform: scale(0.8);
  transition: color 0.25s ease, transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.ui-star.is-lit { color: #ffd34a; transform: scale(1); }
.ui-results { list-style: none; margin: 0.2em 0; padding: 0; text-align: left; font-size: 14px; line-height: 1.5; }
.ui-results li { color: #b8a888; }
.ui-results li.is-met { color: #f0e6d0; }
.ui-results li:not(.is-met) { color: #f2c46a; }
.ui-res-mark { display: inline-block; width: 1.1em; text-align: center; color: #f2c46a; }
.ui-results li.is-met .ui-res-mark { color: #f0c040; font-weight: 700; }
.ui-stars-how { font-size: 12px; margin: 0.1em 0 0.3em; opacity: 0.9; }
.ui-res-best { color: #f0d078; font-size: 0.9em; }
.ui-clear-next { font-size: 13px; margin: 0.2em 0 0.3em; }

/* Gamepad toast */
.ui-toast {
  position: absolute;
  left: 50%;
  top: max(54px, calc(env(safe-area-inset-top) + 44px));
  transform: translate(-50%, -6px);
  z-index: 30;
  padding: 6px 14px;
  font: 700 13px/1.2 "Source Sans 3", system-ui, sans-serif;
  color: #fff4d8;
  background: rgba(12, 8, 6, 0.85);
  border: 1px solid rgba(212, 168, 75, 0.6);
  border-radius: 999px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.ui-toast.is-shown { opacity: 1; transform: translate(-50%, 0); }

/* Credits: roll stops with the last lines resting mid-view; footer compacts on short screens */
.ui-credits-roll.is-rolling {
  animation: pq-credits-r3 var(--pq-roll-dur, 46s) linear 0.6s both;
}
@keyframes pq-credits-r3 {
  from { transform: translateY(var(--pq-roll-from, 60vh)); }
  to { transform: translateY(var(--pq-roll-end, -100%)); }
}
.ui-credits-view.is-done { overflow-y: auto; pointer-events: auto; }
@media (max-height: 460px) {
  .ui-credits-foot { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 4px 14px; }
  .ui-credits-foot .ui-actions { margin-top: 0; }
  .ui-credits-foot .ui-start-btn, .ui-credits-foot .ui-share-btn { min-height: 34px; padding-top: 4px; padding-bottom: 4px; }
  .ui-credits-view {
    -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 10%, #000 92%, transparent 100%);
    mask-image: linear-gradient(180deg, transparent 0%, #000 10%, #000 92%, transparent 100%);
  }
}
@media (orientation: landscape) and (max-height: 500px) {
  .ui-pause-panel { width: min(92%, 520px); }
  .ui-pause-panel .ui-menu { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .ui-chapter-grid { gap: 6px; }
  .ui-chapter-card { min-height: 64px; padding: 5px 4px; }
  .ui-chapter-num { font-size: 16px; }
  .ui-chapter-name { font-size: 12px; }
  .ui-chapter-stars { font-size: 14px; }
  .ui-results { font-size: 13px; line-height: 1.35; }
  .ui-star { font-size: 28px; }
  .ui-title-options { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 56px); }
  .ui-opt-btn { font-size: 11px; padding: 4px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .ui-star { transition: none; }
}
/* Touch stick + A/B only during play, so they never cover menu buttons */
body[data-state]:not([data-state="playing"]) #touch-controls { visibility: hidden; pointer-events: none; }
@media (orientation: landscape) and (max-height: 500px) {
  #ui-title .ui-title-actions { gap: 10px; }
  #ui-title .ui-title-actions .ui-start-btn { min-width: 120px; padding-left: 14px; padding-right: 14px; }
}
/* Results card fits a phone held sideways */
@media (orientation: landscape) and (max-height: 500px) {
  #ui-clear .ui-panel { max-height: 94dvh; padding-top: 10px; padding-bottom: 10px; }
  #ui-clear .ui-flourish { display: none; }
  #ui-clear .ui-heading { font-size: 22px; margin: 0; }
  #ui-clear .ui-stars { margin: 0; gap: 8px; }
  #ui-clear .ui-star { font-size: 26px; }
  #ui-clear .ui-results { margin: 0.1em 0; }
  #ui-clear .ui-score { margin: 0.2em 0; }
  #ui-clear .ui-clear-next { display: none; }
  #ui-clear .ui-start-btn { margin-top: 0.3em; }
}

/* —— Round 4: full screen, journal parchment, camp meeting —— */
.ui-install { display: none !important; }
.fs-btn {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 36px;
  padding: 0;
  border: 2px solid #d4a84b;
  background: rgba(12, 10, 8, 0.82);
  color: #f0e6c8;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.fs-btn:active { transform: translateY(1px); }
.fs-btn.is-on { color: #ffe39a; }
#hud.is-paused .fs-btn { visibility: hidden; }
#hud[hidden] .fs-btn { display: none; }
.ui-fs-title-btn {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  z-index: 14;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px 9px 13px;
  font: 800 14px/1 "Source Sans 3", system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #1c1208;
  background: linear-gradient(180deg, #f6d886, #d4a84b);
  border: 2px solid #fff0c0;
  border-radius: 999px;
  box-shadow: 0 3px 0 #6a4a14, 0 6px 16px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.ui-fs-title-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #6a4a14, 0 3px 10px rgba(0, 0, 0, 0.5); }
.ui-fs-title-btn.is-selected { outline: 3px solid #fff4c8; outline-offset: 3px; }
html.is-standalone .ui-fs-title-btn,
html.is-standalone .fs-btn,
html.is-standalone .ui-menu-btn--fs { display: none !important; }

/* iPhone: illustrated Add to Home Screen guide */
.ui-fs-help {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 4, 2, 0.72);
  pointer-events: auto;
}
.ui-fs-help[hidden] { display: none; }
.ui-fs-card {
  width: min(92%, 640px);
  max-height: 94dvh;
  overflow-y: auto;
  padding: 14px 18px 14px;
  text-align: center;
  color: #2a1a0c;
  background: radial-gradient(ellipse at 50% 40%, #fbf1d6 0%, #f0dfb4 70%, #e2c98f 100%);
  border: 3px solid #7a5a2a;
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6), inset 0 0 0 2px rgba(255, 245, 210, 0.6);
  font-family: Georgia, "Times New Roman", serif;
}
.ui-fs-title { margin: 0 0 4px; font: 800 22px/1.1 Cinzel, "Palatino Linotype", Palatino, serif; color: #5a3a12; }
.ui-fs-lead { margin: 0 0 10px; font-size: 16px; line-height: 1.35; }
.ui-fs-steps { list-style: none; margin: 0 0 6px; padding: 0; display: flex; align-items: flex-start; justify-content: center; gap: 6px; }
.ui-fs-steps > li { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1 1 0; min-width: 0; }
.ui-fs-steps > li.ui-fs-arrow { flex: 0 0 auto; font-size: 26px; color: #8a6a3a; padding-top: 14px; }
.ui-fs-ico {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 58px;
  min-width: 58px;
  padding: 0 8px;
  background: #fff;
  border: 1px solid #c8b088;
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(60, 40, 10, 0.25);
}
.ui-fs-ico--share { animation: pq-fs-pulse 1.6s ease-in-out infinite; }
@keyframes pq-fs-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(47, 124, 246, 0.45), 0 2px 6px rgba(60, 40, 10, 0.25); }
  50% { box-shadow: 0 0 0 7px rgba(47, 124, 246, 0), 0 2px 6px rgba(60, 40, 10, 0.25); }
}
.ui-fs-menu-row { display: inline-flex; align-items: center; gap: 8px; font: 600 13px/1 system-ui, -apple-system, sans-serif; color: #111; white-space: nowrap; }
.ui-fs-ico--app img { border-radius: 10px; display: block; }
.ui-fs-cap { font-size: 13px; line-height: 1.25; }
.ui-fs-cap b:first-child {
  display: inline-block;
  min-width: 18px;
  margin-right: 3px;
  border-radius: 999px;
  background: #5a3a12;
  color: #fff4d8;
  font: 800 11px/18px system-ui, sans-serif;
}
.ui-fs-note { margin: 2px 0 8px; font-size: 12px; color: #6a4a22; }
.ui-fs-card .ui-start-btn { margin: 0 auto; }
@media (prefers-reduced-motion: reduce) { .ui-fs-ico--share { animation: none; } }
@media (orientation: landscape) and (max-height: 500px) {
  .ui-fs-card { padding: 10px 14px; }
  .ui-fs-title { font-size: 18px; }
  .ui-fs-lead { font-size: 14px; margin-bottom: 6px; }
  .ui-fs-ico { height: 50px; }
  .ui-fs-title-btn { padding: 7px 13px 7px 10px; font-size: 12px; }
}

/* Journal parchment */
#ui-journal:not([hidden]) { pointer-events: auto; }
.ui-parchment {
  position: relative;
  width: min(92%, 600px);
  max-height: 92dvh;
  overflow-y: auto;
  padding: 18px 26px 16px;
  text-align: left;
  color: #2e1c0a;
  background:
    radial-gradient(ellipse at 20% 15%, rgba(255, 250, 225, 0.9), rgba(255, 250, 225, 0) 55%),
    radial-gradient(ellipse at 85% 90%, rgba(150, 100, 40, 0.25), rgba(150, 100, 40, 0) 50%),
    linear-gradient(180deg, #f3e3b8, #e8d29c);
  border: 2px solid #6a4a1e;
  border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.65), inset 0 0 30px rgba(120, 80, 30, 0.35), inset 0 0 0 6px rgba(255, 245, 215, 0.35);
  font-family: Georgia, "Palatino Linotype", Palatino, "Times New Roman", serif;
  animation: pq-parch-in 0.35s cubic-bezier(0.2, 1.2, 0.4, 1) both;
}
.ui-parchment::before, .ui-parchment::after {
  content: "";
  position: absolute;
  left: -8px;
  right: -8px;
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(180deg, #8a6230, #5a3a14);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}
.ui-parchment::before { top: -6px; }
.ui-parchment::after { bottom: -6px; }
@keyframes pq-parch-in { from { opacity: 0; transform: translateY(10px) scale(0.96); } to { opacity: 1; transform: none; } }
.ui-parch-kicker { margin: 4px 0 0; font: 700 11px/1 "Source Sans 3", system-ui, sans-serif; letter-spacing: 0.16em; text-transform: uppercase; color: #8a6a3a; text-align: center; }
.ui-parch-title { margin: 6px 0 2px; font: 800 24px/1.1 Cinzel, "Palatino Linotype", Palatino, serif; color: #4a2e0c; text-align: center; }
.ui-parch-place { margin: 0 0 10px; font-style: italic; font-size: 13px; color: #7a5a2a; text-align: center; }
.ui-parch-body { margin: 0 0 10px; font-size: 16px; line-height: 1.5; }
.ui-parch-body::first-letter { float: left; font: 800 40px/0.9 Cinzel, Georgia, serif; color: #7a3a10; margin: 4px 6px 0 0; }
.ui-parch-tip {
  margin: 0 0 10px;
  padding: 8px 12px;
  font: 600 14px/1.4 "Source Sans 3", system-ui, sans-serif;
  color: #3a240a;
  background: rgba(255, 248, 220, 0.75);
  border-left: 4px solid #b08840;
  border-radius: 4px;
}
.ui-parch-tip[hidden] { display: none; }
.ui-parch-btn { display: block; margin: 4px auto 2px; }
@media (prefers-reduced-motion: reduce) { .ui-parchment { animation: none; } }
@media (orientation: landscape) and (max-height: 500px) {
  .ui-parchment { padding: 10px 20px 10px; width: min(94%, 720px); }
  .ui-parch-title { font-size: 19px; margin-top: 2px; }
  .ui-parch-place { margin-bottom: 4px; font-size: 12px; }
  .ui-parch-body { font-size: 14px; line-height: 1.38; margin-bottom: 6px; }
  .ui-parch-body::first-letter { font-size: 30px; }
  .ui-parch-tip { font-size: 13px; padding: 5px 10px; margin-bottom: 6px; }
}

/* Chapters: journal entries row */
.ui-journal-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; margin: 0.2em 0 0.3em; }
.ui-journal-label { font: 800 12px/1 Cinzel, Georgia, serif; letter-spacing: 0.08em; color: #d4a84b; margin-right: 2px; }
.ui-journal-btn {
  appearance: none;
  -webkit-appearance: none;
  min-width: 34px;
  height: 30px;
  padding: 0 8px;
  font: 800 13px/1 Georgia, serif;
  color: #2e1c0a;
  background: linear-gradient(180deg, #f3e3b8, #dcc48c);
  border: 1px solid #7a5a2a;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.ui-journal-btn:disabled { opacity: 0.3; cursor: default; background: #6a5a44; color: #2a2016; }
.ui-journal-btn:not(:disabled):active { transform: translateY(1px); }
.ui-journal-hint { flex-basis: 100%; text-align: center; font-size: 11px; color: #b8a888; }
.ui-journal-hint[hidden] { display: none; }
@media (orientation: landscape) and (max-height: 500px) {
  .ui-journal-row { gap: 4px; margin: 0.1em 0; }
  .ui-journal-btn { height: 26px; min-width: 30px; }
  .ui-journal-hint { display: none; }
}

/* ── Controls screen (round 6) ─────────────────────────── */
#ui-controls { padding: 1.5% 2%; }
#ui-controls:not([hidden]) { pointer-events: auto; }
.ui-controls-panel { pointer-events: auto; width: min(96%, 660px); max-height: 100%; overflow-y: auto; gap: 0.2em; padding: 0.6em 1em 0.7em; }
.ui-controls-panel .ui-heading { font-size: clamp(18px, 3.2vw, 26px); margin: 0; }
.ui-ctl-table { width: 100%; border-collapse: separate; border-spacing: 0 3px; font: 600 13px/1.2 system-ui, -apple-system, sans-serif; color: #f0e6d0; }
.ui-ctl-table thead th { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: #c8b088; text-align: left; padding: 0 6px; }
.ui-ctl-table tbody th { text-align: left; font-weight: 800; padding: 0 6px; white-space: nowrap; }
.ui-ctl-table td { padding: 0 4px; }
.ui-ctl-pad, .ui-ctl-touch { font-size: 12px; color: #d8c8a8; white-space: nowrap; }
.ui-key-btn {
  appearance: none; -webkit-appearance: none; pointer-events: auto;
  min-width: 84px; height: 28px; padding: 0 10px;
  font: 800 14px/1 system-ui, -apple-system, sans-serif; color: #2e1c0a;
  background: linear-gradient(180deg, #f3e3b8, #dcc48c); border: 1px solid #7a5a2a; border-radius: 6px;
  box-shadow: 0 2px 0 #5a3e18; cursor: pointer; touch-action: manipulation;
}
.ui-key-btn.is-arrow { font-size: 20px; line-height: 0.9; }
.ui-key-btn.is-empty { color: #8a7458; background: rgba(243, 227, 184, 0.35); font-weight: 600; }
.ui-key-btn.is-listening { color: #1a1208; font-size: 13px; background: linear-gradient(180deg, #fff0b0, #f0c850); animation: ui-key-pulse 0.8s ease-in-out infinite alternate; }
.ui-key-btn.is-selected { outline: 3px solid #fff4c8; outline-offset: 2px; }
.ui-key-btn.is-flash { background: linear-gradient(180deg, #d8f0c0, #a8d888); }
@keyframes ui-key-pulse { from { box-shadow: 0 0 0 0 rgba(255, 220, 120, 0.8); } to { box-shadow: 0 0 0 5px rgba(255, 220, 120, 0); } }
@media (prefers-reduced-motion: reduce) { .ui-key-btn.is-listening { animation: none; } }
.ui-ctl-msg { margin: 0.1em 0; font-size: 12px; color: #f0d078; text-align: center; min-height: 1.2em; }
.ui-ctl-actions { display: flex; gap: 10px; width: 100%; justify-content: center; }
.ui-ctl-actions .ui-menu-btn { min-height: 32px; font-size: 13px; flex: 0 1 200px; padding: 0.2em 0.8em; }
.ui-ctl-actions .ui-ctl-back { color: #1a1208; background: linear-gradient(180deg, #f0d078 0%, #d4a84b 55%, #b88830 100%); border-color: #fff0c0; }
.ui-ctl-actions .ui-ctl-reset { color: #f0e6d0; background: rgba(30, 22, 14, 0.95); border-color: rgba(212, 168, 75, 0.7); }
@media (max-height: 520px) {
  .ui-controls-panel { padding: 0.35em 0.8em 0.45em; gap: 0.1em; }
  .ui-controls-panel .ui-heading { font-size: 16px; }
  .ui-ctl-table { border-spacing: 0 2px; font-size: 12px; }
  .ui-ctl-table thead th { font-size: 9px; }
  .ui-key-btn { height: 23px; min-width: 66px; font-size: 13px; }
  .ui-key-btn.is-arrow { font-size: 17px; }
  .ui-ctl-msg { font-size: 11px; margin: 0; }
  .ui-ctl-actions .ui-menu-btn { min-height: 26px; font-size: 12px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .ui-pause-panel .ui-menu { gap: 5px; }
  .ui-pause-panel .ui-menu-btn { min-height: 30px; font-size: 12px; padding: 0.2em 0.8em; }
}
body[data-state="controls"] .mute-btn { visibility: hidden; }

/* Round 8: HUD feedback */
.hud-heart.is-lost { animation: hudHeartLost 0.45s ease-out; }
.hud-heart.is-gained { animation: hudHeartGain 0.5s ease-out; }
@keyframes hudHeartLost { 0% { transform: scale(1.6); color: #ffd0d0; } 60% { transform: scale(0.8); } 100% { transform: scale(1); } }
@keyframes hudHeartGain { 0% { transform: scale(0.4); text-shadow: 0 0 10px #ffe0a0; } 60% { transform: scale(1.35); } 100% { transform: scale(1); } }
.hud-score { transition: color 0.2s, text-shadow 0.2s; }
.hud-score.is-ticking { color: #ffe9a8; text-shadow: 0 0 8px rgba(255, 210, 120, 0.7), 0 1px 2px #000; }
@media (prefers-reduced-motion: reduce) {
  .hud-heart.is-lost, .hud-heart.is-gained { animation: none; }
}

/* ═════════════════════════════════════════════════════════════════════════
   v75 title screen: full-bleed painted backdrop, gilded lockup, one primary
   action, glass secondary row, Settings sheet. Scoped to #ui-title.pqt.
   ═════════════════════════════════════════════════════════════════════════ */
#title-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  z-index: 1;
  pointer-events: none;
}
#stage.show-title-bg #title-bg { display: block; }
#stage.show-title-bg #game { visibility: hidden; }
body[data-state="title"] #hud { visibility: hidden; }
body[data-state="title"] #hud, body[data-state="title"] #hud * { pointer-events: none !important; }

#ui-title.pqt {
  --pqt-pad-t: max(14px, env(safe-area-inset-top));
  --pqt-pad-r: max(20px, env(safe-area-inset-right));
  --pqt-pad-b: max(18px, env(safe-area-inset-bottom));
  --pqt-pad-l: max(20px, env(safe-area-inset-left));
  --pqt-gold-hi: #fff4cf;
  --pqt-gold: #f1c35e;
  --pqt-gold-lo: #a86e1c;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: minmax(0, 1fr);
  justify-content: stretch;
  align-content: stretch;
  justify-items: center;
  align-items: start;
  padding: var(--pqt-pad-t) var(--pqt-pad-r) var(--pqt-pad-b) var(--pqt-pad-l);
  overflow: hidden;
  pointer-events: auto;
  text-align: center;
  color: #f7ead0;
}
#ui-title.pqt[hidden] { display: none !important; }

/* top bar: best score (left) · sound + full screen (right) */
.pqt-top {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 44px;
  pointer-events: none;
}
.pqt-best {
  margin: 0;
  padding: 7px 14px 7px 12px;
  border-radius: 999px;
  background: rgba(10, 8, 6, 0.42);
  border: 1px solid rgba(241, 195, 94, 0.28);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font: 700 13px/1 "Source Sans 3", system-ui, sans-serif;
  letter-spacing: 0.06em;
  color: #fbeccb;
  font-variant-numeric: tabular-nums;
}
.pqt-best span {
  font: 700 11px/1 Cinzel, serif;
  letter-spacing: 0.18em;
  color: var(--pqt-gold);
  margin-right: 6px;
  text-transform: uppercase;
}
.pqt-best[hidden] { display: none; }
.pqt-top-btns { display: flex; gap: 10px; margin-left: auto; pointer-events: auto; }
.pqt-icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 226, 160, 0.38);
  background: rgba(12, 10, 8, 0.46);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: #fbeccb;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}
.pqt-icon-btn:hover { background: rgba(40, 30, 16, 0.62); border-color: rgba(255, 226, 160, 0.75); color: #fff6dc; transform: translateY(-1px); }
.pqt-icon-btn:active, .pqt-icon-btn.is-active { transform: scale(0.94); }
.pqt-icon-btn:focus-visible { outline: 2px solid #fff1c4; outline-offset: 3px; }
.pqt-icon-btn .pqt-ico-off { display: none; }
.pqt-icon-btn.is-muted .pqt-ico-on { display: none; }
.pqt-icon-btn.is-muted .pqt-ico-off { display: block; }
.pqt-icon-btn.is-muted { color: #c9b590; }
html.is-standalone .pqt-fs-btn,
html.is-standalone .pqt-row-fs { display: none; }

/* ── the lockup ─────────────────────────────────────────────────────────── */
.pqt-lockup {
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: -2vh;
  pointer-events: none;
  --pqt-size: clamp(40px, min(7.6vw, 16vh), 120px);
}
.pqt-kicker {
  display: flex;
  align-items: center;
  gap: 0.9em;
  margin: 0 0 0.35em;
  font: 800 clamp(11px, min(1.4vw, 3vh), 20px)/1 Cinzel, "Palatino Linotype", serif;
  letter-spacing: 0.46em;
  text-indent: 0.46em;
  text-transform: uppercase;
  color: #fff4da;
  text-shadow: 0 1px 1px rgba(30, 14, 0, 0.9), 0 0 10px rgba(40, 20, 0, 0.75), 0 0 26px rgba(40, 20, 0, 0.5);
}
.pqt-kick-line {
  display: block;
  width: clamp(28px, 4.5vw, 64px);
  height: 1px;
  background: linear-gradient(90deg, rgba(241, 195, 94, 0), #f1c35e);
}
.pqt-kick-line:last-child { background: linear-gradient(90deg, #f1c35e, rgba(241, 195, 94, 0)); }

.pqt-name {
  margin: 0;
  font: 900 var(--pqt-size)/0.98 "Cinzel Decorative", Cinzel, "Palatino Linotype", serif;
  letter-spacing: 0.015em;
  white-space: nowrap;
  isolation: isolate;
  filter: drop-shadow(0 0 calc(var(--pqt-size) * 0.22) rgba(255, 190, 90, 0.32));
}
.pqt-name > span {
  position: relative;
  display: inline-block;
  color: transparent;
  background:
    linear-gradient(180deg, #fffaf0 0%, #ffe9a6 22%, #f3c560 44%, #b97b22 50%, #e0a640 58%, #ffd98a 78%, #fff1c4 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-stroke: 0.6px rgba(255, 244, 214, 0.55);
}
/* the struck, embossed body behind the gold leaf */
.pqt-name > span::before {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  z-index: -1;
  color: #4a2a0a;
  -webkit-text-stroke: 0;
  text-shadow:
    0 1px 0 #6b4212,
    0 2px 0 #5a360e,
    0 3px 0 #4a2b0a,
    0 4px 0 #3b2108,
    0 5px 1px rgba(20, 10, 2, 0.9),
    0 10px 22px rgba(0, 0, 0, 0.55),
    0 0 2px rgba(0, 0, 0, 0.9);
}
/* a slow gleam across the gold */
.pqt-name > span::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  color: transparent;
  -webkit-text-stroke: 0;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.95) 49%, rgba(255, 250, 220, 0.6) 51%, transparent 60%);
  background-size: 300% 100%;
  background-position: 120% 0;
  -webkit-background-clip: text;
  background-clip: text;
  mix-blend-mode: screen;
  animation: pqt-gleam 7s ease-in-out 2.2s infinite;
}
.pqt-name-b::after { animation-delay: 2.45s !important; }
@keyframes pqt-gleam {
  0% { background-position: 120% 0; }
  22%, 100% { background-position: -20% 0; }
}
.pqt-orn {
  width: clamp(170px, 24vw, 340px);
  height: auto;
  margin: calc(var(--pqt-size) * 0.12) 0 calc(var(--pqt-size) * 0.06);
  overflow: visible;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.6));
}
.pqt-tag {
  margin: 0;
  font: italic 600 clamp(16px, min(2.1vw, 4.6vh), 28px)/1.2 "Cormorant Garamond", Georgia, serif;
  letter-spacing: 0.02em;
  color: #fff6e4;
  text-shadow: 0 1px 1px rgba(30, 14, 0, 0.9), 0 0 10px rgba(40, 20, 0, 0.7), 0 0 28px rgba(30, 14, 0, 0.55);
}

/* ── menu ───────────────────────────────────────────────────────────────── */
.pqt-menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2vh, 16px);
  pointer-events: auto;
}
.pqt-btn {
  position: relative;
  cursor: pointer;
  border: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.16s cubic-bezier(.2, .8, .3, 1), box-shadow 0.2s ease, filter 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.pqt-btn[hidden] { display: none !important; }
.pqt-btn:focus-visible { outline: none; }

.pqt-primary {
  min-width: clamp(230px, 25vw, 340px);
  min-height: clamp(54px, 9vh, 72px);
  padding: 0.35em 2.2em 0.4em;
  border-radius: 999px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font: 800 clamp(19px, min(2vw, 4.4vh), 27px)/1.05 Cinzel, "Palatino Linotype", serif;
  letter-spacing: 0.14em;
  text-indent: 0.14em;
  text-transform: uppercase;
  color: #3b2206;
  text-shadow: 0 1px 0 rgba(255, 246, 214, 0.75);
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0) 55%),
    linear-gradient(180deg, #ffeaa8 0%, #f4c75e 42%, #d69a35 58%, #eab454 100%);
  box-shadow:
    0 0 0 1px rgba(255, 246, 210, 0.9) inset,
    0 -3px 0 rgba(120, 70, 10, 0.45) inset,
    0 0 0 2px #5a370c,
    0 0 0 4px rgba(255, 214, 130, 0.42),
    0 10px 26px rgba(0, 0, 0, 0.5),
    0 0 40px rgba(255, 196, 96, 0.28);
  overflow: hidden;
}
.pqt-primary small {
  font: 700 clamp(10px, min(1vw, 2.4vh), 13px)/1.1 "Source Sans 3", system-ui, sans-serif;
  letter-spacing: 0.09em;
  text-indent: 0;
  text-transform: uppercase;
  color: #6a4512;
  text-shadow: none;
}
.pqt-primary::after {
  /* sheen that sweeps across on hover / select */
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.65) 50%, transparent 65%);
  transform: translateX(-120%);
  transition: transform 0.7s ease;
  pointer-events: none;
}
.pqt-play-ico {
  display: none;
}
.pqt-play { flex-direction: row; gap: 0.7em; }
.pqt-play .pqt-play-ico {
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: -0.3em;
  border-left: 0.62em solid #3b2206;
  border-top: 0.38em solid transparent;
  border-bottom: 0.38em solid transparent;
  filter: drop-shadow(0 1px 0 rgba(255, 246, 214, 0.75));
}
#ui-title.has-save .pqt-play { display: none !important; }
#ui-title:not(.has-save) .pqt-new { display: none !important; }

@media (hover: hover) {
  .pqt-primary:hover { transform: translateY(-2px) scale(1.02); filter: brightness(1.06) saturate(1.05); box-shadow: 0 0 0 1px rgba(255, 246, 210, 0.95) inset, 0 -3px 0 rgba(120, 70, 10, 0.45) inset, 0 0 0 2px #5a370c, 0 0 0 5px rgba(255, 220, 140, 0.6), 0 14px 30px rgba(0, 0, 0, 0.5), 0 0 60px rgba(255, 196, 96, 0.45); }
  .pqt-primary:hover::after { transform: translateX(120%); }
}
.pqt-primary.is-selected, .pqt-primary:focus-visible {
  box-shadow: 0 0 0 1px rgba(255, 246, 210, 0.95) inset, 0 -3px 0 rgba(120, 70, 10, 0.45) inset, 0 0 0 2px #5a370c, 0 0 0 5px #fff1c4, 0 12px 28px rgba(0, 0, 0, 0.5), 0 0 64px rgba(255, 206, 110, 0.6);
  animation: pqt-pulse 2.2s ease-in-out infinite;
}
.pqt-primary.is-selected::after { transform: translateX(120%); }
.pqt-primary:active, .pqt-primary.is-active {
  transform: translateY(2px) scale(0.985);
  filter: brightness(0.94);
  box-shadow: 0 0 0 1px rgba(255, 246, 210, 0.7) inset, 0 2px 0 rgba(120, 70, 10, 0.4) inset, 0 0 0 2px #5a370c, 0 0 0 4px rgba(255, 214, 130, 0.35), 0 4px 12px rgba(0, 0, 0, 0.5);
}
@keyframes pqt-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.08); }
}

.pqt-sec {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
.pqt-secondary {
  min-width: clamp(112px, 10.5vw, 150px);
  min-height: 44px;
  padding: 0 1.25em;
  border-radius: 999px;
  font: 700 clamp(12px, min(1.15vw, 2.8vh), 15px)/1 Cinzel, "Palatino Linotype", serif;
  letter-spacing: 0.12em;
  text-indent: 0.12em;
  text-transform: uppercase;
  color: #fbecc8;
  background: linear-gradient(180deg, rgba(36, 28, 18, 0.62), rgba(14, 10, 6, 0.7));
  border: 1px solid rgba(241, 195, 94, 0.5);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  backdrop-filter: blur(10px) saturate(1.2);
  box-shadow: inset 0 1px 0 rgba(255, 236, 190, 0.16), 0 6px 16px rgba(0, 0, 0, 0.35);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
@media (hover: hover) {
  .pqt-secondary:hover { transform: translateY(-2px); color: #fff7e2; border-color: rgba(255, 222, 150, 0.95); background: linear-gradient(180deg, rgba(70, 52, 26, 0.7), rgba(28, 20, 10, 0.78)); box-shadow: inset 0 1px 0 rgba(255, 236, 190, 0.22), 0 10px 20px rgba(0, 0, 0, 0.4), 0 0 22px rgba(255, 200, 110, 0.22); }
}
.pqt-secondary.is-selected, .pqt-secondary:focus-visible {
  color: #fff7e2;
  border-color: #fff1c4;
  box-shadow: 0 0 0 2px rgba(255, 241, 196, 0.85), inset 0 1px 0 rgba(255, 236, 190, 0.22), 0 0 26px rgba(255, 206, 110, 0.4);
}
.pqt-secondary:active, .pqt-secondary.is-active { transform: translateY(1px) scale(0.97); background: linear-gradient(180deg, rgba(14, 10, 6, 0.8), rgba(36, 28, 18, 0.7)); }

/* ── Settings sheet ─────────────────────────────────────────────────────── */
.pqt-settings {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: var(--pqt-pad-t) var(--pqt-pad-r) var(--pqt-pad-b) var(--pqt-pad-l);
  background: rgba(6, 4, 2, 0.5);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: pqt-fade 0.22s ease-out both;
}
.pqt-settings[hidden] { display: none !important; }
.pqt-sheet {
  width: min(420px, 92vw);
  max-height: 100%;
  overflow: auto;
  padding: 18px 18px 16px;
  border-radius: 18px;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(255, 210, 130, 0.12), rgba(0, 0, 0, 0) 60%),
    linear-gradient(180deg, #2a2016, #15100a);
  border: 1px solid rgba(241, 195, 94, 0.55);
  box-shadow: 0 0 0 1px #000 inset, 0 0 0 4px rgba(241, 195, 94, 0.12), 0 24px 60px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: pqt-pop 0.28s cubic-bezier(.2, .9, .3, 1.2) both;
}
.pqt-sheet-title {
  margin: 0 0 6px;
  font: 800 20px/1.1 Cinzel, serif;
  letter-spacing: 0.16em;
  text-indent: 0.16em;
  text-transform: uppercase;
  color: var(--pqt-gold);
}
.pqt-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 46px;
  padding: 0 14px 0 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 226, 160, 0.14);
  background: rgba(255, 240, 210, 0.05);
  font: 700 15px/1 "Source Sans 3", system-ui, sans-serif;
  letter-spacing: 0.02em;
  color: #f6e8c8;
  cursor: pointer;
  text-align: left;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}
.pqt-row b {
  min-width: 64px;
  padding: 6px 12px;
  border-radius: 999px;
  text-align: center;
  font: 800 12px/1 "Source Sans 3", system-ui, sans-serif;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #2c1a05;
  background: linear-gradient(180deg, #ffe7a4, #e0a948);
}
.pqt-row:hover { background: rgba(255, 240, 210, 0.1); border-color: rgba(255, 226, 160, 0.4); }
.pqt-row.is-selected, .pqt-row:focus-visible { outline: none; border-color: #fff1c4; box-shadow: 0 0 0 2px rgba(255, 241, 196, 0.6); }
.pqt-row:active, .pqt-row.is-active { transform: scale(0.985); }
.pqt-done { align-self: center; margin-top: 6px; }

/* ── intro choreography ─────────────────────────────────────────────────── */
#ui-title.pqt:not([hidden]) .pqt-kicker { animation: pqt-rise 0.9s 0.35s cubic-bezier(.2, .8, .2, 1) both; }
#ui-title.pqt:not([hidden]) .pqt-name { animation: pqt-title-in 1.25s 0.15s cubic-bezier(.16, .84, .24, 1) both; }
#ui-title.pqt:not([hidden]) .pqt-orn { animation: pqt-orn-in 0.9s 0.85s cubic-bezier(.2, .8, .2, 1) both; }
#ui-title.pqt:not([hidden]) .pqt-tag { animation: pqt-rise 0.9s 1.05s cubic-bezier(.2, .8, .2, 1) both; }
#ui-title.pqt:not([hidden]) .pqt-primary { animation: pqt-rise 0.8s 1.3s cubic-bezier(.2, .9, .25, 1.1) both; }
#ui-title.pqt:not([hidden]) .pqt-sec > * { animation: pqt-rise 0.7s 1.5s cubic-bezier(.2, .8, .2, 1) both; }
#ui-title.pqt:not([hidden]) .pqt-sec > :nth-child(2) { animation-delay: 1.56s; }
#ui-title.pqt:not([hidden]) .pqt-sec > :nth-child(3) { animation-delay: 1.62s; }
#ui-title.pqt:not([hidden]) .pqt-sec > :nth-child(4) { animation-delay: 1.68s; }
#ui-title.pqt:not([hidden]) .pqt-top { animation: pqt-fade 0.8s 1.6s ease-out both; }
#ui-title.pqt.pqt-quick:not([hidden]) :is(.pqt-kicker, .pqt-name, .pqt-orn, .pqt-tag, .pqt-primary, .pqt-sec > *, .pqt-top) {
  animation: pqt-fade 0.35s ease-out both;
}
#ui-title.pqt.pqt-quick:not([hidden]) .pqt-primary.is-selected { animation: pqt-fade 0.35s ease-out both, pqt-pulse 2.2s 0.4s ease-in-out infinite; }
@keyframes pqt-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pqt-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes pqt-title-in {
  0% { opacity: 0; transform: scale(1.08); filter: blur(10px) drop-shadow(0 0 0 rgba(255, 190, 90, 0)); letter-spacing: 0.12em; }
  60% { opacity: 1; filter: blur(0) drop-shadow(0 0 60px rgba(255, 200, 110, 0.7)); }
  100% { opacity: 1; transform: none; filter: drop-shadow(0 0 calc(var(--pqt-size) * 0.22) rgba(255, 190, 90, 0.32)); letter-spacing: 0.015em; }
}
@keyframes pqt-orn-in { from { opacity: 0; transform: scaleX(0.2); } to { opacity: 1; transform: none; } }
@keyframes pqt-pop { from { opacity: 0; transform: translateY(10px) scale(0.96); } to { opacity: 1; transform: none; } }
#ui-title.pqt:not([hidden]) .pqt-primary.is-selected { animation: pqt-rise 0.8s 1.3s cubic-bezier(.2, .9, .25, 1.1) both, pqt-pulse 2.2s 2.2s ease-in-out infinite; }

@media (prefers-reduced-motion: reduce) {
  #ui-title.pqt *, #ui-title.pqt *::before, #ui-title.pqt *::after { animation-duration: 0.01s !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition: none !important; }
}

/* ── phone landscape / short screens ────────────────────────────────────── */
@media (max-height: 500px) {
  #ui-title.pqt {
    --pqt-pad-t: max(8px, env(safe-area-inset-top));
    --pqt-pad-b: max(10px, env(safe-area-inset-bottom));
  }
  .pqt-lockup { --pqt-size: clamp(34px, min(8.2vw, 15.5vh), 76px); margin-top: -4vh; }
  .pqt-kicker { margin-bottom: 0.25em; }
  .pqt-tag { font-size: clamp(14px, 4.2vh, 19px); }
  .pqt-primary { min-height: 50px; min-width: 220px; font-size: 19px; }
  .pqt-menu { gap: 9px; }
  .pqt-sec { gap: 8px; flex-wrap: nowrap; }
  .pqt-secondary { min-width: 0; padding: 0 1em; font-size: 12px; }
  .pqt-icon-btn { width: 40px; height: 40px; }
  .pqt-top { min-height: 40px; }
  .pqt-sheet { padding: 12px 14px; gap: 6px; }
  .pqt-sheet-title { font-size: 16px; margin-bottom: 2px; }
  .pqt-row { min-height: 42px; }
}
@media (max-height: 360px) {
  .pqt-tag { display: none; }
}

/* v76: Netlify-injected "Powered by Netlify" badge (iframe#nl-badge-frame)
   moved from bottom-right to top-left, stacked below the hearts / BEST badge. */
#nl-badge-frame {
  top: calc(max(10px, env(safe-area-inset-top)) + 52px) !important;
  left: calc(max(14px, env(safe-area-inset-left)) - 3px) !important;
  bottom: auto !important;
  right: auto !important;
}
@media (max-height: 500px) {
  #nl-badge-frame { top: calc(max(10px, env(safe-area-inset-top)) + 42px) !important; }
}

/* rotate-fix: layout height follows the live visual viewport (iOS stale dvh after rotation) */
html, body, #game-wrap, html.touch-ui #game-wrap, body.touch-ui #game-wrap { height: var(--app-h, 100dvh); }
html.touch-ui #game-wrap, body.touch-ui #game-wrap { min-height: var(--app-h, 100dvh); }
#stage { height: var(--app-h, 100dvh); max-height: var(--app-h, 100dvh); }
@media (orientation: landscape) and (max-height: 500px) {
  html.touch-ui #stage, body.touch-ui #stage { height: var(--app-h, 100dvh); max-height: var(--app-h, 100dvh); }
}
html, body { overflow: hidden; overscroll-behavior: none; }
.rotate-anyway {
  margin-top: 0.6rem; padding: 0.7em 1.6em; border-radius: 999px; border: 2px solid #d4a84b;
  background: rgba(212, 168, 75, 0.15); color: #f0e6d0; font: inherit; font-size: 0.75em; cursor: pointer;
}

/* iOS / iPadOS: backdrop blur over the live title canvas is re-blurred every frame by
   WebKit; use the same tint, a little more opaque, with no blur */
html.pq-ios .pqt-best,
html.pq-ios .pqt-icon-btn,
html.pq-ios .pqt-secondary,
html.pq-ios .pqt-settings,
html.pq-ios .ui-panel {
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}
html.pq-ios .pqt-best { background: rgba(10, 8, 6, 0.58); }
html.pq-ios .pqt-icon-btn { background: rgba(12, 10, 8, 0.6); }

/* v78: popups always fit the visible viewport (iPhone landscape with the toolbar showing is
   ~330px tall): capped to the live height, body scrolls inside, the action button stays put */
.ui-screen--dim {
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
#ui-journal:not([hidden]), #ui-pause:not([hidden]), #ui-controls:not([hidden]), #ui-chapters:not([hidden]) { pointer-events: auto; }
.ui-screen--dim:not([hidden]) > .ui-panel,
.ui-parchment {
  pointer-events: auto;
  max-height: min(100%, calc(var(--app-h, 100dvh) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 16px));
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  flex-shrink: 1;
  min-height: 0;
}
.ui-parch-btn {
  position: sticky;
  bottom: -10px;
  z-index: 1;
  margin: 4px auto 0;
  box-shadow: 0 -10px 14px 4px rgba(236, 216, 164, 0.95);
}
.ui-intro-card {
  max-height: calc(var(--app-h, 100dvh) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 48px);
  overflow: hidden;
}
@media (max-height: 420px) {
  .ui-parchment { padding: 8px 16px 10px; }
  .ui-parch-kicker { font-size: 10px; margin-top: 2px; }
  .ui-parch-title { font-size: 16px; margin: 3px 0 1px; }
  .ui-parch-place { font-size: 11px; margin-bottom: 3px; }
  .ui-parch-body { font-size: 13px; line-height: 1.32; margin-bottom: 4px; }
  .ui-parch-body::first-letter { font-size: 26px; }
  .ui-parch-tip { font-size: 12px; padding: 4px 8px; margin-bottom: 4px; }
  .ui-intro-title { font-size: 22px; }
  .ui-intro-story { font-size: 13px; line-height: 1.35; }
  .ui-panel { padding: 0.7em 0.9em 0.8em; gap: 0.25em; }
}
/* action rows stay in view at the bottom of scrolling panels */
.ui-chapters-panel > .ui-actions,
.ui-controls-panel > .ui-ctl-actions {
  position: sticky;
  bottom: -0.8em;
  z-index: 1;
  padding: 6px 0 4px;
  background: linear-gradient(180deg, rgba(12, 8, 6, 0), rgba(12, 8, 6, 0.96) 35%);
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 8px;
}
@media (max-height: 420px) { .ui-chapters-panel > .ui-menu-hint { display: none; } }

/* v82: larger invisible touch zones with a faint resting outline (controls never move) */
.touch-btn { position: relative; }
.touch-btn::after,
.touch-stick::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  border: 1.5px dashed rgba(240, 230, 208, 0.16);
  pointer-events: auto;
}
.touch-stick::after { inset: -22px; }
.touch-jump::after { top: -20px; bottom: -20px; left: -20px; right: -5px; }
.touch-attack::after { top: -20px; bottom: -20px; left: -5px; right: -20px; }
.touch-btn:not(.touch-jump):not(.touch-attack)::after { inset: -8px; border-color: transparent; }
.touch-btn.is-active, .touch-btn:active { transform: none; }

/* v83: Retry beside Continue on the star screen (Continue stays primary) */
.ui-clear-actions { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 0.9em; }
.ui-clear-actions .ui-start-btn--compact { margin-top: 0; }
.ui-retry-btn { min-height: 36px; padding: 0.35em 0.9em; font-size: clamp(12px, 3.2vw, 14px); }
.ui-retry-btn.is-selected { outline: 2px solid #fff4c8; outline-offset: 2px; }
@media (max-height: 420px) { .ui-clear-actions { margin-top: 0.5em; } }
