:root {
  --color-sky: #77cee5;
  --color-text: #000;
  --color-surface: #fff;
  --color-choice: #6f2dbd;
  --color-choice-hover-surface: #efe6fa;
  --color-warning: #b00020;
  --color-complete: #1a7f37;
  --color-shadow: rgb(0 0 0 / 25%);
  --color-backdrop: rgb(0 0 0 / 55%);

  --font-pixel: "Press Start 2P", system-ui, sans-serif;
  --font-size-body: clamp(0.75rem, 0.55rem + 0.8vw, 1.1rem);
  --font-size-title: clamp(1.4rem, 0.9rem + 2.4vw, 2.6rem);
  --font-size-heading: clamp(1rem, 0.75rem + 1.2vw, 1.6rem);
  --font-size-small: 0.75em;
  --line-height: 1.9;

  --space-xs: 0.5rem;
  --space-s: 0.75rem;
  --space-m: 1.25rem;
  --space-l: 2rem;

  --border-width: 4px;
  --shadow-offset: 6px;
  --card-max-width: 46rem;
  --touch-target-min: 44px;

  --character-base-height: clamp(90px, 20vh, 220px);
  --character-max-height: 45vh;
  /* Background is anchored bottom with `cover`; the grass sits ~16% up the image, scaled by height or by width (16:9). */
  --scenery-ground-offset: max(16vh, 9vw);
  --gallery-base-height: clamp(4rem, 12vw, 8rem);
  --reward-icon-height: 2.5em;

  --blink-duration: 1s;
  --blink-repeats: 3;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background-color: var(--color-sky);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  color: var(--color-text);
  font-family: var(--font-pixel);
  font-size: var(--font-size-body);
  line-height: var(--line-height);
}

/* A fixed layer keeps the grass at the bottom of the screen even on long, scrolling pages (iOS ignores background-attachment: fixed). */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--color-sky) url("../assets/images/Nature.png") center bottom / cover no-repeat;
  image-rendering: pixelated;
}

img {
  image-rendering: pixelated;
}

button {
  font: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: var(--border-width) solid var(--color-text);
  outline-offset: 3px;
}

.passage:focus {
  outline: none;
}

/* ---------- Top bar ---------- */

.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-s);
  padding: var(--space-s) var(--space-m);
  font-size: var(--font-size-small);
}

.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-s);
}

.hud[hidden] {
  display: none;
}

.sound-toggle {
  margin-left: auto;
}

.timer,
.hud-button {
  margin: 0;
  min-height: var(--touch-target-min);
  padding: var(--space-xs) var(--space-s);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-text);
  box-shadow: var(--shadow-offset) var(--shadow-offset) 0 var(--color-shadow);
  color: var(--color-text);
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
}

.hud-button:hover {
  background: var(--color-choice-hover-surface);
}

.timer-value {
  font-variant-numeric: tabular-nums;
}

.timer.is-low {
  color: var(--color-warning);
  border-color: var(--color-warning);
}

/* ---------- Story card ---------- */

.passage {
  width: 100%;
  max-width: var(--card-max-width);
  margin: 0 auto;
  padding: var(--space-m);
}

.card {
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-text);
  box-shadow: var(--shadow-offset) var(--shadow-offset) 0 var(--color-shadow);
  padding: var(--space-l) var(--space-m);
}

.card > :first-child {
  margin-top: 0;
}

.card h1 {
  font-size: var(--font-size-heading);
  line-height: 1.4;
  margin: 0 0 var(--space-m);
}

[data-passage-type="title"] .card {
  text-align: center;
}

[data-passage-type="title"] .card h1 {
  font-size: var(--font-size-title);
  margin-bottom: var(--space-l);
}

.thought em {
  font-style: italic;
}

.item-list {
  padding-left: var(--space-l);
}

.page-footer {
  text-align: center;
  font-size: var(--font-size-small);
}

/* ---------- Choices ---------- */

.choices {
  list-style: none;
  margin: var(--space-l) 0 0;
  padding: 0;
  display: grid;
  gap: var(--space-s);
}

[data-passage-type="title"] .choices {
  max-width: 22rem;
  margin-inline: auto;
}

.choice {
  width: 100%;
  min-height: var(--touch-target-min);
  padding: var(--space-s) var(--space-m);
  background: var(--color-surface);
  border: var(--border-width) solid currentColor;
  color: var(--color-choice);
  text-align: left;
  line-height: 1.6;
}

.choice::before {
  content: "▸ ";
}

.choice:hover {
  background: var(--color-choice-hover-surface);
}

/* ---------- Pictures ---------- */

.rewards {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin: var(--space-m) 0;
}

.reward-icon {
  height: var(--reward-icon-height);
  width: auto;
  animation: blink var(--blink-duration) var(--blink-repeats);
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.gallery {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: var(--space-m);
  margin: var(--space-l) 0 0;
}

.gallery-image {
  height: calc(var(--gallery-base-height) * var(--scale));
  width: auto;
}

.scenery {
  margin-top: auto;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: var(--space-l);
  padding: var(--space-m) var(--space-m) var(--scenery-ground-offset);
}

.character {
  height: calc(var(--character-base-height) * var(--scale));
  max-height: var(--character-max-height);
  width: auto;
}

/* ---------- Culvert dialog ---------- */

.culvert {
  width: min(90vw, 30rem);
  padding: var(--space-l) var(--space-m);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-text);
  box-shadow: var(--shadow-offset) var(--shadow-offset) 0 var(--color-shadow);
  color: var(--color-text);
  font-family: var(--font-pixel);
  font-size: var(--font-size-body);
  line-height: var(--line-height);
}

.culvert::backdrop {
  background: var(--color-backdrop);
}

.culvert h2 {
  font-size: var(--font-size-heading);
  margin: 0;
}

.culvert-subtitle {
  margin-top: 0;
}

.culvert-items {
  list-style: none;
  padding: 0;
  margin: var(--space-m) 0;
}

.culvert-items li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-xs);
  padding: var(--space-xs) 0;
}

.culvert-items li.is-complete {
  color: var(--color-complete);
}

.culvert-items li.is-complete .culvert-label::before {
  content: "✓ " / "Done: ";
}

/* ---------- Utilities ---------- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .reward-icon {
    animation: none;
  }
}
