/* =========================================================
   SCORE2 Risk Calculator
   Tokens: porcelain paper, green-ink text, cobalt for action.
   Colour is reserved for risk meaning (green → amber → red).
   ========================================================= */

:root {
  --paper: #F2F4F3;
  --surface: #FFFFFF;
  --sunken: #E8ECEA;
  --ink: #16211F;
  --ink-2: #3E4D49;
  --muted: #66756F;
  --line: #D3DBD8;
  --line-strong: #B5C1BC;
  --accent: #2347B5;
  --accent-ink: #FFFFFF;
  --accent-soft: #E3E9FA;
  --focus: #2347B5;

  --c-low: #2F8F5B;
  --c-mod: #7FA62B;
  --c-high: #D9930F;
  --c-vhigh: #C93A2E;
  --c-low-bg: #E3F2E9;
  --c-mod-bg: #EEF4DD;
  --c-high-bg: #FBF0D9;
  --c-vhigh-bg: #F8E1DE;

  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --sans: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 18px;

  --gutter: clamp(16px, 4vw, 40px);
  --maxw: 1240px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #101816;
    --surface: #17211F;
    --sunken: #0C1311;
    --ink: #E6ECEA;
    --ink-2: #BAC6C2;
    --muted: #8D9C97;
    --line: #2A3633;
    --line-strong: #3C4A46;
    --accent: #8EA8FF;
    --accent-ink: #0D1530;
    --accent-soft: #1E2847;
    --focus: #8EA8FF;
    --c-low: #4FB67D;
    --c-mod: #A3C54B;
    --c-high: #F0AE2C;
    --c-vhigh: #F06A5C;
    --c-low-bg: #15291F;
    --c-mod-bg: #222A14;
    --c-high-bg: #2E2410;
    --c-vhigh-bg: #331816;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #101816;
  --surface: #17211F;
  --sunken: #0C1311;
  --ink: #E6ECEA;
  --ink-2: #BAC6C2;
  --muted: #8D9C97;
  --line: #2A3633;
  --line-strong: #3C4A46;
  --accent: #8EA8FF;
  --accent-ink: #0D1530;
  --accent-soft: #1E2847;
  --focus: #8EA8FF;
  --c-low: #4FB67D;
  --c-mod: #A3C54B;
  --c-high: #F0AE2C;
  --c-vhigh: #F06A5C;
  --c-low-bg: #15291F;
  --c-mod-bg: #222A14;
  --c-high-bg: #2E2410;
  --c-vhigh-bg: #331816;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 80px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 500; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }

.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;
}
.skip {
  position: absolute; left: 12px; top: -60px; z-index: 50;
  background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: var(--r-sm);
}
.skip:focus { top: 12px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 10px var(--gutter);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; min-width: 0; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.brand-name { font-weight: 700; letter-spacing: 0.01em; }
.brand-sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 560px) { .brand-sub { display: none; } }
.top-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface); border-radius: 50%;
  cursor: pointer; color: var(--ink-2);
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { border-color: var(--line-strong); color: var(--ink); }

/* ---------- Page ---------- */
.page { max-width: var(--maxw); margin: 0 auto; padding: 0 var(--gutter); }

.intro { padding: clamp(28px, 5vw, 56px) 0 clamp(20px, 3vw, 32px); max-width: 760px; }
.intro h1 {
  font-family: var(--serif);
  font-size: clamp(34px, 5.4vw, 58px);
  line-height: 1.04;
  letter-spacing: -0.015em;
  font-weight: 500;
  font-variation-settings: "opsz" 72;
}
.lede { margin-top: 14px; color: var(--ink-2); font-size: 17px; line-height: 1.55; max-width: 64ch; }
.intro-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: 999px;
  border: 1px solid transparent; cursor: pointer; font-weight: 500; font-size: 15px;
  text-decoration: none; white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:hover { background: var(--surface); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary[disabled] { opacity: 0.6; cursor: progress; }
.btn-block { width: 100%; min-height: 50px; font-size: 16px; }

/* ---------- Workspace ---------- */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: clamp(24px, 4vw, 56px);
  align-items: start;
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Form ---------- */
.form { min-width: 0; }
.group {
  border: 0; margin: 0; padding: 22px 0 26px;
  border-top: 1px solid var(--line);
  min-width: 0;
}
.group legend {
  float: left; width: 100%; padding: 0; margin-bottom: 16px;
  font-family: var(--serif); font-size: 23px; font-weight: 500; letter-spacing: -0.005em;
  font-variation-settings: "opsz" 30;
}
.group legend + * { clear: both; }
.group-quiet legend { color: var(--ink-2); }

.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 520px) { .row { grid-template-columns: minmax(0, 1fr); } }

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; min-width: 0; }
.field:last-child { margin-bottom: 0; }
.row .field { margin-bottom: 0; }
.row + .field, .field + .row, .row + .derived { margin-top: 16px; }
.label { font-size: 14px; font-weight: 500; color: var(--ink-2); }
.hint { font-size: 13px; color: var(--muted); line-height: 1.45; }
.hint-top { margin-bottom: 12px; max-width: 62ch; }
.note {
  font-size: 14px; color: var(--ink-2); background: var(--sunken);
  border-radius: var(--r-sm); padding: 10px 12px; margin-bottom: 14px;
}
.derived { font-size: 14px; color: var(--ink-2); }
.derived strong { font-weight: 600; color: var(--ink); }

/* number input with unit */
.num {
  display: flex; align-items: stretch;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  transition: border-color .15s, box-shadow .15s;
}
.num:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.num input {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none;
  padding: 11px 12px; font-size: 18px; font-weight: 500;
}
.num .unit {
  display: flex; align-items: center; padding: 0 12px; color: var(--muted); font-size: 14px;
  border-left: 1px solid var(--line); white-space: nowrap;
}
.field.is-invalid .num { border-color: var(--c-vhigh); }
.field.is-warn .num { border-color: var(--c-high); }
.field-msg { font-size: 13px; color: var(--c-vhigh); }
.field.is-warn .field-msg { color: color-mix(in srgb, var(--c-high) 70%, var(--ink)); }

.text {
  width: 100%; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  padding: 11px 12px; font-size: 16px; outline: none;
}
.text:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.select { position: relative; }
.select select {
  width: 100%; appearance: none; -webkit-appearance: none;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  padding: 11px 40px 11px 12px; font-size: 16px; cursor: pointer;
}
.select::after {
  content: ""; position: absolute; right: 15px; top: 50%; width: 8px; height: 8px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg); pointer-events: none;
}
.select select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* segmented control */
.seg {
  display: inline-flex; flex-wrap: nowrap; padding: 3px; gap: 2px;
  background: var(--sunken); border-radius: var(--r-md); border: 1px solid var(--line);
  max-width: 100%;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  flex: 1 1 auto; text-align: center; padding: 8px 14px; border-radius: 7px; cursor: pointer;
  font-size: 15px; font-weight: 500; color: var(--ink-2); white-space: nowrap; user-select: none;
  transition: background .15s, color .15s;
}
.seg label:hover { color: var(--ink); }
.seg input:checked + label {
  background: var(--surface); color: var(--ink);
  box-shadow: 0 1px 2px rgba(20, 33, 31, .12), 0 0 0 1px var(--line);
}
.seg input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: 1px; }
.seg-sm label { padding: 5px 11px; font-size: 14px; }
.field > .seg:not(.seg-sm) { display: flex; }
.seg-4 label { padding-left: 6px; padding-right: 6px; }
@media (max-width: 420px) { .seg-4 label { font-size: 13.5px; } }

/* region seg carries the risk colour as a small swatch */
.region-seg label { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.region-seg label::before { content: ""; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.region-seg label[for="reg-low"]::before { background: var(--c-low); }
.region-seg label[for="reg-moderate"]::before { background: var(--c-mod); }
.region-seg label[for="reg-high"]::before { background: var(--c-high); }
.region-seg label[for="reg-veryHigh"]::before { background: var(--c-vhigh); }

/* checks */
.checks { display: flex; flex-direction: column; gap: 4px; }
.check {
  display: grid; grid-template-columns: 22px 1fr; gap: 10px; align-items: start;
  padding: 9px 10px; margin: 0 -10px; border-radius: var(--r-sm); cursor: pointer;
  font-size: 15px; line-height: 1.45; color: var(--ink-2);
}
.check:hover { background: var(--sunken); }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--c-vhigh); cursor: pointer; }
.check:has(input:checked) { color: var(--ink); }

.privacy {
  display: flex; gap: 10px; align-items: flex-start;
  font-size: 13.5px; color: var(--muted); padding: 16px 0 8px; border-top: 1px solid var(--line);
}
.privacy::before {
  content: ""; flex: none; width: 14px; height: 14px; margin-top: 3px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 10V8a6 6 0 1 1 12 0v2h1v12H5V10h1zm2 0h8V8a4 4 0 1 0-8 0v2z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 10V8a6 6 0 1 1 12 0v2h1v12H5V10h1zm2 0h8V8a4 4 0 1 0-8 0v2z'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ---------- Summary (the one bold element) ---------- */
.summary-col { position: sticky; top: 76px; align-self: start; }
@media (max-width: 900px) { .summary-col { position: static; } }

.summary {
  --cat: var(--line-strong);
  --cat-bg: var(--surface);
  background: var(--cat-bg);
  border: 1px solid color-mix(in srgb, var(--cat) 35%, var(--line));
  border-radius: var(--r-lg);
  padding: 24px 24px 22px;
  position: relative;
  overflow: hidden;
  transition: background-color .35s ease, border-color .35s ease;
}
.summary::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--cat);
  transition: background-color .35s ease;
}
.summary[data-cat="low"], .summary[data-cat="lowModerate"] { --cat: var(--c-low); --cat-bg: var(--c-low-bg); }
.summary[data-cat="moderate"] { --cat: var(--c-mod); --cat-bg: var(--c-mod-bg); }
.summary[data-cat="high"] { --cat: var(--c-high); --cat-bg: var(--c-high-bg); }
.summary[data-cat="veryHigh"] { --cat: var(--c-vhigh); --cat-bg: var(--c-vhigh-bg); }
.summary[data-excluded="true"] .risk-value { opacity: .55; }

.summary-empty { padding: 8px 0; }
.empty-title { font-family: var(--serif); font-size: 24px; line-height: 1.2; font-variation-settings: "opsz" 30; }
.empty-body { margin-top: 10px; color: var(--muted); font-size: 14.5px; }

.risk-label { font-size: 14px; color: var(--ink-2); font-weight: 500; }
.risk-value {
  font-family: var(--serif);
  font-size: clamp(76px, 12vw, 112px);
  line-height: .95;
  letter-spacing: -0.035em;
  font-weight: 500;
  font-variation-settings: "opsz" 72;
  margin: 6px 0 4px -3px;
  font-feature-settings: "lnum" 1;
}
.risk-cat {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 17px; font-weight: 600; color: var(--ink);
}
.risk-cat::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--cat); }

.rail { position: relative; height: 12px; margin: 22px 0 6px; border-radius: 6px; display: flex; overflow: visible; }
.rail-seg { height: 100%; }
.rail-seg:first-child { border-radius: 6px 0 0 6px; }
.rail-seg:last-of-type { border-radius: 0 6px 6px 0; }
.rail-marker {
  position: absolute; top: -6px; width: 4px; height: 24px; margin-left: -2px;
  background: var(--ink); border-radius: 2px; box-shadow: 0 0 0 2px var(--cat-bg);
  transition: left .35s cubic-bezier(.2,.7,.2,1);
}
@media (prefers-reduced-motion: reduce) { .rail-marker, .summary, .summary::before { transition: none; } }
.rail-ticks { position: relative; height: 18px; font-size: 12px; color: var(--muted); }
.rail-ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.rail-caption { font-size: 13px; color: var(--muted); margin-top: 2px; }

.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 20px 0 0; padding-top: 16px; border-top: 1px solid color-mix(in srgb, var(--cat) 25%, var(--line)); }
.meta dt { font-size: 12.5px; color: var(--muted); }
.meta dd { margin: 2px 0 0; font-size: 15px; font-weight: 600; }
.meta dd small { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; }

.alert {
  font-size: 14px; line-height: 1.45; padding: 12px 14px; margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--c-vhigh); border-radius: var(--r-md); color: var(--ink);
}
.warnings { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.warnings:empty { display: none; }
.warnings li {
  font-size: 13.5px; line-height: 1.45; color: var(--ink-2);
  padding-left: 20px; position: relative;
}
.warnings li::before {
  content: "!"; position: absolute; left: 0; top: 1px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--c-high); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center;
}
#pdfBtn { margin-top: 20px; }

/* ---------- Details ---------- */
.details { padding: clamp(40px, 6vw, 72px) 0 24px; }
.details > h2 {
  font-family: var(--serif); font-size: clamp(28px, 3.6vw, 38px); letter-spacing: -0.01em;
  font-variation-settings: "opsz" 48; margin-bottom: 8px;
}
.details-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: clamp(24px, 4vw, 56px);
}
@media (max-width: 820px) { .details-grid { grid-template-columns: minmax(0, 1fr); } }
.panel { padding: 24px 0 28px; border-top: 1px solid var(--line); min-width: 0; }
.panel-wide { grid-column: 1 / -1; }
.panel h3 { font-family: var(--serif); font-size: 22px; font-variation-settings: "opsz" 30; }
.panel-lede { color: var(--muted); font-size: 14.5px; margin-top: 6px; max-width: 72ch; }

/* bar list */
.bars { margin-top: 18px; display: flex; flex-direction: column; gap: 12px; }
.bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: baseline; }
.bar-label { font-size: 14.5px; color: var(--ink-2); }
.bar-label small { color: var(--muted); font-size: 12.5px; margin-left: 6px; }
.bar-value { font-weight: 600; font-size: 15px; }
.bar-track { grid-column: 1 / -1; height: 10px; background: var(--sunken); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; transition: width .35s cubic-bezier(.2,.7,.2,1); }
.bar.is-current .bar-label { color: var(--ink); font-weight: 600; }
.bar.is-combined { padding-top: 12px; border-top: 1px dashed var(--line-strong); }
.bars .empty { color: var(--muted); font-size: 14.5px; }
@media (prefers-reduced-motion: reduce) { .bar-fill { transition: none; } }

.chart { margin-top: 16px; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }

/* recommendations */
.recs { margin-top: 18px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 40px; }
@media (max-width: 820px) { .recs { grid-template-columns: minmax(0, 1fr); } }
.rec h4 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.rec p, .rec li { font-size: 15px; color: var(--ink-2); line-height: 1.55; }
.rec ul { margin: 0; padding-left: 18px; }
.rec li + li { margin-top: 4px; }
.rec p + p { margin-top: 6px; }
.rec .em { color: var(--ink); font-weight: 500; }

.method summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
.method summary::-webkit-details-marker { display: none; }
.method summary::after {
  content: ""; width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg); transition: transform .2s; margin-right: 6px;
}
.method[open] summary::after { transform: rotate(-135deg); }
.method > p { margin-top: 12px; color: var(--ink-2); font-size: 15px; max-width: 80ch; }
.method h4 { margin-top: 18px; font-size: 15px; font-weight: 600; }
.refs { margin: 8px 0 0; padding-left: 20px; font-size: 14px; color: var(--ink-2); max-width: 90ch; }
.refs li + li { margin-top: 6px; }

/* ---------- Footer ---------- */
.footer {
  max-width: var(--maxw); margin: 0 auto; padding: 0 var(--gutter) 120px;
  color: var(--muted); font-size: 13.5px;
}
.footer p { border-top: 1px solid var(--line); padding-top: 24px; }
@media (min-width: 901px) { .footer { padding-bottom: 40px; } }

/* ---------- Mobile live bar ---------- */
.livebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
@media (min-width: 901px) { .livebar { display: none !important; } }
body.summary-visible .livebar { display: none; }
.livebar-inner { display: flex; align-items: center; gap: 10px; max-width: 640px; margin: 0 auto; }
.livebar-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--line-strong); flex: none; }
.livebar-text { flex: 1; min-width: 0; font-size: 14px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 400px) { .livebar-text > span:first-child { display: none; } }
.livebar-text strong { font-family: var(--serif); font-size: 22px; font-weight: 600; color: var(--ink); margin: 0 4px; }
.livebar-link {
  flex: none; font-size: 14px; font-weight: 600; color: var(--accent); text-decoration: none;
  padding: 8px 12px; border-radius: 999px; background: var(--accent-soft);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 40;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  max-width: calc(100% - 32px);
}
