/* The scene page. Two moods follow the system colour scheme, as the scene's own grade does
   (hud.js sends the same media query to the app): a golden morning and a blue-hour dusk. */
.scene {
  --hud-fg: var(--graphite);
  --hud-fg-soft: color-mix(in srgb, var(--graphite) 62%, transparent);
  --hud-accent: var(--ram-blue);
  --hud-accent-fg: var(--paper);
  --hud-eyebrow: var(--cognac);
  --hud-track: color-mix(in srgb, var(--ram-blue) 18%, transparent);
  --hud-hover: color-mix(in srgb, var(--paper) 80%, transparent);
  --hud-halo: color-mix(in srgb, var(--paper) 85%, transparent);
  --hud-scrim: color-mix(in srgb, var(--paper) 55%, transparent);
  --hud-glass-hi: color-mix(in srgb, var(--paper) 74%, transparent);
  --hud-glass-lo: color-mix(in srgb, var(--paper) 48%, transparent);
  --hud-edge: color-mix(in srgb, var(--paper) 70%, transparent);
  --hud-shadow: color-mix(in srgb, var(--graphite) 38%, transparent);
  --scene-ground: linear-gradient(180deg, var(--sky-day), var(--paper));
}

@media (prefers-color-scheme: dark) {
  .scene {
    --hud-fg: var(--paper);
    --hud-fg-soft: color-mix(in srgb, var(--paper) 62%, transparent);
    --hud-accent: var(--window-glow);
    --hud-accent-fg: var(--brand-ink);
    --hud-eyebrow: var(--window-glow);
    --hud-track: color-mix(in srgb, var(--paper) 18%, transparent);
    --hud-hover: color-mix(in srgb, var(--paper) 12%, transparent);
    --hud-halo: color-mix(in srgb, var(--sky-night) 90%, transparent);
    --hud-scrim: color-mix(in srgb, var(--sky-night) 70%, transparent);
    --hud-glass-hi: color-mix(in srgb, var(--sky-night) 72%, transparent);
    --hud-glass-lo: color-mix(in srgb, var(--brand-ink) 58%, transparent);
    --hud-edge: color-mix(in srgb, var(--paper) 14%, transparent);
    --hud-shadow: color-mix(in srgb, var(--brand-ink) 60%, transparent);
    --scene-ground: linear-gradient(180deg, var(--sky-night), color-mix(in srgb, var(--sky-night) 60%, var(--brand-ink)));
    color-scheme: dark;
  }
}

html, body.scene { height: 100%; overflow: hidden; overscroll-behavior: none; touch-action: none; }

body.scene { background: var(--scene-ground); color: var(--hud-fg); }

#pastorek-canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; }

/* The scene's panes take the mood's glass; the logo plates stay paper, so the black wordmark reads. */
.scene .glass {
  background: linear-gradient(160deg, var(--hud-glass-hi), var(--hud-glass-lo));
  border-color: var(--hud-edge);
  box-shadow:
    0 1px 0 color-mix(in srgb, var(--paper) 30%, transparent) inset,
    0 24px 48px -24px var(--hud-shadow),
    0 4px 12px -6px var(--hud-shadow);
}
.scene .hud__brand.glass, .scene .end.glass, .scene .fallback__pane.glass {
  background: linear-gradient(160deg, color-mix(in srgb, var(--paper) 82%, transparent), color-mix(in srgb, var(--paper) 60%, transparent));
  border-color: color-mix(in srgb, var(--paper) 70%, transparent);
  color: var(--graphite);
}
.scene .lang { border-color: transparent; background: transparent; }
.scene .lang button { color: var(--hud-fg); }
.scene .lang button[aria-pressed="true"] { background: var(--hud-accent); color: var(--hud-accent-fg); }

.hud { position: fixed; inset: 0; pointer-events: none; padding: max(0.9rem, env(safe-area-inset-top)) clamp(0.75rem, 2.5vw, 1.75rem) max(0.9rem, env(safe-area-inset-bottom)); display: grid; grid-template-rows: auto 1fr auto; }
.hud[hidden] { display: none; }
.hud > * { pointer-events: auto; }
.hud__anchors { pointer-events: none; position: absolute; inset: 0; overflow: hidden; }

/* A soft film scrim under the subtitle and the bar: the scene fades rather than ends at a pane. */
.hud::after {
  content: ""; position: absolute; inset: auto 0 0; height: 11rem; pointer-events: none; z-index: -1;
  background: linear-gradient(0deg, var(--hud-scrim), transparent);
}

.hud__top { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "brand lang" "brand links"; justify-items: end; align-items: start; gap: 0.5rem 0.75rem; }
.hud__brand { grid-area: brand; justify-self: start; display: flex; align-items: center; padding: 0.5rem 0.9rem; border-radius: 16px; }
.hud__brand img { height: 48px; width: auto; }
.hud__lang { grid-area: lang; padding: 3px; border-radius: 999px; }
.hud__lang .lang { padding: 0; }
.hud__links { grid-area: links; display: flex; gap: 0.15rem 0.35rem; padding: 0.15rem 0.4rem; border-radius: 999px; }
.hud__links a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 0.7rem; font-size: 0.85rem; font-weight: 540; font-stretch: 108%; text-decoration: none; border-radius: 999px; color: var(--hud-fg); }
.hud__links a:hover { background: var(--hud-hover); }

/* View controls: a slim column at the right edge, the way byrtus.dev keeps its camera keys. */
.hud__view {
  position: absolute; right: clamp(0.75rem, 2.5vw, 1.75rem); top: 50%; transform: translateY(-50%);
  display: grid; gap: 2px; padding: 3px; border-radius: 16px;
}

.hud__dock {
  grid-row: 3; align-self: end; justify-self: center; width: min(100%, 46rem);
  display: grid; gap: 0.55rem; justify-items: center;
}

.hud__subtitle {
  display: flex; align-items: baseline; justify-content: center; flex-wrap: wrap; gap: 0.2rem 0.75rem;
  max-width: 40rem; text-align: center; min-height: 1.6em;
  text-shadow: 0 0 18px var(--hud-halo), 0 0 3px var(--hud-halo);
}
.hud__text { font-size: clamp(1rem, 1.7vw, 1.2rem); font-weight: 500; font-stretch: 104%; line-height: 1.3; letter-spacing: -0.003em; }

.hud__bar {
  width: 100%; display: flex; align-items: center; gap: 0.6rem;
  padding: 4px 6px 4px 4px; border-radius: 999px;
}
.hud__transport { flex: none; display: flex; align-items: center; }

.hud__scrub { position: relative; flex: 1; min-width: 0; height: 44px; display: grid; align-items: center; }
.hud__scrub input[type="range"] { appearance: none; -webkit-appearance: none; width: 100%; height: 44px; margin: 0; background: transparent; cursor: pointer; --progress: 0%; }
.hud__scrub input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: linear-gradient(90deg, var(--hud-accent) var(--progress), var(--hud-track) var(--progress)); }
.hud__scrub input[type="range"]::-moz-range-track { height: 3px; border-radius: 3px; background: var(--hud-track); }
.hud__scrub input[type="range"]::-moz-range-progress { height: 3px; border-radius: 3px; background: var(--hud-accent); }
.hud__scrub input[type="range"]::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5.5px; border-radius: 50%; background: var(--hud-accent); border: 2px solid var(--paper); box-shadow: 0 1px 6px var(--hud-shadow); transition: transform 140ms; }
.hud__scrub input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.25); }
.hud__scrub input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--hud-accent); border: 2px solid var(--paper); }

.hud__ticks { list-style: none; margin: 0; padding: 0; position: absolute; inset: 0; pointer-events: none; }
.tick { position: absolute; top: 50%; width: 22px; height: 44px; margin: -22px 0 0 -11px; padding: 0; border: 0; background: transparent; cursor: pointer; pointer-events: auto; }
.tick::after { content: ""; position: absolute; left: 50%; top: 50%; width: 3px; height: 3px; margin: -9px 0 0 -1.5px; border-radius: 50%; background: var(--hud-fg-soft); transition: transform 140ms, background 140ms; }
.tick:hover::after { transform: scale(1.6); }
.tick.is-past::after { background: var(--hud-accent); }
.tick.is-current::after { background: var(--hud-eyebrow); transform: scale(1.6); }

.ctl {
  display: inline-grid; place-items: center; min-width: 44px; min-height: 44px; padding: 0;
  border: 0; border-radius: 999px; background: transparent; color: var(--hud-fg);
  font: inherit; font-size: 0.8rem; font-weight: 620; font-stretch: 112%; font-variant-numeric: tabular-nums; cursor: pointer;
  transition: background 140ms, color 140ms, transform 140ms;
}
.ctl:hover { background: var(--hud-hover); }
.ctl:active { transform: scale(0.94); }
.hud__view .ctl { border-radius: 13px; }
.ctl--step { color: var(--hud-fg-soft); }
.ctl--step:hover { color: var(--hud-fg); }
.ctl--play { background: var(--hud-accent); color: var(--hud-accent-fg); box-shadow: 0 6px 16px -8px var(--hud-shadow); }
.ctl--play:hover { background: var(--hud-accent); filter: brightness(1.12); }
.ctl--play .icon-pause, .ctl--play.is-playing .icon-play { display: none; }
.ctl--play.is-playing .icon-pause { display: block; }
.ctl--speed { min-width: 52px; letter-spacing: 0.02em; }

.chip {
  position: absolute; left: 0; top: 0; white-space: nowrap; padding: 0.28rem 0.65rem; border-radius: 999px;
  background: var(--hud-glass-hi); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border: 1px solid var(--hud-edge);
  font-size: 0.7rem; font-weight: 580; font-stretch: 110%; letter-spacing: 0.04em; color: var(--hud-fg);
  box-shadow: 0 10px 24px -14px var(--hud-shadow);
  transition: opacity 200ms; will-change: transform;
}
.chip[hidden] { display: none; }
.hud.is-ended .hud__anchors { visibility: hidden; }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; }
.overlay[hidden] { display: none; }
.overlay--end { pointer-events: none; background: radial-gradient(60% 60% at 50% 45%, var(--hud-scrim), transparent); padding: 1rem 0 7rem; grid-template-rows: minmax(0, 1fr); }
.overlay--end > * { pointer-events: auto; }
/* A column that never exceeds the space between the HUD's top items and the bar: everything keeps its size and the map,
   the one elastic child, takes what is left. */
.end { position: relative; overflow-x: hidden; overflow-y: auto; max-height: 100%; width: min(100% - 2rem, 30rem); padding: 1.25rem 2rem 1rem; display: flex; flex-direction: column; align-items: center; gap: 0.9rem; text-align: center; }
.end > * { flex: none; }
.end > :not(.end__map) { position: relative; }
.end__region { margin-top: -0.6rem; font-size: 0.68rem; font-weight: 600; font-stretch: 112%; letter-spacing: 0.16em; text-transform: uppercase; color: color-mix(in srgb, var(--graphite) 62%, transparent); }

/* The map hint is a small inset between the caption and the buttons. Its border fades softly; the towns sit in the clear part. */
.end__map {
  --map-ink: var(--ram-blue); --map-hill: var(--steel-dark); --map-water: var(--water);
  flex: 0 1 150px; min-height: 128px; width: auto; max-width: min(100%, 300px); aspect-ratio: 2 / 1; pointer-events: none;
  -webkit-mask-image: linear-gradient(90deg, transparent, var(--brand-ink) 8%, var(--brand-ink) 92%, transparent), linear-gradient(180deg, transparent, var(--brand-ink) 7%, var(--brand-ink) 93%, transparent);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(90deg, transparent, var(--brand-ink) 8%, var(--brand-ink) 92%, transparent), linear-gradient(180deg, transparent, var(--brand-ink) 7%, var(--brand-ink) 93%, transparent);
  mask-composite: intersect;
}
.map { width: 100%; height: 100%; }
.map__band { fill: var(--map-hill); fill-rule: evenodd; stroke: none; }
.map__band--1 { opacity: 0.2; }
.map__band--2 { opacity: 0.27; }
.map__band--3 { opacity: 0.34; }
.map__river { fill: none; stroke: var(--map-water); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; opacity: 0.8; }
.map__peak { fill: var(--map-hill); stroke: none; opacity: 0.9; }
.map__region { fill: var(--map-hill); font-family: inherit; font-weight: 600; font-stretch: 112%; opacity: 0.95; }
.map__peakname { fill: var(--map-ink); font-family: inherit; font-weight: 540; opacity: 0.8; }
.map__region, .map__peakname, .map__town text { paint-order: stroke; stroke: var(--paper); stroke-width: 5px; stroke-linejoin: round; }
.end > .end__credit { margin-top: 15px; display: flex; flex-wrap: wrap; justify-content: center; column-gap: 0.8rem; row-gap: 29px; font-size: 0.66rem; line-height: 1.35; color: color-mix(in srgb, var(--graphite) 80%, var(--paper)); }
/* A link is 44 px tall to touch; its padding lies in the space the credit reserves above and below it, so no hit area reaches another control. */
.end__credit a { display: inline-block; padding: 15px 2px; margin: -15px 0; color: inherit; text-decoration: underline; text-underline-offset: 0.15em; }
.map__town { opacity: 0; transition: opacity 700ms ease calc(var(--order, 0) * 140ms); }
.is-shown .map__town--primary { opacity: 1; }
.is-shown .map__town--secondary { opacity: 0.85; }
.map__town circle { fill: var(--map-ink); }
.map__town .map__halo { fill: color-mix(in srgb, var(--map-ink) 14%, transparent); stroke: var(--map-ink); stroke-width: 1.4; opacity: 0.6; }
.map__town text { fill: var(--map-ink); font-family: inherit; font-weight: 540; letter-spacing: 0.02em; }
@media (prefers-reduced-motion: reduce) {
  .map__town { transition: none; }
  .map__town--primary { opacity: 1; }
  .map__town--secondary { opacity: 0.85; }
}
/* The card sits below the links where they share its columns, and above the story bar. No camera controls behind a modal. */
.hud.is-ended .hud__view { visibility: hidden; }
@media (max-width: 1100px) { .overlay--end { padding-top: 8rem; } }
@media (max-width: 480px) {
  .overlay--end { padding-bottom: 7.9rem; }
  .end { padding: 1.25rem 0.8rem 1rem; gap: 0.6rem; }
}
/* Short screens: the story subtitle goes (the card says it), the bar is all the card must clear, and the logo shrinks. */
@media (max-height: 760px) {
  .overlay--end { padding-bottom: 4.4rem; }
  .end { gap: 0.55rem; }
  .end img { height: 52px; }
  .hud.is-ended .hud__subtitle { visibility: hidden; }
}
/* Only when even the smallest map would not fit: no logo or caption. */
@media (max-height: 660px), (max-width: 480px) and (max-height: 700px) {
  .end img, .end__region { display: none; }
  .end h2 { font-size: 1.35rem; }
}
/* endfit.js adds these when the content still overflows, one after another: caption, logo, the long credit and the big title, then a card that scrolls with its credit pinned. */
.credit__short { display: none; }
.end.is-tight > .end__region, .end.is-tighter > img { display: none; }
.end.is-tightest > h2 { font-size: 1.2rem; }
.end.is-tightest .credit__full { display: none; }
.end.is-tightest .credit__short { display: inline; }
.end.is-scroll > .end__credit { position: sticky; bottom: 0; background: var(--paper); }
/* A phone held sideways: two columns, the map left, the words and buttons right; nothing scrolls, and the links, brand and language give way to the card. */
@media (orientation: landscape) and (max-height: 500px) {
  .overlay--end { padding: 0.6rem 0 4.6rem; }
  .hud.is-ended .hud__top { visibility: hidden; }
  .end { width: min(100% - 2rem, 44rem); display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; justify-items: center; column-gap: 1rem; row-gap: 0.4rem; padding: 1.25rem 1.2rem 1rem; }
  .end > img, .end > .end__region { display: none; }
  .end > .end__map { grid-column: 1; grid-row: 1 / span 3; width: clamp(256px, 44vw, 300px); height: auto; max-width: none; }
  .end > h2, .end > .end__actions, .end > #pk-replay { grid-column: 2; }
  .end > .end__credit { grid-column: 1 / -1; grid-row: 4; }
}
.end img { height: 74px; width: auto; }
.end h2 { font-size: clamp(1.5rem, 5vw, 2.1rem); }
@media (max-width: 480px) { .end img { height: 56px; } .end__region { margin-top: -0.3rem; } }
@media (max-height: 760px) { .end img { height: 52px; } }
@media (max-height: 660px), (max-width: 480px) and (max-height: 700px) { .end h2 { font-size: 1.35rem; } }
.end__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem; }
.btn--ghost { border-color: transparent; background: transparent; text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--ram-blue) 40%, transparent); }

.overlay--loading { z-index: 10; gap: 1.2rem; align-content: center; justify-items: center; }
.overlay--loading img { width: min(18rem, 70vw); height: auto; }
.overlay--loading p { font-size: 0.9rem; font-weight: 520; font-stretch: 112%; letter-spacing: 0.04em; }
progress { appearance: none; -webkit-appearance: none; width: min(16rem, 60vw); height: 3px; border: 0; border-radius: 3px; background: color-mix(in srgb, var(--ram-blue) 18%, transparent); overflow: hidden; }
progress::-webkit-progress-bar { background: color-mix(in srgb, var(--ram-blue) 18%, transparent); }
progress::-webkit-progress-value { background: var(--brand-red); border-radius: 3px; transition: width 200ms; }
progress::-moz-progress-bar { background: var(--brand-red); }

@media (prefers-color-scheme: dark) {
  /* Opaque paper at dusk: translucent paper over the navy ground reads grey. */
  .scene .hud__brand.glass, .scene .end.glass, .scene .fallback__pane.glass { background: var(--paper); }
  /* The loading screen keeps its paper: it frames the black wordmark, then hands over to the dusk. */
  .scene .overlay--loading { color: var(--graphite); }
}

.fallback { position: fixed; inset: 0; overflow: auto; display: grid; place-items: start center; padding: 1.5rem; touch-action: auto; }
.fallback[hidden] { display: none; }
.fallback__pane { width: min(100%, 38rem); padding: clamp(1.5rem, 5vw, 2.5rem); display: grid; gap: 1.5rem; justify-items: start; }
.fallback__pane img { height: 70px; width: auto; }
.fallback__lead { font-size: 1.15rem; font-weight: 480; font-stretch: 106%; }
.fallback__steps { margin: 0; padding: 0 0 0 1.4rem; display: grid; gap: 0.55rem; }
.fallback__steps li::marker { color: var(--cognac); font-weight: 650; }

@media (max-width: 720px) {
  .hud__brand img { height: 32px; }
  .hud__brand { padding: 0.4rem 0.7rem; border-radius: 14px; }
  .hud__links a { padding: 0 0.55rem; }
  .hud__view { top: auto; bottom: calc(max(0.9rem, env(safe-area-inset-bottom)) + 7.5rem); transform: none; }
  .hud__dock { gap: 0.4rem; }
  .hud__subtitle { flex-direction: column; align-items: center; gap: 0.1rem; min-height: 3.2em; }
  .hud__bar { gap: 0.25rem; }
  .tick { pointer-events: none; }
  .hud::after { height: 9rem; }
}

/* Short screens (a phone held sideways): the view column would cover the top links, so it becomes a
   row beside the bar and the dock gives it room. Last, so it wins over the narrow layout. */
@media (max-height: 520px) {
  .hud__view { top: auto; bottom: max(0.9rem, env(safe-area-inset-bottom)); transform: none; grid-auto-flow: column; }
  .hud__dock { justify-self: start; width: min(100% - 13rem, 46rem); }
  .hud__subtitle { flex-direction: row; min-height: 1.6em; }
}
