/* Spacing: 2 4 8 12 16 24 32 40 48 px only. Type: Tailwind scale steps only. Touch targets: 48px. */
:root {
  --bg: #131209;
  --panel: #181818;
  --raise: #272727;
  --raise-hover: #313131;
  --text: #f3ead9;
  --muted: #b3aa99;
  --accent: #f2b077;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.credits-link { display: inline-flex; align-items: center; min-height: 48px; padding: 8px 12px; color: var(--text); font-size: 14px; line-height: 20px; text-underline-offset: 4px; }
.credits-link:hover { color: var(--accent); }
.shot-feedback { position: absolute; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: min(320px, calc(100% - 224px)); padding: 8px 12px; border-radius: 12px; background: #142739e8; color: #fff5e2; font-size: 14px; line-height: 20px; text-align: center; pointer-events: none; }
@media (max-width: 560px) { .shot-feedback { bottom: 120px; max-width: calc(100% - 48px); width: max-content; } }
.card .reward { color: var(--accent); }
.card .payoff { color: var(--text); }

html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/24px Geist, Manrope, system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, p, ol { margin: 0; }
h1 { font-size: 18px; line-height: 28px; font-weight: 600; }
h2 { font-size: 24px; line-height: 32px; font-weight: 600; text-wrap: balance; }
p { text-wrap: pretty; }
h1:focus { outline: none; }
.small { font-size: 14px; line-height: 20px; color: var(--muted); }

/* One view at a time, each the size of the visible viewport, clear of notches and gesture bars. */
.view {
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- controls ---- */
button {
  min-height: 48px;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--raise);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 300ms var(--ease), transform 300ms var(--ease);
}
button:hover { background: var(--raise-hover); }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); color: #131209; }
button.primary:hover { background: #f7c798; }
button.big { padding: 12px 24px; font-size: 16px; line-height: 24px; }
button.icon { flex: none; width: 48px; padding: 0; display: grid; place-items: center; background: none; }
button.icon:hover { background: var(--raise); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bar { flex: none; display: flex; align-items: center; gap: 4px; padding: 4px; }
.bar h1 { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ---- opening ---- */
.title { position: relative; align-items: center; justify-content: space-between; text-align: center; }
.art { position: absolute; inset: 0; width: 100%; height: 100%; }
.title-copy, .title-actions { position: relative; padding: 48px 24px 0; }
.title-copy h1 { font-size: 48px; line-height: 1; text-shadow: 0 2px 16px #15183a; }
.title-copy p { margin: 12px auto 0; max-width: 320px; text-shadow: 0 1px 8px #15183a; }
.title-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; padding: 0 24px 40px; }
.title-actions .primary { min-width: 160px; }
.title-options, .audio-settings { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.title-options { flex-basis: 100%; }
.audio-toggle { flex: none; padding: 8px; font-size: 12px; line-height: 16px; }
[data-sound][aria-pressed="false"], [data-music][aria-pressed="false"] { color: var(--muted); }
.loading { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 16px; padding: 24px; background: var(--bg); text-align: center; }
.opening-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 5% center; }
.title-lantern { position: absolute; width: 48px; height: 80px; object-fit: contain; top: 36%; left: 72%; filter: drop-shadow(0 0 16px #ffd27a); }
.title.painted { background: #212236 url('assets/production/runtime/sunset-sky.webp') center / cover; }
.title.painted > svg { display: none; }
.title-copy { z-index: 1; }
.title-copy p { padding: 8px 12px; border-radius: 8px; background: rgba(19,18,31,.84); }
.title-actions { z-index: 1; }
#artNotice:empty { display: none; }
#artNotice { flex-basis: 100%; padding: 8px; background: #181818; }
.spirit { animation: bob 3200ms ease-in-out infinite alternate; }
.flame { animation: breathe 2400ms ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(-6px); } }
@keyframes breathe { from { opacity: 0.7; } }

/* Story art is framed separately from its readable, user-paced caption. */
.story { position: relative; justify-content: space-between; background: #242c42; }
.story-art { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.story-art img { position: absolute; transition: opacity 800ms var(--ease), transform 1400ms var(--ease); }
.story-sky, .story-painting { inset: 0; width: 100%; height: 100%; object-fit: cover; }
.story-sky { filter: brightness(.6) saturate(.7); }
.story-coast { left: -8%; bottom: 16%; width: 116%; height: 36%; object-fit: fill; opacity: .65; }
.story-dark-light { height: 44%; width: 48%; left: 24%; bottom: 30%; object-fit: contain; }
.story-spirit { height: 48%; width: 90%; left: -8%; bottom: 30%; object-fit: contain; opacity: 0; }
.story-painting { object-position: 5% center; opacity: 1; }
.story-flame { width: 48px; height: 80px; object-fit: contain; top: 32%; left: 72%; filter: drop-shadow(0 0 16px #ffd27a); opacity: 0; }
.story-beat-1 .story-painting, .story-beat-2 .story-painting { opacity: 0; }
.story-beat-2 .story-dark-light { opacity: 0; }
.story-beat-2 .story-spirit { opacity: 1; }
.story-beat-2 .story-flame { opacity: 1; }
.story-beat-3 .story-painting { object-position: 96% center; }
.story-bar { position: relative; z-index: 1; background: rgba(19,18,31,.78); }
.story-bar p { flex: 1; }
.story-copy { position: relative; z-index: 1; margin: 16px; padding: 24px; max-width: 480px; border-radius: 16px; background: rgba(19,18,31,.92); display: flex; flex-direction: column; gap: 12px; overflow-y: auto; max-height: calc(100% - 80px); }
.story-step { color: var(--accent); }
.story-copy h1 { font-size: 24px; line-height: 32px; text-wrap: balance; }
.story-copy > p:not(.small) { font-size: 18px; line-height: 28px; }
.story-copy .primary { align-self: flex-start; min-width: 160px; }

/* ---- map ---- */
.map { overflow-y: auto; }
.map .bar h1 { flex: 1; }
.map .bar p { padding-right: 12px; white-space: nowrap; }
/* Twelve stops need room: the chart is its own scroller, tall in portrait and long in landscape. */
.chart {
  flex: 1 1 0;
  min-height: 320px;
  margin: 0 12px;
  border-radius: 16px;
  overflow: hidden auto;
  overscroll-behavior: contain;
  background: #1d5a66;
}
.chart-in { position: relative; width: min(100%, 480px); margin: 0 auto; aspect-ratio: 720 / 3908; }
#chartArt > svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.chart .islet { fill: #2e2340; }
.chart .way { fill: none; stroke: var(--accent); stroke-opacity: 0.7; stroke-width: 2; stroke-dasharray: 2 8; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart .wide { display: none; }
.map-paint { display: none; }
.chart .has-paint .map-paint { display: inline; }
.chart .has-paint .islet { display: none; }
.stopname, .stopstars { padding: 2px 8px; border-radius: 4px; background: rgba(19,18,31,.9); font-size: 12px; line-height: 16px; white-space: nowrap; }
.stop:disabled { opacity: .7; }
.chart ol { list-style: none; padding: 0; }
.mapnote { flex: none; padding: 12px 16px 16px; text-align: center; }

.stop {
  position: absolute;
  left: calc(var(--tx) * 1%);
  top: calc(var(--ty) * 1%);
  transform: translate(-50%, -24px); /* the beacon sits on the route point */
  width: 128px;
  min-height: 96px;
  padding: 0 0 4px;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 2px;
  background: none;
}
.stop:hover { background: none; }
.stop:active { transform: translate(-50%, -24px) scale(0.98); }
.beacon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 2px solid #4a3358;
  border-radius: 9999px;
  background: #1c1629;
  color: #cfc2b4;
}
.beacon .lamp { fill: #2b2540; }
.stop.lit .beacon { border-color: #ffe0a0; background: var(--accent); color: #131209; box-shadow: 0 0 24px rgba(255, 214, 130, 0.6); }
.stop.lit .lamp { fill: #fff6d8; }
.stop.next .beacon { border-color: var(--accent); animation: beckon 1600ms var(--ease) infinite alternate; }
.stopname { text-shadow: 0 1px 4px #131209; }
.stopstars { color: var(--accent); text-shadow: 0 1px 4px #131209; }
@keyframes beckon { to { box-shadow: 0 0 0 8px rgba(242, 176, 119, 0.25); } }

/* ---- play ---- */
.game { position: relative; padding: 0; }
.gamemain { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.ident { flex: 1; min-width: 0; }
.play { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Fit the complete world; controls float within it, never in a sidebar. */
.stagewrap { flex: 1; min-width: 0; min-height: 0; container-type: size; display: grid; place-items: center; }
.stage { position: relative; width: 100%; height: 100%; background: #15183a; }
.shot {
  position: absolute; right: max(24px, env(safe-area-inset-right)); bottom: max(24px, env(safe-area-inset-bottom)); z-index: 1;
  width: 80px; height: 80px; padding: 0; display: grid; place-items: center; border-radius: 50%;
  color: #fff1cf; background: rgba(166, 222, 225, .12); border: 1px solid rgba(235, 255, 255, .6);
  backdrop-filter: blur(8px) saturate(150%); -webkit-backdrop-filter: blur(8px) saturate(150%);
  box-shadow: inset 0 2px 4px #ffffff77, inset 0 -4px 12px #436c7766, 0 4px 24px #0d233b55;
}
.shot:hover { background: rgba(205, 238, 237, .22); }
.shot:active { transform: scale(.94); }
.scene-tools { position: absolute; left: max(16px, env(safe-area-inset-left)); top: max(16px, env(safe-area-inset-top)); z-index: 2; }
.scene-tools > summary { width: 48px; height: 48px; justify-content: center; border-radius: 50%; color: #effcfc; background: #14334340; border: 1px solid #e3ffff55; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); list-style: none; }
.scene-tools > summary::-webkit-details-marker { display: none; }
.scene-tools .panel { position: absolute; top: 56px; left: 0; width: min(340px, calc(100vw - 48px)); max-height: calc(100dvh - 96px); border-radius: 12px; background: #181818f5; box-shadow: 0 4px 24px #0008; }
/* Out of flow: the canvas's pixel size (set by the renderer) must never feed back into the stage's layout size. */
canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
canvas:active { cursor: grabbing; }

.panel {
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.place { color: var(--accent); }
.status { min-height: 40px; }
.panel .big { align-self: stretch; }
summary { min-height: 48px; display: flex; align-items: center; font-size: 14px; line-height: 20px; font-weight: 600; cursor: pointer; }
details ol { padding: 0 0 8px 24px; }
details li + li { margin-top: 4px; }
.aim { display: grid; grid-template-columns: auto 1fr 48px; align-items: center; gap: 4px 16px; padding-bottom: 8px; }
.aim label { font-size: 14px; line-height: 20px; font-weight: 600; }
.aim input { width: 100%; height: 40px; accent-color: var(--accent); }
.aim output { font-size: 14px; line-height: 20px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

/* ---- result ---- */
.win {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(19, 18, 9, 0.6);
}
.card {
  width: min(100%, 360px);
  max-height: 100%;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  border: 1px solid var(--raise-hover);
  border-radius: 16px;
  background: var(--panel);
  animation: rise 800ms var(--ease);
}
.card p { color: var(--muted); }
.stars { display: flex; justify-content: center; gap: 8px; font-size: 36px; line-height: 40px; }
.stars span { color: var(--raise-hover); }
.stars .on { color: var(--accent); animation: pop 600ms var(--ease) backwards; }
.stars .on:nth-child(2) { animation-delay: 200ms; }
.stars .on:nth-child(3) { animation-delay: 400ms; }
.win-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
@keyframes pop { from { opacity: 0; transform: scale(0.4); } }

/* ---- landscape: fit the world to the height that is left ---- */
@media (orientation: landscape) {
  .story-copy { align-self: flex-end; width: min(48%, 480px); }
  .story-dark-light { left: 8%; bottom: 12%; width: 28%; height: 70%; }
  .story-spirit { left: 0; bottom: 0; width: 46%; height: 80%; }
  .story-painting { object-position: center; }
  .story-flame { left: 35%; top: 38%; }
  .opening-art { object-position: center; }
  .title-lantern { display: none; }
  .stage { border-radius: 0; }

  .chart { min-height: 264px; overflow: auto hidden; display: flex; align-items: center; background: #5a3f7c; }
  .chart-in { flex: none; width: auto; height: 100%; max-height: 480px; margin: 0; aspect-ratio: 4608 / 640; }
  .chart .tall { display: none; }
  .chart .wide { display: inline; }
  .stop { left: calc(var(--wx) * 1%); top: calc(var(--wy) * 1%); }
}

/* Compact landscape chrome, with all controls kept in the scene. */
@media (orientation: landscape) and (max-height: 560px) {
  .story-copy { margin: 12px; padding: 16px; gap: 8px; }
  .story-copy > p:not(.small) { font-size: 16px; line-height: 24px; }
  .title-copy { padding-top: 16px; }
  .title-copy h1 { font-size: 36px; line-height: 40px; }
  .title-copy p { margin-top: 4px; max-width: 480px; font-size: 14px; line-height: 20px; }
  .title-actions { padding-bottom: 16px; }
  .card { width: min(100%, 560px); padding: 16px; gap: 8px; }
  .win-actions { flex-direction: row; justify-content: center; }
  .mapnote { padding: 8px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .story-art img { transition: none; }
  .card, .stars .on, .spirit, .flame, .stop.next .beacon { animation: none; }
  button { transition: none; }
}
.view[hidden] *, .tab-hidden * { animation-play-state: paused !important; }
