:root {
  --ink: #1b2430;
  --muted: #5b6776;
  --line: #d9dee5;
  --panel: #ffffff;
  --burn: #c2410c;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: #f4f6f8;
}
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1.5rem;
  padding: 0.6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 1.15rem; }
.tagline { margin: 0.1rem 0 0; font-size: 0.85rem; color: var(--muted); }
.topnav { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; font-size: 0.85rem; }
.topnav a { color: #1f6fb2; text-decoration: none; }
.topnav a:hover { text-decoration: underline; }
.stage { position: relative; flex: 1; min-height: 320px; }
#map { position: absolute; inset: 0; }
.map-status {
  position: absolute; left: 50%; top: 1rem; transform: translateX(-50%); margin: 0;
  padding: 0.5rem 0.8rem; background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  font-size: 0.9rem; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

/* Legend and details panel */
.card {
  position: absolute; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12); padding: 0.75rem 0.9rem; font-size: 0.85rem;
}
.card h2 { margin: 0 0 0.4rem; font-size: 0.95rem; }
.fine { margin: 0.4rem 0 0; font-size: 0.75rem; color: var(--muted); line-height: 1.35; }
.legend { right: 3.4rem; top: 0.6rem; width: 17rem; max-height: calc(100% - 2.6rem); overflow-y: auto; }
.yearline { display: flex; align-items: center; justify-content: space-between; }
.yearline h2 { margin: 0; }
#year-label { font-variant-numeric: tabular-nums; }
.steps button {
  width: 1.7rem; height: 1.7rem; font: inherit; font-size: 1rem; line-height: 1; cursor: pointer;
  background: #fff; color: var(--ink); border: 1px solid #9aa4b1; border-radius: 5px;
}
.steps button:disabled { opacity: 0.4; cursor: default; }
#year { width: 100%; margin: 0.45rem 0 0.2rem; accent-color: var(--burn); }
.yearchart svg { display: block; width: 100%; height: auto; }
.yearchart rect { fill: #e6b99f; cursor: pointer; }
.yearchart rect.on { fill: var(--burn); }
.yearchart text { font-size: 9px; fill: var(--muted); }
#year-facts { margin: 0.2rem 0 0.55rem; padding-bottom: 0.55rem; border-bottom: 1px solid var(--line); color: var(--ink); }
#layers summary { cursor: pointer; font-weight: 600; margin-bottom: 0.3rem; }
.check { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; padding: 0.1rem 0; }
.swatch { width: 0.8rem; height: 0.8rem; flex: none; }
.swatch.burned { background: rgba(194, 65, 12, 0.45); border: 1px solid var(--burn); }
.swatch.firedot { width: 0.5rem; height: 0.5rem; margin: 0 0.15rem; border-radius: 50%; background: #3b1d0f; }
.swatch.aqhi { border-radius: 50%; background: #fff; border: 2px solid #4b5563; }
.legend-list { list-style: none; margin: 0.15rem 0 0.4rem 1.4rem; padding: 0; }
.legend-list li { display: flex; align-items: center; gap: 0.45rem; padding: 0.08rem 0; }
.legend-list .dot { width: 0.75rem; height: 0.75rem; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.35); flex: none; }
.legend-list .count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

.panel { left: 0.75rem; top: 0.75rem; width: 23rem; max-width: calc(100% - 1.5rem); max-height: calc(100% - 2.5rem); overflow-y: auto; }
.panel .close {
  position: absolute; right: 0.4rem; top: 0.3rem; border: 0; background: none; font-size: 1.4rem;
  line-height: 1; cursor: pointer; color: var(--muted); padding: 0.2rem 0.45rem;
}
.panel h2 { padding-right: 1.6rem; }
.sub { margin: 0; color: var(--muted); }
.trendline { margin: 0.6rem 0 0.2rem; font-weight: 600; }
.chart { margin-top: 0.4rem; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .axis text { font-size: 10px; fill: var(--muted); }
.chart .axis path, .chart .axis line { stroke: #b8c0ca; }
.chart .grid line { stroke: #e7ebf0; }
.chart rect.bar { fill: #9aa4b1; cursor: pointer; }
.chart rect.bar.on { fill: var(--ink); }
.popup { font-size: 0.82rem; line-height: 1.4; }
.popup strong { display: block; font-size: 0.9rem; }

@media (max-width: 720px) {
  .legend { left: 0.5rem; right: 0.5rem; top: auto; bottom: 2.4rem; width: auto; max-height: 55%; }
  .legend .fine { display: none; }
  #year-facts { display: block; border-bottom: 0; margin-bottom: 0.2rem; padding-bottom: 0; }
  .yearchart { display: none; }
  .panel { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-width: none; max-height: 62%; border-radius: 12px 12px 0 0; z-index: 3; }
}
