:root {
  --paper: #fbf8f2;
  --paper-2: #f3eee4;
  --ink: #23201b;
  --muted: #6f675c;
  --line: #e4ddd0;
  --accent: #2f6f8f;
  --accent-soft: #e2eef3;
  --radius: 14px;
  --panel-w: 340px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body { background: #dfe9ee; overflow: hidden; }

#map { position: absolute; inset: 0; }

/* ---------- Panel ---------- */

.panel {
  position: absolute;
  top: 12px;
  left: 12px;
  bottom: 12px;
  width: var(--panel-w);
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(35, 32, 27, 0.18), 0 2px 6px rgba(35, 32, 27, 0.08);
  overflow: hidden;
  z-index: 2;
}

.panel[hidden] { display: none; }

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fffdf8, var(--paper));
}

.eyebrow {
  margin: 0 0 2px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-family: Fraunces, Georgia, serif;
  font-weight: 600;
  font-size: 24px;
  line-height: 1.1;
}

.panel-body {
  overflow-y: auto;
  padding: 4px 18px 18px;
  scrollbar-width: thin;
}

section { padding: 14px 0 12px; border-bottom: 1px solid var(--line); }
section:last-child { border-bottom: 0; }

h2 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.note { margin: 8px 0 0; font-size: 12px; line-height: 1.4; color: var(--muted); }
.note:empty { display: none; }

.icon-btn {
  flex: none;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  font-size: 20px;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
}

.panel-open {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--paper);
  box-shadow: 0 6px 18px rgba(35, 32, 27, 0.16);
  font: 600 14px/1 Inter, system-ui, sans-serif;
  color: var(--ink);
  cursor: pointer;
}

button:focus-visible, input:focus-visible + span::before {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Continentes ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font: 500 13px/1 Inter, system-ui, sans-serif;
  color: var(--ink);
  cursor: pointer;
}
.chip:hover { border-color: #cfc5b4; }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.field { margin-top: 12px; }
.field-first { margin-top: 0; }
.field-label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.field.is-disabled { opacity: 0.45; pointer-events: none; }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 3px;
  border-radius: 10px;
  background: var(--paper-2);
  border: 1px solid var(--line);
}
.segmented button {
  padding: 7px 4px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  font: 500 13px/1 Inter, system-ui, sans-serif;
  color: var(--muted);
  cursor: pointer;
}
.segmented button[aria-checked="true"] {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(35, 32, 27, 0.15);
}

/* ---------- Estilos del mapa ---------- */

.themes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }

.theme {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
}
.theme:hover { border-color: #cfc5b4; }
.theme[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.theme-swatch { height: 34px; border-radius: 7px; border: 1px solid rgba(0, 0, 0, 0.08); }
.theme-name { font-size: 13px; font-weight: 600; }
.theme-hint { font-size: 11.5px; color: var(--muted); line-height: 1.25; }

/* ---------- Interruptores ---------- */

.switch {
  position: relative; /* el input invisible queda en su fila: si no, al tocarlo el panel salta hasta él */
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}
.switch[hidden] { display: none; }
.switch input { position: absolute; top: 0; left: 0; width: 34px; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.switch span { display: flex; align-items: center; gap: 10px; }
.switch span::before {
  content: "";
  flex: none;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: #d8d0c3 radial-gradient(circle at 10px 10px, #fff 7px, transparent 7.5px);
  transition: background 0.15s;
}
.switch input:checked + span::before {
  background: var(--accent) radial-gradient(circle at 24px 10px, #fff 7px, transparent 7.5px);
}

/* ---------- Niveles de ciudades ---------- */

.tiers { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 2px; }

.tier {
  display: grid;
  grid-template-columns: 18px 22px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 9px;
  cursor: pointer;
}
.tier:hover { background: var(--paper-2); }
.tier input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.tier img { width: 18px; height: 18px; justify-self: center; }
.tier-name { font-size: 14px; line-height: 1.2; }
.tier-hint { display: block; font-size: 11.5px; color: var(--muted); }
.tier-count {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--paper-2);
  padding: 2px 7px;
  border-radius: 999px;
}

/* ---------- Exportar ---------- */

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }

.btn {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font: 600 14px/1 Inter, system-ui, sans-serif;
  color: var(--ink);
  cursor: pointer;
}
.btn:hover { border-color: #cfc5b4; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn-primary:hover { background: #3a352d; }
.btn-wide { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: 0.5; cursor: progress; }

/* ---------- Controles de MapLibre ---------- */

.maplibregl-ctrl-group { border-radius: 10px !important; overflow: hidden; }

/* ---------- Celular: el panel pasa a ser una hoja desde abajo ---------- */

@media (max-width: 720px) {
  .panel {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: 62vh;
  }
  .panel-head { padding: 12px 14px 10px; }
  h1 { font-size: 20px; }
  .panel-body { padding: 0 14px 14px; }
  .panel-open { top: auto; bottom: 12px; }
}

/* ---------- Hoja de impresión marcada sobre el mapa ---------- */

.sheet-frame {
  position: absolute;
  z-index: 1;
  pointer-events: none; /* el mapa se sigue moviendo por debajo */
  outline: 2px solid var(--ink);
  box-shadow: 0 0 0 100vmax rgba(35, 32, 27, 0.38);
}
.sheet-frame[hidden] { display: none; }
.sheet-cell {
  position: absolute;
  box-sizing: border-box;
  border: 1px dashed rgba(35, 32, 27, 0.7);
}
.sheet-cell b {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(251, 248, 242, 0.92);
  font: 600 11px/1.4 Inter, system-ui, sans-serif;
  color: var(--ink);
}
.sheet-size {
  position: absolute;
  bottom: 100%;
  left: -2px;
  margin-bottom: 6px;
  padding: 3px 9px;
  border-radius: 7px;
  background: var(--ink);
  font: 600 12px/1.4 Inter, system-ui, sans-serif;
  color: var(--paper);
  white-space: nowrap;
}

/* ---------- Impresión: sólo las imágenes, una por hoja ---------- */

#print-sheet { display: none; }

@media print {
  body { background: #fff; overflow: visible; height: auto; }
  body > *:not(#print-sheet) { display: none !important; }
  #print-sheet { display: block !important; }
  .print-page {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100vh;
    break-after: page;
    overflow: hidden;
  }
  .print-page:last-child { break-after: auto; }
  .print-page img { max-width: 100%; max-height: 100%; object-fit: contain; }
}
