:root {
  --sea: #9fc3d1;
  --ui-bg: rgba(255, 255, 255, 0.95);
  --ui-text: #1b2a33;
  --ui-muted: #55636d;
  --ui-line: #d3dbe0;
  --ui-accent: #1d5d86;
  --ui-accent-text: #ffffff;
  /* Legend placeholders. Final colors replace these five values. */
  --c-intact: #efe9dd;
  --c-possible: #e7c873;
  --c-moderate: #e09a4f;
  --c-severe: #c8553d;
  --c-destroyed: #a39a8c;
  --gutter: 16px;
  --bottom-h: 200px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ui-text);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sea);
  -webkit-text-size-adjust: 100%;
}

#map {
  position: fixed !important; /* OpenSeadragon sets position: relative inline */
  top: 0; right: 0; bottom: 0; left: 0;
  background: var(--sea);
  touch-action: none;
}

.card {
  background: var(--ui-bg);
  border: 1px solid var(--ui-line);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
  color: var(--ui-text);
}

:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 2px; }

button { font: inherit; color: inherit; }

/* Left column */
#left {
  position: fixed;
  top: var(--gutter);
  left: var(--gutter);
  width: min(356px, calc(100vw - 2 * var(--gutter) - 44px));
  max-height: calc(100% - 2 * var(--gutter) - var(--bottom-h));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 5;
  scrollbar-width: thin;
}

#title { padding: 8px 12px; }
#title h1 { margin: 0; font-size: 13px; font-weight: 600; line-height: 1.3; }

.panel summary,
.panel-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.panel summary::-webkit-details-marker { display: none; }
.panel summary::after {
  content: "";
  width: 7px; height: 7px;
  border-right: 1.5px solid var(--ui-muted);
  border-bottom: 1.5px solid var(--ui-muted);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.15s;
}
.panel[open] summary::after { transform: rotate(-135deg) translateY(-1px); }
.panel-btn { width: 100%; text-align: left; }
.panel-btn:hover, .panel summary:hover, .btn:hover, .tool:hover { background: #fff; border-color: #aab6bd; }

.panel-body { padding: 0 12px 10px; }
.caption { margin: 0; font-size: 12px; line-height: 1.4; color: var(--ui-muted); }
.caption a { color: var(--ui-accent); }

.legend { list-style: none; margin: 0; padding: 0 12px 10px; font-size: 12.5px; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.swatch { width: 16px; height: 16px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, 0.25); flex: none; }

/* Counts table */
.table-wrap { margin-top: 6px; overflow-x: auto; }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 10.5px; font-variant-numeric: tabular-nums; }
.table-wrap th, .table-wrap td { padding: 3px 2px 3px 5px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--ui-line); }
.table-wrap th:first-child, .table-wrap td:first-child { text-align: left; padding-left: 0; white-space: normal; }
.table-wrap thead th { font-weight: 600; color: var(--ui-muted); vertical-align: bottom; white-space: normal; }
.table-wrap tfoot th, .table-wrap tfoot td { font-weight: 700; border-bottom: 0; border-top: 1.5px solid var(--ui-muted); }

/* Map tools */
#tools {
  position: fixed;
  top: var(--gutter);
  right: var(--gutter);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
}
.tool { width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer; padding: 0; }

/* Bottom area */
#bottom {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 5;
}
#timeline {
  pointer-events: auto;
  width: min(760px, calc(100% - 2 * var(--gutter)));
  padding: 10px 14px 12px;
}
.tl-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.date-label { font-size: 15px; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
#slider { display: block; width: 100%; margin: 6px 0 0; accent-color: var(--ui-accent); height: 28px; }
.tl-ends { display: flex; justify-content: space-between; gap: 12px; font-size: 11px; color: var(--ui-muted); margin-bottom: 4px; }
#coverage { min-height: 1.4em; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 6px 12px;
  background: #fff; border: 1px solid var(--ui-line); border-radius: 6px;
  font-size: 13px; cursor: pointer; white-space: nowrap;
}
.btn svg[hidden] { display: none; }

.painted-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--ui-line); }
.painted-row .caption { flex: 1 1 100%; }
.seg { display: inline-flex; border: 1px solid var(--ui-line); border-radius: 6px; overflow: hidden; }
.seg button { background: #fff; border: 0; padding: 6px 12px; min-height: 34px; font-size: 13px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--ui-line); }
.seg button[aria-pressed="true"] { background: var(--ui-accent); color: var(--ui-accent-text); }
.seg button:disabled { opacity: 0.5; cursor: default; }

#foot {
  pointer-events: auto;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 2px 16px;
  padding: 4px var(--gutter) max(4px, env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.88);
  font-size: 11px;
  line-height: 1.4;
  color: var(--ui-muted);
}
#foot a { color: var(--ui-accent); }
#attribution { text-align: right; margin-left: auto; }

/* Drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(460px, 100%);
  background: #fff;
  border-left: 1px solid var(--ui-line);
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.12);
  display: flex; flex-direction: column;
  z-index: 20;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px var(--gutter); border-bottom: 1px solid var(--ui-line); }
.drawer-head h2 { margin: 0; font-size: 15px; }
.drawer-body { padding: 4px var(--gutter) 24px; overflow-y: auto; font-size: 13px; line-height: 1.5; }
.drawer-h { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ui-muted); margin: 18px 0 8px; }
.sources { list-style: none; margin: 0; padding: 0; }
.sources li { padding: 10px 0; border-bottom: 1px solid var(--ui-line); }
.sources .s-name { font-weight: 600; }
.sources .s-meta { color: var(--ui-muted); font-size: 12px; }
.sources a, .method a { color: var(--ui-accent); overflow-wrap: anywhere; }
.method h4 { margin: 14px 0 4px; font-size: 13px; }
.method p { margin: 0 0 8px; }

/* Map overlays */
.gov-label {
  font-size: 12px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
  color: #14222a; white-space: nowrap; pointer-events: none;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 6px #fff;
  transition: opacity 0.2s;
}
.gov-label.is-off { opacity: 0; }
.pilot { border: 1.5px dashed #14222a; pointer-events: none; transition: opacity 0.2s; }
.pilot span {
  position: absolute; left: -1px; bottom: 100%;
  background: var(--ui-bg); border: 1px solid var(--ui-line); border-bottom: 0;
  padding: 1px 6px; font-size: 11px; white-space: nowrap; color: var(--ui-text);
}
.pilot.is-near { opacity: 0.25; }
.pilot.is-near span { display: none; }

.noscript { position: fixed; top: 0; right: 0; bottom: 0; left: 0; margin: 0; padding: 24px; background: #fff; z-index: 50; }

@media (max-width: 600px) {
  #left { width: calc(100vw - 2 * var(--gutter)); max-height: calc(100% - 2 * var(--gutter) - var(--bottom-h) - 52px); }
  #tools { top: auto; bottom: calc(var(--bottom-h) + 8px); flex-direction: row; }
  .table-wrap table { font-size: 10px; }
  .table-wrap th, .table-wrap td { padding-left: 3px; }
  .date-label { font-size: 14px; }
  .tl-head { gap: 10px; }
  #timeline { padding: 8px 12px 10px; }
  #foot { justify-content: flex-start; }
  #attribution { text-align: left; margin-left: 0; }
}
@media (max-width: 600px) { .gov-label { font-size: 10px; } }
@media (prefers-reduced-motion: reduce) {
  .gov-label, .pilot { transition: none; }
}

.legend li { align-items: flex-start; line-height: 1.35; }
.legend li b { font-weight: 600; margin-right: 4px; }
.swatch.sw-intact { background: var(--c-intact); }
.swatch.sw-possible { background: radial-gradient(circle at 80% 85%, #8f877c 0 2px, transparent 2.5px), var(--c-intact); }
.swatch.sw-moderate { background: radial-gradient(circle at 35% 35%, #6b6057 0 2px, transparent 2.5px), radial-gradient(circle at 70% 60%, #6b6057 0 1.6px, transparent 2px), var(--c-intact); }
.swatch.sw-severe { background: linear-gradient(135deg, var(--c-intact) 0 50%, var(--c-destroyed) 50% 100%); }
.swatch.sw-destroyed { background: radial-gradient(circle at 30% 40%, #6f675d 0 1.5px, transparent 2px), radial-gradient(circle at 70% 70%, #cfc7b8 0 1.5px, transparent 2px), var(--c-destroyed); }
.legend-note { margin: 0 12px 10px; font-size: 11.5px; color: var(--muted, #666); }
