/* ============================================================
   Amsterdam-Oxford PSC Score Calculator
   ============================================================ */

:root {
  --bg: #eef2f4;
  --bg-grad-a: #e8eef0;
  --bg-grad-b: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f7f9fa;
  --surface-3: #eef2f4;
  --border: #e2e8ec;
  --border-strong: #cfd9df;
  --text: #14232b;
  --text-muted: #5a6b74;
  --text-faint: #8a99a1;
  --primary: #0d9488;
  --primary-strong: #0f766e;
  --primary-soft: #d7f0ec;
  --primary-ink: #06544c;
  --accent: #2563eb;
  --danger: #c2564f;
  --good: #0d9488;
  --warn: #d99a2b;
  --shadow-sm: 0 1px 2px rgba(16, 40, 50, .06);
  --shadow: 0 6px 24px -12px rgba(16, 40, 50, .30);
  --shadow-lg: 0 24px 60px -30px rgba(16, 40, 50, .45);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 22px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Newsreader", Georgia, serif;
  --maxw: 1120px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1416;
    --bg-grad-a: #0c171a;
    --bg-grad-b: #0a1214;
    --surface: #101d21;
    --surface-2: #16262b;
    --surface-3: #1b2f35;
    --border: #22383f;
    --border-strong: #2d4750;
    --text: #e6eef1;
    --text-muted: #9db0b8;
    --text-faint: #6f858e;
    --primary: #2dd4bf;
    --primary-strong: #14b8a6;
    --primary-soft: #12312f;
    --primary-ink: #7ff0e2;
    --accent: #60a5fa;
    --danger: #e08880;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 8px 30px -14px rgba(0, 0, 0, .7);
    --shadow-lg: 0 30px 70px -34px rgba(0, 0, 0, .8);
  }
}
:root[data-theme="dark"] {
  --bg: #0b1416;
  --bg-grad-a: #0c171a;
  --bg-grad-b: #0a1214;
  --surface: #101d21;
  --surface-2: #16262b;
  --surface-3: #1b2f35;
  --border: #22383f;
  --border-strong: #2d4750;
  --text: #e6eef1;
  --text-muted: #9db0b8;
  --text-faint: #6f858e;
  --primary: #2dd4bf;
  --primary-strong: #14b8a6;
  --primary-soft: #12312f;
  --primary-ink: #7ff0e2;
  --accent: #60a5fa;
  --danger: #e08880;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 8px 30px -14px rgba(0, 0, 0, .7);
  --shadow-lg: 0 30px 70px -34px rgba(0, 0, 0, .8);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(1200px 600px at 80% -10%, var(--bg-grad-a), transparent 60%),
              radial-gradient(900px 500px at -10% 10%, var(--bg-grad-b), transparent 55%),
              var(--bg);
  background-attachment: fixed;
  line-height: 1.5;
  min-height: 100vh;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding-inline: 20px; }

/* ---------- Masthead ---------- */
.masthead {
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: saturate(140%) blur(12px);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  border-bottom: 1px solid var(--border);
}
.masthead__inner { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand__mark {
  display: grid; place-items: center; width: 38px; height: 38px; flex: none;
  border-radius: 11px; color: #fff;
  background: linear-gradient(145deg, var(--primary), var(--primary-strong));
  box-shadow: var(--shadow-sm);
}
.brand__text { display: flex; flex-direction: column; min-width: 0; }
.brand__title { font-weight: 650; letter-spacing: -.01em; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand__sub { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.theme-toggle {
  display: grid; place-items: center; width: 38px; height: 38px; flex: none;
  border: 1px solid var(--border); border-radius: 11px; background: var(--surface);
  color: var(--text-muted); cursor: pointer; transition: .18s ease;
}
.theme-toggle:hover { color: var(--text); border-color: var(--border-strong); }
.theme-toggle__moon { display: none; }
:root[data-theme="dark"] .theme-toggle__sun,
:root:not([data-theme="light"]) .theme-toggle__sun { }
.theme-toggle__sun { display: block; }
.theme-toggle__moon { display: none; }
:root[data-theme="dark"] .theme-toggle__sun { display: none; }
:root[data-theme="dark"] .theme-toggle__moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle__sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle__moon { display: block; }
}

/* ---------- Layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: 22px; align-items: start; padding-block: 28px 12px;
}
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: 22px;
}
.results { position: sticky; top: 84px; }
@media (max-width: 880px) {
  .results { position: static; }
}
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card__title { margin: 0; font-size: 18px; font-weight: 650; letter-spacing: -.01em; }

.linkbtn {
  border: 0; background: none; color: var(--primary-strong); cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 550; padding: 4px 2px; border-radius: 6px;
}
.linkbtn:hover { text-decoration: underline; }

/* ---------- Fields ---------- */
.field { margin-bottom: 16px; }
.field__label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 7px; }
.field__sub { color: var(--text-faint); font-weight: 500; font-size: 11px; margin-left: 6px; text-transform: uppercase; letter-spacing: .04em; }

.control {
  display: flex; align-items: stretch; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface-2); overflow: hidden;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.control:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); background: var(--surface); }
.control--error { border-color: var(--danger); }
.control--error:focus-within { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 22%, transparent); }
.control__input {
  flex: 1 1 auto; min-width: 0; border: 0; background: none; color: var(--text);
  font: inherit; font-size: 15px; font-variant-numeric: tabular-nums; padding: 11px 12px;
}
.control__input:focus { outline: none; }
.control__input::placeholder { color: var(--text-faint); }
/* strip number spinners for a cleaner look */
.control__input::-webkit-outer-spin-button,
.control__input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.control__input[type="number"] { -moz-appearance: textfield; }

.control__unit--static {
  display: flex; align-items: center; padding: 0 13px; font-size: 13px;
  color: var(--text-muted); background: var(--surface-3); border-left: 1px solid var(--border);
  white-space: nowrap;
}

/* lab row: value + reference + unit toggle */
.lab { margin-bottom: 16px; }
.lab__head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.lab__name { font-size: 13px; font-weight: 600; }
.lab__limit { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; }
.lab__row { display: flex; gap: 8px; align-items: stretch; }
.lab__value { flex: 1 1 auto; min-width: 0; }
.lab__ref {
  position: relative; flex: 0 0 84px;
}
.lab__ref .control { background: var(--surface); }
.lab__ref-tag {
  position: absolute; top: -7px; left: 10px; z-index: 2; font-size: 9px; font-weight: 600;
  letter-spacing: .05em; text-transform: uppercase; color: var(--text-faint);
  background: var(--surface); padding: 0 5px;
}
.lab__ref .control__input { padding: 11px 8px; text-align: center; font-size: 13px; }
.lab__ref--custom .control { border-color: var(--primary); }
.lab__ref--custom .control__input { color: var(--primary-strong); font-weight: 600; }

.units {
  display: inline-flex; flex: none; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2);
}
.units__opt {
  border: 0; background: none; color: var(--text-muted); font: inherit; font-size: 12px;
  font-weight: 550; padding: 0 11px; cursor: pointer; white-space: nowrap; transition: .14s ease;
}
.units__opt + .units__opt { border-left: 1px solid var(--border); }
.units__opt:hover { color: var(--text); }
.units__opt[aria-checked="true"] { background: var(--primary); color: #fff; }

/* segmented (subtype) */
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
.segmented__opt {
  border: 0; background: none; color: var(--text-muted); font: inherit; font-size: 14px;
  font-weight: 550; padding: 9px 12px; border-radius: 7px; cursor: pointer; transition: .16s ease;
}
.segmented__opt:hover { color: var(--text); }
.segmented__opt[aria-checked="true"] {
  background: var(--surface); color: var(--primary-strong); font-weight: 650;
  box-shadow: var(--shadow-sm);
}
:root[data-theme="dark"] .segmented__opt[aria-checked="true"] { background: var(--surface-3); color: var(--primary-ink); }

.field__error { margin: 6px 2px 0; font-size: 12px; color: var(--danger); font-weight: 500; }

/* ---------- Age slider ---------- */
.field__labelrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.field__labelrow .field__label { margin-bottom: 0; }

.agebox {
  display: inline-flex; align-items: baseline; gap: 3px; padding: 5px 10px;
  border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface-2);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.agebox:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); background: var(--surface); }
.agebox.control--error { border-color: var(--danger); }
.agebox__num {
  width: 2.6ch; border: 0; background: none; color: var(--text); font: inherit;
  font-size: 18px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; padding: 0;
}
.agebox__num:focus { outline: none; }
.agebox__num::-webkit-outer-spin-button, .agebox__num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.agebox__num[type="number"] { -moz-appearance: textfield; }
.agebox__unit { font-size: 12px; font-weight: 600; color: var(--text-muted); }

.slider {
  -webkit-appearance: none; appearance: none; width: 100%; height: 8px; margin: 4px 0 0;
  border-radius: 999px; background: var(--surface-3); cursor: pointer; outline: none;
}
.slider:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent); }
.slider::-webkit-slider-runnable-track { height: 8px; border-radius: 999px; background: transparent; }
.slider::-moz-range-track { height: 8px; border-radius: 999px; background: var(--surface-3); }
.slider::-moz-range-progress { height: 8px; border-radius: 999px; background: linear-gradient(90deg, var(--primary), var(--primary-strong)); }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 22px; height: 22px; margin-top: -7px;
  border-radius: 50%; background: var(--surface); border: 3px solid var(--primary);
  box-shadow: var(--shadow-sm); cursor: grab; transition: transform .12s ease;
}
.slider::-webkit-slider-thumb:active { cursor: grabbing; transform: scale(1.12); }
.slider::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%; background: var(--surface);
  border: 3px solid var(--primary); box-shadow: var(--shadow-sm); cursor: grab;
}
.slider__scale { display: flex; justify-content: space-between; margin-top: 5px; font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }

.divider { display: flex; align-items: center; gap: 12px; margin: 22px 0 16px; color: var(--text-faint); }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--border); flex: 1; }
.divider span { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }

.inputs__note { margin: 6px 2px 0; font-size: 12px; color: var(--text-muted); line-height: 1.5; }

/* ---------- Results ---------- */
.results__status {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); background: var(--surface-3); padding: 4px 10px; border-radius: 999px;
}
.results.is-live .results__status { color: var(--primary-ink); background: var(--primary-soft); }

.results__body { display: none; }
.results.is-live .results__body { display: block; }
.results.is-live .results__empty { display: none; }

.results__empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 12px; color: var(--text-faint); padding: 48px 20px; min-height: 320px;
}
.results__empty p { margin: 0; max-width: 260px; font-size: 14px; }

.score {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 18px 20px; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--primary-soft), color-mix(in srgb, var(--primary-soft) 40%, var(--surface)));
  border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--border));
}
.score__main { display: flex; flex-direction: column; gap: 2px; }
.score__label { font-size: 12px; font-weight: 600; color: var(--primary-ink); text-transform: uppercase; letter-spacing: .04em; }
.score__value {
  font-family: var(--font-display); font-size: 52px; line-height: 1; font-weight: 600;
  color: var(--text); font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.score__hint { font-size: 12px; color: var(--text-muted); max-width: 190px; text-align: right; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 16px 0; }
@media (max-width: 460px) { .stats { grid-template-columns: 1fr; } }
.stat {
  display: flex; flex-direction: column; gap: 3px; padding: 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
}
.stat__year { font-size: 12px; font-weight: 650; color: var(--text-muted); }
.stat__value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat__cap { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .03em; line-height: 1.3; }
.stat__bar { display: block; height: 5px; border-radius: 999px; background: var(--surface-3); margin-top: 8px; overflow: hidden; }
.stat__bar i { display: block; height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, var(--primary), var(--primary-strong)); transition: width .5s cubic-bezier(.22,1,.36,1); }

/* ---------- Chart ---------- */
.chart { margin: 8px 0 0; }
.chart__title { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .04em; }
.chart__holder { position: relative; width: 100%; }
.chart__holder svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-grid--minor { stroke: color-mix(in srgb, var(--border) 55%, transparent); stroke-width: 1; }
.chart-axis { stroke: var(--border-strong); stroke-width: 1.25; }
.chart-tick { fill: var(--text-muted); font-size: 12px; font-weight: 500; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart-axis-label { fill: var(--text); font-size: 12px; font-weight: 600; font-family: var(--font); text-transform: uppercase; letter-spacing: .05em; }
.chart-area { fill: url(#areaGrad); }
.chart-line { fill: none; stroke: var(--primary); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--surface); stroke: var(--primary); stroke-width: 2; }
.chart-marker { fill: var(--primary); }
.chart-hover-line { stroke: var(--primary); stroke-width: 1; stroke-dasharray: 3 3; opacity: .5; }
.chart-hit { fill: transparent; cursor: crosshair; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 3; transform: translate(-50%, -110%);
  background: var(--text); color: var(--surface); padding: 6px 9px; border-radius: 8px;
  font-size: 12px; font-weight: 550; white-space: nowrap; box-shadow: var(--shadow);
  opacity: 0; transition: opacity .12s ease;
}
.chart-tip strong { color: #fff; }
:root[data-theme="dark"] .chart-tip { background: #e6eef1; color: #0b1416; }
:root[data-theme="dark"] .chart-tip strong { color: #0b1416; }

/* ---------- Info accordions ---------- */
.info { display: grid; gap: 10px; margin-top: 14px; }
.acc {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2px 18px; box-shadow: var(--shadow-sm);
}
.acc summary {
  cursor: pointer; list-style: none; padding: 14px 0; font-weight: 600; font-size: 15px;
  display: flex; align-items: center; justify-content: space-between;
}
.acc summary::-webkit-details-marker { display: none; }
.acc summary::after {
  content: ""; width: 9px; height: 9px; border-right: 2px solid var(--text-faint);
  border-bottom: 2px solid var(--text-faint); transform: rotate(45deg); transition: transform .2s ease; margin-left: 12px;
}
.acc[open] summary::after { transform: rotate(-135deg); }
.acc p { margin: 0 0 14px; color: var(--text-muted); font-size: 14px; line-height: 1.6; }
.acc p + p { margin-top: -4px; }

.foot { padding: 26px 20px 40px; text-align: center; }
.foot p { margin: 0; font-size: 12px; color: var(--text-faint); }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: var(--radius-sm);
  padding: 12px 18px; border: 1px solid transparent; transition: .16s ease;
}
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-strong); }
.btn--block { width: 100%; }

/* ---------- Disclaimer gate ---------- */
.gate {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px;
  background: color-mix(in srgb, #04101340 90%, transparent); backdrop-filter: blur(6px);
  animation: fade .25s ease;
}
.gate[hidden] { display: none; }
.gate__card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); max-width: 460px; width: 100%; padding: 28px;
  animation: pop .28s cubic-bezier(.22,1,.36,1);
}
.gate__badge {
  display: grid; place-items: center; width: 48px; height: 48px; border-radius: 14px;
  background: color-mix(in srgb, var(--warn) 18%, var(--surface)); color: var(--warn); margin-bottom: 16px;
}
.gate__card h2 { margin: 0 0 10px; font-size: 21px; letter-spacing: -.01em; }
.gate__card p { margin: 0 0 12px; color: var(--text-muted); font-size: 14px; line-height: 1.6; }
.gate__card strong { color: var(--text); }
.gate__fine { font-size: 12.5px !important; color: var(--text-faint) !important; }
.gate__card .btn { margin-top: 8px; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
