:root {
  --bg: #f5f3ee;
  --ink: #1a1a1a;
  --ink-soft: #555;
  --border: #d9d5cc;
  --accent: #2d4a3e;
  --panel-bg: #ffffff;
  --panel-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  --no-data: #cfcfcf;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

#top-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.brand .subtitle {
  font-size: 12px;
  color: var(--ink-soft);
  display: block;
}

.provenance {
  flex: 1;
  font-size: 12px;
  color: var(--ink-soft);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

#share-btn {
  padding: 6px 12px;
  font-size: 13px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

#share-btn:hover { opacity: 0.9; }
#share-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

main {
  flex: 1;
  display: flex;
  min-height: 0;
}

#map {
  flex: 1;
  min-width: 0;
  background: var(--bg);
}

#side-panel {
  width: 300px;
  flex-shrink: 0;
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
}

.panel-section { margin-bottom: 20px; }
.panel-section h2 {
  margin: 0 0 8px 0;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}

.hint {
  font-size: 11px;
  color: var(--ink-soft);
  margin: 6px 0 0 0;
  line-height: 1.4;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.slider-row input[type=range] { flex: 1; }
#year-label {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 600;
  font-size: 14px;
  min-width: 42px;
  text-align: right;
}

.radio-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.chip-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chip-row .chip {
  padding: 5px 10px;
  font-size: 12px;
  background: #f0ece2;
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  color: var(--ink);
  font-family: inherit;
}
.chip-row .chip:hover { background: #e4e0d4; }
.chip-row .chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.radio-row label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  cursor: pointer;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}
.month-grid button {
  padding: 6px 4px;
  font-size: 11px;
  background: #f0ece2;
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  color: var(--ink);
}
.month-grid button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.month-grid .all-btn {
  grid-column: span 4;
  margin-bottom: 4px;
  font-weight: 600;
}

.legend-section #legend-scale {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 12px;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.legend-swatch {
  width: 20px;
  height: 12px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

#legend-validation { margin-bottom: 12px; }
#legend-validation .legend-row { margin-bottom: 2px; }
.legend-border-sample {
  width: 22px;
  height: 12px;
  background: #e5e1d5;
  flex-shrink: 0;
}

#legend-other .legend-row { margin-bottom: 2px; }

#tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(26, 26, 26, 0.95);
  color: white;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.4;
  max-width: 260px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 120ms;
  z-index: 20;
}
#tooltip.visible { opacity: 1; }
#tooltip .tt-title { font-weight: 600; margin-bottom: 4px; }
#tooltip .tt-row { display: flex; justify-content: space-between; gap: 10px; }
#tooltip .tt-row .k { color: #c6c6c6; }
#tooltip .tt-row .v { font-variant-numeric: tabular-nums; }
#tooltip .tt-meta { color: #c6c6c6; font-size: 11px; margin-top: 4px; }

#chart-panel {
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: 520px;
  max-width: calc(100% - 340px);
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
  padding: 12px 14px 10px 14px;
  z-index: 15;
  transform: translateY(calc(100% + 32px));
  transition: transform 180ms ease-out;
  pointer-events: none;
}
#chart-panel.visible {
  transform: translateY(0);
  pointer-events: auto;
}
.chart-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 2px;
}
.chart-title {
  font-size: 13px;
  font-weight: 600;
}
#chart-close {
  background: none;
  border: none;
  font-size: 18px;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0 4px;
}
#chart-close:hover { color: var(--ink); }
.chart-meta {
  font-size: 11px;
  color: var(--ink-soft);
  margin-bottom: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
#chart-svg { display: block; }
#chart-svg .grid { stroke: var(--border); stroke-width: 0.5; }
#chart-svg .axis { stroke: #888; stroke-width: 0.7; }
#chart-svg .axis-label { font-size: 10px; fill: var(--ink-soft); }
#chart-svg .pred-line { stroke: #2d4a3e; stroke-width: 1.8; fill: none; }
#chart-svg .pred-line.other-lead { stroke: #2d4a3e; stroke-width: 0.8; stroke-opacity: 0.25; fill: none; }
#chart-svg .obs-dot { fill: #c46b2f; stroke: #fff; stroke-width: 1.2; }
#chart-svg .hover-line { stroke: #999; stroke-width: 0.6; stroke-dasharray: 2 2; }
#chart-svg text.year-label { font-size: 10px; fill: var(--ink-soft); }
.chart-legend {
  font-size: 11px;
  color: var(--ink-soft);
  display: flex;
  gap: 14px;
  margin-top: 4px;
}
.chart-legend .swatch {
  display: inline-block;
  width: 14px;
  height: 3px;
  vertical-align: middle;
  margin-right: 4px;
}
.chart-legend .swatch.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

@media (max-width: 720px) {
  #chart-panel {
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
    bottom: 8px;
  }
}

@media (max-width: 720px) {
  main { flex-direction: column; }
  #side-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 45vh;
  }
  #top-bar { flex-wrap: wrap; }
  .provenance { flex-basis: 100%; order: 3; }
}
