:root {
  color-scheme: light;
  --paper: #eef2ec;
  --panel: #fbfcf8;
  --ink: #17231d;
  --muted: #65736b;
  --line: #cbd5cd;
  --green: #16724b;
  --green-soft: #dcebe1;
  --blue: #2a628f;
  --yellow: #e8b746;
  --orange: #c96c33;
  --red: #a63e35;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.4;
}
button { font: inherit; }
h1, h2, p { margin-top: 0; }
h1 { margin: 0; font-size: clamp(1.45rem, 3.4vw, 2.55rem); line-height: 1.08; letter-spacing: -0.04em; }
h2 { margin: 0; font-size: 1rem; letter-spacing: -0.02em; }
.topbar, main, footer { width: min(72rem, calc(100% - 2rem)); margin-inline: auto; }
.topbar { display: flex; justify-content: space-between; gap: 1rem; padding: 0.9rem 0; border-bottom: 1px solid var(--line); }
.brand { color: var(--ink); font-weight: 950; letter-spacing: 0.16em; text-decoration: none; }
.topbar-actions { display: flex; align-items: center; gap: 0.8rem; }
.feedback-entry { padding: 0.3rem 0.55rem; color: white; background: var(--green); font-size: 0.72rem; font-weight: 850; text-decoration: none; }
.freshness { color: var(--muted); font-size: 0.72rem; text-align: right; }
main { padding-bottom: 1rem; }
main > section { margin-top: 1rem; }
.feedback-boundary { margin-top: 0.65rem; color: var(--muted); font-size: 0.7rem; }
.eyebrow { display: block; margin-bottom: 0.25rem; color: var(--muted); font-size: 0.61rem; font-weight: 900; letter-spacing: 0.13em; text-transform: uppercase; }

.needs-alai { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.75rem 1rem; border: 1px solid var(--green); background: var(--green-soft); }
.needs-alai > .eyebrow { margin: 0; color: var(--green); }
.needs-alai div { display: flex; align-items: baseline; gap: 0.8rem; }
.needs-alai p { margin: 0; color: var(--muted); font-size: 0.8rem; }
.needs-alai.urgent { color: white; border-color: var(--red); background: var(--red); }
.needs-alai.urgent .eyebrow, .needs-alai.urgent p { color: white; }

.command-board, .portfolio, .goal-detail, .portfolio-path, .history { border: 1px solid var(--line); background: var(--panel); }
.command-board { padding: clamp(0.8rem, 2.5vw, 1.5rem); }
.board-heading, .section-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.board-heading h1 {
  display: -webkit-box;
  max-width: 48rem;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.goal-state, .liveness, .health-state { padding: 0.34rem 0.58rem; color: white; background: var(--green); font-size: 0.68rem; font-weight: 900; letter-spacing: 0.06em; }
.board-grid { display: grid; grid-template-columns: minmax(20rem, 1.2fr) minmax(16rem, 0.8fr); align-items: center; gap: 1rem; margin-top: 0.5rem; }
.loop-wrap { min-width: 0; }
.deming-loop { display: block; width: min(100%, 31rem); max-height: 25rem; margin: auto; }
.loop-arrows path { fill: none; stroke: var(--line); stroke-width: 4; marker-end: url(#arrow); }
.loop-arrows marker path { fill: var(--muted); }
.loop-step circle { fill: var(--panel); stroke: var(--line); stroke-width: 3; }
.loop-step text { fill: var(--muted); font-size: 12px; font-weight: 850; text-anchor: middle; dominant-baseline: middle; }
.loop-step.complete circle { fill: var(--green-soft); stroke: var(--green); }
.loop-step.current circle { fill: var(--green); stroke: var(--green); stroke-width: 6; }
.loop-step.current text { fill: white; font-size: 13px; }
.loop-step.next circle { stroke: var(--blue); stroke-dasharray: 4 3; }
.loop-step.next text { fill: var(--blue); }
.loop-center circle { fill: white; stroke: var(--ink); stroke-width: 2; }
.loop-center text { fill: var(--ink); text-anchor: middle; font-weight: 900; }
#loop-goal-id { fill: var(--green); font-size: 22px; }
#loop-step-name { font-size: 15px; letter-spacing: 0.08em; }
#loop-liveness { fill: var(--muted); font-size: 10px; letter-spacing: 0.06em; }
.truth-panel { min-width: 0; padding: 1rem; border-left: 1px solid var(--line); }
.condition { margin: 0.9rem 0 1rem; overflow-wrap: anywhere; font-size: clamp(1rem, 2.2vw, 1.35rem); font-weight: 760; }
.truth-facts { margin: 0; }
.truth-facts div { display: grid; grid-template-columns: 7rem 1fr; gap: 0.5rem; padding: 0.5rem 0; border-top: 1px solid var(--line); }
.truth-facts dt { color: var(--muted); font-size: 0.67rem; font-weight: 850; text-transform: uppercase; }
.truth-facts dd { margin: 0; overflow-wrap: anywhere; font-size: 0.78rem; }
body[data-liveness="WAITING"] .liveness { background: var(--blue); }
body[data-liveness="STALLED"] .liveness, body[data-liveness="BLOCKED"] .liveness { background: var(--red); }
body[data-liveness="NEEDS_ALAI"] .liveness { color: var(--ink); background: var(--yellow); }

.health-strip { display: grid; grid-template-columns: auto auto 1fr; align-items: center; gap: 0.75rem; padding-top: 0.8rem; border-top: 1px solid var(--line); }
.health-strip ul { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem; margin: 0; padding: 0; list-style: none; }
.health-strip li { padding: 0.4rem; border-left: 3px solid var(--green); background: white; font-size: 0.64rem; font-weight: 760; }
.health-strip li[data-status="DEGRADED"] { border-left-color: var(--red); background: #f7e5e1; }

.portfolio, .goal-detail, .portfolio-path, .history { padding: 1rem; }
.section-heading { margin-bottom: 0.8rem; }
.section-heading > span { color: var(--muted); font-size: 0.72rem; }
.active-goals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.55rem; }
.active-goal-card button { display: flex; align-items: center; width: 100%; padding: 0.55rem; border: 1px solid var(--line); color: var(--ink); background: white; text-align: left; cursor: pointer; }
.active-goal-card button[aria-pressed="true"] { border-color: var(--green); box-shadow: inset 0 0 0 1px var(--green); }
.mini-loop { width: 4.4rem; flex: 0 0 auto; overflow: visible; }
.mini-loop path { fill: none; stroke: var(--line); stroke-width: 2; }
.mini-loop circle { fill: white; stroke: var(--line); stroke-width: 2; }
.mini-loop .complete circle { fill: var(--green-soft); stroke: var(--green); }
.mini-loop .current circle { fill: var(--green); stroke: var(--green); stroke-width: 3; }
.mini-copy { min-width: 0; }
.mini-copy > * { display: block; }
.mini-copy strong { color: var(--green); font-size: 0.8rem; }
.mini-copy span { margin-top: 0.15rem; font-size: 0.7rem; font-weight: 850; }
.mini-copy i { margin-top: 0.15rem; color: var(--muted); font-size: 0.6rem; font-style: normal; }

.goal-statement { max-width: 60rem; margin: 0 0 1rem; overflow-wrap: anywhere; font-size: 1rem; font-weight: 720; }
.detail-grid, .todo-items { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.55rem; }
.detail-grid article, .todo-items article { min-width: 0; padding: 0.75rem; border: 1px solid var(--line); background: white; }
.detail-grid p, .todo-items p { margin: 0; overflow-wrap: anywhere; font-size: 0.78rem; }
.todo-items article > * { display: block; }
.todo-items span { margin-top: 0.25rem; color: var(--muted); font-size: 0.7rem; }
.todo-items p { margin-top: 0.5rem; }
.correction { margin-top: 0.55rem; padding: 0.75rem; border-left: 4px solid var(--orange); background: #f5e5d8; }
.correction p { margin: 0.35rem 0 0; font-size: 0.78rem; }
.goal-history { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.history-goal-card button { display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 0.7rem; border: 1px solid var(--line); color: var(--ink); background: white; cursor: pointer; }
.history-goal-card span { color: var(--muted); font-size: 0.65rem; }
.history-goal-card i { color: var(--green); font-size: 0.62rem; font-style: normal; font-weight: 900; }
footer { display: flex; justify-content: space-between; gap: 1rem; padding: 1rem 0 1.5rem; color: var(--muted); font-size: 0.68rem; }

@media (max-width: 680px) {
  .topbar, main, footer { width: min(100% - 0.8rem, 34rem); }
  .topbar { padding: 0.55rem 0; }
  .topbar-actions { align-items: end; flex-direction: column-reverse; gap: 0.25rem; }
  main > section { margin-top: 0.55rem; }
  .needs-alai { align-items: start; padding: 0.55rem 0.65rem; }
  .needs-alai div { display: block; }
  .needs-alai p { margin-top: 0.15rem; font-size: 0.68rem; }
  .command-board { padding: 0.65rem; }
  .board-heading { align-items: start; }
  .board-heading h1 { font-size: 1.05rem; -webkit-line-clamp: 2; }
  .board-grid { display: block; margin-top: 0; }
  .deming-loop { height: 17.2rem; }
  .truth-panel { display: grid; grid-template-columns: auto 1fr; align-items: start; gap: 0.5rem; padding: 0 0 0.55rem; border: 0; }
  .condition { margin: 0; font-size: 0.88rem; line-height: 1.25; }
  .truth-facts { grid-column: 1 / -1; }
  .truth-facts div { grid-template-columns: 6rem 1fr; padding: 0.3rem 0; }
  .truth-facts dd { font-size: 0.7rem; }
  .health-strip { grid-template-columns: 1fr auto; gap: 0.4rem; padding-top: 0.5rem; }
  .health-strip ul { grid-column: 1 / -1; grid-template-columns: repeat(2, 1fr); gap: 0.25rem; }
  .health-strip li { padding: 0.25rem; font-size: 0.58rem; }
  .portfolio, .goal-detail, .portfolio-path, .history { padding: 0.7rem; }
  .active-goals { grid-template-columns: repeat(2, 1fr); }
  .mini-loop { width: 3.7rem; }
  .detail-grid, .todo-items { grid-template-columns: 1fr; }
  footer { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
