/* ============================================================
   PROGRESSIVE TREE 0.1E
   Theme tokens first — replace palette values here only
   ============================================================ */

:root {
  /* Shared structural tokens */
  --font-sans: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", "SF Mono", ui-monospace, monospace;
  --radius: 2px;
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--decision);

  /* Motion (overridden by controls) */
  --motion-scale: 1;
  --ack-ms: 150ms;
  --travel-ms: 320ms;
  --arrive-ms: 240ms;
  --retract-ms: 200ms;
  --theme-ms: 420ms;   /* palette changes ease, never flash */
  --settle-ms: 480ms;  /* ack: options settle into selected / inactive */

  /* Geometry (overridden by controls) */
  --branch-spread: 90px;
  --vertical-space: 48px;
  --line-weight: 1.5px;

  /* Waiting */
  --waiting-mode: static;

  /* One connector colour per theme, derived from the palette so it follows
     theme switches with a single CSS transition and is never animated. */
  --line: color-mix(in srgb, var(--ink) 36%, var(--bg));
}

/* ---------- 01 DARK / LEMON ---------- */
[data-theme="dark-lemon"] {
  --bg: #0c0c0c;
  --bg-elevated: #141414;
  --ink: #f2f2f0;
  --ink-muted: #8a8a84;
  --information: #f2f2f0;
  --possibility: #3d3d38;
  --decision: #ffee00;
  --history: #5c5c56;
  --connector: #ffee00;
  --connector-history: #3a3a36;
  --choice-bg: transparent;
  --choice-border: #3d3d38;
  --choice-hover: #1f1f1c;
  --selected-bg: #ffee00;
  --selected-ink: #0c0c0c;
  --waiting-cue: #ffee00;
  --control-bg: #141414;
  --control-border: #2a2a28;
}

/* ---------- 02 LIGHT / ANNA ---------- */
[data-theme="light-anna"] {
  --bg: #f7f5f0;
  --bg-elevated: #ffffff;
  --ink: #1a1a18;
  --ink-muted: #6b6b64;
  --information: #1a1a18;
  --possibility: #c8d4d0;
  --decision: #2d5f67;
  --history: #8a9a96;
  --connector: #2d5f67;
  --connector-history: #c8d4d0;
  --choice-bg: transparent;
  --choice-border: #c8d4d0;
  --choice-hover: #e8eeec;
  --selected-bg: #2d5f67;
  --selected-ink: #f7f5f0;
  --waiting-cue: #2d5f67;
  --control-bg: #ffffff;
  --control-border: #d8d4cc;
}

/* ---------- 03 ANNA × LEMON JUICE ---------- */
[data-theme="anna-lemon"] {
  --bg: #0f1210;
  --bg-elevated: #171b18;
  --ink: #f0f2f0;
  --ink-muted: #8a928c;
  --information: #f0f2f0;       /* white = information */
  --possibility: #eeabee;       /* Anna teal = possibility */
  --decision: #ffee00;          /* Lemon = selected / illumination */
  --history: #4a524e;           /* gray = history */
  --connector: #ffee00;
  --connector-history: #2a322e;
  --choice-bg: transparent;
  --choice-border: #eeabee;
  --choice-hover: #152825;
  --selected-bg: #ffee00;
  --selected-ink: #0f1210;
  --waiting-cue: #769e79;
  --control-bg: #171b18;
  --control-border: #2a322e;
}

/* ============================================================
   Base
   ============================================================ */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--theme-ms) ease, color var(--theme-ms) ease;
}

/* ============================================================
   Lab chrome
   ============================================================ */

.lab {
  display: grid;
  grid-template-columns: 220px 1fr 200px;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header header header"
    "controls specimen inspector";
  min-height: 100dvh;
  gap: 0;
}

.lab-header {
  grid-area: header;
  display: flex;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--control-border);
  background: var(--bg-elevated);
  transition: background-color var(--theme-ms) ease, border-color var(--theme-ms) ease;
}

.lab-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.lab-mark {
  font-size: 22px;
  line-height: 1;
}

.lab-header h1 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.lab-sub {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
}

/* Controls */

.controls {
  grid-area: controls;
  padding: 16px 14px;
  border-right: 1px solid var(--control-border);
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  transition: background-color var(--theme-ms) ease, border-color var(--theme-ms) ease;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-group > label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.theme-switch,
.waiting-switch {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.theme-btn,
.waiting-btn {
  appearance: none;
  border: 1px solid var(--control-border);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  padding: 7px 10px;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 120ms ease, border-color 120ms ease;
}

.theme-btn:hover,
.waiting-btn:hover {
  background: var(--choice-hover);
}

.theme-btn.is-active,
.waiting-btn.is-active {
  border-color: var(--decision);
  background: color-mix(in srgb, var(--decision) 12%, transparent);
  color: var(--ink);
}

.theme-btn:focus-visible,
.waiting-btn:focus-visible,
.reset-btn:focus-visible,
.choice:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--decision);
  height: 4px;
}

.control-hint {
  font-size: 11px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.reset-btn {
  appearance: none;
  border: 1px solid var(--control-border);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: var(--radius);
  width: 100%;
}

.reset-btn:hover {
  border-color: var(--decision);
  background: color-mix(in srgb, var(--decision) 10%, transparent);
}

/* Inspector */

.inspector {
  grid-area: inspector;
  padding: 16px 14px;
  border-left: 1px solid var(--control-border);
  background: var(--bg-elevated);
  overflow-y: auto;
  transition: background-color var(--theme-ms) ease, border-color var(--theme-ms) ease;
}

.inspector h2 {
  margin: 0 0 10px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

#state-view {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  color: var(--information);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ============================================================
   Specimen / Diagram
   ============================================================ */

.specimen-wrap {
  grid-area: specimen;
  position: relative;
  overflow: auto;
  padding: 40px 32px 80px;
  min-height: 0;
  transition: background-color var(--theme-ms) ease;
}

.diagram {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--vertical-space);
  min-width: min(100%, 320px);
  margin: 0 auto;
  z-index: 1;
}

/* SVG overlay — never drives layout */
.connectors {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 0;
}

/* 0.1E: a connector is born in its final colour and keeps it. Growth is
   stroke reveal only (WAAPI dashoffset); no hue or state-colour switching. */
.connectors path {
  fill: none;
  stroke: var(--line);
  stroke-width: var(--line-weight);
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  transition: stroke var(--theme-ms) ease, opacity var(--settle-ms) ease;
}

/* Twigs to options not taken recede with their words. */
.connectors path[data-dim="true"] {
  opacity: 0.4;
}

/* ============================================================
   Nodes — typographic diagram (0.1B)
   Words and lines form the interface. No cards / pills / shadows.
   ============================================================ */

.node {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  max-width: 22rem;
  text-align: center;
  opacity: 1;
  transform: translateX(var(--node-shift, 0px));
  transition: transform 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.node[data-state="inactive"],
.node[data-state="retracting"] {
  pointer-events: none;
}

/* Weight stays constant across states: a weight change reflows the label
   and moves everything under it. History is carried by colour alone. */
.node[data-state="history"] .label {
  color: var(--history);
}

.node[data-state="current"] .label {
  color: var(--information);
}

/* Question / label — large instructional type */
.label {
  font-size: clamp(1.45rem, 4.5vw, 2.15rem);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1.28;
  color: var(--information);
  white-space: pre-line;
  max-width: 18ch;
  transition: color var(--settle-ms) ease;
}

.label .price {
  display: block;
  margin-top: 0.45rem;
  font-size: clamp(1.35rem, 4.2vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  text-transform: none;
  color: var(--decision);
  transition: color var(--theme-ms) ease;
}


.detail {
  max-width: 34rem;
  margin-top: -0.35rem;
  font-family: var(--font-mono);
  font-size: clamp(0.72rem, 1.8vw, 0.86rem);
  line-height: 1.5;
  letter-spacing: 0.015em;
  color: var(--ink-muted);
  text-transform: none;
  transition: color var(--theme-ms) ease;
}

.node[data-terminal="true"]::after {
  content: "↩  tap an earlier answer to revise";
  transition: color var(--theme-ms) ease;
  margin-top: 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--history);
}

/* Choices — native buttons, visually pure typography */
.choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  /* Row gap + top margin are the lanes the fork travels in (0.1E). */
  gap: 1rem 1.5rem;
  position: relative;
  /* no padding/box that reads as a card */
  padding: 0;
  margin: 0.6rem 0 0;
}

.choice {
  appearance: none;
  -webkit-appearance: none;
  min-width: 0;
  min-height: 44px; /* touch target */
  padding: 0.35rem 0.15rem;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--ink);
  font: inherit;
  font-size: clamp(1.12rem, 3.7vw, 1.5rem);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color var(--settle-ms) ease, opacity var(--settle-ms) ease, text-decoration-color 140ms ease;
  text-decoration: none;
  text-underline-offset: 0.22em;
  text-decoration-thickness: 2px;
  white-space: pre-line;
}

/* Fixed-width glyph slot so state changes can never reflow the row. */
.choice::before {
  content: "↓";
  display: inline-block;
  width: 1.15em;
  text-align: left;
  font-weight: 400;
  opacity: 0.45;
  letter-spacing: 0;
  transition: color var(--settle-ms) ease, opacity var(--settle-ms) ease;
}

.choice:hover:not(:disabled) {
  color: var(--decision);
  background: transparent;
}

.choice:hover:not(:disabled)::before {
  opacity: 0.9;
}

.choice:focus {
  outline: none;
}

.choice:focus-visible {
  outline: none;
  text-decoration: underline;
  text-decoration-color: var(--decision);
  color: var(--decision);
}

.choice:focus-visible::before {
  opacity: 1;
  color: var(--decision);
}

/* Available on current fork */
.choice[data-state="possible"] {
  color: var(--information);
}

.choice[data-state="possible"]::before {
  color: var(--possibility);
  opacity: 0.7;
}

/* Selected — the ack and the resting history state are the same style, so
   nothing changes when growth finishes. Colour only: no weight or glyph
   swap (both reflow the row). The ↓ now points at the stem it grew. */
.choice[data-state="selected"],
.choice[data-state="history"] {
  color: var(--decision);
  background: transparent;
}

.choice[data-state="selected"]::before,
.choice[data-state="history"]::before {
  opacity: 1;
  color: var(--decision);
}

/* Alternate (non-selected) history — muted but STILL clickable for revision */
.choice[data-state="inactive"] {
  opacity: 0.4;
  color: var(--history);
  /* pointer-events remains auto — required for revision */
}

.choice[data-state="inactive"]::before {
  opacity: 0.35;
}

.choice:disabled {
  cursor: default;
}

/* Waiting cue — diagram-native, not a box-shadow card */
/* Waiting cue — out of flow so its arrival/departure never changes node
   height (0.1D: removing it collapsed the row under the fork). */
.choices::after {
  content: "◇";
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 0.5rem);
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  color: var(--waiting-cue);
  opacity: 0;
  text-align: center;
  pointer-events: none;
  transition: color var(--theme-ms) ease, opacity 160ms ease;
}

.node[data-state="current"][data-waiting="static"] .choices::after,
.node[data-state="current"][data-waiting="pulse"] .choices::after {
  opacity: 0.55;
}

.node[data-state="current"][data-waiting="pulse"] .choices::after {
  animation: waiting-tick 1.8s ease-in-out infinite;
}

@keyframes waiting-tick {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 0.85; }
}

@media (prefers-reduced-motion: reduce) {
  .node[data-state="current"][data-waiting="pulse"] .choices::after {
    animation: none;
    opacity: 0.55;
  }
}

/* Clearance fallback only (router is primary): a bg-colour halo hugging the
   glyphs, applied by JS to a text run a line still touches. */
[data-knockout="true"] {
  text-shadow:
    0 0 2px var(--bg), 0 0 3px var(--bg), 0 0 5px var(--bg), 0 0 7px var(--bg);
}

/* Terminal nodes */
.node[data-terminal="true"] .label {
  font-weight: 600;
}

/* ============================================================
   Mobile / narrow
   ============================================================ */

@media (max-width: 860px) {
  .lab {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas:
      "header"
      "controls"
      "specimen"
      "inspector";
  }

  .controls {
    border-right: none;
    border-bottom: 1px solid var(--control-border);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px 16px;
    padding: 12px 14px;
  }

  .control-group {
    min-width: 120px;
    flex: 1 1 120px;
  }

  .theme-switch,
  .waiting-switch {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .inspector {
    border-left: none;
    border-top: 1px solid var(--control-border);
    max-height: 140px;
  }

  .specimen-wrap {
    padding: 28px 16px 60px;
  }

  .diagram {
    gap: calc(var(--vertical-space) * 0.85);
  }

  /* Keep large readable type; tree grows taller/narrower */
  .label {
    font-size: clamp(1.3rem, 6vw, 1.8rem);
  }

  .choice {
    font-size: clamp(1.05rem, 4.8vw, 1.35rem);
    min-height: 44px;
  }

  .diagram {
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 400px) {
  .specimen-wrap {
    padding: 20px 12px 48px;
  }

  .node {
    max-width: calc(100% - 44px);
  }
}


/* Embedded Anna-page mode */
html,body{min-height:0}
body{overflow-x:hidden}
.embed-shell{min-height:0;background:var(--bg);color:var(--ink);transition:background-color var(--theme-ms) ease,color var(--theme-ms) ease}
.embed-head{display:flex;flex-wrap:wrap;justify-content:space-between;align-items:flex-end;gap:14px;padding:14px 16px;border-bottom:1px solid var(--control-border);font-family:var(--font-sans)}
.embed-head p{margin:0;color:var(--ink-muted);font-size:11px;letter-spacing:.08em;text-transform:uppercase}
.embed-head h1{margin:3px 0 0;font-size:14px;line-height:1.25;letter-spacing:.05em;text-transform:uppercase}
.embed-actions{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
.embed-actions .theme-btn,.embed-actions .reset-btn{width:auto;padding:6px 9px;font-size:11px;text-align:center}
.embed-hidden{display:none!important}
.specimen-wrap{position:relative;overflow:hidden;padding:34px 18px 52px;min-height:0;background:var(--bg)}
.diagram{max-width:760px;min-height:0}
.inspector{display:none}
@media(max-width:560px){.specimen-wrap{padding:26px 10px 44px;min-height:0}.label{font-size:clamp(1.25rem,7vw,1.7rem)}.choice{font-size:clamp(1rem,5vw,1.3rem)}}
