:root, [data-theme="light"] {
  --color-bg: #f5f5f0;
  --color-surface: #fbfbf8;
  --color-surface-2: #ffffff;
  --color-surface-offset: #ecebe3;
  --color-border: oklch(0.3 0.02 210 / 0.14);
  --color-divider: oklch(0.3 0.02 210 / 0.09);
  --color-text: #17262a;
  --color-text-muted: #56646a;
  --color-text-faint: #8a959a;
  --color-text-inverse: #f7f5ee;
  --color-primary: #14505a;
  --color-primary-hover: #0e3d45;
  --color-primary-soft: #dbe7e6;
  --color-straw: #efe6c9;
  --color-straw-ink: #6b5717;
  --ok: #2f6b2a; --ok-bg: #dfeadb;
  --due: #8a5a00; --due-bg: #f3e5c2;
  --late: #9a2f2f; --late-bg: #f2d9d6;
  --draft: #56646a; --draft-bg: #e6e7e3;
  --shadow-sm: 0 1px 2px oklch(0.25 0.03 210 / 0.06);
  --shadow-md: 0 6px 20px oklch(0.25 0.03 210 / 0.08);
}
[data-theme="dark"] {
  --color-bg: #0f1719;
  --color-surface: #142023;
  --color-surface-2: #182629;
  --color-surface-offset: #1c2b2e;
  --color-border: oklch(0.9 0.02 200 / 0.12);
  --color-divider: oklch(0.9 0.02 200 / 0.07);
  --color-text: #e6ebe9;
  --color-text-muted: #9fadb0;
  --color-text-faint: #6c7a7d;
  --color-text-inverse: #0f1719;
  --color-primary: #7fc2c4;
  --color-primary-hover: #a3d6d7;
  --color-primary-soft: #1d3a3d;
  --color-straw: #3a3420;
  --color-straw-ink: #e8d79c;
  --ok: #9ad08f; --ok-bg: #1f3320;
  --due: #e8c26a; --due-bg: #3a2f14;
  --late: #f0a39b; --late-bg: #3d1f1d;
  --draft: #a8b3b5; --draft-bg: #263235;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.3);
  --shadow-md: 0 6px 20px rgb(0 0 0 / 0.35);
}

:root {
  --font-display: 'Zodiak', 'Georgia', serif;
  --font-body: 'Switzer', 'Helvetica Neue', sans-serif;
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --text-2xl: clamp(2rem, 1.2rem + 2.5vw, 3.5rem);
  --text-3xl: clamp(2.5rem, 1rem + 4vw, 4.75rem);
  --space-1: .25rem; --space-2: .5rem; --space-3: .75rem; --space-4: 1rem; --space-5: 1.25rem;
  --space-6: 1.5rem; --space-8: 2rem; --space-10: 2.5rem; --space-12: 3rem; --space-16: 4rem; --space-20: 5rem; --space-24: 6rem;
  --radius-sm: .375rem; --radius-md: .625rem; --radius-lg: 1rem;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--color-bg); color: var(--color-text);
  font-family: var(--font-body); font-size: var(--text-base); line-height: 1.6;
  -webkit-font-smoothing: antialiased; min-height: 100vh; display: flex; flex-direction: column;
}
main { flex: 1; outline: none; }
a { color: var(--color-primary); text-underline-offset: 3px; }
a:hover { color: var(--color-primary-hover); }
h1, h2, h3 { margin: 0; line-height: 1.15; font-weight: 500; }
p { margin: 0 0 var(--space-4); }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 3px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.wrap { width: min(1180px, 100% - 2 * clamp(var(--space-4), 4vw, var(--space-10))); margin-inline: auto; }
.muted { color: var(--color-text-muted); }
.small { font-size: var(--text-sm); }
.xs { font-size: var(--text-xs); }
.skip { position: absolute; left: -999px; top: var(--space-2); background: var(--color-primary); color: var(--color-text-inverse); padding: var(--space-2) var(--space-4); z-index: 100; border-radius: var(--radius-sm); }
.skip:focus { left: var(--space-2); }
.eyebrow { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .12em; font-weight: 600; color: var(--color-text-muted); margin-bottom: var(--space-3); }

/* Header */
.site-header { position: sticky; top: 0; z-index: 50; background: oklch(from var(--color-bg) l c h / 0.88); backdrop-filter: blur(12px); border-bottom: 1px solid var(--color-divider); }
.header-inner { display: flex; align-items: center; gap: var(--space-6); height: 64px; }
.brand { display: flex; align-items: center; gap: var(--space-2); color: var(--color-text); text-decoration: none; }
.brand:hover { color: var(--color-text); }
.logo { width: 30px; height: 30px; color: var(--color-primary); }
.brand-word { font-family: var(--font-display); font-size: 1.375rem; font-weight: 500; letter-spacing: -0.01em; }
.brand-tld { color: var(--color-text-muted); }
.nav { display: flex; gap: var(--space-1); margin-left: auto; }
.nav a { font-size: var(--text-sm); color: var(--color-text-muted); text-decoration: none; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); font-weight: 500; white-space: nowrap; transition: color .2s, background .2s; }
.nav a:hover { color: var(--color-text); background: var(--color-surface-offset); }
.nav a[aria-current="page"] { color: var(--color-primary); background: var(--color-primary-soft); }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--color-border); background: transparent; color: var(--color-text); border-radius: var(--radius-md); cursor: pointer; }
.icon-btn:hover { background: var(--color-surface-offset); }
@media (max-width: 760px) {
  .header-inner { height: auto; flex-wrap: wrap; padding-block: var(--space-3); gap: var(--space-2); }
  .nav { order: 3; width: 100%; margin-left: 0; overflow-x: auto; }
  #themeToggle { margin-left: auto; }
}

/* Hero */
.hero { padding-block: clamp(var(--space-12), 9vw, var(--space-24)) clamp(var(--space-10), 6vw, var(--space-16)); position: relative; overflow: hidden; }
.hero-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: clamp(var(--space-8), 5vw, var(--space-16)); align-items: end; }
.hero h1 { font-family: var(--font-display); font-size: var(--text-3xl); letter-spacing: -0.02em; font-weight: 400; max-width: 14ch; }
.hero h1 em { font-style: italic; color: var(--color-primary); }
.hero-lede { font-size: var(--text-base); color: var(--color-text-muted); max-width: 46ch; margin-top: var(--space-6); }
.hero-vessel { position: absolute; inset: auto 0 0 0; height: 140px; color: var(--color-primary); opacity: .14; pointer-events: none; }
@media (max-width: 900px) { .hero-grid { grid-template-columns: 1fr; } }

.search { display: flex; align-items: center; gap: var(--space-2); background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4); box-shadow: var(--shadow-md); }
.search:focus-within { border-color: var(--color-primary); }
.search svg { flex: none; color: var(--color-text-muted); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; font: inherit; color: var(--color-text); padding: var(--space-3) 0; outline: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: 44px; padding: var(--space-2) var(--space-5); border-radius: var(--radius-md); border: 1px solid transparent; font: inherit; font-size: var(--text-sm); font-weight: 600; cursor: pointer; text-decoration: none; transition: background .2s, color .2s, border-color .2s; }
.btn-primary { background: var(--color-primary); color: var(--color-text-inverse); }
.btn-primary:hover { background: var(--color-primary-hover); color: var(--color-text-inverse); }
.btn-ghost { background: transparent; color: var(--color-text); border-color: var(--color-border); }
.btn-ghost:hover { background: var(--color-surface-offset); color: var(--color-text); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.quick { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }
.chip { font-size: var(--text-xs); font-weight: 500; padding: var(--space-1) var(--space-3); border-radius: 999px; border: 1px solid var(--color-border); background: transparent; color: var(--color-text-muted); cursor: pointer; font-family: inherit; min-height: 32px; }
.chip:hover { color: var(--color-text); border-color: var(--color-text-faint); }

/* Stats strip */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--color-divider); border-bottom: 1px solid var(--color-divider); }
.stat { padding: var(--space-6) var(--space-4); border-right: 1px solid var(--color-divider); }
.stat:last-child { border-right: 0; }
.stat-num { font-family: var(--font-display); font-size: var(--text-xl); line-height: 1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: var(--space-2); }
@media (max-width: 700px) { .stats { grid-template-columns: repeat(2, 1fr); } .stat:nth-child(2) { border-right: 0; } .stat:nth-child(-n+2) { border-bottom: 1px solid var(--color-divider); } }

/* Sections */
.section { padding-block: clamp(var(--space-10), 6vw, var(--space-20)); }
.section-tight { padding-block: clamp(var(--space-8), 4vw, var(--space-12)); }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-6); flex-wrap: wrap; }
.section-head h2 { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 400; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-6); }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }

.door { display: flex; flex-direction: column; justify-content: space-between; min-height: 260px; padding: var(--space-8); border-radius: var(--radius-lg); text-decoration: none; color: var(--color-text); background: var(--color-surface); border: 1px solid var(--color-border); transition: transform .3s var(--ease), box-shadow .3s var(--ease); }
.door:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); color: var(--color-text); }
.door h3 { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 400; margin-bottom: var(--space-3); }
.door.patients { background: var(--color-straw); border-color: transparent; }
.door.patients .door-cta { color: var(--color-straw-ink); }
.door-cta { font-weight: 600; font-size: var(--text-sm); color: var(--color-primary); display: inline-flex; gap: var(--space-2); align-items: center; }

.partners { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: var(--space-8); padding: var(--space-10) 0; }
.partner h3 { font-size: var(--text-lg); font-weight: 600; margin-bottom: var(--space-1); }
.partner p { font-size: var(--text-sm); color: var(--color-text-muted); margin: 0; }
.partner:last-child { text-align: right; }
.partner-link { color: var(--color-primary); font-size: var(--text-sm); }
.bridge { width: 160px; color: var(--color-primary); }
@media (max-width: 760px) { .partners { grid-template-columns: 1fr; text-align: left; } .partner:last-child { text-align: left; } .bridge { width: 120px; transform: rotate(90deg); margin: var(--space-2) 0; } }

/* Library */
.page-head { padding-block: clamp(var(--space-10), 5vw, var(--space-16)) var(--space-6); }
.page-head h1 { font-family: var(--font-display); font-size: var(--text-2xl); font-weight: 400; letter-spacing: -0.015em; }
.page-head p { color: var(--color-text-muted); max-width: 60ch; margin-top: var(--space-3); }
.library { display: grid; grid-template-columns: 240px 1fr; gap: clamp(var(--space-6), 4vw, var(--space-12)); padding-bottom: var(--space-20); }
@media (max-width: 860px) { .library { grid-template-columns: 1fr; } }
.filters { position: sticky; top: 88px; align-self: start; display: flex; flex-direction: column; gap: var(--space-6); }
@media (max-width: 860px) { .filters { position: static; } }
.filter-groups { display: flex; flex-direction: column; gap: var(--space-6); }
.filters fieldset { border: 0; padding: 0; margin: 0; }
.filters legend { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .1em; font-weight: 600; color: var(--color-text-muted); margin-bottom: var(--space-2); padding: 0; }
.check { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); padding: var(--space-1) 0; cursor: pointer; min-height: 32px; }
.check input { accent-color: var(--color-primary); width: 16px; height: 16px; }
.check .count { margin-left: auto; color: var(--color-text-faint); font-variant-numeric: tabular-nums; font-size: var(--text-xs); }
.filters-mobile-toggle { display: none; }
@media (max-width: 860px) {
  .filters-mobile-toggle { display: inline-flex; }
  .filters[data-open="false"] .filter-groups { display: none; }
  .filter-groups { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
}
.results-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); margin: var(--space-4) 0; font-size: var(--text-sm); color: var(--color-text-muted); flex-wrap: wrap; }
.results-bar select { font: inherit; font-size: var(--text-sm); color: var(--color-text); background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); min-height: 40px; }

.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--color-divider); }
.row { display: grid; grid-template-columns: 1fr auto; gap: var(--space-4); padding: var(--space-5) var(--space-2); border-bottom: 1px solid var(--color-divider); transition: background .2s; }
.row:hover { background: var(--color-surface); }
.row-title { font-weight: 600; font-size: var(--text-base); line-height: 1.35; color: var(--color-text); text-decoration: none; }
.row-title:hover { color: var(--color-primary); }
.row-meta { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); align-items: center; margin-top: var(--space-2); font-size: var(--text-xs); color: var(--color-text-muted); }
.row-summary { font-size: var(--text-sm); color: var(--color-text-muted); margin: var(--space-2) 0 0; max-width: 72ch; }
.row-actions { display: flex; align-items: start; gap: var(--space-2); }
@media (max-width: 600px) { .row { grid-template-columns: 1fr; } }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-xs); font-weight: 600; padding: 2px var(--space-2); border-radius: 999px; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-current { color: var(--ok); background: var(--ok-bg); }
.b-due { color: var(--due); background: var(--due-bg); }
.b-overdue { color: var(--late); background: var(--late-bg); }
.b-draft { color: var(--draft); background: var(--draft-bg); }
.b-none { color: var(--color-text-muted); background: var(--color-surface-offset); }
.tag-svc { font-weight: 600; color: var(--color-text); }
.dot-sep::before { content: "·"; margin-right: var(--space-3); color: var(--color-text-faint); }

.empty { padding: var(--space-16) var(--space-4); text-align: center; color: var(--color-text-muted); border: 1px dashed var(--color-border); border-radius: var(--radius-lg); }

/* Leaflet cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--space-4); }
.card { display: flex; flex-direction: column; gap: var(--space-3); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-6); }
.card h3 { font-size: var(--text-base); font-weight: 600; line-height: 1.35; }
.card h3 a { color: var(--color-text); text-decoration: none; }
.card h3 a:hover { color: var(--color-primary); }
.card p { font-size: var(--text-sm); color: var(--color-text-muted); margin: 0; flex: 1; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; }
.leaf-mark { width: 40px; height: 52px; border-radius: 4px; background: var(--color-straw); position: relative; }
.leaf-mark::after { content: ""; position: absolute; inset: 12px 8px auto; height: 2px; background: var(--color-straw-ink); opacity: .5; box-shadow: 0 6px 0 var(--color-straw-ink), 0 12px 0 var(--color-straw-ink), 0 18px 0 var(--color-straw-ink); }

/* Detail */
.detail { display: grid; grid-template-columns: 1fr 320px; gap: clamp(var(--space-8), 5vw, var(--space-16)); padding-bottom: var(--space-20); }
@media (max-width: 900px) { .detail { grid-template-columns: 1fr; } }
.crumbs { font-size: var(--text-sm); color: var(--color-text-muted); margin-bottom: var(--space-4); }
.crumbs a { color: var(--color-text-muted); }
.detail h1 { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 400; letter-spacing: -0.01em; max-width: 28ch; }
.detail-summary { font-size: var(--text-base); max-width: 62ch; margin-top: var(--space-5); }
.note { background: var(--due-bg); color: var(--color-text); padding: var(--space-4) var(--space-5); border-radius: var(--radius-md); font-size: var(--text-sm); max-width: 62ch; }
.meta-panel { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-6); align-self: start; position: sticky; top: 88px; }
.meta-panel dl { margin: 0 0 var(--space-6); display: grid; grid-template-columns: auto 1fr; gap: var(--space-3) var(--space-4); font-size: var(--text-sm); }
.meta-panel dt { color: var(--color-text-muted); }
.meta-panel dd { margin: 0; font-weight: 500; }
.meta-panel .btn { width: 100%; margin-bottom: var(--space-2); }
.tags { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-6); }
.tag { font-size: var(--text-xs); padding: 2px var(--space-3); border-radius: 999px; background: var(--color-surface-offset); color: var(--color-text-muted); }

/* Prose pages */
.prose { max-width: 68ch; }
.prose h2 { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 500; margin: var(--space-10) 0 var(--space-3); }
.prose ul, .prose ol { padding-left: var(--space-5); margin: 0 0 var(--space-4); }
.prose li { margin-bottom: var(--space-2); }
.steps { list-style: none; padding: 0; margin: var(--space-8) 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; border-top: 2px solid var(--color-primary); }
.steps li { padding: var(--space-5) var(--space-5) 0 0; position: relative; }
.steps li::before { content: ""; position: absolute; top: -7px; left: 0; width: 12px; height: 12px; border-radius: 50%; background: var(--color-bg); border: 2px solid var(--color-primary); }
.steps .n { font-size: var(--text-xs); font-weight: 600; color: var(--color-primary); letter-spacing: .08em; text-transform: uppercase; }
.steps h3 { font-size: var(--text-base); font-weight: 600; margin: var(--space-1) 0 var(--space-2); }
.steps p { font-size: var(--text-sm); color: var(--color-text-muted); }
@media (max-width: 800px) { .steps { grid-template-columns: 1fr 1fr; row-gap: var(--space-8); } }
.code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: var(--text-xs); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: var(--space-5); overflow-x: auto; white-space: pre; line-height: 1.6; }
.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: clamp(var(--space-8), 5vw, var(--space-16)); padding-bottom: var(--space-20); }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
.aside-box { background: var(--color-primary-soft); border-radius: var(--radius-lg); padding: var(--space-6); align-self: start; }
.aside-box h2 { font-size: var(--text-base); font-weight: 600; margin-bottom: var(--space-3); }
.aside-box p, .aside-box li { font-size: var(--text-sm); }

/* Footer */
.site-footer { border-top: 1px solid var(--color-divider); padding-block: var(--space-12); background: var(--color-surface); }
.footer-inner { display: grid; grid-template-columns: 1fr 1.3fr; gap: var(--space-10); }
.footer-brand { font-family: var(--font-display); font-size: var(--text-lg); margin-bottom: var(--space-2); }
.footer-legal p { margin-bottom: var(--space-2); }
@media (max-width: 760px) { .footer-inner { grid-template-columns: 1fr; } }

.fade-in { animation: fade .45s var(--ease); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media print {
  .site-header, .site-footer, .filters, .row-actions, .meta-panel .btn { display: none !important; }
  body { background: #fff; color: #000; }
}
