/* ===== Tokens: el estilo del mapa se ajusta aquí ===== */
:root {
  /* papel y terreno */
  --paper: #efe8d6;
  --park: #a6cf7a;
  --park-glow: #c9dfa5;
  --park-edge: #86b35d;
  --lot: #e2ddd1;
  --service: #e8dfd1;
  --walk: #fbf4ec;
  --walk-edge: #d8c5b0;
  --water: #5aaee6;
  --water-edge: #2f7cbc;
  --tree-0: #5c9c43;
  --tree-1: #4b8a38;
  --tree-2: #72b250;
  --tree-shadow: rgba(38, 72, 28, .38);
  /* techos */
  --roof-a: #bf7a5e;
  --roof-b: #9d6b54;
  --roof-c: #5b78b3;
  --roof-d: #48a2bb;
  --roof-e: #aea4ab;
  --roof-line: #3a2d29;
  /* montañas rusas */
  --track: #cc2b40;
  --track-in: #f59aa3;
  /* nivel de emoción (1 a 5) e infantil */
  --lv1: #2c86d8;
  --lv2: #23a05a;
  --lv3: #f2c21b;
  --lv4: #f5841a;
  --lv5: #e2312b;
  --infantil: #a795cc;
  --food: #8a5a32;
  --show: #d23f9b;
  --terror: #ff7a12;
  --terror-ink: #2a1236;
  /* interfaz */
  --ui-bg: #ffffff;
  --ui-ink: #1f2a37;
  --ui-muted: #647083;
  --ui-line: #e3e6ec;
  --ui-soft: #f2f4f7;
  --brand: #2f6fb5;
  --shadow: 0 6px 20px rgba(20, 30, 50, .18);
  --radius: 16px;
  --list-w: 400px;
  --font-title: "Fredoka", "Nunito", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--ui-ink); font-family: var(--font-body); -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ===== Mapa ===== */
#map { position: fixed; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
#map.dragging { cursor: grabbing; }
#map > svg { width: 100%; height: 100%; display: block; }

.bg { fill: var(--paper); }
.park-glow { fill: var(--park-glow); stroke: var(--park-glow); stroke-width: 26; }
.park { fill: var(--park); stroke: var(--park-edge); stroke-width: 1.5; }
.lot { fill: var(--lot); stroke: #cdc6b7; stroke-width: 1; }
.service { fill: var(--service); }
.walk-edge { fill: none; stroke: var(--walk-edge); stroke-width: 2.4; stroke-linejoin: round; }
.walk { fill: var(--walk); }
.water-edge { fill: none; stroke: var(--water-edge); stroke-width: 2.2; stroke-linejoin: round; }
.water { fill: var(--water); }
.tree-sh { fill: var(--tree-shadow); }
.tree.t0 { fill: var(--tree-0); }
.tree.t1 { fill: var(--tree-1); }
.tree.t2 { fill: var(--tree-2); }
.b-sh { fill: rgba(40, 30, 25, .32); }
.b { stroke: var(--roof-line); stroke-width: .7; stroke-linejoin: round; }
.roof-a { fill: var(--roof-a); } .roof-b { fill: var(--roof-b); } .roof-c { fill: var(--roof-c); }
.roof-d { fill: var(--roof-d); } .roof-e { fill: var(--roof-e); }
.track-sh { fill: none; stroke: rgba(30, 10, 10, .22); stroke-width: 4.2; transform: translate(1.5px, 1.8px); stroke-linecap: round; stroke-linejoin: round; }
.track { fill: none; stroke: var(--track); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.track-in { fill: none; stroke: var(--track-in); stroke-width: .8; stroke-linecap: round; }

.zones text {
  font-family: var(--font-title); font-weight: 700; font-size: 11px; letter-spacing: .6px;
  fill: #fff; stroke: #2e4a1f; stroke-width: 3; paint-order: stroke; stroke-linejoin: round;
  text-anchor: middle; text-transform: uppercase; opacity: .92; transition: opacity .25s;
}
#map.z2 .zones text { opacity: 0; }

/* ===== Pines (tamaño constante en pantalla vía --k) ===== */
.pin { transform: translate(calc(var(--x) * 1px), calc(var(--y) * 1px)) scale(var(--k, 1)); cursor: pointer; }
.pin .hit { fill: transparent; }
.pin .sh { fill: rgba(0, 0, 0, .25); transform: translate(1px, 1.6px); }
.pin .body { stroke: #fff; stroke-width: 2.6; }
.pin.lv1 .body { fill: var(--lv1); }
.pin.lv2 .body { fill: var(--lv2); }
.pin.lv3 .body { fill: var(--lv3); }
.pin.lv4 .body { fill: var(--lv4); }
.pin.lv5 .body { fill: var(--lv5); }
.pin.infantil .body { fill: var(--infantil); }
.pin.food .body { fill: var(--food); stroke-width: 2; }
.pin.show .body { fill: var(--show); stroke-width: 2; }
.pin.terror .body { fill: var(--terror); stroke: var(--terror-ink); stroke-width: 2.4; }
.pin .glyph { fill: #fff; font: 800 13px var(--font-body); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.pin.lv3 .glyph { fill: #4a3700; }
.pin.infantil .glyph { font-size: 11px; }
.pin .label {
  font: 800 14px var(--font-body); fill: var(--ui-ink); stroke: #fff; stroke-width: 3.6; paint-order: stroke;
  stroke-linejoin: round; pointer-events: none; display: none;
}
.pin.infantil .label { fill: #4e4466; }
.pin .label .n { font-weight: 800; }
.pin .wait rect { fill: var(--ui-ink); }
.pin .wait text { fill: #fff; font: 800 10.5px var(--font-body); text-anchor: middle; dominant-baseline: central; }
.pin .wait.low rect { fill: #1f8a4c; }
.pin .wait.mid rect { fill: #c77700; }
.pin .wait.high rect { fill: #c0262d; }
#map.z2 .pin.ride:not(.infantil) .label,
#map.z2 .pin.terror .label,
#map.z3 .pin .label { display: block; }
.pin.hidden { display: none; }
.pin .ring {
  fill: none; stroke: var(--ui-ink); stroke-width: 3; pointer-events: none;
  transform-box: fill-box; transform-origin: center; animation: ring 1.4s ease-out infinite;
}
@keyframes ring { 0% { transform: scale(.7); opacity: 1; } 100% { transform: scale(1.6); opacity: 0; } }
.pin.sel .body { stroke: var(--ui-ink); stroke-width: 3; }
.pin.sel .label { display: block; }
#map.parkopen .pin.closed { opacity: .5; }
#map.parkopen .pin.closed .body { filter: saturate(.25); }

/* ===== Barra superior ===== */
.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 0; pointer-events: none;
  display: flex; flex-direction: column; gap: 8px; max-width: 560px;
}
.top > * { pointer-events: auto; }
.toprow { display: flex; gap: 8px; }
.search {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; background: var(--ui-bg); border-radius: 999px;
  box-shadow: var(--shadow); padding: 0 8px 0 14px; height: 46px;
}
.search svg { width: 20px; height: 20px; fill: none; stroke: var(--ui-muted); stroke-width: 2.2; stroke-linecap: round; flex: none; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; font: 700 16px var(--font-body); background: transparent; color: var(--ui-ink); }
.search input::-webkit-search-cancel-button { display: none; }
.icon-btn { border: 0; background: var(--ui-soft); width: 32px; height: 32px; border-radius: 50%; font-size: 20px; line-height: 1; flex: none; }
.list-btn {
  flex: none; height: 46px; border: 0; border-radius: 999px; background: var(--ui-ink); color: #fff; box-shadow: var(--shadow);
  display: inline-flex; align-items: center; gap: 7px; padding: 0 16px 0 13px; font-weight: 800; font-size: 15px;
}
.list-btn svg { width: 20px; height: 20px; fill: #fff; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; }
.list-btn[aria-expanded="true"] { background: var(--brand); }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 4px; margin: 0 -12px; padding-left: 12px; padding-right: 12px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 999px;
  padding: 7px 12px; background: rgba(255, 255, 255, .92); box-shadow: 0 2px 8px rgba(20, 30, 50, .14);
  font-weight: 800; font-size: 13px; color: var(--ui-muted);
}
.chip.on { background: var(--ui-ink); color: #fff; }
.chip[data-layer="terror"].on { background: var(--terror-ink); color: var(--terror); }

.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; flex: none; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.12); }
.dot.ride { background: conic-gradient(var(--lv5) 0 20%, var(--lv4) 0 40%, var(--lv3) 0 60%, var(--lv2) 0 80%, var(--lv1) 0); }
.dot.food { background: var(--food); } .dot.show { background: var(--show); }
.dot.terror { background: var(--terror); border-color: var(--terror-ink); }
.dot.lv1 { background: var(--lv1); } .dot.lv2 { background: var(--lv2); } .dot.lv3 { background: var(--lv3); }
.dot.lv4 { background: var(--lv4); } .dot.lv5 { background: var(--lv5); } .dot.infantil { background: var(--infantil); }

.results {
  list-style: none; margin: 0; padding: 6px; background: var(--ui-bg); border-radius: var(--radius);
  box-shadow: var(--shadow); max-height: min(55vh, 420px); overflow-y: auto;
}
.results li button { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; text-align: left; padding: 10px; border-radius: 10px; }
.results li button:hover, .results li button:focus-visible { background: var(--ui-soft); outline: 0; }
.results .r-name { font-weight: 800; font-size: 15px; }
.results .r-sub { font-size: 12.5px; color: var(--ui-muted); }
.results .empty { padding: 12px; color: var(--ui-muted); font-size: 14px; }

/* ===== Leyenda, zoom, estado en vivo ===== */
.legend {
  position: fixed; left: 12px; bottom: calc(env(safe-area-inset-bottom) + 34px); z-index: 5;
  background: rgba(255, 255, 255, .95); border-radius: 14px; box-shadow: var(--shadow); padding: 7px 11px 8px;
}
.legend-title { font: 700 11px var(--font-title); text-transform: uppercase; letter-spacing: .6px; color: var(--ui-muted); margin-bottom: 5px; }
.legend ul { list-style: none; margin: 0; padding: 0; display: flex; align-items: center; gap: 6px; }
.legend li.kid { display: flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 800; color: #5b4f75; margin-left: 4px; }
.lg {
  width: 21px; height: 21px; border-radius: 50%; display: grid; place-items: center; font: 800 12px var(--font-body); font-style: normal;
  color: #fff; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.14);
}
.lg.lv1 { background: var(--lv1); } .lg.lv2 { background: var(--lv2); } .lg.lv3 { background: var(--lv3); color: #4a3700; }
.lg.lv4 { background: var(--lv4); } .lg.lv5 { background: var(--lv5); } .lg.infantil { background: var(--infantil); width: 17px; height: 17px; }

.zoom { position: fixed; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 34px); z-index: 5; display: grid; gap: 8px; transition: right .2s; }
.zoom button {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--ui-bg); box-shadow: var(--shadow);
  font-size: 24px; font-weight: 700; display: grid; place-items: center;
}
.zoom svg { width: 20px; height: 20px; fill: none; stroke: var(--ui-ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.live {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 8px); z-index: 4;
  font-size: 12px; font-weight: 800; color: var(--ui-muted); background: rgba(255,255,255,.85); padding: 3px 10px; border-radius: 999px;
  white-space: nowrap; max-width: calc(100vw - 24px); overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
.credits {
  position: fixed; right: 64px; bottom: calc(env(safe-area-inset-bottom) + 34px); z-index: 3; font-size: 10px; color: var(--ui-muted);
  background: rgba(255,255,255,.7); padding: 2px 6px; border-radius: 6px; max-width: 360px; text-align: right; line-height: 1.35;
}
.credits a { color: inherit; }

/* ===== Ficha ===== */
.sheet {
  position: fixed; z-index: 20; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 12px);
  max-width: 420px; margin: 0 auto; background: var(--ui-bg); border-radius: 20px; box-shadow: 0 10px 34px rgba(20,30,50,.28);
  padding: 16px 16px 18px; animation: up .18s ease-out;
  max-height: calc(100dvh - 130px); overflow-y: auto; overscroll-behavior: contain;
}
@keyframes up { from { transform: translateY(20px); opacity: 0; } }
.sheet-close { position: absolute; top: 12px; right: 12px; z-index: 2; }
.sheet h2 { margin: 0 40px 4px 0; font: 600 22px/1.15 var(--font-title); }
.sheet .zone { display: flex; align-items: center; gap: 7px; color: var(--ui-muted); font-size: 14px; font-weight: 800; }
.znum {
  flex: none; min-width: 24px; height: 24px; padding: 0 5px; border-radius: 7px; color: #fff; display: inline-grid; place-items: center;
  font: 700 13px var(--font-title);
}
.meter-wrap { display: flex; align-items: flex-end; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.meter { display: inline-flex; align-items: flex-end; gap: 3px; height: 21px; }
.meter i { width: 9px; border-radius: 3px; background: #e2e5ea; }
.meter i:nth-child(1) { height: 9px; } .meter i:nth-child(2) { height: 12px; } .meter i:nth-child(3) { height: 15px; }
.meter i:nth-child(4) { height: 18px; } .meter i:nth-child(5) { height: 21px; }
.meter i.b1, .mini i.b1 { background: var(--lv1); } .meter i.b2, .mini i.b2 { background: var(--lv2); }
.meter i.b3, .mini i.b3 { background: var(--lv3); } .meter i.b4, .mini i.b4 { background: var(--lv4); }
.meter i.b5, .mini i.b5 { background: var(--lv5); }
.meter-wrap.infantil .meter i.on, .mini.infantil i.on { background: var(--infantil); }
.mini { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; flex: none; }
.mini i { width: 5px; border-radius: 1.5px; background: #dfe3e8; }
.mini i:nth-child(1) { height: 6px; } .mini i:nth-child(2) { height: 8px; } .mini i:nth-child(3) { height: 10px; }
.mini i:nth-child(4) { height: 12px; } .mini i:nth-child(5) { height: 14px; }
.lvnum { font: 700 13px var(--font-title); color: var(--ui-ink); }
.lvtxt { font-size: 12.5px; }
.kidtxt { color: #5b4f75; }
.extra .xs { display: none; }
.extra { font-size: 12px; color: #7a5b00; background: #fff6d6; padding: 0 6px; border-radius: 6px; margin-left: 2px; }
.photo { margin: -16px -16px 12px; position: relative; }
.photo img { display: block; width: 100%; height: 150px; object-fit: cover; border-radius: 20px 20px 0 0; background: var(--ui-soft); }
.photo figcaption { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 12px 5px; font-size: 10.5px; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.6)); }
.photo figcaption a { color: #fff; }
.sheet:has(.photo) .sheet-close { background: rgba(255,255,255,.9); }
.meter-num { font: 700 26px/0.85 var(--font-title); }
.meter-txt { font-size: 13px; font-weight: 700; color: var(--ui-muted); padding-bottom: 1px; }
.sheet .tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; font-size: 13px; font-weight: 800; background: var(--ui-soft); }
.tag.infantil { background: #eeebf5; color: #5b4f75; }
.tag.terror { background: var(--terror-ink); color: var(--terror); }
.tag.warn { background: #fff6d6; color: #7a5b00; }
.sheet dl { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; margin: 14px 0 0; font-size: 15px; }
.sheet dt { color: var(--ui-muted); font-weight: 700; }
.sheet dd { margin: 0; font-weight: 800; }
.sheet .note { margin: 12px 0 0; font-size: 13.5px; color: var(--ui-muted); }

/* tiempo de espera (ficha y listado) */
.w { flex: none; font-weight: 800; font-size: 13px; padding: 4px 9px; border-radius: 999px; white-space: nowrap; background: var(--ui-soft); color: var(--ui-muted); }
.w.low { background: #dff3e7; color: #16693a; }
.w.mid { background: #fff0d4; color: #8a5300; }
.w.high { background: #fde2e1; color: #a31d18; }
.w.open { background: #dff3e7; color: #16693a; }
.w.loading { animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .45; } }
.sheet dd .w { font-size: 14px; }

/* ===== Listado ===== */
.list {
  position: fixed; z-index: 15; left: 0; right: 0; bottom: 0; height: 64vh; height: 64dvh;
  background: var(--ui-bg); border-radius: 22px 22px 0 0; box-shadow: 0 -8px 30px rgba(20,30,50,.22);
  display: flex; flex-direction: column; animation: up .2s ease-out;
}
.list-head { position: relative; padding: 8px 16px 10px; border-bottom: 1px solid var(--ui-line); }
.grab { width: 44px; height: 5px; border-radius: 3px; background: #d5d9e0; margin: 0 auto 8px; }
.list-head h2 { margin: 0; font: 600 20px var(--font-title); }
.list-head .icon-btn { position: absolute; right: 12px; top: 16px; }
.list-tools { display: flex; gap: 8px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--ui-soft); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 999px; font-weight: 800; font-size: 13px; color: var(--ui-muted); }
.seg button.on { background: var(--ui-bg); color: var(--ui-ink); box-shadow: 0 1px 4px rgba(20,30,50,.15); }
.toggle { border: 1.5px solid var(--ui-line); background: none; border-radius: 999px; padding: 5px 12px; font-weight: 800; font-size: 13px; color: var(--ui-muted); }
.toggle.on { background: #eeebf5; border-color: var(--infantil); color: #5b4f75; }
.list-body { flex: 1; overflow-y: auto; padding: 4px 8px calc(env(safe-area-inset-bottom) + 16px); overscroll-behavior: contain; }
.list-note { margin: 10px 8px 4px; font-size: 13px; color: var(--ui-muted); font-weight: 700; }
.zgroup h3 {
  position: sticky; top: 0; z-index: 1; margin: 0; padding: 12px 8px 4px; background: var(--ui-bg);
  font: 600 17px var(--font-title); color: var(--zc); display: flex; align-items: center; gap: 8px;
}
.zgroup h3::before { content: ""; width: 14px; height: 14px; border-radius: 4px; background: var(--zc); }
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; text-align: left; padding: 6px 8px; border-radius: 12px; }
.row:hover, .row:focus-visible { background: var(--ui-soft); outline: 0; }
.row.sel { background: #e6eef9; box-shadow: inset 0 0 0 2px var(--brand); }
.row.kid .rname { color: #5b4f75; }
.rmain { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.rname { font-weight: 800; font-size: 15px; line-height: 1.2; }
.rsub { display: flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 700; color: var(--ui-muted); }

@media (min-width: 760px) {
  .list { left: auto; top: 0; width: var(--list-w); height: 100%; border-radius: 0; box-shadow: -8px 0 30px rgba(20,30,50,.16); animation: none; }
  .grab { display: none; }
  .rmain { flex-direction: row; align-items: center; gap: 10px; }
  .rname { flex: 1; min-width: 0; font-size: 14.5px; }
  .rsub { flex: none; }
  .row { padding: 5px 8px; }
  .lvtxt.kidtxt { display: none; }
  .extra .xl { display: none; }
  .extra .xs { display: inline; font-weight: 800; }
  .list-head { padding-top: 16px; }
  body.list-open .zoom { right: calc(var(--list-w) + 12px); }
  body.list-open .credits { right: calc(var(--list-w) + 64px); }
  body.list-open .live { left: calc((100vw - var(--list-w)) / 2); }
  .sheet { left: auto; right: 72px; margin: 0; width: 380px; }
  body.list-open .sheet { right: calc(var(--list-w) + 72px); }
}
@media (max-width: 759px) {
  .credits { display: none; }
  .legend-title { display: none; }
  .sheet { z-index: 16; }
}
@media (max-width: 380px) {
  .list-btn span { display: none; }
  .list-btn { padding: 0 13px; }
}
