/* ============================================================
   RunSAFi: commercial site for the SAFi open-source project
   Palette and typography follow the SAFi application: neutral
   grays, a single green accent, Inter for UI, Source Serif 4
   for display and pull quotes.
   ============================================================ */

/* Self-hosted fonts. No third-party font CDN callout, matching
   the application's own policy. Licenses in assets/fonts/. */
@font-face {
  font-family: 'Inter';
  src: url('../assets/fonts/InterVariable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('../assets/fonts/InterVariable-Italic.woff2') format('woff2');
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'Source Serif 4';
  src: url('../assets/fonts/SourceSerif4Variable-Roman.woff2') format('woff2');
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}

/* ---------- tokens: light ---------- */
:root {
  --bg:            #ffffff;
  --bg-sunken:     #fafafa;
  --bg-raised:     #ffffff;
  --bg-inverse:    #171717;
  --border:        #e5e5e5;
  --border-strong: #d4d4d4;
  --text:          #171717;
  --text-muted:    #525252;
  --text-faint:    #737373;
  --text-inverse:  #fafafa;
  --accent:        #16a34a;
  --accent-hover:  #15803d;
  --accent-soft:   #f0fdf4;
  --accent-text:   #15803d;
  --shadow-sm:     0 1px 2px rgba(0,0,0,.05);
  --shadow-md:     0 4px 16px rgba(0,0,0,.06);

  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --wrap: 1120px;
  --wrap-narrow: 760px;
}

/* ---------- tokens: dark ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #171717;
    --bg-sunken:     #121212;
    --bg-raised:     #1f1f1f;
    --bg-inverse:    #fafafa;
    --border:        #2e2e2e;
    --border-strong: #404040;
    --text:          #f5f5f5;
    --text-muted:    #a3a3a3;
    --text-faint:    #8a8a8a;
    --text-inverse:  #171717;
    --accent:        #22c55e;
    --accent-hover:  #4ade80;
    --accent-soft:   #14261a;
    --accent-text:   #4ade80;
    --shadow-sm:     0 1px 2px rgba(0,0,0,.4);
    --shadow-md:     0 4px 16px rgba(0,0,0,.35);
  }
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'calt' on, 'liga' on;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; letter-spacing: -0.02em; font-weight: 600; }
p { margin: 0 0 1.1em; }
ul, ol { margin: 0 0 1.1em; padding-left: 1.3em; }
li { margin-bottom: .5em; }
strong { font-weight: 600; color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 3px; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--bg); color: var(--text);
  padding: .75rem 1rem; z-index: 200; border: 1px solid var(--border);
}
.skip-link:focus { left: 1rem; top: 1rem; }

/* ---------- layout ---------- */
.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 1.5rem; }
.wrap-narrow { max-width: var(--wrap-narrow); }
section { padding: 5.5rem 0; }
section.tight { padding: 3.5rem 0; }
.sunken { background: var(--bg-sunken); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }

.eyebrow {
  font-size: .75rem; font-weight: 600; letter-spacing: .12em;
  text-transform: uppercase; color: var(--accent-text);
  margin: 0 0 1rem;
}
.section-head { max-width: 46rem; margin-bottom: 3rem; }
.section-head h2 { font-size: clamp(1.75rem, 3.4vw, 2.4rem); margin-bottom: .9rem; }
.section-head p:not(.eyebrow) { color: var(--text-muted); font-size: 1.075rem; margin: 0; }
.lede { font-size: 1.15rem; color: var(--text-muted); }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .site-header { background: var(--bg); }
}
.site-header .wrap {
  display: flex; align-items: center; gap: 2rem;
  height: 64px;
}
.brand {
  display: inline-flex; align-items: center; gap: .625rem;
  font-weight: 600; font-size: 1.0625rem; letter-spacing: -.02em;
  color: var(--text); text-decoration: none; flex-shrink: 0;
}
.brand:hover { text-decoration: none; }
.brand-mark { display: block; flex-shrink: 0; line-height: 0; }
/* Transparent-background marks, so no box or border is needed in either
   theme. The artwork fills 84% of its canvas, hence 40px here to render an
   optically ~34px mark. */
.brand-mark img { width: 40px; height: 40px; }

.nav { display: flex; align-items: center; gap: 1.75rem; margin-left: auto; }
.nav a:not(.btn) {
  color: var(--text-muted); font-size: .9375rem; font-weight: 500;
  text-decoration: none; white-space: nowrap;
}
.nav a:not(.btn):hover, .nav a:not(.btn)[aria-current="page"] { color: var(--text); text-decoration: none; }
.nav a:not(.btn)[aria-current="page"] { font-weight: 600; }

.nav-toggle {
  display: none; margin-left: auto;
  background: none; border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); padding: .4rem .6rem; font: inherit; font-size: .875rem;
  cursor: pointer;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .7rem 1.25rem; border-radius: 8px;
  font-size: .9375rem; font-weight: 600; letter-spacing: -.01em;
  text-decoration: none; border: 1px solid transparent; cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #ffffff; }
.btn-primary:hover { background: var(--accent-hover); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #052e13; } }
.btn-secondary { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--bg-sunken); border-color: var(--text-faint); }
.btn-sm { padding: .5rem .9rem; font-size: .875rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }

/* ---------- hero ---------- */
.hero { padding: 6rem 0 5rem; }
.hero h1 {
  font-size: clamp(2.25rem, 5.2vw, 3.5rem);
  letter-spacing: -.035em; line-height: 1.08;
  max-width: 22ch; margin-bottom: 1.5rem;
}
.hero .lede { max-width: 46rem; font-size: clamp(1.075rem, 1.6vw, 1.25rem); margin-bottom: 2rem; }
.hero-note { font-size: .875rem; color: var(--text-faint); margin: 1.5rem 0 0; }

/* ---------- hero figure: boundary diagram ---------- */
.hero-grid {
  display: grid; grid-template-columns: 1.08fr 1fr;
  gap: 3.5rem; align-items: center;
}
.hero-copy h1 { max-width: 18ch; }
.hero-copy .lede { max-width: none; }

.hero-figure { margin: 0; }
.boundary-diagram {
  display: block; width: 100%; height: auto;
  font-family: var(--sans);
}
.boundary-diagram .bd-label {
  font-size: 9.5px; font-weight: 600; letter-spacing: .12em;
  fill: var(--text-faint);
}
.boundary-diagram .bd-title {
  font-size: 13px; font-weight: 600; letter-spacing: -.01em;
  fill: var(--text);
}
.boundary-diagram .bd-note {
  font-size: 10.5px; font-weight: 400; fill: var(--text-muted);
}
.hero-figure figcaption {
  margin-top: 1.25rem; font-size: .8125rem; line-height: 1.5;
  color: var(--text-faint); max-width: 34rem;
}

/* A prose block that keeps normal paragraph rhythm, unlike .section-head
   which collapses margins for single-paragraph intros. */
.copy-block { max-width: 46rem; }
.copy-block h2 { font-size: clamp(1.6rem, 3vw, 2.15rem); margin-bottom: 1rem; }
.copy-block p { color: var(--text-muted); }

/* ---------- five principles, laid out across one card ---------- */
.principles-card { margin-top: 4rem; padding: 2rem; }
.principles-card h3 { font-size: 1.25rem; margin-bottom: .5rem; }
/* .card p later in the file zeroes paragraph margins, so this needs the extra
   class to win on specificity rather than order. */
.card.principles-card > p {
  font-size: .9375rem; color: var(--text-muted);
  max-width: 58ch; margin: 0 0 2rem;
}
.principles {
  list-style: none; padding: 0; margin: 0;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1.75rem;
}
.principles li { margin: 0; }
.principles strong {
  display: block; font-size: .9375rem; font-weight: 600; margin-bottom: .375rem;
}
.principles span { font-size: .875rem; color: var(--text-muted); line-height: 1.55; }

.tagline {
  font-family: var(--serif); font-size: clamp(1.35rem, 2.6vw, 1.85rem);
  line-height: 1.35; color: var(--text); font-weight: 400;
  border-left: 3px solid var(--accent); padding-left: 1.5rem;
  margin: 0; max-width: 34rem;
}
.tagline span { display: block; color: var(--text-muted); }
.tagline strong { font-weight: 600; }

/* ---------- cards & grids ---------- */
.grid { display: grid; gap: 1.5rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-split { grid-template-columns: 1.05fr .95fr; gap: 4rem; align-items: center; }

.card {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 12px; padding: 1.75rem;
}
.card h3 { font-size: 1.0625rem; margin-bottom: .625rem; }
.card p:last-child { margin-bottom: 0; }
.card p { color: var(--text-muted); font-size: .9375rem; margin-bottom: 0; }
.card-num {
  font-family: var(--mono); font-size: .75rem; font-weight: 600;
  color: var(--accent-text); margin-bottom: .875rem; display: block;
}

/* ---------- ownership split (we bring / you bring) ---------- */
.split-panel {
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  background: var(--bg-raised);
}
.split-panel > header {
  padding: 1.25rem 1.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
}
.split-panel > header h3 { font-size: 1rem; margin-bottom: .2rem; }
.split-panel > header p { font-size: .8125rem; color: var(--text-faint); margin: 0; }
.split-panel ul { list-style: none; padding: 1.5rem 1.75rem; margin: 0; }
.split-panel li {
  position: relative; padding-left: 1.6rem; margin-bottom: .9rem;
  font-size: .9375rem; color: var(--text-muted);
}
.split-panel li:last-child { margin-bottom: 0; }
.split-panel li::before {
  content: ''; position: absolute; left: 0; top: .58em;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
}
.split-panel li strong { color: var(--text); }

/* ---------- responsibility table ---------- */
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .9375rem; min-width: 34rem; }
thead th {
  text-align: left; font-weight: 600; font-size: .75rem;
  letter-spacing: .08em; text-transform: uppercase; color: var(--text-faint);
  padding: .9rem 1.25rem; background: var(--bg-sunken);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: .9rem 1.25rem; border-bottom: 1px solid var(--border); color: var(--text-muted); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody th {
  text-align: left; font-weight: 600; color: var(--text);
  padding: .9rem 1.25rem; border-bottom: 1px solid var(--border); vertical-align: top;
}
tbody tr:last-child th { border-bottom: 0; }

/* ---------- steps ---------- */
.steps { list-style: none; padding: 0; margin: 0; counter-reset: step; }
.steps li {
  position: relative; padding-left: 3.5rem; padding-bottom: 2rem;
  counter-increment: step; margin: 0;
}
.steps li::before {
  content: counter(step);
  position: absolute; left: 0; top: -2px;
  width: 2.25rem; height: 2.25rem; border-radius: 50%;
  background: var(--bg-raised); border: 1px solid var(--border-strong);
  color: var(--text); font-size: .875rem; font-weight: 600;
  display: grid; place-items: center;
}
.steps li::after {
  content: ''; position: absolute; left: 1.125rem; top: 2.5rem; bottom: .25rem;
  width: 1px; background: var(--border);
}
.steps li:last-child { padding-bottom: 0; }
.steps li:last-child::after { display: none; }
.steps h3 { font-size: 1.0625rem; margin-bottom: .4rem; }
.steps p { color: var(--text-muted); font-size: .9375rem; margin: 0; }

/* ---------- pricing ---------- */
.price-card {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 12px; padding: 2rem; display: flex; flex-direction: column;
}
.price-card.featured { border-color: var(--accent); box-shadow: var(--shadow-md); }
.price-card .kind {
  font-size: .75rem; font-weight: 600; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-faint); margin-bottom: 1rem;
}
.price-card.featured .kind { color: var(--accent-text); }
.price-card h3 { font-size: 1.5rem; margin-bottom: .5rem; letter-spacing: -.025em; }
.price-card .terms { font-size: .9375rem; color: var(--text-muted); margin-bottom: 1.5rem; }
.price-card ul { list-style: none; padding: 0; margin: 0 0 1.75rem; }
.price-card li {
  position: relative; padding-left: 1.5rem; font-size: .9375rem;
  color: var(--text-muted); margin-bottom: .75rem;
}
.price-card li::before {
  content: '✓'; position: absolute; left: 0; top: 0;
  color: var(--accent); font-weight: 600; font-size: .875rem;
}
.price-card .btn { margin-top: auto; }

.callout {
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0; background: var(--accent-soft);
  padding: 1.5rem 1.75rem;
}
.callout p:last-child { margin-bottom: 0; }
.callout h3 { font-size: 1rem; margin-bottom: .5rem; }
.callout p { font-size: .9375rem; color: var(--text-muted); }

.note {
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg-sunken); padding: 1.25rem 1.5rem;
  font-size: .9375rem; color: var(--text-muted);
}
.note p:last-child { margin-bottom: 0; }

/* ---------- "what this is not" ---------- */
.exclusions { list-style: none; padding: 0; margin: 0; }
.exclusions li {
  position: relative; padding-left: 1.75rem; margin-bottom: 1rem;
  color: var(--text-muted); font-size: .9375rem;
}
.exclusions li::before {
  content: ''; position: absolute; left: 0; top: .72em;
  width: 11px; height: 2px; border-radius: 1px;
  background: var(--text-faint);
}
.exclusions strong { color: var(--text); }

/* ---------- CTA band ---------- */
.cta-band {
  background: var(--bg-inverse); color: var(--text-inverse);
  padding: 4.5rem 0;
}
.cta-band h2 { font-size: clamp(1.6rem, 3.2vw, 2.15rem); margin-bottom: 1rem; max-width: 28ch; }
.cta-band p { color: color-mix(in srgb, var(--text-inverse) 68%, transparent); max-width: 44rem; font-size: 1.05rem; }
@supports not (color: color-mix(in srgb, red 50%, blue)) {
  .cta-band p { opacity: .72; }
}
.cta-band .btn-primary { background: var(--accent); color: #ffffff; }
@media (prefers-color-scheme: dark) { .cta-band .btn-primary { color: #052e13; } }
.cta-band .btn-secondary {
  color: var(--text-inverse);
  border-color: color-mix(in srgb, var(--text-inverse) 32%, transparent);
}
.cta-band .btn-secondary:hover {
  background: color-mix(in srgb, var(--text-inverse) 10%, transparent);
  border-color: var(--text-inverse);
}

/* In dark mode --bg-inverse resolves to near-white, which would make this the
   one band on the page that gets brighter instead of darker. Override it with
   an elevated dark surface so it still reads as a distinct band, and let the
   green button carry the emphasis the dark slab carries in light mode. */
@media (prefers-color-scheme: dark) {
  .cta-band {
    background: var(--bg-raised);
    color: var(--text);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }
  .cta-band p { color: var(--text-muted); }
  .cta-band .btn-secondary { color: var(--text); border-color: var(--border-strong); }
  .cta-band .btn-secondary:hover {
    background: var(--bg-sunken); border-color: var(--text-faint);
  }
}

/* ---------- enquiry form ---------- */
.form-layout {
  display: grid; grid-template-columns: 1.45fr 1fr; gap: 3.5rem; align-items: start;
}
.form-heading { font-size: clamp(1.6rem, 3vw, 2.15rem); margin-bottom: 1rem; }
.form-intro { color: var(--text-muted); max-width: 46ch; margin-bottom: 2rem; }

.enquiry-form { margin: 0; }
.field-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem 1.5rem; margin-bottom: 1.5rem;
}
.field { margin: 0 0 1.5rem; display: flex; flex-direction: column; }
.field-grid .field { margin-bottom: 0; }
.field label {
  font-size: .875rem; font-weight: 600; color: var(--text);
  margin-bottom: .4rem; display: flex; align-items: baseline; gap: .4rem;
}
.req { color: var(--accent-text); font-weight: 700; }
.opt {
  font-size: .75rem; font-weight: 400; color: var(--text-faint);
  text-transform: none; letter-spacing: 0;
}

.field input, .field select, .field textarea {
  font: inherit; font-size: .9375rem;
  width: 100%; padding: .65rem .8rem;
  color: var(--text); background: var(--bg-raised);
  border: 1px solid var(--border-strong); border-radius: 8px;
  transition: border-color .15s ease, box-shadow .15s ease;
  -webkit-appearance: none; appearance: none;
}
.field textarea { resize: vertical; min-height: 7rem; line-height: 1.55; }
.field select {
  /* the arrow is drawn here because appearance:none removes the native one */
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23737373' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .8rem center;
  padding-right: 2.2rem; cursor: pointer;
}
.field input::placeholder, .field textarea::placeholder { color: var(--text-faint); }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.field input[aria-invalid="true"], .field textarea[aria-invalid="true"] {
  border-color: #dc2626;
}
.field-hint { font-size: .8125rem; color: var(--text-faint); margin-top: .35rem; }
.field-error { font-size: .8125rem; color: #dc2626; margin-top: .35rem; font-weight: 500; }
@media (prefers-color-scheme: dark) {
  .field-error, .field input[aria-invalid="true"], .field textarea[aria-invalid="true"] { color: #f87171; }
  .field input[aria-invalid="true"], .field textarea[aria-invalid="true"] { border-color: #f87171; }
}

/* honeypot: off-screen but still focusable-free, never display:none (some bots skip those) */
.hp {
  position: absolute; left: -9999px; width: 1px; height: 1px;
  overflow: hidden;
}

.form-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 1rem;
  margin-top: .5rem;
}
.form-actions .btn[aria-busy="true"] { opacity: .7; pointer-events: none; }
.form-note { font-size: .8125rem; color: var(--text-faint); max-width: 34ch; line-height: 1.5; }

.form-status {
  border-radius: 10px; padding: 1rem 1.25rem; margin-bottom: 1.75rem;
  font-size: .9375rem; border: 1px solid var(--border);
}
.form-status[data-state="ok"] {
  background: var(--accent-soft); border-color: var(--accent);
  color: var(--text);
}
.form-status[data-state="error"] {
  background: color-mix(in srgb, #dc2626 8%, var(--bg-raised));
  border-color: #dc2626;
}
.form-status strong { display: block; margin-bottom: .25rem; }
.form-status p { margin: 0; color: var(--text-muted); font-size: .875rem; }

.contact-aside { display: grid; gap: 1.5rem; }
.plain-list { list-style: none; padding: 0; margin: 0; font-size: .9375rem; }
.plain-list li { margin-bottom: .5rem; }
.plain-list li:last-child { margin-bottom: 0; }

/* ---------- contact ---------- */
.contact-card {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 12px; padding: 2rem;
}
.contact-card h3 { font-size: 1.125rem; margin-bottom: .625rem; }
.contact-card p { color: var(--text-muted); font-size: .9375rem; }
.contact-mail {
  font-family: var(--mono); font-size: 1rem; font-weight: 500;
  word-break: break-all;
}
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li {
  position: relative; padding-left: 1.75rem; margin-bottom: .9rem;
  color: var(--text-muted); font-size: .9375rem;
}
.checklist li::before {
  content: ''; position: absolute; left: .1rem; top: .5em;
  width: 8px; height: 8px; border: 1.5px solid var(--border-strong);
  border-radius: 2px;
}
.checklist strong { color: var(--text); }

/* ---------- chat widget ---------- */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.chat-root { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 150; }

.chat-launcher {
  display: inline-flex; align-items: center; gap: .55rem;
  padding: .7rem 1.1rem; border-radius: 999px; border: 1px solid transparent;
  background: var(--accent); color: #ffffff;
  font: inherit; font-size: .9375rem; font-weight: 600; letter-spacing: -.01em;
  cursor: pointer; box-shadow: 0 6px 20px rgba(0,0,0,.18);
  transition: background-color .15s ease, transform .15s ease;
}
.chat-launcher:hover { background: var(--accent-hover); }
.chat-launcher:active { transform: translateY(1px); }
.chat-launcher-icon { display: grid; place-items: center; }
@media (prefers-color-scheme: dark) { .chat-launcher { color: #052e13; } }
.chat-open .chat-launcher { display: none; }

.chat-panel {
  width: min(24rem, calc(100vw - 2.5rem));
  height: min(34rem, calc(100vh - 3rem));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 16px 48px rgba(0,0,0,.24);
}
.chat-panel[hidden] { display: none; }
.chat-panel-lg {
  width: min(38rem, calc(100vw - 2.5rem));
  height: min(46rem, calc(100vh - 3rem));
}

.chat-header {
  display: flex; align-items: flex-start; gap: 1rem;
  padding: 1rem 1.1rem; border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
}
.chat-heading { min-width: 0; }
.chat-header h2 { font-size: .9375rem; margin: 0 0 .15rem; }
.chat-header p { font-size: .75rem; color: var(--text-faint); margin: 0; line-height: 1.45; }
.chat-actions { margin-left: auto; flex-shrink: 0; display: flex; gap: .15rem; }
.chat-btn {
  background: none; border: 0; border-radius: 6px; padding: .3rem;
  color: var(--text-muted); cursor: pointer; line-height: 0;
}
.chat-btn:hover { color: var(--text); background: var(--bg-raised); }
.chat-ico-shrink { display: none; }
.chat-panel-lg .chat-ico-grow { display: none; }
.chat-panel-lg .chat-ico-shrink { display: block; }

.chat-log {
  flex: 1; overflow-y: auto; padding: 1.1rem;
  display: flex; flex-direction: column; gap: 1rem;
  overscroll-behavior: contain;
}
.chat-msg { display: flex; flex-direction: column; max-width: 92%; }
.chat-msg-you { align-self: flex-end; align-items: flex-end; }
.chat-msg-bot { align-self: flex-start; }

.chat-bubble {
  padding: .6rem .85rem; border-radius: 12px;
  font-size: .875rem; line-height: 1.55; white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-msg-you .chat-bubble {
  background: var(--accent); color: #ffffff; border-bottom-right-radius: 4px;
}
@media (prefers-color-scheme: dark) { .chat-msg-you .chat-bubble { color: #052e13; } }
.chat-msg-bot .chat-bubble {
  background: var(--bg-sunken); color: var(--text);
  border: 1px solid var(--border); border-bottom-left-radius: 4px;
}
/* Rendered markdown inside a bot bubble. pre-wrap is dropped here because the
   markdown renderer produces real block elements. */
.chat-md { white-space: normal; }
.chat-md > :first-child { margin-top: 0; }
.chat-md > :last-child { margin-bottom: 0; }
.chat-md p { margin: 0 0 .6em; }
.chat-md h4 {
  font-size: .875rem; font-weight: 600; margin: .9em 0 .35em; letter-spacing: -.01em;
}
.chat-md ul, .chat-md ol { margin: 0 0 .6em; padding-left: 1.15rem; }
.chat-md li { margin-bottom: .3em; }
.chat-md li:last-child { margin-bottom: 0; }
.chat-md strong { font-weight: 600; color: inherit; }
.chat-md em { font-style: italic; }
.chat-md code {
  font-family: var(--mono); font-size: .8125em;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; padding: .05em .3em;
}
.chat-md a { color: var(--accent-text); text-decoration: underline; }

/* Caret on the line currently being written. It rides the active block rather
   than the bubble: on a bubble whose children are block elements, ::after would
   render on its own line below the text instead of at the end of it. Using
   ::after rather than a real node keeps it out of the text-node walk the
   typewriter does. */
.chat-typing::after {
  content: '';
  display: inline-block;
  width: 2px; height: 1em;
  margin-left: 1px;
  vertical-align: text-bottom;
  background: var(--text-muted);
  animation: chat-caret 1s steps(1) infinite;
}
@keyframes chat-caret { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .chat-typing::after { display: none; }
}

.chat-meta {
  font-size: .6875rem; color: var(--text-faint); margin: .35rem 0 0;
  letter-spacing: .01em;
}

.chat-thinking { display: inline-flex; gap: .28rem; align-items: center; padding: .8rem .85rem; }
.chat-thinking span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint);
  animation: chat-blink 1.2s infinite ease-in-out both;
}
.chat-thinking span:nth-child(2) { animation-delay: .16s; }
.chat-thinking span:nth-child(3) { animation-delay: .32s; }
@keyframes chat-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .chat-thinking span { animation: none; opacity: .5; }
}

.chat-form {
  display: flex; align-items: flex-end; gap: .5rem;
  padding: .75rem; border-top: 1px solid var(--border);
}
.chat-form textarea {
  flex: 1; font: inherit; font-size: .875rem; line-height: 1.5;
  padding: .55rem .7rem; resize: none; max-height: 120px;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border-strong); border-radius: 9px;
}
.chat-form textarea::placeholder { color: var(--text-faint); }
.chat-form textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.chat-send {
  flex-shrink: 0; width: 2.35rem; height: 2.35rem; border-radius: 9px;
  display: grid; place-items: center; cursor: pointer;
  background: var(--accent); color: #ffffff; border: 0;
}
.chat-send:hover { background: var(--accent-hover); }
.chat-send:disabled { opacity: .5; cursor: default; }
@media (prefers-color-scheme: dark) { .chat-send { color: #052e13; } }

.chat-foot {
  margin: 0; padding: 0 1.1rem .9rem;
  font-size: .6875rem; line-height: 1.5; color: var(--text-faint);
}

@media (max-width: 520px) {
  .chat-root { right: .75rem; bottom: .75rem; left: .75rem; }
  .chat-launcher { width: 100%; justify-content: center; }
  .chat-panel,
  .chat-panel-lg { width: 100%; height: min(30rem, calc(100vh - 2rem)); }

  /* Expanded on a phone, anchor to BOTH edges instead of setting a height.
     100vh on mobile is the viewport with the browser chrome hidden, so a
     100vh-tall panel pinned to the bottom pushes its own header off the top of
     the screen — taking the shrink and close buttons with it, which strands the
     visitor with no way out but a page reload. Anchoring top and bottom removes
     the dependency on vh entirely. */
  .chat-panel-lg {
    position: fixed;
    top: .75rem; right: .75rem; bottom: .75rem; left: .75rem;
    width: auto; height: auto;
  }
}

/* Where dvh is supported it tracks the *visible* viewport, so the unexpanded
   panel stops overshooting when the address bar is showing. */
@supports (height: 100dvh) {
  .chat-panel { height: min(34rem, calc(100dvh - 3rem)); }
  .chat-panel-lg { height: min(46rem, calc(100dvh - 3rem)); }
  @media (max-width: 520px) {
    .chat-panel { height: min(30rem, calc(100dvh - 2rem)); }
    .chat-panel-lg { height: auto; }
  }
}
@media print { .chat-root { display: none; } }

/* ---------- footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
  padding: 3.5rem 0 2.5rem;
  font-size: .875rem;
}
.footer-grid {
  display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr;
  gap: 2.5rem; margin-bottom: 3rem;
}
.footer-grid h4 {
  font-size: .75rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-faint); margin-bottom: 1rem; font-weight: 600;
}
.footer-grid ul { list-style: none; padding: 0; margin: 0; }
.footer-grid li { margin-bottom: .625rem; }
.footer-grid a { color: var(--text-muted); }
.footer-grid a:hover { color: var(--text); }
.footer-about p { color: var(--text-muted); max-width: 30ch; margin: .875rem 0 0; }
.footer-bottom {
  border-top: 1px solid var(--border); padding-top: 1.75rem;
  display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between;
  color: var(--text-faint); font-size: .8125rem;
}
.footer-bottom p { margin: 0; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .grid-split { grid-template-columns: 1fr; gap: 2.5rem; }
  .form-layout { grid-template-columns: 1fr; gap: 2.5rem; }
  .hero-grid { grid-template-columns: 1fr; gap: 3rem; }
  .hero-copy h1 { max-width: 22ch; }
  .boundary-diagram { max-width: 30rem; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .principles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .footer-grid { grid-template-columns: 1fr 1fr; gap: 2rem; }
}
@media (max-width: 720px) {
  body { font-size: 16px; }
  section { padding: 4rem 0; }
  .hero { padding: 3.5rem 0 3rem; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .field-grid { grid-template-columns: 1fr; gap: 1.25rem; margin-bottom: 1.25rem; }
  .principles { grid-template-columns: 1fr; gap: 1.25rem; }
  .nav {
    display: none; position: absolute; top: 64px; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 0;
    background: var(--bg); border-bottom: 1px solid var(--border);
    padding: .5rem 1.5rem 1.25rem;
  }
  .nav.open { display: flex; }
  .nav a:not(.btn) { padding: .75rem 0; border-bottom: 1px solid var(--border); }
  .nav .btn { margin-top: 1rem; border-bottom: 0; justify-content: center; }
  .nav-toggle { display: block; }
  /* the diagram scales down with the viewport, so grow its type inside the
     viewBox to keep the labels readable once shrunk */
  .boundary-diagram .bd-label { font-size: 10.5px; }
  .boundary-diagram .bd-title { font-size: 14.5px; }
  .boundary-diagram .bd-note  { font-size: 11.5px; }
  .tagline { padding-left: 1.125rem; }
  .steps li { padding-left: 3rem; }
}
@media (max-width: 520px) {
  .footer-grid { grid-template-columns: 1fr; }
  .btn { width: 100%; }
  .btn-row { flex-direction: column; align-items: stretch; }
  .nav .btn { width: auto; }
}

@media print {
  .site-header, .nav-toggle, .cta-band { display: none; }
  body { font-size: 11pt; }
}
