:root {
  color-scheme: dark;
  --ocean-deep: #081d33;
  --ocean: #0b2545;
  --ocean-2: #13315c;
  --panel: #0f2b4c;
  --card: #12304f;
  --card-hover: #163a5e;
  --line: #1d4267;
  --sand: #f6efe3;
  --text: #eaf2f8;
  --muted: #9db6cc;
  --aqua: #2ec4b6;
  --sky: #00b4d8;
  --sun: #ffd166;
  --coral: #ff7f50;
  --coral-2: #ff9e6b;
  --radius: 14px;
}

* { box-sizing: border-box; }

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

body { display: flex; flex-direction: column; }

/* ---------------------------------------------------------------- header */
.topbar {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  padding: 14px 22px;
  background: linear-gradient(120deg, var(--ocean-deep) 0%, var(--ocean) 55%, var(--ocean-2) 100%);
}

.brand { display: flex; align-items: center; gap: 12px; }

.logo { width: 52px; height: 52px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.45)); }

.wordmark { display: flex; flex-direction: column; line-height: 1; }
.wm1 {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 1px;
  color: var(--text);
}
.wm2 {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 5px;
  background: linear-gradient(90deg, var(--aqua), var(--sky), var(--sun));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.controls {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.controls label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.controls select, .controls button {
  background: #14324f;
  color: var(--text);
  border: 1px solid var(--aqua);
  border-radius: 999px;
  padding: 7px 28px 7px 13px;
  font-size: 13px;
  font-family: inherit;
}
.controls select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%232ec4b6' d='M2 4l4 4 4-4z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 12px;
  cursor: pointer;
}
.controls select:hover { border-color: var(--coral); }
.controls select:focus, .controls button:focus { outline: 2px solid var(--aqua); outline-offset: 1px; }
.controls button { cursor: pointer; font-size: 16px; padding: 5px 12px; background: linear-gradient(120deg, var(--coral), var(--coral-2)); border: none; color: #fff; }

/* ---------------------------------------------------------------- wave divider */
.wave-divider { line-height: 0; margin-top: -1px; }
.wave-divider svg { width: 100%; height: 26px; display: block; }

/* ---------------------------------------------------------------- layout */
main { display: flex; flex: 1; min-height: 0; }

#panel {
  width: 420px;
  max-width: 46vw;
  overflow-y: auto;
  background: linear-gradient(180deg, var(--sand) 0%, #fdf9f0 100%);
  color: var(--ocean-deep);
  padding: 14px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#map { flex: 1; min-height: 400px; }

/* ---------------------------------------------------------------- search */
.search-wrap { position: relative; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 14px; opacity: .6; }
.search-wrap input {
  width: 100%;
  padding: 11px 12px 11px 36px;
  border-radius: 999px;
  border: 2px solid #d8e4ee;
  background: #fff;
  color: var(--ocean-deep);
  font-size: 14px;
  font-family: inherit;
  box-shadow: 0 2px 8px rgba(8, 29, 51, .08);
}
.search-wrap input:focus { outline: none; border-color: var(--aqua); box-shadow: 0 0 0 3px rgba(46,196,182,.18); }

/* ---------------------------------------------------------------- browse by locality */
.browse { border-top: 1px solid #e2ecf4; padding-top: 10px; }
.browse-head { font-family: "Baloo 2", sans-serif; font-weight: 800; font-size: 13px; color: var(--ocean-2); letter-spacing: .5px; margin-bottom: 6px; }
.browse details { margin: 3px 0; }
.browse summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  color: var(--ocean-2);
  padding: 7px 10px;
  background: #fff;
  border: 1px solid #e4edf5;
  border-radius: 10px;
  list-style: none;
  transition: border-color .12s ease, background .12s ease;
}
.browse summary::-webkit-details-marker { display: none; }
.browse summary::before { content: "▸"; display: inline-block; margin-right: 6px; transition: transform .15s ease; color: var(--coral); }
.browse details[open] summary::before { transform: rotate(90deg); }
.browse summary:hover { border-color: var(--aqua); }
.browse ul { list-style: none; margin: 4px 0 8px 4px; padding: 0 0 0 12px; border-left: 2px solid #e2ecf4; }
.browse li {
  padding: 5px 8px;
  font-size: 12.5px;
  cursor: pointer;
  border-radius: 8px;
  color: #33546c;
  transition: background .1s ease, color .1s ease;
}
.browse li:hover { background: #e7f5f2; color: var(--ocean-deep); }
.browse li .bt { opacity: .5; font-size: 10.5px; margin-left: 5px; text-transform: uppercase; letter-spacing: .3px; }

/* ---------------------------------------------------------------- status / list */
.status { font-size: 12.5px; font-weight: 700; color: var(--ocean-2); padding: 2px 6px; }

ol#results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.card {
  background: #fff;
  border: 1px solid #e4edf5;
  border-radius: var(--radius);
  padding: 11px 13px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(8, 29, 51, .07);
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--aqua); box-shadow: 0 6px 16px rgba(8,29,51,.14); }

.card .rank { display: flex; align-items: center; gap: 10px; }
.card .pos {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  color: var(--coral);
  font-size: 15px;
  min-width: 24px;
}
.card h3 { margin: 0; font-size: 15px; font-weight: 800; color: var(--ocean-deep); }
.card .meta { font-size: 12px; color: #6b8296; margin-top: 1px; }

.badge {
  margin-left: auto;
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
  padding: 3px 10px;
  border-radius: 999px;
}

.conds { font-size: 12px; color: #5f7689; margin-top: 7px; }
.conds b { color: var(--ocean-2); }

.reasons { font-size: 12px; margin: 7px 0 0; padding-left: 16px; color: #466072; }
.reasons li { margin: 2px 0; }
.warn { color: #d97706; }

/* ---------------------------------------------------------------- legend */
.legend {
  position: absolute; z-index: 1000; background: rgba(11,37,69,.92); color: #eaf2f8; padding: 10px 12px;
  border-radius: 10px; font-size: 12px; right: 12px; bottom: 24px; line-height: 1.7;
  border: 1px solid rgba(46,196,182,.35);
}
.legend span { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

/* ---------------------------------------------------------------- footer */
.disclaimer {
  font-size: 11px; color: var(--muted); padding: 9px 18px;
  background: var(--ocean-deep); border-top: 1px solid var(--line); text-align: center;
}

/* ---------------------------------------------------------------- responsive */
@media (max-width: 760px) {
  body { height: 100dvh; }

  /* Cabecera compacta */
  .topbar { gap: 8px; padding: 10px 12px; }
  .logo { width: 38px; height: 38px; }
  .wm1 { font-size: 16px; }
  .wm2 { font-size: 10px; letter-spacing: 3px; }
  .topnav { order: 3; width: 100%; gap: 6px; }
  .topnav button { flex: 1; padding: 6px 6px; font-size: 11.5px; }
  .controls {
    order: 4;
    width: 100%;
    margin-left: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 8px;
  }
  .controls label { font-size: 10px; }
  .controls select { width: 100%; }
  .controls button { grid-column: span 2; width: 100%; }

  /* Layout: panel arriba (con buscador) y mapa debajo */
  main { flex-direction: column; }
  #panel {
    order: 1;
    width: 100%;
    max-width: none;
    max-height: none;
    height: 46vh;
    flex: none;
  }
  #map { order: 2; flex: 1; min-height: 0; }
  .disclaimer { display: none; }

  /* Buscador fijo arriba del panel al hacer scroll */
  .search-wrap { position: sticky; top: -14px; z-index: 5; padding-top: 14px; background: linear-gradient(180deg, var(--sand), rgba(246,239,227,0)); }
}

/* ---------------------------------------------------------------- top nav buttons */
.topnav { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.topnav button {
  background: transparent;
  border: 1px solid rgba(46, 196, 182, .5);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 15px;
  font-size: 12.5px;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: .3px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.topnav button:hover { background: rgba(46, 196, 182, .16); border-color: var(--aqua); }

/* ---------------------------------------------------------------- modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 2000; background: rgba(4, 14, 26, .74);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal-box {
  background: linear-gradient(180deg, #f6efe3 0%, #fff 100%);
  color: var(--ocean-deep);
  border-radius: 16px;
  max-width: 720px;
  width: 100%;
  max-height: 84vh;
  overflow-y: auto;
  padding: 26px 30px 30px;
  position: relative;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .55);
}
.modal-close {
  position: absolute; top: 10px; right: 16px; border: none; background: transparent;
  font-size: 28px; line-height: 1; cursor: pointer; color: var(--ocean-2);
}
.modal-box h2 { font-family: "Baloo 2", sans-serif; margin: 0 26px 8px 0; color: var(--ocean-deep); font-size: 24px; }
.modal-box h2 span { color: var(--coral); }
.modal-box h3 { font-family: "Baloo 2", sans-serif; margin: 18px 0 4px; font-size: 16px; color: var(--ocean-2); }
.modal-box p, .modal-box li { font-size: 14px; color: #33546c; line-height: 1.65; }
.modal-box ul, .modal-box ol { padding-left: 22px; margin: 6px 0; }
.modal-box li { margin: 4px 0; }
.modal-box .pill {
  display: inline-block; background: #e7f5f2; color: var(--ocean-2);
  border-radius: 999px; padding: 3px 11px; font-size: 12px; font-weight: 700; margin: 2px 2px;
}
.modal-box .note { background: #fff4e5; border: 1px solid #ffdfae; color: #b45309; border-radius: 10px; padding: 10px 12px; font-size: 12.5px; }
.modal-box .mail {
  display: inline-block; margin-top: 14px; background: linear-gradient(120deg, var(--coral), var(--coral-2));
  color: #fff; padding: 11px 20px; border-radius: 999px; font-weight: 800; text-decoration: none; font-size: 14px;
}
