:root {
  --bg: #171511;
  --tile: #211d18;
  --lift: #1e1b16;
  --line: #352d24;
  --ink: #fff4dd;
  --muted: #b9aa92;
  --accent: #ff873c;
  --branch: #5c3b23; /* The accent at rest: a dendrite with nothing travelling it. */
  --ok: #7ed6a5;
  --warn: #f4d35e;
  --bad: #ff7088;
  --display: "Bricolage Grotesque", "DM Sans", system-ui, "Segoe UI", sans-serif;
  --text: "DM Sans", system-ui, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.45 var(--text); font-variant-numeric: tabular-nums; }
h1, h2, h3, h4, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.muted { color: var(--muted); }

/* ---- Shell ---- */
.app { max-width: 1520px; min-height: 100dvh; margin: 0 auto; padding: 18px max(16px, env(safe-area-inset-right)) 28px max(16px, env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 14px; }
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.brand { border-radius: 9px; flex: none; }
.top-title { flex: 1 1 260px; min-width: 0; }
.top h1 { font: 700 clamp(21px, 2.3vw, 30px)/1.15 var(--display); letter-spacing: -0.01em; text-wrap: balance; }
.subline { color: var(--muted); margin-top: 3px; text-wrap: pretty; }
.pc { display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 99px; font-size: 13px; font-weight: 500; white-space: nowrap; background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); }
.pc::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pc.online { --c: var(--ok); }
.pc.offline { --c: var(--warn); }
.pc.offline::before { background: none; box-shadow: inset 0 0 0 1.5px currentColor; }
.quiet { background: none; border: 1px solid var(--line); border-radius: 99px; padding: 5px 13px; font-size: 13px; color: var(--muted); }
.quiet:hover { color: var(--ink); border-color: var(--muted); }
.stale-line { padding: 9px 13px; border-radius: 12px; background: color-mix(in srgb, var(--warn) 12%, transparent); color: var(--warn); font-weight: 500; }

.body { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(330px, 400px); gap: 28px; align-items: start; }
.stage { container-type: inline-size; min-width: 0; }

/* ---- The neuron ---- */
.graph { position: relative; height: clamp(470px, calc(100dvh - 300px), 780px); user-select: none; }
.wires { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.dendrite { fill: none; stroke: var(--branch); stroke-width: 5; stroke-linecap: round; transition: stroke .4s; }
.dendrite.twig { stroke-width: 4; }
.dendrite.lit { stroke: var(--accent); }
.dendrite.faint { stroke-width: 3; stroke-dasharray: 1 9; }
.soma { fill: var(--accent); }
.impulse { fill: none; stroke: var(--ink); stroke-linecap: round; filter: drop-shadow(0 0 5px rgba(255, 244, 221, .55)); animation: travel 2s linear infinite; }
.impulse.codex { stroke-linecap: butt; }
@keyframes travel { from { stroke-dashoffset: var(--from); } to { stroke-dashoffset: -100; } }

.node { position: absolute; transform: translate(-50%, -23px); display: flex; flex-direction: column; align-items: center; gap: 3px; width: max-content; max-width: 150px; text-align: center; cursor: pointer; }
.tile-wrap { position: relative; display: block; margin-bottom: 5px; border-radius: 12px; outline: 2px solid var(--c, var(--line)); outline-offset: 3px; transition: transform .2s; }
.node:hover .tile-wrap { transform: scale(1.07); }
.node.selected .tile-wrap { outline-width: 3px; outline-offset: 4px; box-shadow: 0 0 0 9px color-mix(in srgb, var(--c, var(--ink)) 16%, transparent); }
.tile { display: block; border-radius: 12px; background: var(--tile); }
.tile.letter { display: grid; place-items: center; width: 46px; height: 46px; font: 700 18px var(--display); color: var(--muted); border: 2px dashed var(--line); background: var(--bg); }
.node.faint .tile.letter { width: 26px; height: 26px; border-radius: 50%; }
.node.up { transform: translate(-50%, calc(-100% + 23px)); }
.node.up .tile-wrap { order: 1; margin: 5px 0 0; }
.node.faint { transform: translate(-50%, -13px); }
.node.faint.up { transform: translate(-50%, calc(-100% + 13px)); }
.node.faint .tile-wrap { outline: none; border-radius: 50%; }
.node-name { font: 700 14px/1.2 var(--display); }
.node.faint .node-name { color: var(--muted); font-weight: 500; }
.docks { position: absolute; top: -8px; right: -12px; display: flex; align-items: center; gap: 3px; padding: 4px 5px; border-radius: 99px; background: var(--bg); }
.docks b { font-size: 10px; font-weight: 600; }
.dock { display: inline-block; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }
.dock.codex { border-radius: 1px; transform: rotate(45deg) scale(.86); }
.soma-count { position: absolute; transform: translate(-50%, -50%); font: 700 34px/1 var(--display); color: var(--tile); pointer-events: none; }
.soma-count.small { font-size: 23px; }
.soma-words { position: absolute; transform: translateX(-50%); padding: 1px 7px; border-radius: 99px; background: var(--bg); color: var(--muted); font-size: 12.5px; white-space: nowrap; pointer-events: none; }
.app.stale .wires, .app.stale .node { filter: saturate(.2); opacity: .7; }

@container (max-width: 559px) {
  .graph { height: 440px; }
  .dendrite { stroke-width: 3.5; }
  .dendrite.twig { stroke-width: 3; }
  .node { transform: translate(-50%, -18px); max-width: 86px; }
  .node.up { transform: translate(-50%, calc(-100% + 18px)); }
  .node.up .tile-wrap { margin: 4px 0 0; }
  .tile-wrap, .tile { border-radius: 9px; }
  .tile-wrap { outline-offset: 2px; margin-bottom: 4px; }
  .tile.letter { width: 36px; height: 36px; }
  .node-name { font-size: 12.5px; }
  .node .chip { font-size: 11px; padding: 1px 7px; }
}

/* ---- Words for every state: tinted chips, never an edge stripe ---- */
.chip { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 12.5px; font-weight: 500; line-height: 1.35; background: color-mix(in srgb, var(--c) 15%, transparent); color: var(--c); }
.ok { --c: var(--ok); }
.warn { --c: var(--warn); }
.bad { --c: var(--bad); }
.note { --c: var(--ink); }
.unknown { --c: var(--muted); }
.chip.unknown { background: none; box-shadow: inset 0 0 0 1px var(--line); }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; margin-top: 4px; color: var(--muted); font-size: 12.5px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .dock { background: var(--muted); }

.usage { display: flex; flex-wrap: wrap; gap: 14px 36px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.use { display: grid; grid-template-columns: auto auto; align-items: center; gap: 2px 10px; }
.use-label { grid-column: 1 / -1; color: var(--muted); font-size: 12.5px; }
.use-value { font-size: 13.5px; }
.use-value strong { font: 700 15px var(--display); }
.days { display: inline-flex; align-items: flex-end; gap: 3px; height: 26px; }
.days i { width: 7px; border-radius: 2px; background: var(--branch); }
.days i.today { background: var(--accent); }
.meter { display: block; width: 96px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 3px; background: var(--ink); }

/* ---- The reading ---- */
.reading h2 { font: 500 13px var(--text); color: var(--muted); padding: 0 10px 6px; }
.row { border-top: 1px solid var(--line); }
.row.open { border-color: transparent; border-radius: 16px; background: var(--lift); margin: 4px 0; }
.row.open + .row { border-color: transparent; }
.row-head { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 10px; background: none; border: 0; border-radius: 16px; text-align: start; }
.row-head:hover { background: var(--lift); }
.row-head .tile { border-radius: 8px; flex: none; }
.row-head .tile.letter { width: 32px; height: 32px; font-size: 14px; }
.row-name { flex: 1; min-width: 0; display: flex; flex-direction: column; font: 700 15.5px/1.25 var(--display); }
.row-work { font: 400 13px var(--text); color: var(--accent); }
.row-head .chip { flex: none; max-width: 52%; text-align: center; }
.detail { padding: 2px 14px 16px; display: grid; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.facts { color: var(--muted); font-size: 13.5px; }
.subject { font-size: 14px; }
.detail h4 { font: 500 12.5px var(--text); color: var(--muted); margin-top: 4px; }
.sessions { display: grid; gap: 8px; }
.sessions li { display: grid; grid-template-columns: 10px 1fr; align-items: baseline; gap: 0 9px; }
.sessions .muted { grid-column: 2; font-size: 13px; }

/* ---- Sign-in ---- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.gate-card { width: min(360px, 100%); display: grid; justify-items: center; gap: 20px; }
.gate-logo { border-radius: 16px; }
.gate-forms { width: 100%; display: grid; gap: 16px; }
.gate-forms h1 { font: 700 30px var(--display); text-align: center; }
.gate-form { display: grid; gap: 12px; }
.gate-form label { display: grid; gap: 6px; font-size: 13.5px; color: var(--muted); }
.gate-form input { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--tile); color: var(--ink); font-size: 16px; }
.gate-form input:focus-visible { outline-offset: 0; border-radius: 12px; }
.primary { padding: 12px 18px; border: 0; border-radius: 12px; background: var(--accent); color: #211d18; font-weight: 600; }
.primary:hover { background: #ff9a5c; }
.primary:disabled { opacity: .6; cursor: default; }
.link { background: none; border: 0; padding: 6px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.login-message { min-height: 1.45em; text-align: center; color: var(--bad); }

.install { position: fixed; z-index: 20; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); width: min(340px, calc(100vw - 32px)); padding: 16px; border-radius: 18px; background: var(--tile); border: 1px solid var(--line); display: grid; gap: 12px; }
.install .actions { display: flex; gap: 8px; }
.install .primary { padding: 8px 16px; border-radius: 10px; }

@media (max-width: 960px) {
  .body { grid-template-columns: minmax(0, 1fr); gap: 22px; }
  .graph { height: 500px; }
}
@media (max-width: 480px) {
  .app { padding-top: 14px; }
  .brand { width: 30px; height: 30px; }
  .top-title { flex-basis: calc(100% - 50px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
  /* Each impulse stops where it is on its branch; the list still says "firing". */
  .impulse { animation: none; stroke-dashoffset: var(--rest); }
}
