/* Opzet: resultaat bovenaan, instellingen als vaste zijbalk rechts (op telefoon direct onder het resultaat),
   daaronder de animatie van één trein en de verdiepende grafieken. Seinhuis-sfeer: betonkleurig grijs,
   seingeel voor de perronrand, één blauwe lijn voor jou. */
:root {
  --bg: #e9edee;
  --surface: #f7f9f9;
  --ink: #162026;
  --muted: #55656f;
  --line: #c9d2d7;
  --accent: #1a5bb0;
  --ahead: #d9480f;
  --signal: #e0a100;
  --signal-soft: rgba(224, 161, 0, 0.24);
  --series2: #a85a00;
  --train: #8c9ea9;
  --rail: #c3ccd2;
  --platform: #e2e8eb;
  --door: #0b7f64;
  --font-display: 'Barlow Condensed', 'Arial Narrow', 'Helvetica Neue', sans-serif;
  --font-body: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1519;
    --surface: #172026;
    --ink: #e5ebee;
    --muted: #96a5ae;
    --line: #2a363d;
    --accent: #6ea8ff;
    --ahead: #ff8a3d;
    --signal: #f1bd2e;
    --signal-soft: rgba(241, 189, 46, 0.22);
    --series2: #f0a64a;
    --train: #586974;
    --rail: #0c1115;
    --platform: #1f2a31;
    --door: #3cc2a5;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1519;
  --surface: #172026;
  --ink: #e5ebee;
  --muted: #96a5ae;
  --line: #2a363d;
  --accent: #6ea8ff;
  --ahead: #ff8a3d;
  --signal: #f1bd2e;
  --signal-soft: rgba(241, 189, 46, 0.22);
  --series2: #f0a64a;
  --train: #586974;
  --rail: #0c1115;
  --platform: #1f2a31;
  --door: #3cc2a5;
  color-scheme: dark;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}
.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding-block: 28px 56px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.1; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(32px, 5.4vw, 50px); font-weight: 700; letter-spacing: 0.005em; }
h2 { font-size: 24px; }
h3 { font-size: 19px; }
p { margin: 0; }
.lede { max-width: none; margin-top: 12px; color: var(--muted); font-size: 17px; }
.head { margin-bottom: 24px; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "scn" "set" "sim" "res" "more" "sens" "notes" "shot";
  gap: 20px;
}
.layout:not(.has-res) .rs { display: none; }
.layout:not(.has-res) { grid-template-areas: "scn" "set" "sim" "notes" "shot"; }
@media (min-width: 920px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-areas: "scn set" "sim set" "res set" "more set" "sens set" "notes set" "shot set";
    gap: 20px 24px;
  }
  .layout:not(.has-res) { grid-template-areas: "scn set" "sim set" "notes set" "shot set"; }
  .settings > summary { pointer-events: none; cursor: default; }
  .settings > summary::after { display: none; }
  .settings { position: sticky; top: 16px; align-self: start; max-height: calc(100vh - 32px); overflow-y: auto; }
}
.sim { grid-area: sim; } .res { grid-area: res; } .settings { grid-area: set; } .scn { grid-area: scn; } .shotp { grid-area: shot; } .more { grid-area: more; } .notes { grid-area: notes; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 20px; min-width: 0; }
@media (max-width: 480px) { .panel { padding: 16px; } }
.label { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* Uitkomst */
.verdict { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 24px; align-items: start; margin: 10px 0 18px; }
@media (max-width: 560px) { .verdict { grid-template-columns: minmax(0, 1fr); } }
.big { font-family: var(--font-display); font-weight: 700; font-size: clamp(60px, 10vw, 88px); line-height: 0.9; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.big .pre { font-size: 0.3em; color: var(--muted); font-weight: 600; margin-right: 8px; }
.big .unit { font-size: 0.38em; color: var(--muted); font-weight: 600; margin-left: 6px; }
.verdict-text { display: grid; gap: 8px; max-width: 62ch; }
.safety { font-size: 14px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; margin-top: 16px; }
.chart { width: 100%; min-width: 0; }
.chart svg { display: block; max-width: 100%; height: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--muted); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.sw { display: inline-block; width: 22px; height: 0; border-top: 3px solid var(--accent); }
.sw.dash { border-top: 2px dashed var(--muted); }
.sw.s2 { border-top-color: var(--series2); }
.sw.band { height: 12px; width: 14px; border: 0; background: var(--signal-soft); }
.sw.ring { width: 11px; height: 11px; border: 2px solid var(--ink); border-radius: 50%; background: var(--surface); }
.sw.dot { width: 11px; height: 11px; border: 0; border-radius: 50%; background: var(--accent); }
.sw.rng { border-top: 8px solid var(--signal-soft); border-radius: 4px; }

/* SVG-onderdelen */
.grid { stroke: var(--line); stroke-width: 1; }
.ax { font: 12px var(--font-body); fill: var(--muted); font-variant-numeric: tabular-nums; }
.lab { font: 600 12px var(--font-body); fill: var(--ink); }
.mean { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.p90 { fill: none; stroke: var(--muted); stroke-width: 1.75; stroke-dasharray: 5 4; }
.line2 { fill: none; stroke: var(--series2); stroke-width: 2.25; stroke-linejoin: round; }
.plateau { fill: var(--signal-soft); }
.dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.you { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }
.rng { stroke: var(--signal); stroke-opacity: 0.45; stroke-width: 10; stroke-linecap: round; }
.guide { stroke: var(--muted); stroke-dasharray: 3 3; stroke-width: 1; }
.link { fill: none; stroke: var(--accent); stroke-width: 1.5; opacity: 0.55; }

/* Scene */
.rail { fill: var(--rail); }
.platform { fill: var(--platform); }
.edge { stroke: var(--signal); stroke-width: 3; }
.train { fill: var(--train); }
.joint { stroke: var(--rail); stroke-width: 1.5; }
.door { fill: var(--surface); stroke: var(--door); stroke-width: 1.5; }
.door.open { fill: var(--door); }
.door.chosen { stroke: var(--accent); stroke-width: 3; }
.person { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.trail { fill: none; stroke: var(--accent); stroke-width: 1.5; opacity: 0.45; }
.band { fill: var(--signal-soft); }
.ectick { stroke: var(--signal); stroke-width: 2.5; }
.bord { stroke: var(--muted); stroke-dasharray: 3 3; stroke-width: 1; }
.t11 { font: 11px var(--font-body); fill: var(--muted); }
.scene svg { display: block; width: 100%; height: auto; }
.scene-ctl { display: grid; gap: 12px; margin: 14px 0 10px; }
.ctl-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.readouts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-top: 12px; }
.stat { border-top: 2px solid var(--line); padding-top: 6px; min-width: 0; }
.stat .k { font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.stat .v { font-family: var(--font-display); font-size: 28px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.scene-note { margin-top: 12px; min-height: 1.5em; }

/* Besturing */
label, .lbl { font-weight: 500; }
button, select {
  font: inherit; font-weight: 500; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 4px; padding: 7px 12px; cursor: pointer;
}
button:hover, select:hover { border-color: var(--accent); }
button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
button.iconbtn { width: 40px; height: 40px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
button.iconbtn svg { width: 20px; height: 20px; }
.tools { margin: 12px 0 10px; }
.tempo-l { margin-left: auto; }
.infobtn { display: none; width: 26px; height: 26px; padding: 0; margin-left: 10px; border-radius: 50%; font: italic 700 15px/1 var(--font-body); vertical-align: 4px; color: var(--accent); border-color: var(--accent); }
@media (max-width: 600px) {
  .tempo-l { display: none; }
  .seg.tempo { margin-left: auto; }
  .infobtn { display: inline-flex; align-items: center; justify-content: center; }
  .lede:not(.show) { display: none; }
}
.seg.tempo { margin-top: 0; flex-wrap: nowrap; }
.lgd { margin-top: 12px; }
.lgd > summary { cursor: pointer; font-weight: 600; }
.distctl { margin: 12px 0 4px; }
.distctl .row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 4px; }
.distctl output { font-weight: 600; color: var(--accent); }
button.linkish { border: 0; background: none; color: var(--accent); padding: 4px 0; text-decoration: underline; text-underline-offset: 3px; }
input[type=range] { width: 100%; accent-color: var(--accent); margin: 6px 0 0; }
select { width: 100%; }
.ctl-row select { width: auto; }
.field { display: grid; gap: 2px; padding: 14px 0; border-top: 1px solid var(--line); }
.field:first-of-type { border-top: 0; padding-top: 8px; }
.field .row { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.field output { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--accent); white-space: nowrap; }
.hint { font-size: 13px; color: var(--muted); }
.settings .field { padding: 9px 0; }
.settings .row { position: relative; }
.tip { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; margin-left: 6px; border: 1px solid var(--muted); border-radius: 50%; color: var(--muted); font: 600 11px/1 var(--font-body); cursor: help; vertical-align: 1px; }
.tip:hover, .tip:focus-visible { color: var(--accent); border-color: var(--accent); }
.tip::after { content: attr(data-tip); position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20; padding: 8px 10px; background: var(--ink); color: var(--surface); border-radius: 4px; font: 400 13px/1.35 var(--font-body); text-align: left; box-shadow: 0 4px 14px rgba(0,0,0,0.25); opacity: 0; visibility: hidden; pointer-events: none; transition: opacity 0.12s; }
.tip:hover::after, .tip:focus::after { opacity: 1; visibility: visible; }
.settings h2 { margin-bottom: 4px; }
details > summary { cursor: pointer; font-weight: 500; }
.adv { border-top: 1px solid var(--line); padding-top: 12px; }
.adv .field:first-of-type { padding-top: 12px; border-top: 0; }
.tbl { overflow-x: auto; margin-top: 10px; }
table { border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; width: 100%; min-width: 440px; }
th, td { text-align: right; padding: 5px 10px; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.charts2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 28px 24px; margin-top: 16px; }
.charts2 > div { min-width: 0; }
.notes p { max-width: 68ch; margin-top: 10px; }
.notes summary { font-family: var(--font-display); font-size: 22px; font-weight: 600; }
.crowd { fill: var(--muted); opacity: 0.5; }
.crowd.ahead { fill: var(--ahead); opacity: 0.9; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.seg button { padding: 5px 11px; font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.sens { grid-area: sens; }
.cv { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.cur { fill: none; stroke: var(--series2); stroke-width: 3; stroke-linejoin: round; }
.dumb { stroke: var(--muted); stroke-width: 3; stroke-opacity: 0.55; stroke-linecap: round; }
.lo { fill: var(--surface); stroke: var(--accent); stroke-width: 2.5; }
.hi { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.rowlab { font: 500 13px var(--font-body); fill: var(--ink); }
.rowsub { font: 11px var(--font-body); fill: var(--muted); }
.trains { display: grid; gap: 8px; margin-top: 8px; }
.trainBtn { display: block; width: 100%; padding: 8px 10px 9px; text-align: left; background: var(--surface); }
.trainBtn .timg { position: relative; aspect-ratio: 1690 / 153; overflow: hidden; border-radius: 4px; background: #252527; margin-bottom: 6px; }
.trainBtn .timg img { display: block; width: 100%; height: 100%; object-fit: cover; }
.trainBtn .crop3 img { position: absolute; left: 0; top: 50%; width: 300%; height: auto; max-width: none; transform: translateY(-50%); }
.trainBtn span { font-size: 14px; }
.trainBtn[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.dists { display: flex; flex-wrap: wrap; gap: 6px; }
.initd { margin: 10px 0 4px; }
.initd .lab { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.distBtn { display: block; width: 74px; padding: 3px 5px 4px; text-align: left; background: var(--surface); line-height: 1.15; }
.distBtn svg { display: block; width: 100%; height: auto; margin-bottom: 4px; }
.distBtn span { font-size: 11px; }
.distBtn[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.distBtn .bar { fill: var(--muted); opacity: 0.55; }
.distBtn[aria-pressed="true"] .bar { fill: var(--accent); opacity: 1; }
/* Foto met opgemeten deuren */
.door.fc { fill: var(--rail); stroke: var(--muted); stroke-dasharray: 2 2; }
.fctag { font: 600 10px var(--font-body); fill: var(--ink); }
.shotwrap { overflow-x: auto; margin-top: 14px; }
.shot { position: relative; min-width: 900px; padding-bottom: 46px; }
.shot img { display: block; width: 100%; height: auto; border-radius: 4px; }
.shot .mk { position: absolute; top: 0; bottom: 46px; width: 0; border-left: 2px solid var(--door); transform: translateX(-1px); pointer-events: none; }
.shot .mk.fc { border-left-color: var(--signal); }
.shot .mk.est { border-left-style: dashed; }
.shot .jt { position: absolute; top: 0; bottom: 46px; width: 0; border-left: 1px dashed rgba(255, 255, 255, 0.5); }
.shot .tag { position: absolute; top: 6px; transform: translateX(-50%); background: var(--signal); color: #1a1a1a; font: 600 11px var(--font-body); padding: 1px 6px; border-radius: 3px; white-space: nowrap; }
.shot .span { position: absolute; bottom: 28px; height: 8px; border: 1px solid var(--muted); border-top: 0; box-sizing: border-box; }
.shot .span b { position: absolute; top: 10px; left: 0; right: 0; text-align: center; font: 500 12px var(--font-body); color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
.calc { position: fixed; right: 16px; bottom: 16px; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-radius: 999px; background: #1c2430; color: #fff; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.calc[hidden] { display: none; }
.spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* Instellingen: op mobiel een los, standaard gesloten paneel */
.settings > summary { list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 12px; cursor: pointer; }
.settings > summary::-webkit-details-marker { display: none; }
.settings > summary::after { content: ''; width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin-right: 4px; transition: transform 0.15s; }
.settings[open] > summary::after { transform: rotate(-135deg); }
.settings .h2 { font-family: var(--font-display); font-weight: 600; font-size: 24px; line-height: 1.1; }
.settings > .sub { margin-top: 8px; }
/* Simulatie over grote aantallen */
.sim .seg button { min-width: 64px; padding: 8px 14px; }
.sim #startSim { padding: 9px 22px; }
.sim #startSim:disabled { opacity: 0.55; cursor: default; }
.bar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 12px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

/* Instellingen als harmonica */
.set-top { margin: 10px 0 12px; }
.set-top button { padding: 5px 12px; font-size: 14px; }
.acc-wrap { border-top: 1px solid var(--line); }
.acc { border-bottom: 1px solid var(--line); }
.acc > summary { list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; cursor: pointer; font-family: var(--font-display); font-size: 19px; font-weight: 600; }
.acc > summary::-webkit-details-marker { display: none; }
.acc > summary::after { content: ''; flex: none; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin-right: 4px; transition: transform 0.15s; }
.acc[open] > summary::after { transform: rotate(-135deg); }
.acc[open] { padding-bottom: 6px; }
.acc > .field:first-of-type { border-top: 0; padding-top: 2px; }

/* Opgemeten deuren: invouwbaar */
.foldp > summary { list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 12px; cursor: pointer; }
.foldp > summary::-webkit-details-marker { display: none; }
.foldp > summary::after { content: ''; flex: none; width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin-right: 4px; transition: transform 0.15s; }
.foldp[open] > summary::after { transform: rotate(-135deg); }
.foldp .h2 { font-family: var(--font-display); font-weight: 600; font-size: 24px; line-height: 1.1; }
.foldp[open] > summary { margin-bottom: 4px; }
/* Zo rekent het model: zelfde uitvouwstijl */
.notes > details > summary { list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 12px; cursor: pointer; font-size: 24px; line-height: 1.1; }
.notes > details > summary::-webkit-details-marker { display: none; }
.notes > details > summary::after { content: ''; flex: none; width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin-right: 4px; transition: transform 0.15s; }
.notes > details[open] > summary::after { transform: rotate(-135deg); }

/* Aantal gewijzigde instellingen per categorie, en opvallende reset */
.cnt { font-style: normal; font-family: var(--font-body); font-size: 12px; font-weight: 600; margin-left: 10px; padding: 2px 8px; border-radius: 999px; background: var(--accent); color: var(--surface); vertical-align: 2px; white-space: nowrap; }
.cnt[hidden] { display: none; }
.set-top button { width: auto; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 20px; font-size: 15px; font-weight: 600; }
.set-top button svg { width: 18px; height: 18px; }
.set-top button:hover { filter: brightness(1.1); }
.sim .foldp > .sub { margin-top: 8px; }

/* Tooltips bij de stippen in de grafieken */
.hit { fill: transparent; stroke: none; cursor: help; pointer-events: all; outline: none; }
.hit:focus-visible { stroke: var(--accent); stroke-width: 2; }
.tt { position: fixed; z-index: 40; max-width: 270px; padding: 10px 12px; background: var(--ink); color: var(--surface); border-radius: 6px; font: 400 13px/1.4 var(--font-body); box-shadow: 0 6px 20px rgba(0,0,0,0.28); pointer-events: none; }
.tt[hidden] { display: none; }
.tt b { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.tt p { margin: 3px 0 0; }
.tt p:last-child { margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(128,128,128,0.45); }

/* Relatie tussen de twee grafieken: dezelfde kleur voor de instelling die links getoond wordt */
.cv.ext { stroke: var(--door); stroke-width: 2.75; }
.lo.sel { stroke: var(--door); stroke-width: 3; }
.hi.sel { fill: var(--door); }
.dumb.sel { stroke: var(--door); stroke-opacity: 0.85; }
.rowlab.sel { fill: var(--door); font-weight: 700; }
