:root {
  --bg: #faf6f0;
  --card: #ffffff;
  --ink: #2b2420;
  --muted: #7a6e66;
  --line: #eadfd3;
  --accent: #b4532a;
  --accent-dark: #7a3b1e;
  --ok: #2f7d4f;
  --ok-bg: #e7f4ec;
  --no: #8b8580;
  --no-bg: #f1eeeb;
  --warn: #a15c00;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .06);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

.hero {
  background: linear-gradient(135deg, #7a3b1e 0%, #b4532a 55%, #d98b3a 100%);
  color: #fff;
  padding: 28px 0 18px;
}
.kicker { margin: 0 0 4px; text-transform: uppercase; letter-spacing: .08em; font-size: 12px; opacity: .85; }
.hero h1 { margin: 0 0 8px; font-size: clamp(24px, 6vw, 38px); line-height: 1.15; }
.sub { margin: 0 0 14px; font-size: 15px; opacity: .95; max-width: 640px; }
.jump { display: flex; gap: 8px; flex-wrap: wrap; }
.jump a {
  color: #fff; text-decoration: none; font-size: 14px; font-weight: 600;
  background: rgba(255,255,255,.18); padding: 6px 12px; border-radius: 999px;
}

.panel, .card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel { padding: 16px; margin: 16px 0; }
.panel h2, .section-title { margin: 0 0 6px; font-size: 20px; }
.section-title { margin: 24px 0 10px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.heart-inline { color: var(--accent); }
.status { margin: 8px 0 0; font-size: 13px; color: var(--muted); min-height: 1em; }
.status.err { color: #b3261e; }

.btn-ghost {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 6px 12px; border-radius: 999px; font-size: 14px; cursor: pointer;
}

/* Ranking */
.ranking { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ranking li {
  display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px;
  padding: 6px 0; border-bottom: 1px solid var(--line);
}
.ranking li:last-child { border-bottom: 0; }
.rk-pos { font-weight: 700; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.rk-main { min-width: 0; }
.rk-name { text-decoration: none; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.rk-bar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.rk-bar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }

/* Vote button */
.vote {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1.5px solid var(--accent); color: var(--accent); background: #fff;
  border-radius: 999px; padding: 5px 12px; font-size: 15px; font-weight: 700;
  cursor: pointer; font-variant-numeric: tabular-nums; min-width: 64px; justify-content: center;
}
.vote .h { font-size: 16px; line-height: 1; }
.vote.on { background: var(--accent); color: #fff; }
.vote:disabled { opacity: .6; cursor: progress; }
.vote.sm { padding: 3px 9px; font-size: 14px; min-width: 52px; }

/* Table */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 860px; font-size: 14px; }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th {
  position: sticky; top: 0; background: #fbf8f4; font-size: 12px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); cursor: pointer; user-select: none; white-space: nowrap;
}
th[data-k]::after { content: " ↕"; opacity: .35; }
th.asc::after { content: " ↑"; opacity: 1; color: var(--accent); }
th.desc::after { content: " ↓"; opacity: 1; color: var(--accent); }
.sticky { position: sticky; left: 0; z-index: 1; background: inherit; }
th.sticky { z-index: 3; background: #fbf8f4; box-shadow: 1px 0 0 var(--line); }
td.sticky { background: #fff; box-shadow: 1px 0 0 var(--line); max-width: 190px; }
.t-name { font-weight: 650; display: block; }
.t-name a { color: inherit; text-decoration: none; }
.t-zone { font-size: 12px; color: var(--muted); display: block; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.big { font-weight: 700; font-size: 15px; }
.far { color: var(--warn); font-weight: 600; }
.icons { min-width: 150px; }
.chip { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; margin: 1px 2px 1px 0; white-space: nowrap; }
.chip.y { background: var(--ok-bg); color: var(--ok); }
.chip.n { background: var(--no-bg); color: var(--no); font-weight: 600; }
.chip.q { background: #fff4e0; color: var(--warn); }
.legend { align-items: center; font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 10px 0 0; }

/* Map */
#map { height: 420px; border-radius: 10px; z-index: 0; }
.pop h3 { margin: 0 0 4px; font-size: 15px; }
.pop p { margin: 2px 0; font-size: 13px; }

/* Cards */
.cards { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 700px) { .cards { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1020px) { .cards { grid-template-columns: 1fr 1fr 1fr; } }
.card { overflow: hidden; display: flex; flex-direction: column; }
.card .ph { aspect-ratio: 4 / 3; background: #eee; position: relative; }
.card .body { padding: 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card h3 { margin: 0; font-size: 18px; line-height: 1.2; }
.card .zone { margin: 0; color: var(--muted); font-size: 14px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 2px 0; }
.fact { background: var(--bg); border-radius: 10px; padding: 7px 10px; }
.fact b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.fact span { font-size: 12px; color: var(--muted); }
.amen { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.amen li { font-size: 13px; padding: 3px 9px; border-radius: 999px; background: var(--no-bg); color: var(--no); }
.amen li.y { background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.amen li.q { background: #fff4e0; color: var(--warn); }
.card .txt { margin: 0; font-size: 14px; }
.card .note { margin: 0; font-size: 13px; color: var(--muted); }
.card .plans { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.plan {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 6px 10px 6px 6px;
  font: inherit; color: var(--ink); cursor: pointer;
}
.plan:hover, .plan:focus-visible { border-color: var(--accent); background: #fff; }
.plan img { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; flex: none; background: #eee; }
.plan-t { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.plan-t b { font-size: 14px; line-height: 1.25; }
.plan-t small { font-size: 12px; color: var(--muted); }
.plan-go { font-size: 22px; color: var(--accent); line-height: 1; }
.card .lbl { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 4px 0 0; }
.card .actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; padding-top: 8px; }
.btn-link {
  text-decoration: none; background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 10px;
  font-size: 14px; font-weight: 600;
}

.foot { color: var(--muted); font-size: 13px; padding: 20px 0 40px; }
td:last-child { white-space: nowrap; }

.t-votos { font-weight: 700; color: var(--accent); }

/* Voting at the end */
.vote-panel { border-top: 4px solid var(--accent); margin-top: 28px; }
.vote-lead { margin: 4px 0 8px; font-size: 16px; }

/* Gallery */
.gal { position: relative; width: 100%; height: 100%; }
.gal-track {
  display: flex; width: 100%; height: 100%; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; scrollbar-width: none; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
}
.gal-track::-webkit-scrollbar { display: none; }
.gal-track:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.gal-slide { flex: 0 0 100%; margin: 0; scroll-snap-align: start; scroll-snap-stop: always; }
.gal-slide img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gal-btn {
  position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.9); color: var(--ink); font-size: 26px; line-height: 1; padding: 0 0 3px;
  cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.25); display: grid; place-items: center;
}
.gal-btn.prev { left: 8px; }
.gal-btn.next { right: 8px; }
.gal-btn:disabled { opacity: 0; pointer-events: none; }
.gal-dots { position: absolute; bottom: 8px; left: 0; right: 0; display: flex; justify-content: center; gap: 6px; pointer-events: none; }
.gal-dots span { width: 7px; height: 7px; border-radius: 50%; background: rgba(255,255,255,.55); box-shadow: 0 0 2px rgba(0,0,0,.4); transition: transform .2s; }
.gal-dots span.on { background: #fff; transform: scale(1.3); }
.gal-count { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.5); color: #fff; font-size: 12px; padding: 1px 7px; border-radius: 999px; }

/* Modal */
body.noscroll { overflow: hidden; }
.modal {
  border: 0; padding: 0; max-width: none; width: min(640px, calc(100vw - 20px)); max-height: calc(100dvh - 20px);
  border-radius: var(--radius); background: var(--card); color: var(--ink); box-shadow: 0 10px 40px rgba(0,0,0,.35);
  overflow: hidden;
}
.modal::backdrop { background: rgba(30, 20, 12, .6); }
.modal-box { position: relative; max-height: calc(100dvh - 20px); overflow-y: auto; }
.modal-x {
  position: absolute; top: 8px; right: 8px; z-index: 5; width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.6); color: #fff; font-size: 24px; line-height: 1; cursor: pointer; padding: 0 0 2px;
}
.gal-modal { aspect-ratio: 3 / 2; height: auto; background: #ddd; }
.gal-modal .gal-count { right: auto; left: 8px; }
.credit { margin: 4px 12px 0; font-size: 11px; color: var(--muted); line-height: 1.35; }
.credit a { color: var(--muted); }
.modal-txt { padding: 6px 16px 18px; }
.modal-txt h3 { margin: 4px 0 2px; font-size: 21px; line-height: 1.2; }
.modal-from { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.modal-dist { margin: 0 0 8px; font-size: 14px; background: var(--bg); border-radius: 8px; padding: 7px 10px; }
.modal-txt p:last-child { margin: 0; font-size: 15px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Objetivos táctiles de 44 px */
.jump a { min-height: 44px; display: inline-flex; align-items: center; padding: 0 16px; }
.btn-ghost { min-height: 44px; padding: 0 16px; }
.vote, .vote.sm { min-height: 44px; min-width: 64px; }
.btn-link { min-height: 44px; display: inline-flex; align-items: center; }
.rk-name { line-height: 24px; padding: 10px 0; }
.zgz { height: 44px; display: flex; align-items: center; }
.zgz span { width: 100%; background: #2b2420; color: #fff; font: 700 12px/22px system-ui, sans-serif; text-align: center; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.rk-bar { margin-top: 0; }
.card .gal-slide img { cursor: zoom-in; }

/* Orden en móvil */
.sort-bar { display: none; align-items: center; gap: 8px; margin: 0 0 12px; flex-wrap: wrap; }
.sort-bar label { font-size: 14px; font-weight: 600; }
.sort-bar select {
  flex: 1; min-width: 0; min-height: 44px; font: inherit; font-size: 16px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 0 10px;
}
td .t-zone + small, td small { color: var(--muted); }

/* Mapa */
.map-wrap { position: relative; }
.pin span {
  display: block; width: 20px; height: 20px; margin: 12px; border-radius: 50%;
  background: var(--accent); border: 2.5px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.map-lock {
  position: absolute; right: 10px; top: 10px; z-index: 500;
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 0; font: 600 15px/1 system-ui, sans-serif;
  background: var(--ink); color: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.3); cursor: pointer;
}
.map-lock[aria-pressed="true"] { background: var(--accent); }
#map.live { outline: 3px solid var(--accent); outline-offset: 2px; }
.leaflet-touch .leaflet-bar a { width: 44px; height: 44px; line-height: 44px; font-size: 22px; }
.leaflet-container a.leaflet-popup-close-button { width: 44px; height: 44px; font: 24px/44px Tahoma, Verdana, sans-serif; }
.pop { padding-right: 18px; }
.pop a { display: inline-block; padding: 12px 0; font-weight: 600; }

/* Visor de fotos a pantalla completa */
.modal.photos { width: 100vw; height: 100dvh; max-height: none; border-radius: 0; background: #111; }
.modal.photos .modal-box { height: 100%; max-height: none; overflow: hidden; display: flex; flex-direction: column; }
.modal.photos #act-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.gal-full { flex: 1; min-height: 0; }
.gal-full .gal-slide img { object-fit: contain; cursor: default; }
.gal-full .gal-count { right: auto; left: 12px; top: 14px; }
.photos-cap { margin: 0; padding: 12px 64px calc(12px + env(safe-area-inset-bottom)) 16px; color: #eee; font-size: 14px; }
.modal.photos .modal-x { background: rgba(255,255,255,.18); top: calc(8px + env(safe-area-inset-top)); }

@media (max-width: 640px) {
  .wrap { padding: 0 12px; }
  .panel { padding: 14px 12px; }
  /* Tabla convertida en tarjetas compactas */
  .sort-bar { display: flex; }
  .table-scroll { overflow: visible; }
  #tabla-casas, #tabla-casas tbody { display: block; min-width: 0; width: 100%; }
  #tabla-casas thead { display: none; }
  #tabla-casas tr {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 10px;
    padding: 10px 0 14px; border-bottom: 1px solid var(--line);
  }
  #tabla-casas td { display: block; padding: 0; border: 0; min-width: 0; white-space: normal; font-size: 15px; }
  #tabla-casas td[data-l]::before {
    content: attr(data-l); display: block; font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .04em; color: var(--muted); margin-bottom: 1px;
  }
  #tabla-casas td.t-head { grid-column: 1 / -1; position: static; max-width: none; min-width: 0; box-shadow: none; background: none; }
  #tabla-casas td.t-head .t-name { font-size: 17px; }
  #tabla-casas td.t-head .t-name a { display: block; padding: 10px 0; line-height: 24px; }
  #tabla-casas td[data-l="Hab."] { order: 4; }
  #tabla-casas td[data-l="Nota"] { order: 5; }
  #tabla-casas td[data-l="Votos"] { order: 6; }
  #tabla-casas td.icons { order: 7; }
  #tabla-casas td.t-link { order: 8; }
  #tabla-casas td.t-head .t-zone { margin-top: -6px; }
  #tabla-casas td.icons { grid-column: 1 / -1; min-width: 0; }
  #tabla-casas td.icons::before { display: none; }
  #tabla-casas td.t-link { grid-column: 1 / -1; }
  #tabla-casas td.t-link a {
    display: flex; align-items: center; justify-content: center; min-height: 44px; font-size: 14px;
    border: 1px solid var(--line); border-radius: 10px; text-decoration: none; font-weight: 600;
  }
  #tabla-casas .chip { font-size: 12px; padding: 3px 8px; }
  .legend { font-size: 12px; }
  #map { height: 380px; }

  /* Modal de planes a pantalla completa */
  .modal { width: 100vw; height: 100dvh; max-height: none; border-radius: 0; margin: 0; }
  .modal-box { height: 100%; max-height: none; }
  .modal-x { top: calc(8px + env(safe-area-inset-top)); right: 8px; }
  .gal-modal { aspect-ratio: auto; height: 50dvh; }
  .modal-txt { padding: 6px 16px calc(24px + env(safe-area-inset-bottom)); }
}
