:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --hover: rgba(11, 11, 11, 0.05);
  --good-text: #006300;
  --bad-text: #b02a2a;
  /* status colours (Schulabgleich style); every status also has its own glyph */
  --st-good: #0ca30c;
  --st-bad: #d03b3b;
  --st-warn: #fab219;
  --st-info: #2a78d6;
  --ctrl-icon-filter: none;
  --ctrl-active: #e8eef9;
  --ctrl-active-text: #1b4f9c;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --hover: rgba(255, 255, 255, 0.06);
    --good-text: #0ca30c;
    --bad-text: #ec6b6b;
    --st-info: #3987e5;
    --ctrl-icon-filter: invert(1);
    --ctrl-active: #1f3350;
    --ctrl-active-text: #9cc2f5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --accent: #3987e5;
  --hover: rgba(255, 255, 255, 0.06);
  --good-text: #0ca30c;
  --bad-text: #ec6b6b;
  --st-info: #3987e5;
  --ctrl-icon-filter: invert(1);
  --ctrl-active: #1f3350;
  --ctrl-active-text: #9cc2f5;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 18px; }
h2 { font-size: 22px; }
h3 { font-size: 15px; font-weight: 600; }
a { color: var(--accent); }
.muted { color: var(--text-muted); font-size: 13px; }
.secondary { color: var(--text-secondary); }

.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr) 300px; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { margin-bottom: 20px; }
.brand p { margin: 4px 0 0; }

#missions { display: flex; flex-direction: column; gap: 4px; }
.mission-link {
  display: block; color: inherit; text-decoration: none;
  padding: 10px 12px; border-radius: 8px;
}
.mission-link:hover { background: var(--hover); }
.mission-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mission-link[aria-current="true"] { background: var(--hover); box-shadow: inset 3px 0 0 var(--accent); }
.mission-link .t { font-weight: 600; display: block; }
.mission-link .n { color: var(--text-secondary); font-size: 13px; }
.bar { display: block; height: 4px; border-radius: 2px; background: var(--grid); margin-top: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--st-good); border-radius: 2px; }

.main { padding: 24px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.mission-head p { margin: 6px 0 0; max-width: 70ch; }
.overview { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.stat-value { font-size: 40px; font-weight: 600; line-height: 1; }
.stat-label { margin-top: 4px; }
.stat-delta { font-size: 13px; margin-top: 2px; color: var(--text-secondary); }
.stat-delta.up { color: var(--good-text); }
.stat-delta.down { color: var(--bad-text); }

.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.legend img { width: 18px; height: 18px; }
.legend .swatch { margin-left: -4px; }
.area-toggle button { width: auto !important; padding: 0 8px; font: 600 12px system-ui, sans-serif; color: var(--text-primary); }
.area-toggle button[aria-pressed="true"] { background: var(--ctrl-active); color: var(--ctrl-active-text); }

/* MapLibre controls follow the theme */
.maplibregl-ctrl-group { background: var(--surface); box-shadow: 0 0 0 1px var(--border); }
.maplibregl-ctrl-group button + button { border-top-color: var(--border); }
.maplibregl-ctrl-group button:not(:disabled):hover { background-color: var(--hover); }
.maplibregl-ctrl button .maplibregl-ctrl-icon { filter: var(--ctrl-icon-filter); }
.maplibregl-ctrl.maplibregl-ctrl-attrib { background: color-mix(in srgb, var(--surface) 80%, transparent); color: var(--text-secondary); }
.maplibregl-ctrl-attrib a { color: var(--text-secondary); }
.maplibregl-ctrl-attrib-button { filter: var(--ctrl-icon-filter); }
.maplibregl-ctrl-scale { background: color-mix(in srgb, var(--surface) 80%, transparent); color: var(--text-secondary); border-color: var(--text-secondary); }

.theme { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.legend .cnt { color: var(--text-secondary); font-variant-numeric: tabular-nums; }

.map { height: 60vh; min-height: 360px; border-radius: 10px; border: 1px solid var(--border); overflow: hidden; }
.maplibregl-popup-content {
  background: var(--surface); color: var(--text-primary);
  border-radius: 8px; padding: 12px 14px; max-width: 320px;
}
.maplibregl-popup-tip { border-top-color: var(--surface) !important; border-bottom-color: var(--surface) !important; }
.maplibregl-popup-close-button { color: var(--text-secondary); font-size: 18px; }
.popup h4 { margin: 0 24px 4px 0; font-size: 15px; }
.popup .st { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--text-secondary); }
.popup .st img { width: 16px; height: 16px; }
.popup ul { margin: 6px 0; padding-left: 18px; font-size: 13px; }
.popup table { font-size: 12px; border-collapse: collapse; margin-top: 6px; }
.popup td { padding: 1px 6px 1px 0; vertical-align: top; word-break: break-word; }
.popup td:first-child { color: var(--text-muted); white-space: nowrap; }
.popup .links { margin-top: 8px; display: flex; gap: 12px; font-size: 13px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.panel h3 { display: inline; }
.chart { margin-top: 8px; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .axis text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .baseline { stroke: var(--axis); }
.chart .band { stroke: none; }
.chart .gap { fill: none; stroke: var(--surface); stroke-width: 2; }
.chart .direct text { fill: var(--text-secondary); font-size: 12px; }
.chart .direct .cnt { fill: var(--text-primary); font-weight: 600; }
.chart svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .cross { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .sel line { stroke: var(--text-primary); stroke-width: 2; }
.chart .sel-dot { stroke: var(--surface); stroke-width: 2; }
.panel .hint { margin: 2px 0 0; }
.when { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; margin-top: 6px; }
.when p { margin: 0; }
.compare { display: flex; align-items: center; gap: 6px; font-size: 13px; }
select {
  font: inherit; color: var(--text-primary); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px;
}
.chart .range { fill: var(--text-primary); opacity: 0.06; }
.chart .base-line { stroke: var(--text-primary); stroke-width: 1.5; stroke-dasharray: 4 3; }
.popup .step { margin: 6px 0 0; font-size: 13px; }
.popup .stack-note { margin: 0 24px 8px 0; font-size: 12px; color: var(--text-muted); }
.popup hr { border: 0; border-top: 1px solid var(--grid); margin: 10px 0; }
.maplibregl-popup-content { max-height: 60vh; overflow-y: auto; }
.popup del { color: var(--bad-text); }
.popup ins { color: var(--good-text); text-decoration: none; }
.changes-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 420px; overflow-y: auto; }
.changes-list li { border-bottom: 1px solid var(--grid); }
.changes-list button {
  all: unset; box-sizing: border-box; cursor: pointer; width: 100%;
  display: grid; grid-template-columns: 18px minmax(0, 14em) 1fr; gap: 10px; align-items: center;
  padding: 6px 4px; font-size: 13px;
}
.changes-list button:hover { background: var(--hover); }
.changes-list button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.changes-list img { width: 18px; height: 18px; }
.changes-list .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.changes-list .what { color: var(--text-secondary); }
@media (max-width: 560px) {
  .changes-list button { grid-template-columns: 18px 1fr; }
  .changes-list .what { grid-column: 2; }
}
.past { color: var(--text-primary); font-weight: 600; }
.tooltip {
  position: fixed; pointer-events: none; z-index: 10;
  background: var(--surface); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px;
  font-size: 13px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.tooltip .row { display: flex; align-items: center; gap: 6px; }
.tooltip .row img { width: 14px; height: 14px; }
.tooltip .row b { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }
.chart .empty { color: var(--text-muted); font-size: 13px; padding: 12px 0; }

.contrib {
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 20px 16px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.contrib h3 { font-size: 16px; }
.contrib #contrib-range { margin: 6px 0 12px; }
.contrib-list { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
.contrib-list > li { counter-increment: rank; border-bottom: 1px solid var(--grid); }
.contrib-list summary {
  cursor: pointer; list-style: none; display: grid; align-items: center;
  grid-template-columns: 2.2em minmax(0, 1fr) auto; gap: 2px 6px; padding: 8px 0;
}
.contrib-list summary::-webkit-details-marker { display: none; }
.contrib-list summary::before { content: counter(rank) "."; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.contrib-list summary .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contrib-list summary .cnt { font-weight: 600; font-variant-numeric: tabular-nums; }
.contrib-list summary .bar { grid-column: 2 / 4; margin-top: 0; }
.contrib-list summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.contrib-list ul { list-style: none; margin: 0 0 8px 2.6em; padding: 0; font-size: 13px; }
.contrib-list ul li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.contrib-list ul button { all: unset; cursor: pointer; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contrib-list ul button:hover { text-decoration: underline; }
.contrib-list ul button:focus-visible { outline: 2px solid var(--accent); }
.contrib-list ul a { white-space: nowrap; text-decoration: none; }
.contrib-list .profile { margin: 0 0 10px 2.6em; font-size: 13px; }
.contrib-foot { margin-top: 12px; font-size: 12px; }

.layout.no-contrib { grid-template-columns: 300px minmax(0, 1fr); }
.layout.no-contrib .contrib { display: none; }

@media (max-width: 1200px) {
  .layout { grid-template-columns: 300px minmax(0, 1fr); }
  .contrib { grid-column: 2; position: static; height: auto; border-left: 0; margin: 0 24px 24px; border: 1px solid var(--border); border-radius: 10px; }
}

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .contrib { grid-column: 1; margin: 0 16px 16px; }
  #missions { flex-direction: row; overflow-x: auto; }
  .mission-link { min-width: 200px; flex: 0 0 auto; }
  .main { padding: 16px; }
  .map { height: 55vh; }
}
