:root {
  color-scheme: light dark;
  --bg: #fbfcfb;
  --fg: #1b2a2f;
  --muted: #566a70;
  --line: #d8e0df;
  --hover: #eaf1f2;
  --accent: #0f5f8c;
  --panel-width: 23rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141c1f;
    --fg: #e5eded;
    --muted: #9db0b4;
    --line: #2e3b3f;
    --hover: #223035;
    --accent: #7cc4ea;
  }
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, "Segoe UI", Arial, sans-serif;
  line-height: 1.55;
}

#map { flex: 1; height: 100%; min-width: 0; background: #e8eeee; }

#panel {
  display: flex;
  flex-direction: column;
  width: var(--panel-width);
  height: 100%;
  border-inline-end: 1px solid var(--line);
}

#panel > header { padding: 1rem 1rem .75rem; border-block-end: 1px solid var(--line); }

h1 { margin: 0 0 .6rem; font-size: 1.35rem; }

h2 { margin: 0; font-size: 1.3rem; line-height: 1.25; }

h3 { margin: 1.1rem 0 .35rem; font-size: .85rem; color: var(--muted); font-weight: 600; }

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.search { position: relative; }

#q {
  width: 100%;
  padding: .5rem .7rem;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
}

#results {
  position: absolute;
  inset-inline: 0;
  z-index: 1000;
  max-height: 16rem;
  margin: .25rem 0 0;
  padding: .25rem;
  overflow-y: auto;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgb(0 0 0 / 18%);
}

.toggle {
  display: flex;
  align-items: flex-start;
  gap: .45rem;
  margin-block-start: .6rem;
  font-size: .9rem;
  cursor: pointer;
}

.toggle input { flex: none; margin: .3rem 0 0; }

.toggle small { color: var(--muted); }

.link {
  display: inline;
  padding: 0;
  font: inherit;
  color: var(--accent);
  text-align: start;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  background: none;
  border: 0;
}

#results button {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  width: 100%;
  padding: .4rem .5rem;
  font: inherit;
  color: inherit;
  text-align: start;
  cursor: pointer;
  background: none;
  border: 0;
  border-radius: 6px;
}

#results button:hover, #results button:focus-visible { background: var(--hover); }

#results small { color: var(--muted); white-space: nowrap; }

#details { flex: 1; padding: 1rem; overflow-y: auto; }

#panel > footer {
  padding: .6rem 1rem;
  font-size: .75rem;
  color: var(--muted);
  border-block-start: 1px solid var(--line);
}

#panel > footer p { margin: 0; }

.legend { display: grid; gap: .15rem; margin: 0; padding: 0; list-style: none; }

.legend button {
  display: flex;
  align-items: center;
  gap: .6rem;
  width: 100%;
  padding: .4rem .5rem;
  font: inherit;
  color: inherit;
  text-align: start;
  cursor: pointer;
  background: none;
  border: 0;
  border-radius: 6px;
}

.legend button:hover, .legend button:focus-visible { background: var(--hover); }

.legend button[aria-pressed="true"] { background: var(--hover); font-weight: 600; }

.legend small { margin-inline-start: auto; color: var(--muted); font-weight: 400; }

.swatch { flex: none; width: 1.1rem; height: .3rem; border-radius: 2px; }

.back { margin-block-end: .7rem; font-size: .9rem; }

.en { margin: .1rem 0 0; color: var(--muted); font-size: .9rem; }

.basin-tag {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  margin-block-start: .6rem;
  font-size: .9rem;
}

.flow { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .4rem; margin: 0; padding: 0; list-style: none; }

.flow li:not(:last-child)::after { content: " ←"; color: var(--muted); }

.facts { display: grid; grid-template-columns: auto 1fr; gap: .15rem .9rem; margin: .9rem 0 0; }

.facts dt { color: var(--muted); }

.facts dd { margin: 0; }

.tribs { display: flex; flex-wrap: wrap; gap: .1rem .7rem; margin: 0; padding: 0; list-style: none; }

.summary { margin: 0; }

.note { color: var(--muted); font-size: .9rem; }

.leaflet-container { font-family: inherit; }

@media (max-width: 720px) {
  body { flex-direction: column-reverse; }

  #map { flex: 1 1 50%; height: auto; min-height: 0; }

  #panel {
    flex: 1 1 50%;
    width: 100%;
    height: auto;
    min-height: 0;
    border-inline-end: 0;
    border-block-start: 1px solid var(--line);
  }

  #panel > header { display: flex; flex-wrap: wrap; align-items: center; gap: .1rem .75rem; padding: .6rem 1rem; }

  .toggle { flex-basis: 100%; margin-block-start: .35rem; font-size: .8rem; }

  h1 { flex: none; margin: 0; font-size: 1.05rem; }

  .search { flex: 1; }

  #q { padding: .35rem .6rem; }
}
