:root {
  --ink: #f8ead6;
  --ink-muted: #d7c3a9;
  --deep-ocean: #07121f;
  --ocean: #102a43;
  --ocean-2: #0b3b4b;
  --kanga-ivory: #f4e3c1;
  --zanzibar-coral: #d76653;
  --clove-gold: #c58b3a;
  --lagoon-teal: #1d9a8a;
  --mangrove-green: #166f5d;
  --shadow: rgba(0, 0, 0, 0.42);
  --glass: rgba(8, 20, 32, 0.78);
  --glass-strong: rgba(8, 20, 32, 0.92);
  --line: rgba(244, 227, 193, 0.22);
  --focus: #f9c96c;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--deep-ocean);
  color: var(--ink);
  font-family: "Noto Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  overflow: hidden;
}

.skip-link {
  position: absolute;
  z-index: 4000;
  left: 1rem;
  top: -5rem;
  color: var(--deep-ocean);
  background: var(--focus);
  padding: 0.6rem 0.8rem;
  border-radius: 999px;
  transition: top 160ms ease;
}
.skip-link:focus { top: 1rem; }

.app-shell {
  position: relative;
  min-height: 100svh;
  overflow: hidden;
}

.map {
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    radial-gradient(circle at 65% 35%, rgba(29,154,138,0.10), transparent 38%),
    linear-gradient(135deg, var(--deep-ocean), var(--ocean));
}

.leaflet-container {
  background: #07121f;
  font-family: "Noto Sans", sans-serif;
}

.leaflet-control-attribution {
  background: rgba(7, 18, 31, 0.78) !important;
  color: rgba(248, 234, 214, 0.72) !important;
  border-radius: 10px 0 0 0;
  font-size: 11px;
}
.leaflet-control-attribution a { color: #f1bd74 !important; }

.hero-panel {
  position: absolute;
  z-index: 1200;
  left: clamp(14px, 3vw, 36px);
  top: clamp(14px, 3vw, 32px);
  width: min(470px, calc(100vw - 28px));
  padding: 1.15rem 1.2rem 1.15rem;
  border: 1px solid var(--line);
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(8,20,32,0.88), rgba(8,20,32,0.70)),
    radial-gradient(circle at 10% 0%, rgba(197,139,58,0.25), transparent 40%);
  box-shadow: 0 22px 60px var(--shadow);
  backdrop-filter: blur(15px) saturate(125%);
}

.kanga-border {
  height: 9px;
  margin: -0.2rem 0 0.9rem;
  border-radius: 999px;
  background:
    repeating-linear-gradient(90deg,
      var(--kanga-ivory) 0 10px,
      var(--zanzibar-coral) 10px 21px,
      var(--clove-gold) 21px 31px,
      var(--lagoon-teal) 31px 44px,
      var(--ocean-2) 44px 55px);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08) inset;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--clove-gold);
  font-family: "Alegreya Sans", sans-serif;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: "Noto Serif", Georgia, serif;
  font-size: clamp(1.75rem, 3.3vw, 2.75rem);
  line-height: 0.98;
  letter-spacing: -0.045em;
  color: #fff7e8;
}

.subtitle {
  margin: 0.85rem 0 1rem;
  color: var(--ink-muted);
  font-size: 0.96rem;
  line-height: 1.45;
}

.mode-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.45rem;
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,0.04);
}

.mode-btn, .map-actions button, .legend-toggle, .modal-close {
  font: inherit;
  border: 1px solid rgba(244, 227, 193, 0.18);
  color: var(--ink);
  background: rgba(255,255,255,0.06);
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.mode-btn {
  border-radius: 14px;
  padding: 0.65rem 0.8rem;
  text-align: left;
  font-weight: 700;
}

.mode-btn:hover, .map-actions button:hover, .legend-toggle:hover {
  background: rgba(255,255,255,0.12);
  transform: translateY(-1px);
}

.mode-btn:focus-visible, .map-actions button:focus-visible, .legend-toggle:focus-visible,
.modal-close:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.mode-btn.active {
  color: #09141d;
  background: linear-gradient(135deg, var(--kanga-ivory), #f1bd74);
  border-color: rgba(255,255,255,0.7);
  box-shadow: 0 10px 22px rgba(0,0,0,0.22);
}

.mode-narrative {
  margin: 0.85rem 0 0;
  color: rgba(248, 234, 214, 0.82);
  font-size: 0.86rem;
  line-height: 1.45;
}

.legend-panel {
  position: absolute;
  z-index: 1300;
  right: clamp(12px, 2vw, 30px);
  bottom: clamp(72px, 8vw, 94px);
  width: min(360px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 20px 50px var(--shadow);
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(125%);
}

.legend-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 0.78rem 0.95rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.05);
  font-weight: 800;
}

.legend-content {
  padding: 0.85rem 0.95rem 0.95rem;
}

.legend-row {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 0.65rem;
  align-items: center;
  margin: 0.38rem 0;
  color: var(--ink-muted);
  font-size: 0.86rem;
}

.swatch {
  width: 34px;
  height: 19px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.42);
}

.symbol-demo {
  width: 34px;
  height: 24px;
  display: grid;
  place-items: center;
}
.symbol-circle {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(244, 227, 193, 0.35);
  border: 2px solid #f4e3c1;
  box-shadow: 0 0 18px rgba(244, 227, 193, 0.22);
}
.symbol-hollow {
  background: transparent;
  border: 2px dashed rgba(244, 227, 193, 0.86);
}

.legend-note {
  margin: 0.75rem 0 0;
  padding-top: 0.7rem;
  border-top: 1px solid var(--line);
  color: rgba(248, 234, 214, 0.68);
  font-size: 0.78rem;
  line-height: 1.38;
}

.map-actions {
  position: absolute;
  z-index: 1350;
  right: clamp(12px, 2vw, 30px);
  bottom: clamp(14px, 2vw, 28px);
  display: flex;
  gap: 0.55rem;
}

.map-actions button {
  border-radius: 999px;
  padding: 0.72rem 0.9rem;
  background: var(--glass-strong);
  box-shadow: 0 14px 34px var(--shadow);
  font-weight: 800;
}

.loading {
  position: absolute;
  z-index: 2000;
  left: 50%;
  bottom: 2rem;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--ink);
  background: var(--glass-strong);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.75rem 1rem;
  box-shadow: 0 18px 44px var(--shadow);
}

.loading.hidden {
  display: none;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 3px solid rgba(244, 227, 193, 0.2);
  border-top-color: var(--clove-gold);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }


/* Explicitly honor the hidden attribute.
   Author-level display rules can otherwise override the browser's default
   [hidden] { display: none; } behavior, making the sources modal appear open
   and impossible to dismiss. */
.modal-backdrop[hidden] {
  display: none !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 3500;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(1, 6, 12, 0.62);
  backdrop-filter: blur(8px);
}

.modal {
  position: relative;
  width: min(760px, 94vw);
  max-height: min(760px, 88vh);
  overflow: auto;
  border-radius: 28px;
  border: 1px solid var(--line);
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(8,20,32,0.98), rgba(12,39,52,0.96));
  padding: 1.4rem;
  box-shadow: 0 28px 80px rgba(0,0,0,0.52);
}

.modal h2, .modal h3 {
  font-family: "Noto Serif", Georgia, serif;
  letter-spacing: -0.02em;
  color: #fff7e8;
}
.modal h2 { margin: 0 2rem 0.7rem 0; }
.modal h3 { margin: 1.1rem 0 0.35rem; font-size: 1.05rem; }
.modal p, .modal li {
  color: var(--ink-muted);
  line-height: 1.48;
}
.modal a { color: #f1bd74; }
.modal-close {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 1.7rem;
}

.made-with {
  margin-top: 1.2rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--line);
}

.country-popup .leaflet-popup-content-wrapper {
  border-radius: 21px;
  color: var(--ink);
  background: rgba(8,20,32,0.96);
  border: 1px solid rgba(244,227,193,0.22);
  box-shadow: 0 18px 52px rgba(0,0,0,0.45);
}
.country-popup .leaflet-popup-tip {
  background: rgba(8,20,32,0.96);
}
.leaflet-popup-content {
  margin: 0;
  width: min(330px, 76vw) !important;
}
.popup-card {
  padding: 1rem;
}
.popup-card h2 {
  margin: 0 0 0.25rem;
  font-family: "Noto Serif", Georgia, serif;
  letter-spacing: -0.035em;
  color: #fff7e8;
}
.popup-score {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  margin: 0.25rem 0 0.7rem;
  border-radius: 999px;
  padding: 0.28rem 0.55rem;
  color: #0b1420;
  background: var(--kanga-ivory);
  font-weight: 800;
  font-size: 0.82rem;
}
.popup-grid {
  display: grid;
  gap: 0.55rem;
}
.popup-label {
  display: block;
  color: var(--clove-gold);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 800;
}
.popup-value {
  color: var(--ink-muted);
  line-height: 1.36;
}
.popup-foot {
  margin-top: 0.8rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--line);
  color: rgba(248, 234, 214, 0.62);
  font-size: 0.76rem;
  line-height: 1.35;
}

.country-label {
  color: rgba(255,247,232,0.92);
  background: rgba(7,18,31,0.64);
  border: 1px solid rgba(244,227,193,0.18);
  border-radius: 999px;
  padding: 0.12rem 0.45rem;
  box-shadow: 0 10px 22px rgba(0,0,0,0.28);
  font-family: "Alegreya Sans", sans-serif;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.leaflet-tooltip-top::before,
.leaflet-tooltip-bottom::before,
.leaflet-tooltip-left::before,
.leaflet-tooltip-right::before {
  display: none;
}

@media (min-width: 680px) {
  .mode-card {
    grid-template-columns: repeat(3, 1fr);
  }
  .mode-btn {
    text-align: center;
    font-size: 0.84rem;
  }
}

@media (max-width: 720px) {
  body { overflow: hidden; }
  .hero-panel {
    top: 10px;
    left: 10px;
    right: 10px;
    width: auto;
    padding: 0.85rem;
    border-radius: 20px;
  }
  h1 { font-size: 1.45rem; line-height: 1.05; }
  .subtitle { display: none; }
  .mode-narrative { font-size: 0.78rem; }
  .legend-panel {
    left: 10px;
    right: 10px;
    bottom: 76px;
    width: auto;
  }
  .map-actions {
    left: 10px;
    right: 10px;
    justify-content: space-between;
  }
  .map-actions button { flex: 1; }
}


/* --------------------------------------------------------------------------
   Mobile-first control redesign
   --------------------------------------------------------------------------
   The title now stays compact, while all map manipulation tools live in a
   bottom-up "Explore Kiswahili" panel. This prevents the title card, legend,
   and utility buttons from competing with popups on narrow portrait screens.
*/

.compact-title {
  width: min(520px, calc(100vw - 28px));
  padding: 0.95rem 1rem;
}

.compact-title .kanga-border {
  height: 7px;
  margin-bottom: 0.65rem;
}

.compact-title .eyebrow {
  font-size: clamp(0.66rem, 2.3vw, 0.82rem);
  letter-spacing: 0.14em;
}

.compact-title h1 {
  font-size: clamp(1.18rem, 4.1vw, 2.25rem);
  line-height: 1.03;
  letter-spacing: -0.035em;
}

.compact-title .subtitle {
  margin: 0.55rem 0 0;
  font-size: clamp(0.78rem, 2.4vw, 0.94rem);
  line-height: 1.38;
}

.settings-panel {
  position: absolute;
  z-index: 1450;
  right: clamp(12px, 2vw, 30px);
  bottom: clamp(12px, 2vw, 26px);
  width: min(390px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 26px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(8,20,32,0.94), rgba(7,18,31,0.86)),
    radial-gradient(circle at 20% 0%, rgba(29,154,138,0.20), transparent 44%);
  box-shadow: 0 24px 68px var(--shadow);
  backdrop-filter: blur(16px) saturate(130%);
}

.settings-toggle {
  width: 100%;
  border: 0;
  color: var(--ink);
  background: rgba(255,255,255,0.055);
  display: grid;
  grid-template-columns: 32px 1fr 32px;
  align-items: center;
  gap: 0.35rem;
  padding: 0.78rem 1rem;
  font: inherit;
  cursor: pointer;
}

.settings-toggle:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -5px;
}

.settings-grip {
  width: 28px;
  height: 4px;
  border-radius: 999px;
  background: rgba(244,227,193,0.45);
  justify-self: start;
}

.settings-title {
  font-family: "Noto Serif", Georgia, serif;
  font-size: 1.12rem;
  font-weight: 700;
  color: #fff7e8;
  text-align: left;
}

.settings-chevron {
  justify-self: end;
  transform: rotate(0deg);
  transition: transform 160ms ease;
  font-size: 1.2rem;
}

.settings-panel.collapsed .settings-chevron {
  transform: rotate(180deg);
}

.settings-content {
  padding: 0.86rem 0.98rem 1rem;
  border-top: 1px solid var(--line);
}

.settings-panel.collapsed .settings-content {
  display: none;
}

.mode-select-label {
  display: block;
  margin: 0 0 0.32rem;
  color: rgba(248,234,214,0.78);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.mode-select {
  display: none;
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(244,227,193,0.42);
  border-radius: 15px;
  padding: 0.62rem 2.2rem 0.62rem 0.78rem;
  color: #09141d;
  background: linear-gradient(135deg, var(--kanga-ivory), #f1bd74);
  font: 800 1rem "Noto Sans", system-ui, sans-serif;
}

.panel-actions {
  display: flex;
  gap: 0.55rem;
  margin: 0.75rem 0 0.7rem;
}

.icon-btn {
  flex: 1;
  min-height: 42px;
  border-radius: 999px;
  border: 1px solid rgba(244, 227, 193, 0.22);
  color: var(--ink);
  background: rgba(255,255,255,0.065);
  box-shadow: 0 12px 28px rgba(0,0,0,0.22);
  font: 800 0.92rem "Noto Sans", system-ui, sans-serif;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.icon-btn span:first-child {
  display: inline-grid;
  place-items: center;
  width: 1.38rem;
  height: 1.38rem;
  border-radius: 50%;
  color: #09141d;
  background: var(--kanga-ivory);
  font-weight: 900;
  line-height: 1;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  background: rgba(255,255,255,0.14);
}

.icon-btn:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* The legend is now a subsection inside the bottom settings panel. */
.settings-panel .legend-panel {
  position: static;
  width: 100%;
  border-radius: 18px;
  box-shadow: none;
  background: rgba(255,255,255,0.04);
  backdrop-filter: none;
}

.settings-panel .legend-toggle {
  border-radius: 18px;
  border-bottom: 0;
  padding: 0.66rem 0.8rem;
}

/* Popups should win the tight-screen z-index battle. */
.leaflet-popup-pane {
  z-index: 2900 !important;
}

.leaflet-tooltip-pane {
  z-index: 900 !important;
}

.leaflet-popup {
  margin-bottom: 18px;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  box-shadow: 0 20px 56px rgba(0,0,0,0.46);
}

@media (max-width: 760px) {
  .hero-panel.compact-title {
    left: 10px;
    right: 10px;
    top: max(10px, env(safe-area-inset-top));
    width: auto;
    border-radius: 19px;
    padding: 0.72rem 0.82rem 0.78rem;
    background:
      linear-gradient(180deg, rgba(8,20,32,0.92), rgba(8,20,32,0.66)),
      radial-gradient(circle at 10% 0%, rgba(197,139,58,0.20), transparent 45%);
  }

  .compact-title .kanga-border {
    height: 6px;
    margin: -0.1rem 0 0.48rem;
  }

  .compact-title .eyebrow {
    margin-bottom: 0.23rem;
  }

  .compact-title h1 {
    font-size: clamp(1.03rem, 6vw, 1.62rem);
    line-height: 1.02;
    max-width: 95%;
  }

  .compact-title .subtitle {
    display: none;
  }

  .settings-panel {
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    width: auto;
    border-radius: 24px;
  }

  .settings-toggle {
    min-height: 52px;
    padding: 0.64rem 0.85rem;
  }

  .settings-title {
    font-size: 1rem;
  }

  .settings-content {
    max-height: min(58svh, 430px);
    overflow: auto;
    padding: 0.72rem 0.82rem 0.85rem;
  }

  .mode-card {
    display: none;
  }

  .mode-select {
    display: block;
  }

  .mode-narrative {
    font-size: 0.79rem;
    margin-top: 0.55rem;
  }

  .panel-actions {
    margin: 0.62rem 0;
  }

  .icon-btn {
    min-height: 40px;
    font-size: 0.86rem;
  }

  .settings-panel .legend-toggle {
    padding: 0.6rem 0.75rem;
  }

  .legend-content {
    padding: 0.66rem 0.75rem 0.75rem;
  }

  .legend-row {
    font-size: 0.78rem;
    grid-template-columns: 30px 1fr;
    gap: 0.52rem;
  }

  .swatch {
    width: 28px;
    height: 16px;
  }

  .symbol-demo {
    width: 28px;
  }

  .country-popup .leaflet-popup-content {
    width: min(82vw, 310px) !important;
    margin: 0;
  }

  .popup-card {
    max-height: min(58svh, 440px);
    overflow: auto;
  }

  .leaflet-control-attribution {
    max-width: 68vw;
    white-space: normal;
    line-height: 1.15;
    font-size: 10px;
  }
}

@media (max-width: 420px) {
  .compact-title h1 {
    font-size: clamp(0.98rem, 5.65vw, 1.36rem);
  }

  .compact-title .eyebrow {
    font-size: 0.58rem;
    letter-spacing: 0.11em;
  }

  .settings-panel.collapsed .settings-toggle {
    min-height: 48px;
  }

  .btn-text {
    display: none;
  }

  .icon-btn {
    flex: 0 0 48px;
    min-width: 48px;
  }

  .panel-actions {
    justify-content: center;
  }
}
