/* Cognitive Habitat — design system. "The field notebook of a living place":
   warm paper, ink, one verdigris accent; hairlines and whitespace instead of boxes. */

@font-face { font-family: "Fraunces"; src: url("/app/font-fraunces.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Inter"; src: url("/app/font-inter.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }

:root {
  --bg: #f6f3ec; --surface: #fffdf8; --surface-2: #efeae0;
  --line: #e4ddd0; --line-strong: #cfc6b5;
  --ink: #1c1a16; --ink-2: #4f4b43; --ink-3: #8b867b;
  --accent: #1f5c4d; --accent-ink: #fffdf8; --accent-soft: #dfeae4;
  --attention: #b4690e; --attention-soft: #f6e8d0;
  --danger: #a3301f; --danger-soft: #f5ddd6;
  --ok: #2e7d5b; --ok-soft: #dcefe5;
  --c1: #1f5c4d; --c2: #b4690e; --c3: #5b6b9a; --c4: #a3523f; --c5: #7a8a3c; --c6: #7d5a86;
  --k-observation: #3f6f8f; --k-self: #8a5a7a; --k-hypothesis: #b4690e; --k-outcome: #2e7d5b; --k-source: #6d6a5f;
  --font-display: "Fraunces", "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-text: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 72px;
  --r1: 6px; --r2: 12px; --r3: 20px;
  --shadow-1: 0 1px 2px rgba(40, 32, 16, .06), 0 2px 8px rgba(40, 32, 16, .04);
  --shadow-2: 0 8px 28px rgba(40, 32, 16, .14), 0 2px 6px rgba(40, 32, 16, .06);
  --ease: cubic-bezier(.2, .7, .2, 1); --dur: 200ms;
  --rail-w: 208px; --measure: 760px;
  color-scheme: light;
}
[data-theme=dark] {
  --bg: #171613; --surface: #1f1d19; --surface-2: #272520;
  --line: #33302a; --line-strong: #4a463d;
  --ink: #efeae0; --ink-2: #c0baad; --ink-3: #8b867b;
  --accent: #7fc0aa; --accent-ink: #12211c; --accent-soft: #223a33;
  --attention: #e0a04a; --attention-soft: #3a2c14;
  --danger: #e2826f; --danger-soft: #3d201a;
  --ok: #7cc49f; --ok-soft: #1d3329;
  --c1: #7fc0aa; --c2: #e0a04a; --c3: #98a6d4; --c4: #dd8f7c; --c5: #b3c26f; --c6: #b994c2;
  --k-observation: #86b4d2; --k-self: #c89ab8; --k-hypothesis: #e0a04a; --k-outcome: #7cc49f; --k-source: #aaa598;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4); --shadow-2: 0 10px 30px rgba(0,0,0,.55);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-text); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  font-feature-settings: "cv05", "cv11", "ss03";
}
h1, h2, h3, h4, p { margin: 0; }
a { color: var(--accent); text-decoration: none; text-underline-offset: 3px; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
svg.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: var(--r1); z-index: 100; }
.skip:focus { left: 8px; }

/* ── Type primitives ─────────────────────────────────────────── */
.display { font-family: var(--font-display); font-weight: 380; font-size: clamp(32px, 3.4vw, 44px); line-height: 1.1; letter-spacing: -.02em; font-variation-settings: "opsz" 144; }
.title { font-family: var(--font-display); font-weight: 420; font-size: 24px; line-height: 1.2; letter-spacing: -.012em; }
.section { font-family: var(--font-display); font-weight: 460; font-size: 18px; line-height: 1.3; letter-spacing: -.005em; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-3); }
.lede { font-size: 17px; line-height: 1.55; color: var(--ink-2); max-width: 62ch; }
.muted { color: var(--ink-3); }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum", "cv05"; }
.mono { font-family: var(--font-mono); font-size: 12.5px; }

/* ── Controls ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: var(--s2); height: 34px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); color: var(--ink);
  font-size: 13.5px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease), transform 80ms;
}
.btn:hover { border-color: var(--ink-3); background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled=true] { opacity: .5; cursor: default; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.1); background: var(--accent); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--ink-2); padding: 0 10px; }
.btn.quiet:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12.5px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: inherit; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }

.chip { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: 12px; font-weight: 500; white-space: nowrap; }
.sim { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border: 1px dashed var(--attention); border-radius: 4px; color: var(--attention); font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap; }

.seg { display: inline-flex; padding: 2px; border-radius: 999px; background: var(--surface-2); gap: 2px; }
.seg > button { border: 0; background: transparent; height: 28px; padding: 0 12px; border-radius: 999px; font-size: 12.5px; font-weight: 500; color: var(--ink-2); cursor: pointer; transition: background var(--dur) var(--ease), color var(--dur) var(--ease); }
.seg > button:hover { color: var(--ink); }
.seg > button[aria-pressed=true] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

.field, .field input, .field textarea, .field select, input.field, textarea.field, select.field { font: inherit; color: var(--ink); }
input.field, textarea.field, select.field, .field > input, .field > textarea, .field > select {
  width: 100%; padding: 8px 12px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r1);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
input.field:focus, textarea.field:focus, select.field:focus, .field > input:focus, .field > textarea:focus, .field > select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
label.field { display: grid; gap: 6px; font-size: 12.5px; color: var(--ink-2); }
::placeholder { color: var(--ink-3); }

/* ── Layout primitives ───────────────────────────────────────── */
.surface { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r2); padding: var(--s5); }
.rule { border: 0; border-top: 1px solid var(--line); margin: 0; width: 100%; }
.stack { display: flex; flex-direction: column; gap: var(--s4); }
.stack.tight { gap: var(--s2); } .stack.loose { gap: var(--s6); }
.row { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.split { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s4); }
.empty { padding: var(--s5) 0; color: var(--ink-3); font-size: 14.5px; max-width: 56ch; }
.empty strong { display: block; font-family: var(--font-display); font-weight: 440; font-size: 17px; color: var(--ink-2); margin-bottom: 4px; }
.skeleton { display: block; height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 40%, var(--surface-2) 60%); background-size: 300% 100%; animation: shimmer 1.6s linear infinite; color: transparent; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -50% 0; } }

.kind-observation { --kind: var(--k-observation); } .kind-self { --kind: var(--k-self); } .kind-hypothesis { --kind: var(--k-hypothesis); }
.kind-outcome { --kind: var(--k-outcome); } .kind-source { --kind: var(--k-source); }
.kind-observation, .kind-self, .kind-hypothesis, .kind-outcome, .kind-source { color: var(--kind); }
.kind-hypothesis { font-style: italic; }

/* ── Shell ───────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); height: 100vh; overflow: hidden; }
.rail { display: flex; flex-direction: column; padding: var(--s5) var(--s3) var(--s4); border-right: 1px solid var(--line); overflow-y: auto; }
.rail .brand { padding: 0 var(--s3) var(--s5); }
.rail .brand b { display: block; font-family: var(--font-display); font-weight: 480; font-size: 19px; letter-spacing: -.01em; line-height: 1.15; }
.rail .brand span { font-size: 12px; color: var(--ink-3); }
.rail .group { display: flex; flex-direction: column; gap: 1px; padding: var(--s3) 0; }
.rail .group + .group { border-top: 1px solid var(--line); }
.rail a.nav { position: relative; display: flex; align-items: center; gap: var(--s3); height: 36px; padding: 0 var(--s3); border-radius: var(--r1); color: var(--ink-2); font-size: 14px; font-weight: 450; transition: background var(--dur) var(--ease), color var(--dur) var(--ease); }
.rail a.nav:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.rail a.nav[aria-current=page] { color: var(--ink); font-weight: 600; }
.rail a.nav[aria-current=page]::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.rail a.nav[aria-current=page] svg { color: var(--accent); }
.rail a.nav .dot { margin-left: auto; width: 7px; height: 7px; border-radius: 50%; background: var(--attention); }
.rail .foot { margin-top: auto; padding: var(--s3); font-size: 12px; color: var(--ink-3); display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.rail .foot button { background: none; border: 0; padding: 0; color: var(--ink-3); cursor: pointer; font-size: 12px; }
.rail .foot button:hover, .rail .foot a:hover { color: var(--ink); }
.rail .foot a { color: var(--ink-3); }

.stage { position: relative; display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.topbar { display: flex; align-items: center; justify-content: flex-end; gap: var(--s4); height: 56px; padding: 0 var(--gutter); flex: none; }
.conn { margin-right: auto; display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--attention); }
.conn[hidden] { display: none; }
[hidden] { display: none !important; }
.conn::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--attention); animation: pulse 1.4s ease-in-out infinite; }
.cluster { display: flex; align-items: center; gap: var(--s4); font-size: 12.5px; color: var(--ink-2); min-width: 0; }
.cluster .who { display: inline-flex; align-items: center; gap: 8px; min-width: 0; background: none; border: 0; cursor: default; padding: 0; color: var(--ink-3); }
.cluster .who .pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--line-strong); flex: none; }
.cluster .who.live { color: var(--ink); }
.cluster .who.live .pulse { background: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
.cluster .who span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cluster .spend { display: inline-flex; flex-direction: column; gap: 3px; color: var(--ink-3); white-space: nowrap; }
.cluster .spend i { display: block; height: 2px; border-radius: 2px; background: var(--line); overflow: hidden; }
.cluster .spend i b { display: block; height: 100%; background: var(--ink-3); border-radius: 2px; transition: width 400ms var(--ease); }
.cluster .spend.over { color: var(--attention); } .cluster .spend.over i b { background: var(--attention); }
.cluster .sep { width: 1px; height: 18px; background: var(--line); }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.8); } }

.killbanner { flex: none; margin: 0 var(--gutter) var(--s3); padding: var(--s4) var(--s5); border-radius: var(--r2); background: var(--danger); color: #fff; display: flex; align-items: center; gap: var(--s5); animation: drop var(--dur) var(--ease); }
.killbanner[hidden] { display: none; }
.killbanner h2 { font-family: var(--font-display); font-weight: 480; font-size: 20px; line-height: 1.2; }
.killbanner p { font-size: 13.5px; opacity: .92; margin-top: 2px; }
.killbanner .btn { margin-left: auto; background: #fff; color: var(--danger); border-color: #fff; flex: none; }
.killbanner.resumed { background: var(--ok-soft); color: var(--ink); }
.killbanner.resumed h2 { font-size: 16px; }
@keyframes drop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.main { flex: 1; min-height: 0; overflow-y: auto; scroll-behavior: smooth; }
/* Layout contract: a workspace fills the main area up to --page-max and is centred beyond it. Reading text keeps
   to --measure; dashboards, charts, graphs and lists use the width through their own responsive grids. */
:root { --page-max: 2040px; --measure: 74ch; --gutter: clamp(24px, 3vw, 64px); }
.view { padding: var(--s5) var(--gutter) var(--s8); max-width: var(--page-max); margin-inline: auto; width: 100%; box-sizing: border-box; animation: rise 240ms var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.honesty { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 6px var(--s4); padding: 8px var(--gutter); border-top: 1px solid var(--line); font-size: 11.5px; color: var(--ink-3); }
.honesty .lab { display: inline-flex; align-items: center; gap: 6px; }
.honesty .lab::before { content: ""; width: 5px; height: 5px; border-radius: 50%; border: 1px solid var(--attention); }
.honesty .lab.strong { color: var(--ink-2); font-weight: 500; }

/* Inspector drawer */
.inspector { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 92vw); z-index: 40; background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow-2); display: flex; flex-direction: column; animation: slide 220ms var(--ease); }
.inspector[hidden] { display: none; }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.inspector > header { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); }
.inspector > header h2 { font-family: var(--font-display); font-weight: 460; font-size: 18px; }
.inspector > .body { flex: 1; overflow: auto; padding: var(--s5); font-size: 13.5px; }
.inspector pre, pre.code { margin: 0; padding: var(--s3); background: var(--surface-2); border-radius: var(--r1); font-family: var(--font-mono); font-size: 12px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; overflow: auto; }
.kv { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 6px var(--s3); font-size: 13px; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; word-break: break-word; }

/* Toasts */
.toasts { position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; padding: 9px 16px; border-radius: 999px; background: var(--ink); color: var(--bg); font-size: 13.5px; box-shadow: var(--shadow-2); animation: rise 200ms var(--ease); max-width: 80vw; }
.toast.ok { background: var(--accent); color: var(--accent-ink); }
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(4px); transition: opacity 200ms, transform 200ms; }

@media (max-width: 1100px) { :root { --rail-w: 184px; } .cluster .who span.t { max-width: 300px; } }
@media (max-width: 820px) { :root { --rail-w: 56px; } .rail .brand, .rail a.nav .lbl, .rail .foot { display: none; } .rail a.nav { justify-content: center; padding: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; } }

/* ── Refinement ──────────────────────────────────────────────── */
.rail a.nav { transition: background 150ms var(--ease), color 150ms var(--ease), transform 150ms var(--ease); }
.rail a.nav:hover svg { color: var(--accent); }
.rail a.nav:active { transform: translateX(1px); }
.rail a.nav[aria-current=page] { background: var(--surface); box-shadow: var(--shadow-1); }
.btn:focus-visible { outline-offset: 3px; }
.btn.primary:active { transform: translateY(1px) scale(.98); }
.cluster .who.live .pulse { animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { box-shadow: 0 0 0 0 var(--accent-soft); opacity: 1; } 50% { box-shadow: 0 0 0 6px var(--accent-soft); opacity: .7; } }
.inspector { animation: slide 240ms var(--ease); }
/* Today */
.main .v-today .head .display { font-size: clamp(36px, 3.2vw, 54px); }
.main .v-today .head .eyebrow { color: var(--accent); }
.main .v-today .blk, .main .v-today aside { animation: rise 260ms var(--ease) both; }
.main .v-today aside { animation-delay: 40ms; }
.main .v-today .col-c .blk { animation-delay: 80ms; }
.main .v-today .decision { border: 1px solid color-mix(in srgb, var(--attention) 28%, transparent); box-shadow: var(--shadow-1); }
/* Conversation */
.main .v-conversation .m { animation: rise 180ms var(--ease); }
.main .v-conversation .m.owner { box-shadow: inset 0 0 0 1px var(--line); padding: 11px 18px; }
.main .v-conversation .m.inhabitant .text { line-height: 1.68; }
.main .v-conversation .th { transition: background 150ms var(--ease), box-shadow 150ms var(--ease); }
.main .v-conversation .doing i { margin-right: 28px; animation: dots 1.2s ease-in-out infinite; }
@keyframes dots { 0%, 100% { box-shadow: 14px 0 0 color-mix(in srgb, var(--accent) 45%, transparent), 28px 0 0 color-mix(in srgb, var(--accent) 20%, transparent); } 50% { box-shadow: 14px 0 0 var(--accent), 28px 0 0 color-mix(in srgb, var(--accent) 60%, transparent); } }
.main .v-conversation .shift { color: var(--accent); letter-spacing: .01em; }
.main .v-conversation .shift::before, .main .v-conversation .shift::after { border-top-style: dashed; border-color: var(--line-strong); }
.main .v-conversation .composer .box { box-shadow: var(--shadow-1); }
.main .v-conversation .composer .box:focus-within { box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-1); }
.main .v-conversation .composer .btn.primary:active { transform: scale(.96); }
