* { box-sizing: border-box; }

:root {
  --navy: #1a1a2e;
  --navy-2: #555570;
  --teal: #0F6E56;
  --teal-light: #E1F5EE;
  --aqua: #0A7E8C;
  --cream: #f0f2f5;
  --paper: #f5f6f8;
  --white: #ffffff;
  --ink: #1a1a2e;
  --muted: #555570;
  --line: #d8dce3;
  --amber: #BA7517;
  --red: #B8304F;
  --purple: #534AB7;
  --mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  --sans: "Plus Jakarta Sans", "Segoe UI", Arial, sans-serif;
}

html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
}

.wrap { width: min(1180px, calc(100% - 48px)); margin: 0 auto; }
.site-header { padding: 18px 0 15px; border-bottom: 1px solid var(--line); background: var(--white); }
.header-flex, .footer-flex { display: flex; align-items: center; justify-content: space-between; gap: 28px; }
.brand-block { display: flex; align-items: baseline; gap: 18px; }
.wordmark { color: var(--ink); font-size: 20px; line-height: 1; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; }
.header-links { display: flex; gap: 8px; }
.btn {
  border: 1px solid var(--line); border-radius: 5px; padding: 7px 11px; background: var(--white);
  color: var(--ink); font: inherit; font-size: 12px; font-weight: 600; text-decoration: none;
  cursor: pointer; transition: opacity .15s, border-color .15s;
}
.btn:hover { opacity: .85; border-color: #b8bdc8; }
.btn.dark { background: #185FA5; border-color: #185FA5; color: white; }
.btn.quiet { border-color: var(--line); }
.btn.unavailable { cursor: default; opacity: .58; }
.btn.unavailable:hover { border-color: var(--line); opacity: .58; }

.hero { padding: 34px 0 30px; }
.eyebrow { margin: 0 0 7px; color: #185FA5; font-size: 10px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; }
h1 { max-width: 820px; margin: 0; color: var(--ink); font-size: 26px; font-weight: 600; line-height: 1.25; letter-spacing: 0; }
.hero-copy { max-width: 760px; margin: 10px 0 0; color: var(--muted); font-size: 14px; }

.stream-section { padding: 28px 0 32px; background: var(--white); color: var(--ink); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 28px; }
.section-heading h2 { margin: 0; color: inherit; font-size: 20px; font-weight: 600; letter-spacing: 0; }
.stream-section .eyebrow { color: #185FA5; }
.patient-control { display: grid; gap: 5px; min-width: 230px; }
.patient-control label, .field-label, .rule-label { font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; }
select { width: 100%; border: 1px solid var(--line); border-radius: 5px; padding: 7px 9px; background: #f0f2f5; color: var(--ink); font-family: var(--mono); font-size: 12px; outline: none; }
select:focus { border-color: #3C3489; }
.patient-blurb { min-height: 21px; margin: 7px 0 15px; color: var(--muted); font-size: 12px; }

.stream-frame { display: grid; grid-template-columns: 82px minmax(0, 1fr); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--white); box-shadow: inset 0 1px 3px rgba(0,0,0,.04); }
.stream-labels { position: relative; z-index: 8; display: grid; grid-template-rows: 56px 46px 34px; background: #f0f2f5; border-right: 1px solid var(--line); }
.stream-labels div { display: flex; flex-direction: column; justify-content: center; padding: 0 11px; border-bottom: 1px solid var(--line); }
.stream-labels div:last-child { border-bottom: 0; }
.stream-labels b { color: var(--text-primary, #1a1a2e); font-family: var(--mono); font-size: 10px; text-transform: uppercase; }
.stream-labels span { color: #8888a0; font-size: 8px; }
.timeline-box { position: relative; overflow: hidden; }
.timeline { position: relative; display: flex; width: 100%; min-width: 0; }
.stream-event { position: relative; z-index: 2; display: grid; grid-template-rows: 56px 46px 34px; flex: 1 1 0; width: auto; min-width: 0; border-right: 1px solid var(--line); transition: opacity .15s, background .15s; }
.stream-event > div { display: flex; align-items: center; justify-content: center; padding: 5px 6px; border-bottom: 1px solid var(--line); text-align: center; }
.stream-event > div:last-child { border-bottom: 0; }
.stream-time { color: #8888a0; font-family: var(--mono); font-size: 9px; }
.stream-token { position: relative; color: var(--ink); font-family: var(--mono); font-size: clamp(7px, .7vw, 9px); font-weight: 700; line-height: 1.15; overflow-wrap: anywhere; }
.stream-value { flex-direction: column; color: var(--ink); font-family: var(--mono); font-size: 10px; line-height: 1.15; }
.stream-value small { color: #8888a0; font-size: 8px; }
.stream-event.cat-encounter .stream-token { background: #E8F0FE; color: #185FA5; }
.stream-event.cat-lab .stream-token { background: #C8F7DC; color: #1B5E20; }
.stream-event.cat-med .stream-token { background: #FFCCBC; color: #8B2500; }
.stream-event.cat-outcome .stream-token { background: #FFE0EC; color: #8B1A4A; }
.stream-event.cat-other .stream-token { background: #F0F2F5; color: #555570; }
.stream-event.is-muted { opacity: .34; }
.stream-event::after { content: ""; position: absolute; z-index: 7; inset: 2px; border: 0 solid transparent; border-radius: 4px; pointer-events: none; }
.stream-event.evaluating, .stream-event.focused { opacity: 1; }
.stream-event.evaluating::after, .stream-event.focused::after { border-width: 3px; border-color: var(--amber); background: rgba(186,117,23,.08); }
.stream-event.matched { opacity: 1; }
.stream-event.matched::after { border-width: 2px; border-color: var(--teal); background: rgba(15,110,86,.06); }
.stream-event.matched.focused::after { border-width: 3px; border-color: var(--amber); background: rgba(186,117,23,.10); }
.stream-event.matched .stream-token::after { content: attr(data-el); position: absolute; top: 2px; right: 4px; color: var(--teal); font-size: 8px; }
.stream-event.blocked::after { border-width: 3px; border-color: var(--red); background: rgba(178,77,69,.14); }
.stream-event.midhit .stream-token::before { content: "collected"; position: absolute; bottom: 3px; color: #b9aef2; font-size: 8px; }
#arc-layer { position: absolute; top: 0; left: 0; z-index: 6; width: 100%; height: 100%; overflow: visible; pointer-events: none; }

.stream-note { display: flex; gap: 8px; align-items: flex-start; max-width: 830px; margin-top: 11px; color: var(--muted); font-size: 10px; }
.stream-note code { color: var(--ink); font-family: var(--mono); }
.note-mark { display: inline-flex; flex: 0 0 17px; width: 17px; height: 17px; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 50%; color: #185FA5; font-family: serif; font-style: italic; }
.legend { display: flex; gap: 14px; margin-top: 11px; color: #8888a0; font-size: 9px; text-transform: uppercase; letter-spacing: .06em; }
.legend span { display: flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #8399a0; }
.dot.encounter { background: #185FA5; } .dot.lab { background: #0F6E56; } .dot.med { background: #C05621; } .dot.outcome { background: #B8304F; }

.explore-section { padding: 36px 0 48px; }
.explore-heading { margin-bottom: 16px; }
.explore-heading h2 { color: var(--navy); }
.explore-heading > p { max-width: 390px; margin: 0; color: var(--muted); }
.walkthrough-grid { display: grid; grid-template-columns: minmax(290px, .78fr) minmax(460px, 1.35fr); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: white; box-shadow: 0 1px 3px rgba(0,0,0,.03); }
.pattern-panel { padding: 22px; border-right: 1px solid var(--line); background: #f0f2f5; }
.pattern-panel select { margin: 7px 0 8px; }
.evaluate-btn { width: 100%; margin: 0 0 24px; border: 1px solid #185FA5; border-radius: 5px; padding: 9px 12px; background: #185FA5; color: white; font: inherit; font-size: 11px; font-weight: 750; cursor: pointer; transition: background .15s, opacity .15s; }
.evaluate-btn:hover { background: #14518e; }
.evaluate-btn:disabled { cursor: wait; opacity: .72; }
.pattern-id { color: var(--teal); font-family: var(--mono); font-size: 11px; font-weight: 800; }
.pattern-panel h3 { margin: 5px 0 10px; color: var(--ink); font-size: 19px; line-height: 1.3; font-weight: 600; }
.pattern-question { min-height: 70px; margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.rule-label { color: var(--muted); }
.pattern-rule { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 10px 0 18px; }
.rule-chip { padding: 5px 7px; border: 1px solid #b8c6c4; border-radius: 3px; background: white; color: var(--navy); font-family: var(--mono); font-size: 10px; }
.rule-arrow { color: #8da09e; }
.rule-window { width: 100%; color: var(--teal); font-size: 10px; font-weight: 750; }
.expected-badge { display: inline-block; margin-bottom: 20px; padding: 4px 8px; border-radius: 3px; font-size: 10px; font-weight: 800; }
.expected-badge.yes { background: var(--teal-light); color: var(--teal); }
.expected-badge.no { background: #f7e5e2; color: var(--red); }
.paper-note { margin: 14px 0 0; color: #7a888c; font-size: 10px; font-style: italic; }

.explain-panel { min-width: 0; padding: 22px 24px; }
.explain-topline { display: flex; justify-content: space-between; align-items: center; padding-bottom: 16px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.controls { display: flex; gap: 5px; }
.icon-btn { border: 1px solid var(--line); border-radius: 3px; background: white; color: var(--navy); padding: 5px 8px; font: inherit; font-size: 10px; font-weight: 700; cursor: pointer; }
.explain-state { display: grid; grid-template-columns: 46px 1fr; gap: 18px; min-height: 180px; align-content: center; padding: 27px 0 20px; }
.step-icon { display: flex; width: 42px; height: 42px; align-items: center; justify-content: center; border-radius: 50%; background: #185FA5; color: white; font-family: var(--mono); font-size: 11px; }
.explain-state.hit .step-icon, .explain-state.match .step-icon { background: var(--teal); }
.explain-state.block .step-icon, .explain-state.prune .step-icon { background: var(--red); }
.explain-state.branch .step-icon { background: var(--purple); }
.step-kicker { margin: 0 0 4px; color: var(--teal); font-size: 10px; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.explain-state h3 { margin: 0 0 7px; color: var(--ink); font-size: 18px; font-weight: 600; }
.explain-state p:last-child { margin: 0; color: var(--muted); font-size: 13px; }
.code-snippet { overflow: hidden; border-radius: 5px; background: #1a1a2e; }
.code-head { display: flex; justify-content: space-between; padding: 7px 12px; border-bottom: 1px solid #31515e; color: #85a2a9; font-size: 9px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.code-snippet pre { min-height: 74px; margin: 0; padding: 10px 0; overflow-x: auto; color: #d9d9e8; font-family: var(--mono); font-size: 10.5px; line-height: 1.5; }
.code-statement { display: block; padding: 3px 12px; border-left: 3px solid transparent; white-space: pre-wrap; transition: background .15s, border-color .15s; }
.code-statement.active { background: rgba(15,110,86,.22); border-left-color: #66BB6A; color: #f2fff9; }
.run-verdict { margin-top: 14px; padding: 10px 12px; border-left: 3px solid var(--line); background: #f6f7f5; font-size: 12px; font-weight: 750; }
.run-verdict.yes { border-color: var(--teal); color: var(--teal); background: var(--teal-light); }
.run-verdict.no { border-color: var(--red); color: var(--red); background: #f7e5e2; }
.run-verdict.muted { color: var(--muted); }
.match-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.match-pill { padding: 4px 6px; border: 1px solid var(--line); border-radius: 3px; color: var(--navy); font-family: var(--mono); font-size: 9px; }

.site-footer { padding: 22px 0; background: var(--white); color: var(--ink); border-top: 1px solid var(--line); }
.site-footer strong { font-size: 20px; }
.site-footer span, .site-footer p { color: #8888a0; font-size: 11px; }
.site-footer a { color: #185FA5; font-weight: 650; text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.site-footer p { max-width: 430px; margin: 0; text-align: right; }

@media (max-width: 820px) {
  .wrap { width: min(100% - 30px, 1180px); }
  .header-flex, .brand-block, .section-heading, .footer-flex { align-items: flex-start; }
  .hero { padding: 28px 0 24px; }
  .section-heading { flex-direction: column; }
  .patient-control { width: 100%; }
  .stream-frame { grid-template-columns: 72px minmax(0, 1fr); }
  .stream-labels div { padding: 0 9px; }
  .walkthrough-grid { grid-template-columns: 1fr; }
  .pattern-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .pattern-question { min-height: 0; }
  .footer-flex { flex-direction: column; }
  .site-footer p { text-align: left; }
}

@media (max-width: 960px) {
  .timeline-box { overflow-x: auto; overflow-y: hidden; scrollbar-color: #b8bdc8 #f0f2f5; }
  .timeline { width: max-content; min-width: 100%; }
  .stream-event { flex: 0 0 76px; width: 76px; min-width: 76px; }
}

@media (max-width: 520px) {
  .header-links .quiet { display: none; }
  h1 { font-size: 23px; }
  .hero-copy { font-size: 13px; }
  .legend { gap: 9px; flex-wrap: wrap; }
  .explore-section { padding: 52px 0; }
  .pattern-panel, .explain-panel { padding: 22px 18px; }
  .explain-state { grid-template-columns: 1fr; }
}
