:root {
  --teal:      #2a7f9e;
  --teal-soft: #dceff5;
  --teal-line: #88bbcc;
  --green:     #cce099;
  --green-deep:#dceab9;
  --ink:     #404040;
  --muted:   #7a7a7a;
  --line:    #e2e8ec;
  --row-alt: #f2f6f8;
  --white:   #ffffff;
  --bg:      #ffffff;
  --map-bg:  #dceef5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --teal:       #62b6d6;
    --teal-soft:  #1c323d;
    --teal-line:  #3d6c81;
    --green:      #5d7d37;
    --green-deep: #2d431c;
    --ink:        #c0d3dc;
    --muted:      #93a6b0;
    --line:       #2b3d46;
    --row-alt:    #1a2730;
    --white:      #141d23;
    --bg:         #0e151b;
    --map-bg:     #383e40;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; }

html {
  scrollbar-color: rgba(42, 127, 158, 0.35) transparent;
  scrollbar-width: thin;
}

body {
  display: flex;
  flex-direction: column;
  overflow-x: clip;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}

.topbar {
  background: linear-gradient(180deg, var(--green) 0%, var(--green-deep) 100%);
  border-bottom: 3px solid var(--teal-line);
  padding: 12px 0;
  box-shadow: 0 4px 10px rgba(40, 80, 100, 0.15);
}
.topbar .logo {
  display: block;
  height: 20px;
  width: auto;
}
/* Split the banner: logo on the left, search on the right. */
.topbar-inner {
  max-width: 1080px;
  margin-inline: auto;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

/* Client-side region search. The dropdown is shown/hidden by search.ts. */
.search {
  position: relative;
  width: min(320px, 100%);
}
/* Magnifying-glass icon, floated over the input's left side. */
.search-icon {
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
#gf-search {
  width: 100%;
  padding: 0.45rem 0.75rem 0.45rem 1.9rem;
  border: 1px solid var(--teal-line);
  border-radius: 6px;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--bg);
}
#gf-search:focus {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
  border-color: var(--teal);
}
.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 0.25rem 0 0;
  padding: 0;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--teal-line);
  border-radius: 6px;
  box-shadow: 0 8px 22px rgba(20, 40, 55, 0.18);
  max-height: 320px;
  overflow-y: auto;
  z-index: 60;
}
.search-results[hidden] { display: none; }
.search-results li a {
  display: block;
  padding: 0.45rem 0.75rem;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}
.search-results li a:hover,
.search-results li a:focus {
  background: var(--teal-soft);
  color: var(--teal);
}
.search-results .no-match {
  padding: 0.6rem 0.75rem;
  color: var(--muted);
  font-style: italic;
}
/* Region name + its parent's name behind it. */
.search-results li a {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.search-results .sr-name {
  font-weight: 600;
}
.search-results .sr-parent {
  color: var(--muted);
  font-size: 0.85em;
}

.search-results li a:hover .sr-name {
  color: var(--teal);
}
.search-results li a:hover .sr-parent {
  color: var(--teal-line);
}

.shell {
  flex: 1 0 auto;
  width: 100%;
  max-width: 1080px;
  margin-inline: auto;
  padding: 1.5rem 1.25rem 3rem;
}

#map {
  height: 400px;
  width: min(1000px, 100%);
  margin: 0 auto 1.25rem;
  border-radius: 10px;
  border: 1px solid var(--teal-line);
  background: var(--map-bg);
  box-shadow: 0 1px 4px rgba(40, 80, 100, 0.12);
}
/* Dark theme: dim the light OSM raster tiles so they don't glare. */
@media (prefers-color-scheme: dark) {
  #map .maplibregl-canvas {
    filter: brightness(0.7) contrast(1.5) saturate(0.9);
  }
}

/* Dark theme: lucide SVGs use stroke="currentColor", which in an <img> renders
   black and can't be re-coloured from CSS. Inverting them makes the strokes
   light so they stay visible on the dark background. */
@media (prefers-color-scheme: dark) {
  .search-icon,
  table.subregions td.ql .ql-cross,
  #map .maplibregl-ctrl-group img {
    filter: invert(0.85);
  }
}

@media (prefers-color-scheme: dark) {
  #map .maplibregl-ctrl-group {
    background-color: var(--map-bg);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--teal-line);
  }
  #map .maplibregl-ctrl-group button {
    background-color: transparent;
  }
  #map .maplibregl-ctrl-group button:hover {
    background-color: var(--teal-soft);
  }
  #map .maplibregl-ctrl-group .maplibregl-ctrl-icon {
    filter: invert(0.93);
  }
  #map .maplibregl-ctrl-attrib {
    background-color: rgba(14, 21, 27, 0.8);
  }
  #map .maplibregl-ctrl-attrib-inner,
  #map .maplibregl-ctrl-attrib-inner a {
    color: var(--ink);
  }
  #map .maplibregl-ctrl-attrib .maplibregl-ctrl-attrib-button {
    background-color: transparent;
    filter: invert(0.8);
  }
}

.region-body {
  display: block;
  max-width: 1000px;
  margin: 0 auto;
}

#content nav,
#content h1,
#content h2,
#content p {
  max-width: 1000px;
  margin-inline: auto;
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: baseline;
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}
nav a { color: var(--teal); }
nav a:hover { text-decoration: underline; }
nav span { font-weight: 600; color: var(--ink); }

h1 {
  margin: 0.5rem 0 0.25rem;
  font-size: 1.9rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--teal);
}
h2 {
  margin: 1.75rem 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
}
h3 { margin: 0.75rem 0 0.4rem; font-size: 1rem; }

.dim { color: var(--muted); font-size: 0.85em; }
.dim code { font-size: 0.95em; }

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

ul.downloads {
  list-style: none;
  margin: 0.5rem 0;
  padding: 0;
  display: grid;
  gap: 0;
}
ul.downloads li {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0.75rem;
  align-items: baseline;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--line);
}
ul.downloads li:last-child { border-bottom: none; }
ul.downloads .fmt { font-weight: 600; color: var(--teal); white-space: nowrap; }
ul.downloads .fmt a { color: var(--teal); }
ul.downloads .why { color: var(--ink); }
/* Meta line under each download: size + last-updated timestamp. */
ul.downloads .why .dim {
  display: block;
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.85em;
}

/* Region comment (from the index `comment` field, rendered raw with links). */
.comment {
  max-width: 1000px;
  margin: 0.4rem auto 0.25rem;
  padding: 0.6rem 0.8rem;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--teal-soft);
  border: 1px solid var(--teal-line);
  border-radius: 6px;
}
.comment a { color: var(--teal); }

/* Confirm-before-download modal (shown by client/download-confirm.js). */
.cf-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 40, 55, 0.45);
}
.cf-modal[hidden] { display: none; }
.cf-modal-box {
  background: var(--bg);
  border: 1px solid var(--teal-line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(20, 40, 55, 0.25);
  padding: 1.25rem 1.5rem;
  max-width: 420px;
  text-align: center;
  color: var(--ink);
}
.cf-modal-box p { margin: 0 0 1rem; }
.cf-modal-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
}
.cf-modal-actions button {
  padding: 0.4rem 1.1rem;
  border-radius: 6px;
  font-size: 0.9em;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.cf-modal-actions .cf-cancel {
  background: var(--row-alt);
  color: var(--muted);
  border: 1px solid var(--line);
}
.cf-modal-actions .cf-ok {
  background: var(--teal);
  color: #fff;
  border: 1px solid var(--teal);
}
.cf-modal-actions .cf-ok:hover { background: var(--teal-line); }

table.subregions {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  background: var(--white);
  font-size: 0.95rem;
}
table.subregions caption {
  text-align: left;
  color: var(--ink);
  font-weight: 600;
  padding-bottom: 0.4rem;
}
table.subregions th {
  text-align: left;
  font-weight: 600;
  color: var(--ink);
  border-bottom: 2px solid var(--teal-line);
  padding: 0.4rem 0.6rem;
}
table.subregions th.ql { text-align: center; }
table.subregions td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.12s ease;
}
table.subregions td.ql { text-align: center; }
/* Lucide X marking a format as unavailable in a quick-link cell. */
table.subregions td.ql .ql-cross {
  width: 14px;
  height: 14px;
  vertical-align: middle;
  color: var(--muted);
}
table.subregions td.ql a { font-size: 0.85em; }
table.subregions tbody tr:nth-child(even) { background: var(--row-alt); }
table.subregions tbody tr:hover { background: var(--teal-soft); }
table.subregions td:first-child { font-weight: 600; }
table.subregions a { }

.foot {
  flex-shrink: 0;
  border-top: 2px solid var(--teal-line);
  margin-top: 2rem;
  padding: 0.75rem 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}



@media (max-width: 600px) {
  .shell { padding: 1rem 0.9rem 2rem; }
  #map { width: 100%; max-width: none; height: 280px; }
  h1 { font-size: 1.5rem; }
}
