/*
 * Continuity design system.
 * Shared by the story (index.html) and the engine console (live.html).
 *
 * The look is a technical datasheet: warm paper, ink, hairline rules, mono annotations
 * and one signal colour. Signal means "something changed and needs a decision"; green
 * means a check passed. Everything else is ink at different weights.
 * Light is the default; html[data-theme="dark"] swaps the tokens for graphite.
 */

/* ============================================================ tokens */
:root {
  color-scheme: light;

  /* surfaces */
  --bg: #f3f2ee;
  --bg-2: #eae8e2;
  --surface: #fbfaf8;
  --line: rgba(22, 21, 19, 0.09);
  --line-2: rgba(22, 21, 19, 0.17);

  /* ink */
  --ink: #161513;
  --ink-2: #44423d;
  --muted: #7b7871;
  --faint: #b5b2aa;

  /* signal */
  --signal: #e2501d;
  --signal-ink: #b93c10;
  --signal-bg: rgba(226, 80, 29, 0.08);
  --ok: #2c7a4b;
  --ok-bg: rgba(44, 122, 75, 0.09);

  --on-ink: #f3f2ee;
  --nav-bg: rgba(243, 242, 238, 0.82);
  --shadow: 0 1px 0 rgba(22, 21, 19, 0.04), 0 12px 32px -18px rgba(40, 32, 20, 0.22);

  /* type */
  --sans: "Geist", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;

  /* motion + layout */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --gutter: clamp(16px, 4vw, 40px);
  --maxw: 1200px;
  --r-sm: 6px;
  --r: 10px;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0f0f0e;
  --bg-2: #0a0a09;
  --surface: #171716;
  --line: rgba(236, 234, 228, 0.08);
  --line-2: rgba(236, 234, 228, 0.15);

  --ink: #eceae4;
  --ink-2: #b8b5ad;
  --muted: #838079;
  --faint: #4b4945;

  --signal: #ff6a3d;
  --signal-ink: #ff8a64;
  --signal-bg: rgba(255, 106, 61, 0.1);
  --ok: #5dc48a;
  --ok-bg: rgba(93, 196, 138, 0.1);

  --on-ink: #0f0f0e;
  --nav-bg: rgba(15, 15, 14, 0.8);
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 12px 32px -18px rgba(0, 0, 0, 0.6);
}

/* ============================================================ base */
* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  background: var(--bg);
}

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.55 var(--sans);
  font-feature-settings: "ss01", "cv11";
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.3s, color 0.3s;
}

::selection { background: var(--ink); color: var(--on-ink); }

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 3px; border-radius: 4px; }

.mono { font-family: var(--mono); }
code { font-family: var(--mono); font-size: 0.92em; }
.dim { color: var(--faint); }

.skip {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 90;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  background: var(--ink);
  color: var(--on-ink);
  font: 500 13px var(--mono);
  transform: translateY(-150%);
}
.skip:focus { transform: none; }

/* ============================================================ layout + small parts */
.wrap {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* mono label, the house style for every small heading */
.label {
  font: 500 11px/1.2 var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 24px;
  padding: 0 9px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  font: 500 11px/1 var(--mono);
  color: var(--ink-2);
  white-space: nowrap;
}

.dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.dot.on { background: var(--ok); animation: breathe 2.4s var(--ease-in-out) infinite; }
.dot.warn { background: var(--signal); }
@keyframes breathe { 50% { opacity: 0.35; } }

/* ============================================================ buttons */
.btn {
  --h: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: var(--h);
  padding: 0 16px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: 500 14px/1 var(--sans);
  letter-spacing: -0.005em;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.16s var(--ease), background 0.2s, border-color 0.2s, color 0.2s;
}
.btn:hover { border-color: var(--ink-2); }
.btn:active { transform: scale(0.97); }

.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.btn.primary:hover { background: var(--ink-2); border-color: var(--ink-2); }

.btn.signal { background: var(--signal); border-color: var(--signal); color: #fff; }
.btn.signal:hover { background: var(--signal-ink); border-color: var(--signal-ink); }

.btn .arrow { transition: transform 0.25s var(--ease); }
.btn:hover .arrow { transform: translateX(2px); }

.btn:disabled { opacity: 0.4; cursor: default; transform: none; }

.kbd {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border: 1px solid currentColor;
  border-radius: 4px;
  font: 500 10.5px/1 var(--mono);
  opacity: 0.6;
}

/* theme switch: a plain mono word, not a sun/moon */
.theme-btn {
  height: 28px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  font: 500 11.5px/1 var(--mono);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}
.theme-btn:hover { color: var(--ink); background: var(--line); }

/* ============================================================ logo */
.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
/* A φ:1 rectangle tiled into squares, one quarter disc each; the gaps keep the tiling visible.
   Each square is a shift, each 1/φ the last; the live one is signal. Construction: brand.html */
.logo svg { width: 23px; height: 14px; }
.logo .l-face { fill: var(--ink); }
.logo .l-live { fill: var(--signal); }
.logo small {
  font: 500 11px/1 var(--mono);
  letter-spacing: 0;
  color: var(--muted);
}

/* ============================================================ state board (cards) */
.board { display: grid; gap: 8px; font-size: 13px; }

.b-card {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  transition: border-color 0.5s var(--ease), box-shadow 0.5s var(--ease);
}
.b-card.hot { border-color: var(--signal); box-shadow: inset 3px 0 0 var(--signal); }
.b-card.bad { border-color: var(--signal); box-shadow: inset 3px 0 0 var(--signal); }

.b-h {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font: 500 11px/1 var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.b-h b { font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--ink-2); }
.b-card.bad .b-h b { color: var(--signal-ink); }

.b-top { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; align-items: center; }

/* who acts next */
.actor {
  display: inline-flex;
  align-items: baseline;
  font: 600 32px/0.95 var(--sans);
  letter-spacing: -0.045em;
  color: var(--ink);
}
.actor.us   { color: var(--signal); }
.actor.human { color: var(--signal); }
.actor.none { color: var(--ok); }
.actor-why { font-size: 12.5px; line-height: 1.45; color: var(--ink-2); }

/* requirement checks */
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.check {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 7px 9px;
  border-radius: var(--r-sm);
  background: var(--bg);
  font-size: 12px;
  line-height: 1.3;
  color: var(--ink-2);
  transition: background 0.4s, color 0.4s;
}
.check i,
.light i {
  flex: none;
  width: 7px;
  height: 7px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--faint);
  transition: background 0.4s;
}
.check.pass i,
.light.pass i { background: var(--ok); }
.check.fail { background: var(--signal-bg); color: var(--signal-ink); }
.check.fail i,
.light.fail i { background: var(--signal); animation: blink 1.1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

.light { display: flex; align-items: flex-start; gap: 9px; line-height: 1.35; color: var(--ink-2); }
.light.fail { color: var(--signal-ink); }

.conflict-line {
  margin-top: 10px;
  font: 12px/1.45 var(--mono);
  color: var(--signal-ink);
}

/* term rows (must precede .loop/.doc, which reuse the .row flash class) */
.rows { display: grid; }
.row {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.4fr) auto;
  gap: 10px;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row .k {
  overflow: hidden;
  font: 12px/1.3 var(--mono);
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row .v { min-width: 0; font-weight: 500; color: var(--ink); }
.row .src { font: 11px/1 var(--mono); color: var(--faint); white-space: nowrap; }
.row .was {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: var(--signal);
}
.row.flash { animation: flash 1.8s var(--ease); }
@keyframes flash {
  0%   { background: var(--signal-bg); }
  100% { background: transparent; }
}

/* open loops */
.loop {
  display: flex;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--ink-2);
}
.loop:last-child { border-bottom: 0; }
.loop b { font-weight: 500; color: var(--ink); }
.loop .closes { color: var(--muted); font: 11px var(--mono); }

/* status tags: square, mono */
.tag {
  height: fit-content;
  padding: 3px 5px;
  border-radius: 4px;
  background: var(--bg-2);
  color: var(--ink-2);
  font: 500 10px/1.2 var(--mono);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}
.tag.open,
.tag.stale,
.tag.partially_stale,
.tag.fail { background: var(--signal-bg); color: var(--signal-ink); }
.tag.ok,
.tag.current,
.tag.fulfilled,
.tag.answered { background: var(--ok-bg); color: var(--ok); }
.tag.superseded { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1px var(--line-2); }

/* documents */
.doc { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.doc:last-child { border-bottom: 0; }
.doc .fn { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.doc .fn span {
  overflow: hidden;
  font: 12px var(--mono);
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc .fn .tag { flex: none; }
.doc .st { margin-top: 5px; font: 11.5px/1.45 var(--mono); }
.doc .st.ok { color: var(--ok); }
.doc .st.bad { color: var(--signal-ink); }

/* helpers */
.empty { font: 12px var(--mono); color: var(--muted); }
.clamp  { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.clamp1 { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; overflow: hidden; }
.b-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ============================================================ the thread (svg from board.js) */
.thread-svg { display: block; width: 100%; height: 150px; overflow: visible; }
.thr-future { stroke: var(--line-2); }
.thr-past { stroke: var(--ink); }
.thr-gapline { stroke: var(--faint); }
.thr-t { font: 500 12px var(--mono); fill: var(--ink-2); }
.thr-t.small { font-size: 11px; font-weight: 400; }
.thr-t.sub { fill: var(--muted); }
.thr-t.muted,
.thr-t .muted { fill: var(--faint); }

.thr-node .thr-dot { fill: var(--bg); stroke: var(--faint); stroke-width: 1; }
.thr-node.lit .thr-dot { fill: var(--ink); stroke: var(--ink); }
.thr-node.lit.out .thr-dot { fill: var(--bg); stroke: var(--ink); stroke-width: 1.5; }
.thr-node.hot .thr-dot { fill: var(--signal); stroke: var(--signal); }
.thr-ring {
  fill: none;
  stroke: var(--signal);
  transform-box: fill-box;
  transform-origin: center;
  animation: ring 1.6s var(--ease) infinite;
}
@keyframes ring {
  0%   { opacity: 1; transform: scale(0.4); }
  100% { opacity: 0; transform: scale(1.4); }
}

.thr-agent .thr-life { fill: var(--ink); }
.thr-agent .thr-stem { stroke: var(--ink); opacity: 0.35; }
.thr-agent .thr-name { fill: var(--ink); }
.thr-agent.done .thr-life { fill: var(--muted); }
.thr-agent.done .thr-name { fill: var(--ink-2); }
.thr-agent.killed .thr-life { fill: var(--signal); opacity: 0.55; }
.thr-agent.killed .thr-stem { stroke: var(--signal); }
.thr-agent.killed .thr-name { fill: var(--signal-ink); }
.thr-agent .thr-x { stroke: var(--signal); }
.thr-pulse {
  fill: var(--ink);
  transform-box: fill-box;
  transform-origin: center;
  animation: thrpulse 1.4s var(--ease-in-out) infinite;
}
@keyframes thrpulse { 50% { opacity: 0.3; transform: scale(1.7); } }

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