:root {
  --bg: #ffffff; --bg-2: #f7f8fa; --fg: #1f2328; --muted: #59636e; --line: #e3e6ea;
  --accent: #2f6fd6; --accent-bg: rgba(47, 111, 214, 0.1); --code: #f3f4f6;
  --top: 56px; --left: 264px; --right: 248px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --bg-2: #15181e; --fg: #e6e8eb; --muted: #9aa3ad; --line: #262a31;
    --accent: #5b95f0; --accent-bg: rgba(91, 149, 240, 0.14); --code: #1b1f26;
  }
  :root:not([data-theme="light"]) .content img { background: #fff; }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --bg-2: #15181e; --fg: #e6e8eb; --muted: #9aa3ad; --line: #262a31;
  --accent: #5b95f0; --accent-bg: rgba(91, 149, 240, 0.14); --code: #1b1f26;
}
:root[data-theme="dark"] .content img { background: #fff; }

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--top) + 16px); }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.65 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Top bar */
.topbar { position: fixed; inset: 0 0 auto 0; height: var(--top); z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--fg); letter-spacing: .2px; }
.brand:hover { text-decoration: none; }
.logo { color: var(--accent); }
.tag { color: var(--muted); font-size: 13px; }
.theme-btn, .menu-btn { margin-left: auto; background: none; border: 1px solid var(--line); color: var(--fg);
  border-radius: 8px; height: 32px; min-width: 32px; cursor: pointer; font-size: 15px; }
.menu-btn { display: none; margin-left: 0; }

/* Three-column shell */
.shell { display: grid; grid-template-columns: var(--left) minmax(0, 1fr) var(--right); padding-top: var(--top); }
.sidebar { position: sticky; top: var(--top); height: calc(100vh - var(--top)); overflow-y: auto; padding: 20px 16px; }
.left { background: var(--bg-2); border-right: 1px solid var(--line); }
.right { border-left: 1px solid var(--line); }
.group { margin-bottom: 20px; }
.group-title { margin: 0 0 6px; padding: 0 8px; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li a { display: block; padding: 5px 8px; border-radius: 6px; color: var(--fg); font-size: 14px; }
.sidebar li a:hover { background: var(--accent-bg); text-decoration: none; }
.sidebar li a.active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.filter { width: 100%; margin-bottom: 16px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--fg); font: inherit; font-size: 14px; }
.toc li a { font-size: 13.5px; color: var(--muted); border-left: 2px solid transparent; border-radius: 0; padding-left: 10px; }
.toc li a.active { color: var(--accent); border-left-color: var(--accent); background: none; }
.actions { margin-top: 24px; display: grid; gap: 8px; }
.btn { display: block; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; color: var(--fg); font-size: 13.5px; }
.btn:hover { background: var(--accent-bg); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { opacity: .92; background: var(--accent); }

/* Content */
.content { min-width: 0; max-width: 860px; width: 100%; margin: 0 auto; padding: 36px 40px 64px; }
.content h1 { font-size: 30px; line-height: 1.25; margin: 0 0 6px; }
.content h1 + p { color: var(--muted); margin-top: 0; }
.content h2 { font-size: 21px; margin: 44px 0 12px; padding-top: 4px; border-top: 1px solid var(--line); padding-top: 28px; }
.content blockquote { margin: 18px 0; padding: 10px 14px; border-left: 3px solid var(--accent); background: var(--accent-bg); border-radius: 0 8px 8px 0; }
.content blockquote p { margin: 0; }
.content img { max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 10px; }
.content table { display: block; overflow-x: auto; border-collapse: collapse; font-size: 14px; margin: 16px 0; }
.content th, .content td { border: 1px solid var(--line); padding: 7px 11px; text-align: left; vertical-align: top; }
.content th { background: var(--bg-2); font-weight: 600; }
.content code { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: .86em; background: var(--code); padding: 1px 5px; border-radius: 5px; }
.content pre { background: var(--code); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; overflow-x: auto; line-height: 1.45; }
.content pre code { background: none; padding: 0; }
.page-foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-top: 48px; padding-top: 16px;
  border-top: 1px solid var(--line); color: var(--muted); font-size: 13.5px; }
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 15; }

/* Narrower screens: drop the right sidebar */
@media (max-width: 1180px) {
  .shell { grid-template-columns: var(--left) minmax(0, 1fr); }
  .right { display: none; }
}
/* Phones: left sidebar becomes a drawer */
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-block; }
  .tag { display: none; }
  .left { position: fixed; top: var(--top); left: 0; z-index: 16; width: 280px; transform: translateX(-100%); transition: transform .2s; }
  .left.open { transform: none; }
  .content { padding: 24px 16px 48px; }
}

/* ---------- Animated intro ---------- */
.intro { --warn: #d97706; --bad: #d1242f; --good: #1a7f37; margin: 20px 0 8px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg-2); overflow: hidden; }
.intro .scene { display: block; width: 100%; height: auto; }
.intro .label { font-size: 13px; fill: var(--muted); }
.intro .label.strong { font-weight: 600; fill: var(--fg); }
.intro .name { font-size: 14px; font-weight: 600; fill: var(--fg); }
.intro .tiny { font-size: 11.5px; fill: var(--muted); }
.intro .suit { fill: var(--bg); stroke: var(--muted); stroke-width: 2; }
.intro .visor { fill: var(--accent); opacity: .35; }
.intro .watch { fill: var(--fg); }
.intro .watch-line { fill: none; stroke: #4ade80; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.intro .bpm { font-size: 12px; font-weight: 600; }
.intro .bpm-ok { fill: var(--good); }
.intro .bpm-high { fill: var(--bad); opacity: 0; }
.intro .ble-dot { fill: var(--accent); opacity: 0; }
.intro .ship-body { fill: var(--bg); stroke: var(--line); stroke-width: 1.5; }
.intro .aegis, .intro .medlink { fill: var(--accent-bg); stroke: var(--accent); stroke-width: 1.5; transition: stroke .3s, fill .3s; }
.intro .aegis-note { opacity: 0; transition: opacity .3s; }
.intro .note-warn { fill: var(--warn); font-weight: 600; }
.intro .note-good { fill: var(--good); font-weight: 600; }
.intro .env { fill: var(--bg); stroke: var(--accent); stroke-width: 1.4; opacity: 0; }
.intro .env.reply { stroke: var(--good); }
.intro .link-line { stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: 6 6; fill: none; animation: flow 1s linear infinite; }
.intro .link-x { stroke: var(--bad); stroke-width: 3; stroke-linecap: round; opacity: 0; }
.intro .link-down { fill: var(--bad); font-weight: 600; opacity: 0; }
.intro .planet { fill: #3b82f6; opacity: .22; stroke: #3b82f6; stroke-width: 1.5; }
.intro .land { fill: #22c55e; opacity: .45; }

/* step 1: watch streams readings */
.intro[data-step] .ble-dot { animation: ble 1.2s linear infinite; }
.intro[data-step="1"] .note-ok { opacity: 1; }
/* step 2: AEGIS spots something */
.intro[data-step="2"] .bpm-ok, .intro[data-step="3"] .bpm-ok { opacity: 0; }
.intro[data-step="2"] .bpm-high, .intro[data-step="3"] .bpm-high { opacity: 1; animation: pulse .8s ease-in-out infinite; }
.intro[data-step="2"] .aegis, .intro[data-step="3"] .aegis { stroke: var(--warn); fill: rgba(217, 119, 6, .12); }
.intro[data-step="2"] .note-warn, .intro[data-step="3"] .note-warn { opacity: 1; }
/* step 3: MEDLINK sends it */
.intro[data-step="3"] .send { animation: send 1.6s ease-in-out .3s forwards; }
/* step 4: link breaks, messages wait */
.intro[data-step="4"] .link-line { stroke: var(--bad); opacity: .35; animation: none; }
.intro[data-step="4"] .link-x, .intro[data-step="4"] .link-down { opacity: 1; }
.intro[data-step="4"] .link-ok { opacity: 0; }
.intro[data-step="4"] .note-off { opacity: 1; }
.intro[data-step="4"] .q1 { animation: pop .4s ease-out .3s forwards; }
.intro[data-step="4"] .q2 { animation: pop .4s ease-out 1.1s forwards; }
.intro[data-step="4"] .q3 { animation: pop .4s ease-out 1.9s forwards; }
.intro[data-step="4"] .medlink { stroke: var(--warn); }
/* queue holds the PulseBrief as three layers */
.intro .q1 { stroke: #d1242f; } .intro .q2 { stroke: #d97706; } .intro .q3 { stroke: #2f6fd6; }
.intro .link-short { opacity: 0; }
.intro[data-step="4"] .note-off, .intro[data-step="5"] .note-off, .intro[data-step="6"] .note-off { opacity: 1; }
/* step 5: a short window, only the headline goes */
.intro[data-step="5"] .link-ok { opacity: 0; }
.intro[data-step="5"] .link-short { opacity: 1; fill: var(--warn); font-weight: 600; }
.intro[data-step="5"] .link-line { stroke: var(--warn); }
.intro[data-step="5"] .q1 { --d: 324px; animation: drain 1.2s ease-in-out .3s both; }
.intro[data-step="5"] .q2, .intro[data-step="5"] .q3 { opacity: 1; }
.intro[data-step="5"] .medlink { stroke: var(--warn); }
/* step 6: next window, the rest follows */
.intro[data-step="6"] .q2 { --d: 294px; animation: drain 1.4s ease-in-out .2s both; }
.intro[data-step="6"] .q3 { --d: 264px; animation: drain 1.4s ease-in-out .7s both; }
/* step 7: doctors reply */
.intro[data-step="7"] .reply { animation: reply 1.6s ease-in-out .2s forwards; }
.intro[data-step="7"] .note-good { opacity: 1; transition-delay: 1.6s; }
.intro[data-step="7"] .aegis { stroke: var(--good); fill: rgba(26, 127, 55, .1); transition-delay: 1.6s; }

@keyframes ble { 0% { transform: translateX(0); opacity: 0; } 15% { opacity: 1; } 85% { opacity: 1; } 100% { transform: translateX(66px); opacity: 0; } }
@keyframes flow { to { stroke-dashoffset: -12; } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes send { 0% { opacity: 0; transform: translateX(0); } 10% { opacity: 1; } 90% { opacity: 1; } 100% { opacity: 0; transform: translateX(160px); } }
@keyframes pop { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes drain { 0% { opacity: 1; transform: translateX(0); } 90% { opacity: 1; } 100% { opacity: 0; transform: translateX(var(--d)); } }
@keyframes reply { 0% { opacity: 0; transform: translateX(0); } 10% { opacity: 1; } 90% { opacity: 1; } 100% { opacity: 0; transform: translateX(-160px); } }

.intro figcaption { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--bg); }
.intro-caption { display: flex; align-items: center; gap: 10px; min-height: 28px; font-size: 15px; flex: 1 1 320px; }
.intro-num { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 13px; flex: none; }
.intro-controls { display: flex; align-items: center; gap: 6px; }
.intro-controls button { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--fg); cursor: pointer; font-size: 14px; }
.intro-dots { display: flex; gap: 6px; padding: 0 4px; }
.intro-dots button { width: 9px; height: 9px; padding: 0; border-radius: 50%; border: none; background: var(--line); }
.intro-dots button.on { background: var(--accent); }
@media (prefers-reduced-motion: reduce) { .intro *, .intro *::before { animation-duration: .01s !important; animation-iteration-count: 1 !important; } }

/* ---------- PulseBrief example card ---------- */
.brief { margin: 0; padding: 16px 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg-2); box-shadow: 0 1px 0 var(--line); }
.brief-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.brief-head strong { display: block; font-size: 16px; }
.brief-kicker { display: block; font-size: 11.5px; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); }
.brief-badge { flex: none; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; color: #b45309; background: rgba(217, 119, 6, .14); }
.brief-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 10px; }
.brief-stats div { padding: 8px 10px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); }
.brief-stats b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.brief-stats small { color: var(--muted); font-size: 12px; }
.brief-spark { display: block; width: 100%; height: 48px; }
.brief-spark .base { stroke: var(--line); stroke-dasharray: 4 4; fill: none; }
.brief-spark .line { stroke: #d97706; stroke-width: 2.5; fill: none; stroke-linejoin: round; stroke-dasharray: 420; stroke-dashoffset: 420; animation: draw 2.2s ease-out .3s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.brief-context { list-style: none; margin: 10px 0 0; padding: 0; font-size: 14px; }
.brief-context li { display: flex; gap: 10px; padding: 5px 0; border-top: 1px solid var(--line); }
.brief-foot { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .brief-spark .line { animation: none; stroke-dashoffset: 0; } }

.briefs { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin: 20px 0; align-items: start; }
.brief-q { margin: 14px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.brief-sub { margin: 8px 0 0; font-size: 14px; }
.taps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tap { text-align: center; padding: 8px 4px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; background: var(--bg); }
.tap.on { border-color: #d97706; background: rgba(217, 119, 6, .14); font-weight: 600; }
.todo { margin: 0; padding-left: 0; list-style: none; font-size: 14px; counter-reset: t; }
.todo li { counter-increment: t; display: flex; gap: 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); }
.todo li::before { content: counter(t); display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--muted); font-size: 11px; flex: none; }
.todo li.done { color: var(--muted); text-decoration: line-through; }
.todo li.done::before { content: '✓'; background: #1a7f37; border-color: #1a7f37; color: #fff; }
.tick { font-variant-numeric: tabular-nums; }
.eta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.eta div { padding: 8px 10px; border-radius: 10px; background: var(--accent-bg); }
.eta small { display: block; color: var(--muted); font-size: 12px; }
.eta b { font-size: 18px; }
.layers { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.layer { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12.5px; border: 1px solid var(--line); background: var(--bg); opacity: 0; animation: layer-in .5s ease-out forwards; }
.layer i { width: 8px; height: 8px; border-radius: 50%; }
.layer em { font-style: normal; color: var(--muted); }
.layer.l1 i { background: #d1242f; } .layer.l2 i { background: #d97706; } .layer.l3 i { background: #2f6fd6; }
.layer.l1 { animation-delay: .2s; } .layer.l2 { animation-delay: 1s; } .layer.l3 { animation-delay: 1.8s; border-style: dashed; }
@keyframes layer-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .layer { animation: none; opacity: 1; } }

/* ---------- Our story ---------- */
.story { margin: 16px 0 8px; padding: 22px 26px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg-2); font-size: 17px; line-height: 1.7; }
.story p { margin: 0 0 12px; }
.story-tag { margin: 16px 0 0 !important; font-size: 19px; font-weight: 700; letter-spacing: .3px; color: var(--accent); }

/* ---------- Language switch ---------- */
.lang-switch { margin-left: auto; display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; height: 32px; }
.lang-switch a { display: inline-grid; place-items: center; padding: 0 10px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.lang-switch a:hover { text-decoration: none; color: var(--fg); background: var(--accent-bg); }
.lang-switch a.on { background: var(--accent); color: #fff; }
.lang-switch + .theme-btn { margin-left: 8px; }

/* =====================================================================
   Theme v2: matches the AEGIS-MEDLINK website and console.
   Graphite surfaces, one blue accent, Inter with tight headings,
   structure by surface contrast and space: no hairlines, no small caps.
   Dark is the default (our brand); light stays one click away.
   ===================================================================== */
:root, :root[data-theme="dark"] {
  --bg: #0b0d0e; --bg-2: #121517; --fg: #eef1f3; --muted: #9ea7ad; --line: transparent;
  --accent: #5b9bff; --accent-bg: rgba(91, 155, 255, 0.13); --code: #171b1e; --card: #121517;
}
:root[data-theme="light"] {
  --bg: #f5f6f7; --bg-2: #ffffff; --fg: #15191c; --muted: #5d676d; --line: transparent;
  --accent: #2f6fd6; --accent-bg: rgba(47, 111, 214, 0.08); --code: #eceef0; --card: #ffffff;
}
:root:not([data-theme="light"]) .content img { background: transparent; }

body { font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased; }

/* chrome without rules */
.topbar { border: 0; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(14px) saturate(1.4); }
.brand { letter-spacing: -0.01em; }
.left, .right { border: 0; }
.left { background: var(--bg-2); }
.theme-btn, .menu-btn { border: 0; background: var(--accent-bg); }
.filter { border: 0; background: var(--bg); }
.group-title { text-transform: none; letter-spacing: 0; font-size: 12.5px; color: var(--fg); opacity: 0.6; }
.sidebar li a.active { background: var(--accent-bg); color: var(--accent); }
.toc li a { border-left: 0; border-radius: 8px; padding-left: 8px; }
.toc li a.active { background: var(--accent-bg); color: var(--accent); }
.btn { border: 0; background: var(--bg-2); border-radius: 10px; }
.right .btn { background: var(--accent-bg); }
.btn.primary { background: var(--accent); color: #fff; }
.lang-switch { border: 0; background: var(--accent-bg); }

/* content: tight headings, cards instead of rules */
.content h1 { font-size: 36px; line-height: 1.12; font-weight: 650; letter-spacing: -0.025em; }
.content h2 { border-top: 0; padding-top: 12px; margin-top: 52px; font-size: 24px; font-weight: 650; letter-spacing: -0.02em; }
.content h3 { font-size: 17px; letter-spacing: -0.01em; }
.content blockquote { border-left: 0; border-radius: 14px; background: var(--accent-bg); padding: 14px 18px; }
.content img { border: 0; border-radius: 14px; }
.content pre { border: 0; border-radius: 14px; background: var(--code); }
.content table { border-radius: 14px; overflow: hidden; background: var(--card); border-collapse: separate; border-spacing: 0; }
.content th, .content td { border: 0; padding: 9px 13px; }
.content th { background: var(--accent-bg); font-weight: 600; }
.content tr:nth-child(even) td { background: color-mix(in srgb, var(--fg) 3.5%, transparent); }
.page-foot { border-top: 0; }

/* intro animation, PulseBrief cards, story */
.intro { border: 0; background: var(--card); }
.intro figcaption { border-top: 0; background: color-mix(in srgb, var(--fg) 3%, var(--card)); }
.intro-controls button { border: 0; background: var(--accent-bg); }
.brief { border: 0; box-shadow: none; background: var(--card); }
.brief-kicker, .brief-q { text-transform: none; letter-spacing: 0; }
.brief-stats div { border: 0; background: var(--bg); }
.brief-context li { border-top: 0; padding: 4px 0; }
.tap { border: 0; background: var(--bg); }
.tap.on { background: rgba(217, 119, 6, .18); box-shadow: inset 0 0 0 1.5px #d97706; }
.todo li { border-top: 0; padding: 5px 0; }
.layer { border: 0; background: var(--bg); }
.layer.l3 { border-style: none; opacity: 0.85; }
.story { border: 0; background: var(--card); }
