:root {
  --cover: #22386b;
  --cover-deep: #182a55;
  --page: #e8ecf3;
  --sheet: #f8f9fc;
  --pocket: #eef1f7;
  --ink: #18203a;
  --muted: #58637e;
  --line: #cdd4e2;
  --gold: #f2c14e;
  --gold-ink: #3b2b00;
  --danger: #b3261e;
  --ok: #2f7d4a;
  --radius: 10px;
  --display: "Bricolage Grotesque", "Arial Rounded MT Bold", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #10172a;
    --sheet: #18213c;
    --pocket: #1f2a4a;
    --ink: #e7ebf5;
    --muted: #9ba6c3;
    --line: #2d3a60;
    --cover: #1d2f5e;
    --cover-deep: #142248;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #10172a; --sheet: #18213c; --pocket: #1f2a4a; --ink: #e7ebf5;
  --muted: #9ba6c3; --line: #2d3a60; --cover: #1d2f5e; --cover-deep: #142248;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--display); line-height: 1.1; margin: 0; }

/* ---------- Botones y campos ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: 0 1rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--sheet); color: var(--ink);
  font-weight: 700; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.gold { background: var(--gold); color: var(--gold-ink); border-color: transparent; }
.btn.gold:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.btn.ghost:hover { border-color: #fff; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 .8rem; font-size: .9rem; }
.btn[disabled] { opacity: .55; cursor: progress; }
.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; }

.field { display: grid; gap: .3rem; }
.field > span { font-size: .85rem; color: var(--muted); font-weight: 700; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: .55rem .8rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--sheet);
}
textarea { min-height: 70px; resize: vertical; }

/* ---------- Tapa ---------- */
.cover {
  position: relative;
  background:
    repeating-linear-gradient(115deg, rgba(255,255,255,.025) 0 2px, transparent 2px 7px),
    linear-gradient(180deg, var(--cover), var(--cover-deep));
  color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 1rem) 1.25rem 1.6rem;
}
.cover::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: 8px;
  border-bottom: 2px dashed rgba(255,255,255,.22);
}
.cover-in, .summary, main, .site-foot { max-width: 1240px; margin: 0 auto; }
.cover-in { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .75rem; }
.brand h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -.01em; }
.rings { display: grid; gap: 5px; }
.rings i { width: 12px; height: 12px; border-radius: 50%; background: var(--page); box-shadow: inset 0 2px 3px rgba(0,0,0,.35); }
.cover nav { display: flex; gap: .5rem; flex-wrap: wrap; }

.summary { display: flex; align-items: flex-end; justify-content: space-between; gap: 1.5rem; margin-top: 1.4rem; flex-wrap: wrap; }
.value strong {
  display: block; font-family: var(--display); font-weight: 800;
  font-size: clamp(2.2rem, 6vw, 3.4rem); color: var(--gold); line-height: 1;
  font-variant-numeric: tabular-nums;
}
.value p { margin: .4rem 0 0; color: rgba(255,255,255,.78); }
.spark { width: min(420px, 100%); }
.spark svg { width: 100%; height: 70px; display: block; }
.spark p { margin: .2rem 0 0; font-size: .85rem; color: rgba(255,255,255,.7); text-align: right; }

/* ---------- Filtros ---------- */
main { padding: 1.25rem 1.25rem 3rem; }
.filters {
  display: grid; gap: .75rem;
  grid-template-columns: minmax(200px, 2fr) repeat(auto-fit, minmax(140px, 1fr));
  align-items: end;
}
.types { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .85rem; }
.chip {
  display: inline-flex; align-items: center; gap: .45rem;
  min-height: 36px; padding: 0 .8rem 0 .45rem;
  border: 1px solid var(--line); border-radius: 999px; background: var(--sheet);
  cursor: pointer; font-size: .92rem;
}
.chip .dot { width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 -3px 0 rgba(0,0,0,.18); }
.chip[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--sheet); }
.result-line { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin: 1.1rem 0 .9rem; color: var(--muted); }
.result-line strong { color: var(--ink); }
.sorter { display: flex; align-items: center; gap: 1rem; }
.sorter label { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--ink); }
.sorter select { width: auto; min-height: 40px; }
.filterbox > summary { display: none; }
a { color: inherit; text-underline-offset: 2px; }
.dlg-body a { font-weight: 700; }

/* ---------- Páginas de la carpeta ---------- */
.pages { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); }
.page {
  position: relative;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 6px 14px 14px 6px;
  padding: 14px 14px 10px 40px;
  box-shadow: 0 1px 0 var(--line), 0 10px 24px -18px rgba(10,20,50,.45);
}
.page::before {
  content: ""; position: absolute; left: 12px; top: 0; bottom: 0; width: 14px;
  background:
    radial-gradient(circle at 7px 18%, var(--page) 5px, var(--line) 5.5px, transparent 6.5px),
    radial-gradient(circle at 7px 50%, var(--page) 5px, var(--line) 5.5px, transparent 6.5px),
    radial-gradient(circle at 7px 82%, var(--page) 5px, var(--line) 5.5px, transparent 6.5px);
}
.pockets { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pocket {
  position: relative; display: block; width: 100%; aspect-ratio: 63 / 88;
  padding: 4px; border: 1px solid var(--line); border-radius: 5px;
  background: var(--pocket); cursor: pointer; overflow: hidden;
}
.pocket::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(130deg, rgba(255,255,255,.38) 0%, rgba(255,255,255,0) 28%, rgba(255,255,255,0) 70%, rgba(255,255,255,.14) 100%);
}
.pocket img { width: 100%; height: 100%; object-fit: contain; border-radius: 3px; }
.pocket.empty { cursor: default; background: transparent; border-style: dashed; opacity: .6; }
.pocket.empty::after { display: none; }
.pocket .noimg { display: grid; place-items: center; height: 100%; padding: .4rem; text-align: center; font-size: .78rem; color: var(--muted); }
.tag {
  position: absolute; z-index: 1; font-size: .74rem; font-weight: 700; line-height: 1;
  padding: .28rem .42rem; border-radius: 999px; font-variant-numeric: tabular-nums;
}
.tag.price { left: 6px; bottom: 6px; background: rgba(16,22,40,.82); color: #fff; }
.tag.price.hi { background: var(--gold); color: var(--gold-ink); }
.tag.qty { right: 6px; top: 6px; background: var(--ink); color: var(--sheet); }
.page-foot { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); margin-top: 8px; }

.empty-state { background: var(--sheet); border: 1px dashed var(--line); border-radius: 14px; padding: 2.2rem 1.5rem; text-align: center; }
.empty-state h2 { font-size: 1.5rem; margin-bottom: .5rem; }
.empty-state p { max-width: 52ch; margin: 0 auto 1.2rem; color: var(--muted); }

/* ---------- Diálogos ---------- */
dialog {
  width: min(920px, 94vw); max-height: 92vh; padding: 0;
  border: 0; border-radius: 16px; background: var(--sheet); color: var(--ink);
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.5);
}
dialog::backdrop { background: rgba(10,15,32,.62); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--sheet); z-index: 2; }
.dlg-head h2 { font-size: 1.35rem; }
.dlg-body { padding: 1.25rem; }
.x { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 1.3rem; line-height: 1; }

.detail { display: grid; gap: 1.5rem; grid-template-columns: minmax(220px, 320px) 1fr; }
.detail .art img { width: 100%; border-radius: 12px; box-shadow: 0 16px 40px -20px rgba(0,0,0,.6); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .6rem 1rem; margin: 1rem 0; }
.facts div span { display: block; font-size: .8rem; color: var(--muted); }
.facts div b { font-weight: 700; }
.prices { display: flex; gap: 1.5rem; flex-wrap: wrap; align-items: baseline; margin: .5rem 0; }
.prices .big { font-family: var(--display); font-weight: 800; font-size: 2rem; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.chart svg { width: 100%; height: 150px; display: block; }
.attack { border-top: 1px solid var(--line); padding: .6rem 0; }
.attack header { display: flex; justify-content: space-between; gap: 1rem; font-weight: 700; }
.attack p { margin: .25rem 0 0; color: var(--muted); }
.copies { display: grid; gap: .75rem; margin-top: .5rem; }
.copy { display: grid; gap: .6rem; grid-template-columns: 80px 1fr 1fr 1fr; align-items: end; padding: .8rem; border: 1px solid var(--line); border-radius: var(--radius); }
.copy .wide { grid-column: 1 / -1; display: flex; gap: .5rem; align-items: end; flex-wrap: wrap; }
.copy .wide .field { flex: 1 1 180px; }
.section-title { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }

.results { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); margin-top: 1rem; }
.result { border: 1px solid var(--line); border-radius: 8px; background: var(--pocket); padding: 5px; cursor: pointer; text-align: left; }
.result img { width: 100%; aspect-ratio: 63 / 88; object-fit: contain; }
.result .noimg { aspect-ratio: 63 / 88; display: grid; place-items: center; font-size: .75rem; color: var(--muted); }
.result b { display: block; font-size: .85rem; margin-top: .3rem; line-height: 1.2; }
.result small { display: block; color: var(--muted); font-size: .75rem; line-height: 1.25; }
.result[aria-pressed="true"] { outline: 3px solid var(--gold); }
.picker { display: grid; gap: .75rem; grid-template-columns: 1fr 1fr 90px auto; align-items: end; margin-top: 1rem; padding: 1rem; border-radius: 12px; background: var(--pocket); }
.search-row { display: grid; grid-template-columns: 2fr 1fr; gap: .75rem; }
.hint { font-size: .88rem; color: var(--muted); margin: .5rem 0 0; }

.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: linear-gradient(180deg, var(--cover), var(--cover-deep)); }
.auth-card { width: min(420px, 100%); background: var(--sheet); border-radius: 18px; padding: 2rem 1.6rem; display: grid; gap: 1rem; }
.auth-card h1 { font-size: 2rem; }
.auth-card p { margin: 0; color: var(--muted); }
.err { color: var(--danger); font-weight: 700; min-height: 1.5em; margin: 0; }

.progress { height: 10px; border-radius: 99px; background: var(--pocket); overflow: hidden; border: 1px solid var(--line); }
.progress i { display: block; height: 100%; width: 0; background: var(--gold); transition: width .2s; }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1.2rem; }
.admin-grid div { background: var(--pocket); border-radius: 10px; padding: .8rem; }
.admin-grid b { display: block; font-family: var(--display); font-size: 1.5rem; }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  transform: translate(-50%, calc(100% + 60px)); visibility: hidden; background: var(--ink); color: var(--sheet);
  padding: .75rem 1.1rem; border-radius: 999px; font-weight: 700; z-index: 50;
  transition: transform .25s ease; max-width: 92vw;
}
#toast.on { transform: translate(-50%, 0); visibility: visible; }

.site-foot { padding: 0 1.25rem calc(env(safe-area-inset-bottom, 0px) + 2rem); color: var(--muted); font-size: .85rem; }
.loading { padding: 3rem 0; text-align: center; color: var(--muted); }

@media (max-width: 720px) {
  .filterbox > summary {
    display: flex; align-items: center; justify-content: space-between;
    min-height: 48px; padding: 0 1rem; border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--sheet); font-weight: 700; cursor: pointer; list-style: none;
  }
  .filterbox > summary::-webkit-details-marker { display: none; }
  .filterbox > summary::after { content: "+"; font-size: 1.3rem; }
  .filterbox[open] > summary { margin-bottom: .9rem; }
  .filterbox[open] > summary::after { content: "−"; }
  .detail { grid-template-columns: 1fr; }
  .detail .art { max-width: 280px; margin: 0 auto; }
  .copy { grid-template-columns: 1fr 1fr; }
  .picker { grid-template-columns: 1fr 1fr; }
  .search-row { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .field:first-child { grid-column: 1 / -1; }
  .page { padding-left: 32px; }
  .page::before { left: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
