:root {
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
  --accent: #145ca8;
  --accent-hover: #0f4a88;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(20, 92, 168, 0.12);
  --background: #f7f9fb;
  --surface: #ffffff;
  --surface-alt: #f0f4f9;
  --border-color: #d6dce5;
  --text: #1f2a37;
  --text-muted: #52616b;
  --shadow: rgba(20, 92, 168, 0.08);
}

html {
  height: 100%;
}

body.theme-dark {
  color-scheme: dark;
  --accent: #67b3ff;
  --accent-hover: #88c8ff;
  --accent-contrast: #0b121d;
  --accent-soft: rgba(103, 179, 255, 0.22);
  --background: #0b141f;
  --surface: #111c2b;
  --surface-alt: #16263a;
  --border-color: #203347;
  --text: #e4ecf5;
  --text-muted: #93abc1;
  --shadow: rgba(12, 24, 38, 0.6);
}

body.theme-light {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  /* Ordinary page: grow with content and let the document scroll, so the
     footer always follows the map. A hard height:100vh here made the grid a
     fixed shell that clipped the middle row — in short landscape the map
     (min ~380px) overflowed it and the footer overlapped the map. dvh tracks
     the real viewport as mobile browser chrome shows/hides. The fixed-height
     application shell is restored for desktop and iframe modes below. */
  min-height: 100vh;
  min-height: 100dvh;
  height: auto;
  background: var(--background);
  color: var(--text);
}

header {
  padding: 1rem 1.5rem 0.75rem; /* Reduced padding for better space usage */
  background: var(--surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 0.75rem; /* Reduced gap */
  position: relative;
  flex-shrink: 0; /* Prevent header from shrinking */
}

header h1 {
  margin: 0;
  font-size: 1.5rem; /* Reduced font size for space */
  color: var(--accent);
}

header p {
  margin: 0;
  max-width: 60rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.header-actions {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap; /* controls must never widen the page (WCAG reflow) */
  gap: 0.75rem;
}

.header-subtitle {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.4;
  font-size: 0.95rem;
}

.header-about {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.header-about summary {
  cursor: pointer;
  color: var(--accent);
  width: max-content;
  max-width: 100%;
}

.header-about summary:hover,
.header-about summary:focus-visible {
  text-decoration: underline;
}

.header-about p {
  margin: 0.5rem 0 0;
  max-width: 60rem;
  line-height: 1.5;
}

.filters-toggle {
  display: none;
  align-items: center;
  gap: 0.45rem;
  /* 44px touch target: this is the primary route into every filter on mobile. */
  min-height: 2.75rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.filters-toggle__icon {
  position: relative;
  display: inline-block;
  width: 1.1rem;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

.filters-toggle__icon::before,
.filters-toggle__icon::after {
  content: '';
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

.filters-toggle__icon::before {
  top: -0.35rem;
}

.filters-toggle__icon::after {
  top: 0.35rem;
}

.filters-toggle:hover,
.filters-toggle:focus-visible {
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: translateY(-1px);
  outline: none;
}

.filters-toggle[aria-expanded='true'] {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.filters-panel-header {
  display: none;
  /* Explicit row: the generic `header` element rule sets flex-direction:
     column, which would stack the title above the close button. */
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.filters-panel-header h2 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--accent);
}

.filters-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* 44px: primary dismiss action for the mobile filter drawer. */
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.filters-close:hover,
.filters-close:focus-visible {
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: translateY(-1px);
  outline: none;
}

.filters-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 20, 31, 0.45);
  backdrop-filter: blur(3px);
  /* Above every Leaflet pane and control (Leaflet's maximum is 1000). */
  z-index: 1150;
  display: none;
}

.filter-group--species > .filter-group__body,
.filter-group--stocking > .filter-group__body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.stocking-filter__controls {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.stocking-filter__frequency {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 220px;
}

.stocking-filter__frequency select {
  min-width: 200px;
}


.stocking-filter__match {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  min-width: 220px;
  background: var(--surface-alt);
}

.stocking-filter__match label {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.35rem;
}

.stocking-filter__match label:first-of-type {
  margin-top: 0.25rem;
}

@media (max-width: 900px) {
  .stocking-filter__match {
    width: 100%;
  }
}

@media (max-width: 900px) {
  .stocking-filter__controls {
    flex-direction: column;
    align-items: stretch;
  }
  .stocking-filter__frequency {
    min-width: 0;
  }
}

.species-filter__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.clear-selection {
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--accent);
  border-radius: 999px;
  /* 36px: dense secondary control, above the 32px comfort floor. */
  min-height: 2.25rem;
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.clear-selection:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.clear-selection:hover,
.clear-selection:focus-visible {
  background: var(--accent-soft);
  border-color: var(--accent);
  outline: none;
}

.species-filter__summary,
.stocking-filter__summary {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-height: 1.2rem;
}

.stocking-summary-item {
  padding: 0.75rem 0.85rem;
  margin-top: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--surface-alt);
}

.stocking-summary-item:first-child {
  margin-top: 0;
}

.stocking-summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.stocking-summary-header strong {
  font-size: 0.95rem;
  color: var(--text);
}

.stocking-summary-stats {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.stocking-summary-breakdown {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
}

.stocking-summary-freq-item {
  display: flex;
  gap: 0.3rem;
}

.freq-label {
  color: var(--text-muted);
}

.freq-count {
  font-weight: 600;
  color: var(--accent);
}

.species-filter__controls {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.species-filter__match {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  min-width: 200px;
  background: var(--surface-alt);
}

.species-filter__match label {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.35rem;
}

.species-filter__match label:first-of-type {
  margin-top: 0.25rem;
}

.species-filter__abundance {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 200px;
}

.species-filter__abundance select {
  min-width: 160px;
}

@media (max-width: 900px) {
  .species-filter__controls {
    flex-direction: column;
    align-items: stretch;
  }
  .species-filter__match,
  .species-filter__abundance {
    width: 100%;
  }
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

main {
  display: flex;
  min-height: 0;
  flex: 1; /* Take remaining space */
  overflow: hidden;
  background: linear-gradient(135deg, var(--background) 0%, var(--surface-alt) 100%);
}

.site-credit {
  padding: 0.25rem 0.75rem;
  text-align: center;
  background: var(--surface);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  flex-shrink: 0; /* Prevent footer from shrinking */
}

.site-credit a {
  color: var(--accent);
  text-decoration: none;
}

.site-credit a:hover,
.site-credit a:focus-visible {
  text-decoration: underline;
}

#filters {
  flex: 0 0 clamp(280px, 32vw, 480px); /* Reduced width for more map space */
  max-width: 100%;
  padding: 1rem; /* Reduced padding */
  border-right: 1px solid var(--border-color);
  background: var(--surface);
  overflow-y: auto;
  box-shadow: 12px 0 30px -24px var(--shadow);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); /* Smaller min width */
  gap: 0.75rem; /* Reduced gap */
  align-content: start;
  align-items: start;
  min-height: 0;
}

#map {
  flex: 1;
  min-height: 0;
  height: 100%;
  background: var(--surface-alt);
  position: relative;
}

#map[hidden] {
  display: none;
}

