/* nearmiss accessible map UI — framework-free.
   Risk and significance are never conveyed by color alone; contrast targets
   WCAG 2.2 AA (>= 4.5:1 text), focus is always visible, and interactive targets
   are at least 24x24 px (WCAG 2.5.8). */

:root {
  --fg: #15202b;
  --bg: #ffffff;
  --muted: #4a5560;
  --accent: #0b4f9c; /* >= 4.5:1 on white */
  --hot: #8a1c1c; /* paired ALWAYS with text/pattern, never color alone */
  --line: #c3ccd6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  padding: 0 1rem 3rem;
}

header,
main,
footer {
  max-width: 64rem;
  margin: 0 auto;
}

h1 {
  font-size: 1.6rem;
  margin: 1rem 0 0.25rem;
}

.lede {
  color: var(--fg);
  max-width: 48rem;
}

.lang-switch {
  display: flex;
  gap: 0.25rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.lang-switch button {
  font: inherit;
  cursor: pointer;
  padding: 0.25rem 0.6rem;
  min-height: 24px;
  min-width: 24px;
  border: 1px solid var(--accent);
  background: var(--bg);
  color: var(--accent);
  border-radius: 4px;
}

.lang-switch button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
}

.demo-note,
.real-note {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.95rem;
  max-width: 48rem;
}

/* Amber: synthetic / demo data. */
.demo-note {
  background: #fff4e5;
  border: 1px solid #8a4b00;
  color: #5a2e00; /* >= 4.5:1 on the light background */
}

/* Green: real data. A distinct palette from the demo warning, never the only
   signal — the words "real data" carry the meaning. Text >= 4.5:1 on the bg. */
.real-note {
  background: #e7f4ea;
  border: 1px solid #1b5e20;
  color: #14401a;
}

a {
  color: var(--accent);
}

a:focus-visible,
button:focus-visible,
.table-wrap:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--bg);
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--accent);
}

.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
  z-index: 10;
}

figure {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.5rem;
}

/* Two real maps side by side; stack on narrow screens / at high zoom. */
.map-split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

@media (max-width: 48rem) {
  .map-split {
    grid-template-columns: 1fr;
  }
}

.map-fig {
  margin: 0;
  display: flex;
  flex-direction: column;
}

.map-title {
  font-weight: 700;
  color: var(--fg);
  font-size: 1rem;
  margin: 0 0 0.5rem;
}

.leaflet-map {
  width: 100%;
  height: 22rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #f5f7fa;
}

/* Permanent call-out labels on the protagonist segments (the most-reported
   street on the left, the significant hotspots on the right). High-contrast
   text on white, so the label never relies on color. */
.map-label {
  font: 700 0.78rem/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: #fff;
  border: 1px solid var(--fg);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  white-space: nowrap;
}

figcaption {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

.map-cap {
  margin-top: 0.5rem;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  border-collapse: collapse;
  width: 100%;
  /* Kept modest so the table still reflows usably at 200% zoom / narrow widths;
     the .table-wrap scrolls horizontally only when truly necessary. */
  min-width: 30rem;
}

caption {
  text-align: left;
  padding: 0.5rem 0.75rem;
  color: var(--muted);
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--bg);
  border-bottom: 2px solid var(--fg);
  z-index: 1;
}

/* Keep the segment name (the row header) visible when the table must scroll
   horizontally at 200% zoom / narrow widths. */
th[scope="row"] {
  position: sticky;
  left: 0;
  background: var(--bg);
  z-index: 1;
}

thead th:first-child {
  z-index: 2; /* the top-left corner sits above both sticky axes */
}

th button {
  font: inherit;
  font-weight: 700;
  color: var(--accent);
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  min-height: 24px;
  min-width: 24px;
  padding: 0.15rem 0.35rem;
}

th button:hover {
  text-decoration: underline;
}

/* A significant hotspot row gets a thick left border (a PATTERN, not color
   alone) AND an explicit text marker rendered in the cell. */
tr.is-hotspot td {
  border-left: 6px solid var(--hot);
  background: #fbeeee;
}

.tag {
  display: inline-block;
  border: 1px solid var(--fg);
  border-radius: 999px;
  padding: 0 0.4rem;
  font-size: 0.85rem;
}

.tag-hot {
  border-color: var(--hot);
  color: var(--hot);
  font-weight: 700;
}

.uncertain {
  font-style: italic;
  color: var(--muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

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