/* "Your first generation" walkthrough (first-generation.html). Builds on styles.css tokens; the page
   scrolls like the cheat sheet (<html class="sheet">). Phone: narration, then the 4 seats 2×2, then the
   board, with the controls fixed at the bottom. From 1100px: seats around the board, narration on the right. */

/* --bar-h: height of the sticky header, measured by sim.js (ResizeObserver); 64px until then. It replaces
   the guide's bottom-bar value from styles.css, which this page doesn't use. Focused and scrolled-to
   elements stop below the header. */
html.sheet { --bar-h: 64px; scroll-padding-top: var(--bar-h); }

.sim-page {
  --p4: #7dd3fc; /* your colour (seat 4); p1–p3 come from styles.css */
  min-height: 100%;
  font-size: 15px;
  line-height: 1.45;
}
.c-p4 { fill: var(--p4); color: var(--p4); }

.sim-main {
  position: relative; /* above the fixed .sky */
  max-width: calc(var(--sheet-max) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 max(var(--gutter), env(safe-area-inset-right)) 16px max(var(--gutter), env(safe-area-inset-left));
}
.sim-kicker { margin: 14px 0 10px; }
.sim-page .noscript a { color: var(--ink); }

.sim-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }

/* ---------- narration ---------- */
.sim-story {
  min-width: 0;
  padding: 14px 16px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 30px #0006;
}
.story-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.phase-pill {
  padding: 2px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--mars) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--mars) 55%, transparent);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.story-count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.story-title { margin: 4px 0 6px; font-size: clamp(1.25rem, 1rem + 1vw, 1.6rem); line-height: 1.15; letter-spacing: -.01em; scroll-margin-top: 8px; } /* + the html scroll-padding (header) */
.story-title:focus { outline: none; }
.story-text p { margin: 0 0 8px; }
.story-text p + p { color: var(--muted); }
.story-text .story-prompt { color: var(--gold); font-weight: 600; }

.progress { height: 6px; border-radius: 3px; background: #0d1530; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--mars-2), var(--mars)); transition: width .4s var(--out); }

.sim-controls {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.sim-controls [data-auto] { justify-self: center; min-width: 120px; }
.sim-controls [data-auto][aria-pressed="true"] { border-color: var(--gold); color: var(--gold); }
.sim-controls .progress-bar { grid-column: 1 / -1; }
.sim-keys { margin: 8px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

.story-end { margin-top: 10px; }
.story-end .learned { font-size: 14px; }

/* ---------- your choice panel ---------- */
.choice { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.choice-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.choice-mc { display: inline-flex; align-items: center; gap: 4px; color: var(--ink); font-size: 16px; }
.choice-mc b { color: var(--gold); font-variant-numeric: tabular-nums; }
.choice-mc .ico { width: 18px; height: 18px; }
.opt-group h3 { margin: 10px 0 6px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: 6px; }
.opt {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  min-height: 44px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0d1530;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition: background .2s, border-color .2s, transform .2s var(--back);
}
.opt:hover:not([aria-disabled="true"]) { background: #1d2a52; border-color: var(--gold); }
.opt:active:not([aria-disabled="true"]) { transform: scale(.97); }
.opt[aria-disabled="true"] { cursor: default; }
.opt.is-illegal { opacity: .62; }
.opt-top { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; font-size: 14px; }
.opt-cost { color: var(--gold); white-space: nowrap; font-variant-numeric: tabular-nums; }
.opt-eff { color: var(--muted); }
.opt-why { color: #ffb1a3; font-size: 12px; }
.opt-chosen { color: var(--gold); font-weight: 700; font-size: 12px; }
.opt.is-chosen { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; opacity: 1; }
.opt-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; padding: 8px; border: 1px dashed var(--line); border-radius: 12px; }
.opt-sub[hidden] { display: none; }
.sub-label { width: 100%; color: var(--muted); font-size: 13px; }
.sub-n { min-width: 2ch; font-size: 18px; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }
.sub-what { color: var(--muted); font-weight: 500; }
.choice-again { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 12px 0 0; color: var(--muted); font-size: 13px; }

/* ---------- table: seats and board ---------- */
.sim-table { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; min-width: 0; }
.sim-table > .seat[data-seat="0"] { order: 1; }
.sim-table > .seat[data-seat="1"] { order: 2; }
.sim-table > .seat[data-seat="3"] { order: 3; }
.sim-table > .seat[data-seat="2"] { order: 4; }
.sim-board { order: 5; grid-column: 1 / -1; min-width: 0; }
.sim-board svg { display: block; width: 100%; height: auto; max-height: 72vh; overflow: visible; }
.board-note { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.sim-source { margin-top: 14px; }

.seat {
  position: relative;
  min-width: 0;
  padding: 8px 10px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 4px solid var(--pc, var(--line));
  border-radius: 14px;
  transition: box-shadow .3s, transform .3s var(--back), opacity .3s;
}
.seat[data-seat="3"] { background: color-mix(in srgb, var(--p4) 9%, var(--panel)); }
.seat.is-active { box-shadow: 0 0 0 2px var(--gold), 0 10px 30px #0008; transform: translateY(-2px); }
.seat.is-passed { opacity: .7; }
.seat-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; min-width: 0; } /* badges wrap below a long name */
.seat-marker { flex: none; width: 11px; height: 11px; border-radius: 3px; background: var(--pc); }
.seat-name { margin: 0; overflow: hidden; font-size: 15px; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.seat-no { color: var(--muted); font-size: 12px; font-weight: 500; }
.seat-badges { display: flex; flex: none; gap: 4px; margin-left: auto; }
.seat-first, .seat-status { padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.seat-first { background: var(--gold); color: #1a1206; }
.seat-status { border: 1px solid var(--line); background: var(--space); color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.seat-first[hidden], .seat-status[hidden] { display: none; }
.seat-corp { margin: 2px 0 6px; overflow: hidden; font-size: 13px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.seat-corp.is-unknown { color: var(--muted); font-weight: 500; font-style: italic; }
.seat-res { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; margin: 0; padding: 0; list-style: none; }
.cell {
  position: relative;
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  padding: 2px 4px 2px 5px;
  border: 1px solid #2b3a6366;
  border-radius: 8px;
  background: #0d1530;
}
.cell .ico, .seat-cards .ico { width: 16px; height: 16px; }
.amt { font-size: 15px; font-variant-numeric: tabular-nums; text-align: right; }
.pbox {
  min-width: 20px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--prod);
  color: #f6e3cf;
  font-size: 11px;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.seat-line { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 8px; margin: 6px 0 0; font-size: 13px; }
.seat-tr, .seat-cards { display: inline-flex; align-items: center; gap: 4px; padding: 0 4px; border-radius: 6px; }
.seat-tr b { color: var(--gold); font-variant-numeric: tabular-nums; }
.seat-effect { display: none; margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.3; }
.seat-played { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 0; padding: 0; list-style: none; }
.seat-played:empty { display: none; }
.seat-played li { padding: 1px 8px; border: 1px solid var(--line); border-radius: 999px; background: #0d1530; font-size: 12px; }
.seat-played .tag { color: var(--muted); }

/* a changed value flashes green (up) or red (down) */
.bump-up { animation: bump-up 1s var(--out); }
.bump-down { animation: bump-down 1s var(--out); }
@keyframes bump-up { 0% { background: color-mix(in srgb, var(--green) 50%, #0d1530); } }
@keyframes bump-down { 0% { background: color-mix(in srgb, var(--bad) 45%, #0d1530); } }

/* cubes, coins and cards flying between the seats and the board (sim.js) */
.fly-layer { position: fixed; inset: 0; z-index: 40; width: 100%; height: 100%; overflow: visible; pointer-events: none; }

@media (max-width: 559px) {
  .seat-no { display: none; } /* room for the badges on a phone */
}
@media (min-width: 560px) {
  .seat-res { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .seat-effect { display: block; }
}

/* Phone and tablet: the controls stay at the bottom of the screen. */
@media (max-width: 1099px) {
  html.sheet { scroll-padding-bottom: calc(100px + env(safe-area-inset-bottom)); } /* focus stops above the controls */
  body.sim-page { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
  .fly-layer { z-index: 20; } /* flying cubes pass under the controls */
  .sim-controls {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 30;
    margin: 0;
    padding: 18px max(var(--gutter), env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
    background: linear-gradient(to bottom, #0a0f1f00, #0a0f1fee 30%);
  }
  .sim-keys { display: none; }
}

/* Wide: seats around the board, the narration in a sticky column on the right. */
@media (min-width: 1100px) {
  .sim-layout { grid-template-columns: minmax(0, 1fr) minmax(340px, 30%); align-items: start; gap: 20px; }
  .sim-story { order: 2; position: sticky; top: calc(var(--bar-h) + 12px); max-height: calc(100dvh - var(--bar-h) - 28px); overflow-y: auto; }
  .sim-table {
    order: 1;
    grid-template-columns: minmax(180px, 1fr) minmax(0, 2fr) minmax(180px, 1fr);
    grid-template-areas: "s0 board s1" "s3 board s2";
    align-items: start;
    gap: 12px;
  }
  .sim-table > .seat[data-seat="0"] { grid-area: s0; }
  .sim-table > .seat[data-seat="1"] { grid-area: s1; }
  .sim-table > .seat[data-seat="2"] { grid-area: s2; }
  .sim-table > .seat[data-seat="3"] { grid-area: s3; }
  .sim-board { grid-area: board; }
  .sim-board svg { max-height: calc(100dvh - var(--bar-h) - 96px); }
  .seat-res { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1500px) {
  .seat-res { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .seat.is-active { transform: none; }
}
