/* The home page: a one-screen game. Tokens and resets live in tokens.css and base.css.
 *
 * Type: Instrument Serif for the headline and each question; Instrument Sans for everything else, in three styles only.
 *   body    --text-md, ink, regular       what happened, explanations, the record
 *   label   --text-sm, muted, regular     counters, names, captions, the score
 *   button  --text-md, medium
 * Medium weight otherwise marks only an answer or a value (<b>). Red marks only a tool's name and a changed answer. */

/* ---------- the screen ---------- */

.page {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.masthead .container {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-lg);
}
.wordmark { margin: 0; line-height: 0; }
/* the lockup is drawn at 100 units to the em, 95 tall */
.wordmark img { height: calc(var(--text-3xl) * 0.95); width: auto; }
.contact { font-size: var(--text-sm); color: var(--color-muted); text-decoration-color: var(--color-rule); }

.game {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: var(--gap-columns);
}

/* ---------- the panel: one decision at a time ---------- */

.side {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
  padding-block: var(--space-2xl) var(--space-xl);
  max-width: 34rem;
}
/* while the record is the thing being taught, it sits directly under its explanation */
.side.is-reading { gap: var(--space-lg); }

.meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2xs) var(--space-md);
  margin-bottom: var(--space-md);
  font-size: var(--text-sm);
  color: var(--color-muted);
}
.meta .tag-tool { color: var(--color-accent); }

.side h1 { max-width: none; font-size: clamp(2.75rem, 1.6rem + 4vw, 5rem); line-height: 0.98; }
.side h2 { max-width: 18ch; font-size: clamp(2rem, 1.2rem + 2.4vw, 3.25rem); line-height: 1.02; }

.intro .lead { margin-top: var(--space-md); max-width: 46ch; font-size: var(--text-md); line-height: inherit; }
.intro h1 + .lead { margin-top: var(--space-lg); }

.hint, .said { margin-top: var(--space-md); max-width: 46ch; }
.hint b, .said b { font-weight: 500; }
.small { margin-top: var(--space-sm); min-height: 1.55em; font-size: var(--text-sm); color: var(--color-muted); }

.actions { display: flex; flex-wrap: wrap; gap: var(--space-sm); margin-top: var(--space-lg); }

.btn {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding-inline: var(--space-lg);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-card);
  background: var(--color-accent);
  color: var(--color-accent-ink);
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--dur-short) var(--ease-out), border-color var(--dur-short) var(--ease-out), transform var(--dur-micro) var(--ease-out);
}
.btn:active { background: var(--color-accent-deep); border-color: var(--color-accent-deep); transform: translateY(1px); }
.btn:focus-visible { outline-offset: 3px; }
.btn.ghost { background: none; border-color: var(--color-rule); color: var(--color-ink); }
.btn.ghost:active { background: var(--color-paper-2); border-color: var(--color-muted); }
.btn.is-wrong { animation: shake 260ms var(--ease-out); }
@keyframes shake { 25% { transform: translateX(-4px); } 60% { transform: translateX(3px); } }

.is-busy .btn { pointer-events: none; opacity: 0.55; }

/* a tool is taught in its own block, under its own name, apart from the decision above it */
.toolbox { margin-top: var(--space-lg); padding-top: var(--space-md); border-top: 1px solid var(--color-rule); }
.toolname { font-size: var(--text-sm); color: var(--color-accent); }
.toolbox .hint { margin-top: var(--space-2xs); }
.toolbox .hint + .hint { margin-top: var(--space-sm); }

/* the workflow, drawn as the steps an agent must pass through */
.machine {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs) 0;
  margin: var(--space-lg) 0 0;
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
}
.machine li {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 36px;
  padding-inline: var(--space-sm);
  border: 1px solid var(--color-ink-2);
  border-radius: var(--radius-card);
  transition: background-color var(--dur-micro) var(--ease-out), color var(--dur-micro) var(--ease-out), border-color var(--dur-micro) var(--ease-out);
}
.machine li + li { margin-left: 20px; }
.machine li + li::before {
  content: "";
  position: absolute;
  right: 100%;
  top: 50%;
  width: 20px;
  border-top: 1px solid var(--color-ink-2);
}
.machine li.is-empty { border-style: dashed; border-color: var(--color-rule); color: var(--color-muted); }
.machine li.is-done { border-color: var(--color-accent); color: var(--color-accent); }
.machine li.is-on { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-accent-ink); }

.chips { display: flex; flex-wrap: wrap; gap: var(--space-xs); margin-top: var(--space-lg); }
.chips .btn { min-height: 44px; padding-inline: var(--space-md); }

/* reruns of the locked workflow: one row per changed fact, one cell per changed number */
.reruns, .sweep { margin: var(--space-md) 0 0; padding: 0; list-style: none; }
.sweep { font-size: var(--text-sm); }
.reruns:has(li:not([hidden])) { border-top: 1px solid var(--color-rule); }
.reruns li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 var(--space-md); padding-block: var(--space-xs); border-bottom: 1px solid var(--color-rule); }
.reruns li[hidden] { display: none; }
.reruns b, .sweep b { font-weight: 500; }
.reruns .is-changed b, .sweep .is-changed b { color: var(--color-accent); }

.sweep { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: var(--space-3xs); max-width: 30rem; }
.sweep li { display: flex; flex-direction: column; align-items: center; gap: var(--space-3xs); padding-block: var(--space-xs); border: 1px solid var(--color-rule); border-radius: var(--radius-card); }
.sweep span { color: var(--color-muted); font-variant-numeric: tabular-nums; }
.sweep .is-base { border-color: var(--color-ink-2); }
.sweep .is-changed { border-color: var(--color-accent); }
.sweep .is-pending { border-color: var(--color-rule); }
.sweep .is-pending b { visibility: hidden; }

@media (hover: hover) and (pointer: fine) {
  .btn:hover { background: var(--color-accent-deep); border-color: var(--color-accent-deep); }
  .btn.ghost:hover { background: var(--color-paper-2); border-color: var(--color-muted); }
  .contact:hover { color: var(--color-ink); text-decoration-color: var(--color-accent); }
}

/* ---------- the record ---------- */

.ledger h3 { font-family: var(--font-body); font-size: var(--text-sm); font-weight: 400; letter-spacing: 0; color: var(--color-muted); }
.ledger ol { display: grid; gap: var(--space-xs); margin: var(--space-xs) 0 0; padding: 0; list-style: none; }

/* each decision is a card; one the workflow made opens, one made on gut is an empty outline */
.entry { border: 1px solid var(--color-rule); border-radius: var(--radius-card); background: var(--color-paper); transition: border-color var(--dur-short) var(--ease-out); }
.entry.is-open { border-color: var(--color-ink-2); }
.entry.is-gut { border-style: dashed; }
.entry .row {
  display: flex;
  gap: var(--space-sm);
  align-items: baseline;
  width: 100%;
  min-height: 48px;
  margin: 0;
  padding: var(--space-sm) var(--space-md);
  border: 0;
  background: none;
  color: var(--color-ink);
  text-align: left;
}
.entry button.row { cursor: pointer; }
.entry .num { color: var(--color-muted); font-variant-numeric: tabular-nums; }
.entry .what { flex: 1; min-width: 0; }
.entry small { display: block; font-size: var(--text-sm); color: var(--color-muted); }
.entry.is-gut .what { color: var(--color-muted); }
/* the word that says the card opens */
.entry .more { font-size: var(--text-sm); color: var(--color-ink); text-decoration: underline; text-decoration-color: var(--color-rule); text-underline-offset: 0.2em; }

.entry .why { margin: 0; padding: var(--space-sm) var(--space-md) var(--space-md); border-top: 1px solid var(--color-rule); }
.entry .why div { display: grid; grid-template-columns: 5.5em minmax(0, 1fr); gap: var(--space-sm); }
.entry .why div + div { margin-top: var(--space-xs); }
.entry .why dt { font-size: var(--text-sm); line-height: 1.8; color: var(--color-muted); }
.entry .why dd { margin: 0; }

.ledger.is-asked h3 { display: none; }
@media (hover: hover) and (pointer: fine) {
  .entry:has(button.row:hover) { border-color: var(--color-muted); }
  .entry button.row:hover .more { text-decoration-color: var(--color-accent); }
}

/* ---------- the board ---------- */

/* it keeps its own height, so a longer decision never resizes the picture */
.board {
  position: sticky;
  top: var(--space-md);
  align-self: start;
  display: flex;
  flex-direction: column;
  height: clamp(440px, 100dvh - 150px, 780px);
  margin: 0;
}
.plot { position: relative; flex: 1; min-height: 0; }
.plot canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: manipulation; }

.hud {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-lg);
  padding-block: var(--space-sm);
  font-size: var(--text-sm);
  color: var(--color-muted);
}
.hud b { color: var(--color-ink); font-weight: 500; }

.tag {
  position: absolute;
  left: var(--rx, 85%);
  top: var(--ry, 30%);
  z-index: var(--z-raised);
  transform: translateX(-50%);
  font-size: var(--text-sm);
  color: var(--color-muted);
  pointer-events: none;
  transition: opacity var(--dur-long) var(--ease-out);
}
.board.is-flooded .tag { opacity: 0; }

/* ---------- colophon ---------- */

.colophon .container {
  padding-block: var(--space-md) var(--space-lg);
  font-size: var(--text-sm);
  color: var(--color-muted);
}

.noscript { margin-top: var(--space-lg); max-width: 46ch; }

/* ---------- narrow: the board stays in view above the decision ---------- */

@media (max-width: 56rem) {
  .masthead .container { min-height: 56px; }
  .wordmark img { height: 28px; }
  .game { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .board {
    order: -1;
    top: 0;
    z-index: var(--z-sticky);
    height: clamp(260px, 42dvh, 420px);
    background: var(--color-paper);
    border-bottom: 1px solid var(--color-rule);
  }
  .hud { flex-direction: column; gap: 0; padding-block: var(--space-xs) 0; }
  .side { gap: var(--space-lg); padding-block: var(--space-lg) var(--space-xl); }
  .side h1 { font-size: clamp(2.5rem, 1.6rem + 5vw, 3.5rem); }
  .side h2 { font-size: clamp(1.75rem, 1.2rem + 3vw, 2.5rem); }
}
