/**
 * Seasons -- game stylesheet
 *
 * Single sheet for games/seasons/index.html. Loaded after the site sheet
 * (/css/style.css), so anything inherited from there that fights a full-screen
 * touch game is reset below.
 *
 * Two colour systems meet in this file, and keeping them apart is the main
 * thing to understand:
 *
 * - `--sn-*` are the game's chrome: surfaces, text, borders, buttons. They have
 *   a light and a dark variant and never change during play.
 * - `--season-*` are set on `:root` by JavaScript, from the active art pack's
 *   palette (see js/art/placeholder.js). They change when the season changes.
 *   No rule in this file names a season; that is what lets a replacement art
 *   pack re-theme the whole game without touching CSS.
 *
 * Built for a shared iPad first: 64px tap targets, 100dvh sizing so Safari's
 * toolbars cannot cause a mid-question scroll, and suppressed double-tap zoom,
 * tap highlight, and text selection. Every animation is disabled under
 * `prefers-reduced-motion`.
 */

/* ==================== Reset and base ==================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --sn-bg: #f6f3ec;
  --sn-surface: #fff;
  --sn-surface-alt: #efeae0;
  --sn-ink: #2d3330;
  --sn-ink-muted: #69716c;
  --sn-border: #ddd6c8;
  --sn-primary: #3f7d5c;
  --sn-primary-ink: #fff;
  --sn-correct: #2c864d;
  --sn-correct-bg: #e6f5ea;
  --sn-wrong: #c0453b;
  --sn-wrong-bg: #fbe9e7;

  /* The marked answer buttons put their own colour on their own tint, which is
     a darker pairing than either is against the page. Separate values so the
     text clears 4.5:1 there without dulling the borders and feedback line. */
  --sn-correct-on-tint: #1f6b3b;
  --sn-wrong-on-tint: #a3352c;
  --sn-tap: 64px;
  --sn-radius: 14px;

  /* Overwritten by GameUI.applyPalette; these are the pre-season defaults. */
  --season-sky: #dff3e4;
  --season-far: #a8d5ba;
  --season-ground: #6fae82;
  --season-accent: #e8657f;
  --season-glow: #fff2a8;
  --season-ink: #2b3d31;
  --season-accent-text: #e02c50;
  --season-accent-text-dark: #e86680;

  /* The accent that paints the trail is usually too light to read as text, so
     the art pack supplies a tuned pair and this resolves which one applies.
     Everything that draws text uses --season-accent-ink; only shapes use
     --season-accent. */
  --season-accent-ink: var(--season-accent-text);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --season-accent-ink: var(--season-accent-text-dark);
    --sn-bg: #1c211f;
    --sn-surface: #262c2a;
    --sn-surface-alt: #2f3634;
    --sn-ink: #e8ece9;
    --sn-ink-muted: #9aa5a0;
    --sn-border: #3c4441;
    --sn-primary: #5aa87c;
    --sn-primary-ink: #10201a;
    --sn-correct: #6bc98c;
    --sn-correct-bg: #1f3527;
    --sn-wrong: #e8776c;
    --sn-wrong-bg: #3a231f;
  }
}

/* The site theme toggle wins over the OS preference. Written out in full
   rather than referenced, because a CSS custom property cannot be aliased
   across two different selectors. */
:root[data-theme="dark"] {
  --season-accent-ink: var(--season-accent-text-dark);
  --sn-bg: #1c211f;
  --sn-surface: #262c2a;
  --sn-surface-alt: #2f3634;
  --sn-ink: #e8ece9;
  --sn-ink-muted: #9aa5a0;
  --sn-border: #3c4441;
  --sn-primary: #5aa87c;
  --sn-primary-ink: #10201a;
  --sn-correct: #6bc98c;
  --sn-correct-bg: #1f3527;
  --sn-wrong: #e8776c;
  --sn-wrong-bg: #3a231f;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  background: var(--sn-bg);
  color: var(--sn-ink);
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  overscroll-behavior: none;
  text-size-adjust: 100%;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ==================== Layout ==================== */
.game-layout {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.game-top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--sn-surface);
  border-bottom: 1px solid var(--sn-border);
}

.game-top-bar .level-title {
  flex: 1;
  font-weight: 700;
  font-size: 1.05rem;
  text-align: center;
  color: var(--sn-ink);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--sn-border);
  border-radius: 10px;
  background: var(--sn-surface-alt);
  color: var(--sn-ink);
  font-size: 1.15rem;
  text-decoration: none;
  cursor: pointer;
}

.icon-btn:active {
  transform: scale(0.94);
}

.game-main {
  flex: 1;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.screen-heading {
  margin-bottom: 8px;
  font-size: 1.5rem;
  color: var(--sn-ink);
  text-align: center;
}

/* Each screen change focuses its heading so a screen reader announces where it
   landed. Inline-block so the focus ring hugs the words: on a block-level
   heading it drew a full-width rectangle across the page on every transition,
   which reads as a rendering fault rather than a focus indicator. */
.screen-heading:focus-visible {
  display: inline-block;
  outline: 3px solid var(--sn-primary);
  outline-offset: 6px;
}

.screen-intro {
  max-width: 60ch;
  margin: 0 auto 22px;
  color: var(--sn-ink-muted);
  text-align: center;
  line-height: 1.55;
}

/* ==================== Character select ==================== */

/* Explicit column counts rather than auto-fit. There are exactly four
   characters, and auto-fit picked three columns at tablet widths, which left
   the fourth card alone on its own row. */
.character-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

@media (width >= 900px) {
  .character-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (width <= 430px) {
  .character-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.character-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 16px 20px;
  border: 2px solid var(--sn-border);
  border-radius: var(--sn-radius);
  background: var(--sn-surface);
  color: var(--sn-ink);
  font: inherit;
  text-align: center;
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    transform 0.15s ease;
}

.character-card:hover,
.character-card:focus-visible {
  border-color: var(--sn-primary);
  outline: none;
}

.character-card:active {
  transform: scale(0.97);
}

.character-art {
  display: block;
  width: 108px;
  height: 108px;
}

.character-svg {
  width: 100%;
  height: 100%;
}

.character-name {
  font-size: 1.15rem;
  font-weight: 700;
}

.character-perk {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--sn-primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.character-perk-text {
  font-size: 0.92rem;
  line-height: 1.4;
  color: var(--sn-ink);
}

.character-cost {
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--sn-ink-muted);
}

/* ==================== The demand bar ==================== */
.demand-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border: 1px solid var(--sn-border);
  border-radius: var(--sn-radius);
  background: var(--sn-surface);
}

.villain-portrait {
  flex: none;
  width: 62px;
  height: 62px;
}

.villain-svg {
  width: 100%;
  height: 100%;
}

.demand-copy {
  flex: 1;
  min-width: 0;
}

.demand-line {
  font-size: 0.98rem;
  font-style: italic;
  line-height: 1.4;
  color: var(--sn-ink);
}

.demand-count {
  margin-top: 4px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--season-accent-ink);
}

/* One slot per item she asked for. Earned slots hold the season's collectible,
   wilting ones are drained and dropped, and the rest are empty outlines -- so
   the goal, the progress and the shortfall all read at a glance instead of
   being arithmetic on a counter. */
.item-track {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 6px;
}

.item-pip {
  display: block;
  width: 19px;
  height: 19px;
  border: 2px dashed var(--sn-border);
  border-radius: 50%;
}

.item-pip.is-earned,
.item-pip.is-wilting {
  border: 0;
}

.item-pip.is-wilting {
  opacity: 0.4;
  filter: grayscale(85%);
  transform: translateY(3px) rotate(12deg);
}

.item-svg {
  width: 100%;
  height: 100%;
}

.note {
  margin-top: 4px;
  font-size: 0.86rem;
  line-height: 1.35;
}

.note-wilt {
  color: var(--sn-wrong);
}

.note-perk {
  color: var(--sn-primary);
}

/* ==================== The trail ==================== */
.trail {
  margin: 14px 0;
  overflow: hidden;
  border: 1px solid var(--sn-border);
  border-radius: var(--sn-radius);
}

.trail-svg {
  display: block;
  width: 100%;
  height: auto;
}

/* The camera. Panning this is what scrolls the landscape; a viewBox cannot be
   animated, a transform can. JS owns the transform, so nothing is set here. */
.trail-camera {
  will-change: transform;
}

.trail-ground {
  fill: var(--season-ground);
}

/* Behind a mountain rather than around a dot, so the light haloes the thing
   being climbed. */
.obstacle-glow {
  transform-box: fill-box;
  transform-origin: center;
  fill: var(--season-glow);
  fill-opacity: 0.28;
  animation: seasons-pulse 2.6s ease-in-out infinite;
}

.trail-token {
  will-change: transform;
}

@keyframes seasons-pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.4;
  }

  50% {
    transform: scale(1.14);
    opacity: 0.75;
  }
}

/* ==================== Question ==================== */
.question-block {
  padding: 16px;
  border: 1px solid var(--sn-border);
  border-radius: var(--sn-radius);
  background: var(--sn-surface);
  text-align: center;
}

.question-tag {
  margin-bottom: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--season-accent-ink);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.question-prompt {
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  color: var(--sn-ink);
}

body.is-glowing-question .question-prompt {
  text-shadow: 0 0 18px var(--season-glow);
}

/* The whole wrapper is hidden for an untimed season, not just the number --
   hiding the number alone would leave a full, frozen bar on screen. */
.timer-wrap {
  display: flex;
  gap: 10px;
  align-items: center;
  max-width: 420px;
  margin: 14px auto 4px;
}

.timer-track {
  flex: 1;
  height: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--sn-surface-alt);
}

.timer-bar {
  height: 100%;
  width: 100%;
  background: var(--sn-primary);
  transition: width 0.1s linear;
}

.timer-bar.is-low {
  background: var(--sn-wrong);
}

/* aria-hidden in the markup: a number changing ten times a second is noise to
   a screen reader, and the question itself is the live region that matters. */
.timer {
  min-width: 2.2ch;
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--sn-ink-muted);
  text-align: right;
}

.choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  max-width: 480px;
  margin: 18px auto 0;
}

/* Bordered in the primary green, not the hairline border colour: at 1.45:1
   against the page the old border was below the 3:1 that a control boundary
   needs, and the buttons read as faint tinted rectangles. */
.choice {
  min-height: var(--sn-tap);
  border: 2px solid var(--sn-primary);
  border-radius: var(--sn-radius);
  background: var(--sn-surface-alt);
  color: var(--sn-ink);
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition:
    transform 0.1s ease,
    border-color 0.15s ease;
}

.choice:hover:not(.is-locked),
.choice:focus-visible {
  border-color: var(--sn-primary);
  outline: none;
}

.choice:active:not(.is-locked) {
  transform: scale(0.95);
}

.choice.is-locked {
  cursor: default;
}

/* Dim the two buttons that are neither right nor the one just pressed, so
   only the meaningful ones stay lit. */
.choice.is-locked:not(.is-correct, .is-wrong) {
  opacity: 0.45;
}

.choice.is-correct {
  border-color: var(--sn-correct);
  background: var(--sn-correct-bg);
  color: var(--sn-correct-on-tint);
}

.choice.is-wrong {
  border-color: var(--sn-wrong);
  background: var(--sn-wrong-bg);
  color: var(--sn-wrong-on-tint);
}

/* A glyph as well as a hue. Red/green alone fails for the ~1 boy in 12 with a
   colour vision deficiency, and the shake that used to carry the difference is
   switched off under prefers-reduced-motion -- which left hue as the only
   signal for exactly the users least able to use it. */
.choice.is-correct::after,
.choice.is-wrong::after {
  margin-left: 0.4em;
  font-size: 0.8em;
}

.choice.is-correct::after {
  content: "✓";
}

.choice.is-wrong::after {
  content: "✗";
}

.feedback {
  min-height: 1.5em;
  margin-top: 14px;
  font-size: 1rem;
  font-weight: 600;
}

.feedback.success {
  color: var(--sn-correct);
}

.feedback.error {
  color: var(--sn-wrong);
}

/* BaseGameUI.shakeElement adds this class. */
.shake {
  animation: seasons-shake 0.4s ease;
}

@keyframes seasons-shake {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-7px);
  }

  75% {
    transform: translateX(7px);
  }
}

/* ==================== Result ==================== */
.result-text {
  max-width: 56ch;
  margin: 0 auto 20px;
  font-size: 1.05rem;
  font-style: italic;
  line-height: 1.55;
  color: var(--sn-ink-muted);
  text-align: center;
}

.result-summary {
  max-width: 420px;
  margin: 0 auto 24px;
  border: 1px solid var(--sn-border);
  border-radius: var(--sn-radius);
  background: var(--sn-surface);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--sn-border);
}

.summary-row:last-child {
  border-bottom: none;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
}

.big-btn {
  min-height: var(--sn-tap);
  padding: 0 26px;
  border: 2px solid var(--sn-border);
  border-radius: var(--sn-radius);
  background: var(--sn-surface);
  color: var(--sn-ink);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
}

.big-btn.is-primary {
  border-color: var(--sn-primary);
  background: var(--sn-primary);
  color: var(--sn-primary-ink);
}

.big-btn:active {
  transform: scale(0.96);
}

/* ==================== Short screens ==================== */

/* An iPad in landscape is 768px tall, and the demand bar, the trail and the
   question block together overflowed it -- which put the answer buttons below
   the fold on the one screen the game is actually played on. This tightens the
   vertical rhythm rather than shrinking any single piece. */
@media (height <= 820px) {
  .game-main {
    padding: 10px 16px;
  }

  .trail {
    margin: 10px 0;
  }

  .demand-bar,
  .question-block {
    padding: 10px 16px;
  }

  .question-prompt {
    font-size: clamp(1.8rem, 6vw, 2.5rem);
  }

  .timer-wrap {
    margin: 10px auto 2px;
  }

  .choices {
    gap: 12px;
    margin-top: 12px;
  }

  .feedback {
    margin-top: 8px;
  }
}

/* ==================== Narrow screens ==================== */
@media (width <= 480px) {
  .game-main {
    padding: 12px;
  }

  .demand-bar {
    gap: 10px;
    padding: 10px 12px;
  }

  .villain-portrait {
    width: 48px;
    height: 48px;
  }

  .choices {
    gap: 12px;
  }

  :root {
    --sn-tap: 60px;
  }
}

/* ==================== Reduced motion ==================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
