/* ===== Tokens ===== */
:root {
  color-scheme: dark;
  --bg: #0b1310;
  --surface: #121d18;
  --surface-2: #18261f;
  --line: #233629;
  --line-soft: #1b2b22;
  --text: #e8f0ea;
  --muted: #9bb1a3;
  --accent: #e4b94a;
  --btn: #e4b94a;
  --on-btn: #1b1403;
  --ok: #58c58a;
  --on-ok: #06210f;
  --danger: #ff8a80;
  --sk-bg: #3a2f10; --sk-fg: #f3cb62;
  --pz-bg: #41202a; --pz-fg: #ff9fb2;
  --lv-bg: #1d2f47; --lv-fg: #9ccbff;
  --boss-bg: #3b2014; --boss-fg: #ffb48a;
  --nino: #86e0a8;
  --adulto: #9ccbff;
  --radius: 14px;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f6f3e9; --surface: #fffdf6; --surface-2: #f1ecdc;
    --line: #ddd5bd; --line-soft: #ebe5d0;
    --text: #1d2a22; --muted: #556a5c;
    --accent: #7a5200; --btn: #1f6f45; --on-btn: #ffffff;
    --ok: #1f7a4a; --on-ok: #ffffff; --danger: #b3261e;
    --sk-bg: #fbefc7; --sk-fg: #6d4b00;
    --pz-bg: #fde0e6; --pz-fg: #9b1c3a;
    --lv-bg: #dcebfb; --lv-fg: #174b8b;
    --boss-bg: #fde6d9; --boss-fg: #8a3510;
    --nino: #14603a; --adulto: #174b8b;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f3e9; --surface: #fffdf6; --surface-2: #f1ecdc;
  --line: #ddd5bd; --line-soft: #ebe5d0;
  --text: #1d2a22; --muted: #556a5c;
  --accent: #7a5200; --btn: #1f6f45; --on-btn: #ffffff;
  --ok: #1f7a4a; --on-ok: #ffffff; --danger: #b3261e;
  --sk-bg: #fbefc7; --sk-fg: #6d4b00;
  --pz-bg: #fde0e6; --pz-fg: #9b1c3a;
  --lv-bg: #dcebfb; --lv-fg: #174b8b;
  --boss-bg: #fde6d9; --boss-fg: #8a3510;
  --nino: #14603a; --adulto: #174b8b;
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
body:has(dialog[open]) { overflow: hidden; }
button, input { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.wrap {
  width: 100%;
  max-width: 46rem;
  margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

/* ===== Barra superior ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.bar-row { display: flex; align-items: center; gap: 4px; height: 56px; }
.brand {
  flex: 1; min-width: 0; padding: 0 6px;
  font: 600 1.05rem/1.2 Georgia, "Times New Roman", serif;
  color: var(--text); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand b { color: var(--accent); }
.pct { font-size: .85rem; font-variant-numeric: tabular-nums; color: var(--muted); padding-right: 4px; }
.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 12px;
  background: transparent; border: 1px solid transparent; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { background: var(--line); }
.icon-btn svg[hidden] { display: none; }
.meter { height: 3px; background: var(--line); }
.meter span { display: block; height: 100%; width: 0; background: var(--ok); transition: width .3s ease; }

/* ===== Hero ===== */
.hero { padding: 24px 0 8px; }
.hero h1 { margin: 0; font: 700 clamp(1.7rem, 7vw, 2.4rem)/1.1 Georgia, "Times New Roman", serif; letter-spacing: -.01em; }
.hero h1 span { color: var(--accent); }
.lede { margin: 6px 0 18px; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 12px; min-width: 0; }
.stat-label { font-size: .75rem; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.stat-val { margin: 2px 0 8px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat-val b { font-size: 1.35rem; }
.stat-val small { color: var(--muted); font-size: .85rem; margin-left: 1px; }
.stat-bar { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.stat-bar span { display: block; height: 100%; width: 0; background: var(--ok); transition: width .3s ease; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin: 16px 0 6px; }

/* ===== Botones ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--btn); border-color: var(--btn); color: var(--on-btn); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
:root[data-theme="dark"] .btn.danger { color: #2b0905; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.danger { color: #2b0905; } }
.btn.sm { min-height: 40px; padding: 0 14px; font-size: .9rem; font-weight: 500; }

.switch { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: .95rem; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.sw { position: relative; width: 44px; height: 26px; border-radius: 26px; background: var(--line); border: 1px solid var(--muted); flex: none; transition: background .2s; }
.sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--text); transition: transform .2s; }
.switch input:checked + .sw { background: var(--ok); border-color: var(--ok); }
.switch input:checked + .sw::after { transform: translateX(18px); background: var(--on-ok); }
.switch input:focus-visible + .sw { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ===== Separador de era ===== */
.era-break {
  display: flex; align-items: center; gap: 12px;
  margin: 26px 2px 12px; font-size: .8rem; font-weight: 700;
  letter-spacing: .16em; text-transform: uppercase;
}
.era-break::before, .era-break::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.era-break.nino { color: var(--nino); }
.era-break.adulto { color: var(--adulto); }

/* ===== Zonas ===== */
.zone {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0 0 12px;
  overflow: hidden;
  scroll-margin-top: 70px;
}
.zone.dungeon { box-shadow: inset 4px 0 0 var(--accent); }
.zone.done { box-shadow: inset 4px 0 0 var(--ok); }
.zone-title { margin: 0; font-size: inherit; }
.zone-toggle {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 56px; padding: 10px 14px;
  background: transparent; border: 0; text-align: left; cursor: pointer;
}
.zone-toggle:hover { background: var(--surface-2); }
.num {
  flex: none; min-width: 2.2rem; text-align: center;
  font-size: .78rem; font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 2px 6px; border-radius: 8px; background: var(--surface-2); color: var(--muted);
}
.name { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; }
.name .t { font: 600 1.12rem/1.25 Georgia, "Times New Roman", serif; overflow-wrap: anywhere; }
.tag {
  font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent); border: 1px solid currentColor; border-radius: 999px; padding: 0 8px;
}
.count { flex: none; font-size: .85rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.zone.done .count { color: var(--ok); font-weight: 700; }
.zone.done .name .t { color: var(--muted); }
.chev { flex: none; width: 20px; height: 20px; color: var(--muted); transition: transform .2s; }
.zone.collapsed .chev { transform: rotate(-90deg); }
.zone.collapsed .steps, .zone.collapsed .zone-foot { display: none; }

/* ===== Pasos ===== */
.steps { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.step + .step { border-top: 1px solid var(--line-soft); }
.step label { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; min-height: 48px; cursor: pointer; }
.step:hover { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.step .text { flex: 1; min-width: 0; overflow-wrap: break-word; }
.step.done .text { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.step.done .chip { opacity: .6; }
.step.boss { background: color-mix(in srgb, var(--boss-bg) 60%, transparent); }
.step.boss .text { font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--boss-fg); }
.step.boss.done .text { color: var(--muted); }
.step.pulse, .zone.pulse { animation: pulse 1.8s ease-out; }
@keyframes pulse { 0%, 35% { background: color-mix(in srgb, var(--accent) 28%, transparent); } 100% { background: transparent; } }

/* Casilla */
.step input, .ms input {
  appearance: none; -webkit-appearance: none;
  flex: none; width: 24px; height: 24px; margin: 0;
  border: 2px solid var(--muted); border-radius: 7px; background: transparent;
  display: grid; place-content: center; cursor: pointer; transition: background .15s, border-color .15s;
}
.step input::after, .ms input::after {
  content: ""; width: 6px; height: 11px; margin-top: -2px;
  border: solid var(--on-ok); border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg) scale(0); transition: transform .15s;
}
.step input:checked, .ms input:checked { background: var(--ok); border-color: var(--ok); }
.step input:checked::after, .ms input:checked::after { transform: rotate(45deg) scale(1); }

/* Chips de coleccionables */
.chip {
  display: inline-block; padding: 0 .55em; margin: 0 1px;
  border-radius: 999px; font-weight: 600; font-size: .86em; line-height: 1.6;
  white-space: nowrap; vertical-align: baseline;
}
.chip::first-letter { text-transform: uppercase; }
.chip.sk { background: var(--sk-bg); color: var(--sk-fg); }
.chip.pz { background: var(--pz-bg); color: var(--pz-fg); }
.chip.lv { background: var(--lv-bg); color: var(--lv-fg); }

/* Secuencias de botones (L, R, F) */
.seq {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .9em; letter-spacing: .04em; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 0 .4em;
}

.zone-foot { padding: 8px 14px 12px; border-top: 1px solid var(--line-soft); }

/* Hitos (zonas sin pasos) */
.zone.milestone .ms { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px 14px; cursor: pointer; }
.ms-title { font: 600 1.12rem/1.25 Georgia, "Times New Roman", serif; }
.zone.milestone:has(input:checked) .ms-title { color: var(--muted); text-decoration: line-through; }
.zone.final { border-color: var(--accent); }
.zone.final .ms-title { letter-spacing: .2em; color: var(--accent); }
.zone.final:has(input:checked) .ms-title { color: var(--accent); text-decoration: none; }

/* Ocultar completados (lo recién marcado permanece visible hasta recargar o volver a alternar) */
.hide-done .step.done:not(.fresh) { display: none; }
.hide-done .zone.done:not(.fresh) { display: none; }

/* ===== Pie ===== */
.foot { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: .9rem; }
.foot p { margin: 0; }
.noscript { padding: 16px; border: 1px solid var(--line); border-radius: 12px; }

/* ===== Botón flotante ===== */
.fab {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 15;
  width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); box-shadow: 0 6px 18px rgba(0,0,0,.35);
}
.fab[hidden] { display: none; }

/* ===== Diálogos ===== */
dialog { color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog.sheet {
  margin: 0; padding: 0; border: 0; border-right: 1px solid var(--line);
  width: min(23rem, 90vw); max-width: none; height: 100dvh; max-height: none;
  background: var(--surface);
  inset: 0 auto 0 0;
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: slide .2s ease-out; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: none; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: calc(8px + env(safe-area-inset-top)) 8px 4px 18px; }
.sheet-head h2 { margin: 0; font: 700 1.2rem Georgia, serif; }
.sheet-search { padding: 4px 14px 10px; }
.sheet-search input {
  width: 100%; min-height: 44px; padding: 0 14px; border-radius: 12px;
  background: var(--bg); border: 1px solid var(--line); font-size: 16px;
}
.sheet-list { list-style: none; margin: 0; padding: 0 8px calc(16px + env(safe-area-inset-bottom)); overflow-y: auto; flex: 1; overscroll-behavior: contain; }
.sheet-list a { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 6px 8px; border-radius: 10px; color: var(--text); text-decoration: none; }
.sheet-list a:hover { background: var(--surface-2); }
.sheet-list .t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.sheet-list .c { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.sheet-list a.done .t { color: var(--muted); }
.sheet-list a.done .c { color: var(--ok); font-weight: 700; }
.sheet-list .dg { color: var(--accent); font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.sheet-empty { padding: 18px 12px; color: var(--muted); }

dialog.modal { width: min(24rem, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
dialog.modal h2 { margin: 0 0 8px; font: 700 1.25rem Georgia, serif; }
dialog.modal p { margin: 0 0 18px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ===== Aviso ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 40;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0,0,0,.35);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ===== Pantallas más grandes ===== */
@media (min-width: 640px) {
  .hero { padding-top: 36px; }
  .stat { padding: 14px 16px 16px; }
  .stat-val b { font-size: 1.6rem; }
  .zone-toggle { padding: 12px 18px; }
  .step label { padding: 12px 18px; }
  .zone-foot { padding: 8px 18px 14px; }
}
@media (min-width: 480px) { .pct { font-size: .9rem; } }
@media (max-width: 479px) { .pct { display: none; } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
