:root {
  --bg: #f4f6f8; --panel: #ffffff; --ink: #0f172a; --muted: #556274;
  --line: #e2e8f0; --accent: #0e7490;
  --high: #dc2626; --watch: #d97706; --low: #94a3b8;
  --high-soft: #fef2f2; --watch-soft: #fffbeb;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.08);
  font-variant-numeric: tabular-nums;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --panel: #121a2b; --ink: #e6edf6; --muted: #94a3b8;
    --line: #24304a; --accent: #22d3ee;
    --high: #f05252; --watch: #f59e0b; --low: #64748b;
    --high-soft: #2a1416; --watch-soft: #2a2110;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .001ms !important; animation-duration: .001ms !important; }
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg); line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 1.5rem;
  padding: 1rem 1.5rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand h1 { margin: 0; font-size: 1.25rem; letter-spacing: -0.01em; }
.tagline { margin: .15rem 0 0; color: var(--muted); font-size: .82rem; }
.hero-stat {
  display: flex; align-items: baseline; gap: .6rem; flex-shrink: 0;
  padding: .5rem .9rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.hero-num { font-size: 1.9rem; font-weight: 700; color: var(--accent); letter-spacing: -0.02em; }
.hero-label { font-size: .72rem; color: var(--muted); line-height: 1.2; }

.controls {
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
  padding: .7rem 1.5rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.control-group { display: flex; align-items: center; gap: .4rem; }
#diseaseToggle button {
  font: inherit; font-size: .85rem; padding: .35rem .8rem; border: 1px solid var(--line);
  background: var(--bg); color: var(--muted); border-radius: 8px; cursor: pointer;
  transition: transform .06s ease;
}
#diseaseToggle button:active { transform: scale(.97); }
#diseaseToggle button[aria-pressed="true"] { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.month-control span { font-size: .8rem; color: var(--muted); }
.month-control input[type=range] { width: 190px; accent-color: var(--accent); }
.month-control output { font-weight: 600; min-width: 2.4rem; }
.legend { display: flex; gap: .5rem; margin-left: auto; }
.lg { font-size: .72rem; padding: .12rem .5rem; border-radius: 999px; color: #fff; }
.lg-high { background: var(--high); } .lg-watch { background: var(--watch); } .lg-low { background: var(--low); }

.layout { display: grid; grid-template-columns: 1fr 340px; gap: 0; height: calc(100vh - 240px); min-height: 420px; }
.map-wrap { position: relative; }
#map { position: absolute; inset: 0; background: var(--bg); }
.rail { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
.rail-head { padding: .9rem 1rem .5rem; border-bottom: 1px solid var(--line); }
.rail-head h2 { margin: 0; font-size: .95rem; }
#railSub { margin: .1rem 0 0; font-size: .76rem; color: var(--muted); }
.rail-list { list-style: none; margin: 0; padding: .4rem; overflow-y: auto; flex: 1; }
.rail-item {
  display: grid; grid-template-columns: 1.6rem 1fr auto; gap: .1rem .55rem; align-items: baseline;
  padding: .55rem .6rem; border-radius: 8px; cursor: pointer; border: 1px solid transparent;
}
.rail-item:hover { background: var(--bg); border-color: var(--line); }
.rail-rank { color: var(--muted); font-size: .8rem; font-weight: 600; }
.rail-name { font-weight: 600; font-size: .9rem; }
.rail-state { grid-column: 2; color: var(--muted); font-size: .72rem; }
.rail-badge { font-size: .64rem; font-weight: 700; padding: .1rem .45rem; border-radius: 999px; color: #fff; text-transform: uppercase; letter-spacing: .03em; }
.rail-badge.High { background: var(--high); } .rail-badge.Watch { background: var(--watch); }
.rail-score { grid-column: 3; grid-row: 2; color: var(--muted); font-size: .72rem; }
.rail-driver { grid-column: 1 / -1; margin-top: .25rem; color: var(--muted); font-size: .74rem; line-height: 1.3; }
.rail-note { padding: .6rem 1rem; margin: 0; font-size: .72rem; color: var(--muted); border-top: 1px solid var(--line); }

.briefing { padding: .9rem 1rem; overflow-y: auto; flex: 1; }
.bf-back { font: inherit; font-size: .78rem; color: var(--accent); background: none; border: none; cursor: pointer; padding: 0 0 .6rem; }
.bf-name { font-size: 1.05rem; font-weight: 700; margin: 0; }
.bf-state { color: var(--muted); font-size: .78rem; margin: 0 0 .6rem; }
.bf-tier { display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: #fff; padding: .15rem .55rem; border-radius: 999px; }
.bf-tier.High { background: var(--high); } .bf-tier.Watch { background: var(--watch); } .bf-tier.Low { background: var(--low); }
.bf-conf { font-size: .72rem; color: var(--muted); margin-left: .5rem; }
.bf-text { font-size: .86rem; line-height: 1.5; margin: .8rem 0; }
.bf-plan { border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; margin: .7rem 0; background: var(--panel); }
.bf-plan-head { font-size: .84rem; font-weight: 700; display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .55rem; }
.bf-posture { font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: .15rem .5rem; border-radius: 6px; color: #fff; white-space: nowrap; }
.bf-posture.Mobilise { background: var(--high); }
.bf-posture.Prepare { background: var(--watch); }
.bf-posture.Routine { background: var(--low); }
.bf-actions { margin: 0 0 .55rem; padding-left: 1.1rem; }
.bf-actions li { font-size: .82rem; margin-bottom: .28rem; line-height: 1.35; }
.bf-res { font-size: .8rem; background: var(--bg); border-radius: 6px; padding: .45rem .55rem; margin-bottom: .55rem; }
.bf-timeline { display: flex; flex-direction: column; gap: .35rem; }
.bf-timeline > div { font-size: .8rem; line-height: 1.35; }
.bf-tl-k { display: inline-block; min-width: 5rem; font-weight: 700; color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .02em; margin-right: .4rem; }
.bf-cal-label { font-size: .72rem; color: var(--muted); margin: .8rem 0 .3rem; }
.bf-cal { display: grid; grid-template-columns: repeat(12, 1fr); gap: 2px; }
.bf-cal-cell { text-align: center; font-size: .58rem; color: var(--muted); }
.bf-cal-bar { height: 22px; border-radius: 3px; margin-bottom: 2px; background: var(--low); opacity: .35; }
.bf-cal-bar.High { background: var(--high); opacity: 1; } .bf-cal-bar.Watch { background: var(--watch); opacity: .9; }
.bf-cal-cell.now .bf-cal-bar { outline: 2px solid var(--ink); outline-offset: 1px; }
.bf-agent { margin-top: 1rem; border: 1px solid var(--accent); border-radius: 10px; padding: .7rem .8rem; background: var(--bg); }
.bf-agent-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .55rem; }
.bf-agent-title { font-size: .86rem; font-weight: 700; }
.bf-agent-badge { font-size: .56rem; font-weight: 700; letter-spacing: .05em; color: #fff; background: var(--accent); padding: .14rem .42rem; border-radius: 999px; }
.bf-agent-brief { font: inherit; font-size: .82rem; font-weight: 600; width: 100%; text-align: left; padding: .5rem .65rem; margin-bottom: .4rem; border: none; background: var(--accent); color: #fff; border-radius: 8px; cursor: pointer; }
.bf-agent-brief:disabled { opacity: .6; cursor: default; }
.bf-quick { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; margin-top: .55rem; }
.bf-quick-label { font-size: .66rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-right: .15rem; }
.bf-ask { font: inherit; font-size: .74rem; padding: .22rem .6rem; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; cursor: pointer; color: var(--muted); }
.bf-ask:hover { color: var(--ink); border-color: var(--muted); }
.bf-ask-row { display: flex; gap: .4rem; margin: .5rem 0 .35rem; }
.bf-input { flex: 1; min-width: 0; font: inherit; font-size: .8rem; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
.bf-send { font: inherit; font-size: .8rem; padding: .45rem .8rem; border: none; background: var(--accent); color: #fff; border-radius: 8px; cursor: pointer; }
.bf-send:disabled { opacity: .6; cursor: default; }
.bf-answer { font-size: .82rem; line-height: 1.45; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .65rem; margin-top: .3rem; }
.bf-llm-note { font-size: .68rem; color: var(--muted); margin-top: .8rem; font-style: italic; }

.intro { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center;
  background: rgba(15,23,42,.45); padding: 1rem; }
.intro[hidden] { display: none; }   /* must beat the base .intro display:flex so the hidden attribute works */
.intro-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; max-width: 460px;
  padding: 1.4rem 1.5rem; box-shadow: 0 10px 40px rgba(15,23,42,.25); }
.intro-card h2 { margin: 0 0 .7rem; font-size: 1.25rem; line-height: 1.25; letter-spacing: -0.01em; }
.intro-card p { margin: 0 0 .7rem; font-size: .88rem; line-height: 1.5; color: var(--ink); }
.intro-honest { color: var(--muted) !important; }
.intro-tip { font-size: .82rem !important; color: var(--muted) !important; }
.intro-btn { font: inherit; font-size: .88rem; font-weight: 600; padding: .55rem 1rem; border: none;
  background: var(--accent); color: #fff; border-radius: 9px; cursor: pointer; margin-top: .3rem; }
.intro-btn:active { transform: scale(.98); }
.foot-link { font: inherit; font-size: .72rem; color: var(--accent); background: none; border: none; cursor: pointer; padding: 0; }

.view-nav { display: flex; gap: .3rem; padding: .5rem 1.5rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.view-nav button {
  font: inherit; font-size: .82rem; padding: .3rem .8rem; border: none; background: none;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; border-radius: 0;
}
.view-nav button[aria-pressed="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

#validationView { overflow-y: auto; height: calc(100vh - 184px); background: var(--bg); }
.vwrap { max-width: 780px; margin: 0 auto; padding: 1.6rem 1.25rem 3rem; }
.vwrap > h2 { margin: .2rem 0 .4rem; font-size: 1.5rem; letter-spacing: -0.01em; }
.vlede { color: var(--muted); font-size: .95rem; margin: 0 0 1.4rem; }
.vcard { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1.1rem 1.2rem; margin-bottom: 1.1rem; box-shadow: var(--shadow); }
.vcard h3 { margin: 0 0 .2rem; font-size: 1rem; }
.vsub { margin: 0 0 1rem; font-size: .8rem; color: var(--muted); }

.model-bars { display: flex; flex-direction: column; gap: .55rem; }
.mb-row { display: grid; grid-template-columns: 190px 1fr 3.2rem; align-items: center; gap: .6rem; }
.mb-label { font-size: .8rem; color: var(--muted); }
.mb-row.hi .mb-label { color: var(--ink); font-weight: 600; }
.mb-track { display: block; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; height: 20px; overflow: hidden; }
.mb-fill { display: block; height: 100%; min-width: 2px; background: var(--low); border-radius: 5px 0 0 5px; transition: width .3s ease; }
.mb-row.hi .mb-fill { background: var(--accent); }
.mb-val { font-size: .82rem; font-weight: 600; text-align: right; }
.mb-chance .mb-fill { background: repeating-linear-gradient(45deg, var(--line), var(--line) 4px, transparent 4px, transparent 8px); }

.cc-svg { width: 100%; height: auto; display: block; }
.cc-bar { fill: var(--high); }
.cc-band { fill: color-mix(in srgb, var(--accent) 12%, transparent); }
.cc-axis { fill: var(--muted); font-size: 10px; }
.cc-val { fill: var(--ink); font-size: 10px; font-weight: 600; }
.cc-clim { fill: none; stroke: var(--muted); stroke-width: 1.2; stroke-dasharray: 3 3; }
.cc-caption { font-size: .78rem; color: var(--muted); margin: .5rem 0 0; }
.cc-legend { display: flex; gap: 1rem; font-size: .72rem; color: var(--muted); margin-top: .4rem; }
.cc-legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: .3rem; vertical-align: middle; border-radius: 2px; }
.cc-legend .l-band::before { background: color-mix(in srgb, var(--accent) 30%, transparent); }
.cc-legend .l-bar::before { background: var(--high); }

.vcaveats ul { margin: 0; padding-left: 1.1rem; }
.vcaveats li { font-size: .84rem; color: var(--muted); margin-bottom: .4rem; line-height: 1.4; }

.site-footer { padding: .55rem 1.5rem; font-size: .72rem; color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); }
.foot-sep { margin: 0 .5rem; opacity: .5; }
.bf-trend { font-size: .72rem; font-weight: 600; margin-left: .5rem; }
.bf-trend.rising { color: var(--high); }
.bf-trend.falling { color: var(--accent); }
.bf-trend.flat { color: var(--muted); }

@media (max-width: 860px) {
  .site-header { flex-wrap: wrap; }
  .layout { grid-template-columns: 1fr; height: auto; }
  .map-wrap { height: 56vh; min-height: 320px; }
  #map { position: absolute; }
  .rail { border-left: none; border-top: 1px solid var(--line); max-height: 60vh; }
  .legend { margin-left: 0; }
  #validationView { height: auto; }
  .mb-row { grid-template-columns: 1fr auto; grid-template-areas: "label val" "track track"; row-gap: .3rem; }
  .mb-label { grid-area: label; } .mb-val { grid-area: val; } .mb-track { grid-area: track; }
}

/* OSM tiles are colourful; grey them so risk markers stand out */
.leaflet-tile-pane { filter: grayscale(1) brightness(1.05) contrast(0.9); }
