:root {
  --bg: #ffffff;
  --fg: #0b0b0c;
  --muted: #6b6b70;
  --line: #e6e6e8;
  --card: #f4f4f5;
  --card-2: #ebebed;
  --accent: #0b0b0c;
  --accent-fg: #ffffff;
  --danger: #c62828;
  --ok: #1b7f3b;
  --warn: #9a6700;
  --shadow: 0 10px 30px rgba(0, 0, 0, .08);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b0c; --fg: #f2f2f3; --muted: #9b9ba1; --line: #232327; --card: #151518; --card-2: #1e1e22;
    --accent: #f2f2f3; --accent-fg: #0b0b0c; --danger: #ff6b6b; --ok: #4ade80; --warn: #fbbf24;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0b0c; --fg: #f2f2f3; --muted: #9b9ba1; --line: #232327; --card: #151518; --card-2: #1e1e22;
  --accent: #f2f2f3; --accent-fg: #0b0b0c; --danger: #ff6b6b; --ok: #4ade80; --warn: #fbbf24;
  --shadow: 0 10px 30px rgba(0, 0, 0, .5); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: inherit; }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -.01em; }
.boot { padding: 80px 16px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px max(16px, env(safe-area-inset-left)); height: 58px;
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-size: 17px; white-space: nowrap; }
.brand svg { width: 30px; height: 30px; flex: none; }
.brand b { font-weight: 800; }
.topbar-actions { display: flex; gap: 6px; align-items: center; }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px;
  border: 1px solid var(--line); background: transparent; cursor: pointer;
}
.icon-btn:hover { background: var(--card); }
.icon-btn svg { width: 18px; height: 18px; }

main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 22px 16px 48px; }
.site-footer {
  display: flex; justify-content: space-between; gap: 12px; padding: 18px 16px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 13px; max-width: 1180px; width: 100%; margin: 0 auto;
}
.site-footer a { color: var(--muted); }
.footer-links { display: flex; gap: 16px; }

/* ---------- Anuncios ---------- */
.ad { margin: 26px auto; max-width: 820px; text-align: center; min-height: 100px; }
.ad-label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }
.reader-end .ad { margin: 6px auto 10px; width: 100%; }

/* ---------- Texto legal ---------- */
.legal { max-width: 72ch; }
.legal h1 { font-size: 28px; font-weight: 800; margin-bottom: 6px; }
.legal h2 { font-size: 18px; font-weight: 800; margin: 24px 0 6px; }
.legal p, .legal li { color: var(--fg); }
.help { font-size: 13.5px; color: var(--muted); margin: 0; padding-left: 18px; }
.help li + li { margin-top: 4px; }
.help code, .legal code { background: var(--card); padding: 1px 6px; border-radius: 6px; font-size: 13px; }

/* ---------- Botones y formularios ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 18px;
  border-radius: 11px; border: 1px solid var(--line); background: var(--card); cursor: pointer;
  text-decoration: none; font-weight: 600; white-space: nowrap;
}
.btn:hover { background: var(--card-2); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.primary:hover { opacity: .9; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

label.field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; }
label.field span.hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); outline: none; font-size: 15px;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--fg); }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; font-size: 14px; }
.switch input { width: 18px; height: 18px; accent-color: var(--fg); }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

/* ---------- Inicio ---------- */
.home-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.home-head h1 { font-size: 28px; font-weight: 800; }
.home-head p { margin: 4px 0 0; }
.search { position: relative; width: min(360px, 100%); }
.search input { padding-left: 38px; }
.search svg { position: absolute; left: 12px; top: 50%; translate: 0 -50%; width: 16px; height: 16px; color: var(--muted); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 14px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 13px;
  font-size: 13px; cursor: pointer; font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

.grid { display: grid; gap: 20px 16px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.card { text-decoration: none; display: grid; gap: 8px; min-width: 0; }
.cover {
  position: relative; aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden; background: var(--card);
  border: 1px solid var(--line);
}
.cover img { width: 100%; height: 100%; object-fit: cover; transition: transform .25s ease; }
.card:hover .cover img { transform: scale(1.03); }
.cover .ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-weight: 800; font-size: 34px; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: var(--card-2); color: var(--fg); text-transform: uppercase; letter-spacing: .04em;
}
.cover .badge { position: absolute; left: 8px; top: 8px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(6px); }
.badge.ok { color: var(--ok); } .badge.warn { color: var(--warn); }
.card h3 { font-size: 15px; font-weight: 700; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .meta { font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.empty { padding: 60px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- Serie ---------- */
.series-hero { display: grid; grid-template-columns: 240px minmax(0, 1fr); grid-template-rows: auto auto 1fr; gap: 0 28px; align-items: start; margin-bottom: 28px; }
.series-hero .cover { width: 100%; box-shadow: var(--shadow); grid-row: span 3; }
.series-hero .desc, .series-hero .actions { grid-column: 2; }
.series-hero h1 { font-size: 32px; font-weight: 800; }
.series-hero .author { margin: 6px 0 12px; color: var(--muted); }
.series-hero .desc { white-space: pre-line; margin: 14px 0 18px; max-width: 70ch; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tags .badge { text-transform: none; letter-spacing: 0; font-weight: 600; font-size: 12px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 6px 0 10px; }
.section-head h2 { font-size: 20px; font-weight: 800; }
.chapter-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.chapter-list li + li { border-top: 1px solid var(--line); }
.chapter-list a {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 16px; text-decoration: none;
}
.chapter-list a:hover { background: var(--card); }
.chapter-list .num { font-weight: 700; }
.chapter-list .ctitle { color: var(--muted); }
.chapter-list .date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.chapter-list .read .num, .chapter-list .read .ctitle { opacity: .5; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--fg); margin-right: 8px; vertical-align: middle; }

/* ---------- Lector ---------- */
body.reading .topbar, body.reading .site-footer { display: none; }
body.reading main { max-width: none; padding: 0; }
.reader-bar {
  position: fixed; inset: 0 0 auto; z-index: 30; display: flex; align-items: center; gap: 8px;
  padding: 8px max(10px, env(safe-area-inset-left)); height: 56px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line); transition: transform .2s ease;
}
.reader-bar.hide { transform: translateY(-100%); }
.reader-bar .rtitle { min-width: 0; flex: 1; line-height: 1.2; }
.reader-bar .rtitle a { text-decoration: none; font-weight: 700; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-bar .rtitle small { color: var(--muted); }
.reader-bar select { width: auto; max-width: 150px; min-height: 38px; }
.progress { position: fixed; top: 0; left: 0; height: 3px; background: var(--fg); z-index: 31; width: 0; }
.pages { max-width: 820px; margin: 0 auto; padding-top: 56px; background: var(--bg); }
.pages img { width: 100%; height: auto; background: var(--card); }
.pages img.loaded { background: none; }
.reader-end { max-width: 820px; margin: 0 auto; padding: 28px 16px 60px; display: grid; gap: 14px; text-align: center; }
.reader-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.reader-empty { padding: 120px 16px; text-align: center; color: var(--muted); }

/* ---------- Admin ---------- */
.panel { border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; background: var(--bg); }
.panel + .panel { margin-top: 18px; }
.panel h2 { font-size: 18px; font-weight: 800; margin-bottom: 14px; }
.login { max-width: 380px; margin: 40px auto; }
.login h1 { font-size: 24px; font-weight: 800; margin-bottom: 4px; }
.login form { display: grid; gap: 14px; margin-top: 18px; }
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.admin-head h1 { font-size: 24px; font-weight: 800; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 14px; padding: 12px 0; }
.list li + li { border-top: 1px solid var(--line); }
.list .thumb { width: 48px; aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden; background: var(--card); flex: none; }
.list .thumb img { width: 100%; height: 100%; object-fit: cover; }
.list .info { flex: 1; min-width: 0; }
.list .info a { font-weight: 700; text-decoration: none; }
.list .info .muted { font-size: 13px; }
.series-edit { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 22px; }
.cover-edit { display: grid; gap: 10px; align-content: start; }
.drop {
  display: block; border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px 16px; text-align: center; cursor: pointer;
  color: var(--muted); transition: border-color .15s, background .15s;
}
.drop.over, .drop:hover { border-color: var(--fg); background: var(--card); }
.drop strong { color: var(--fg); }
.upload-status { font-size: 13px; color: var(--muted); margin-top: 10px; }
.bar { height: 6px; border-radius: 6px; background: var(--card-2); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--fg); width: 0; transition: width .2s; }
.page-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); margin-top: 16px; }
.page-tile { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); display: grid; }
.page-tile .img { aspect-ratio: 2 / 3; overflow: hidden; background: var(--card-2); }
.page-tile img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.page-tile .tools { display: flex; align-items: center; gap: 2px; padding: 4px; font-size: 12px; font-weight: 700; }
.page-tile .tools span { flex: 1; padding-left: 4px; }
.page-tile .tools button { border: 0; background: transparent; width: 28px; height: 28px; border-radius: 6px; cursor: pointer; }
.page-tile .tools button:hover { background: var(--card-2); }
.page-tile .tools button.del { color: var(--danger); }

#toast {
  position: fixed; left: 50%; bottom: 22px; translate: -50% 20px; opacity: 0; pointer-events: none; z-index: 50;
  background: var(--accent); color: var(--accent-fg); padding: 11px 18px; border-radius: 12px; font-weight: 600;
  box-shadow: var(--shadow); transition: opacity .2s, translate .2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; translate: -50% 0; }
#toast.error { background: var(--danger); color: #fff; }

@media (max-width: 720px) {
  main { padding: 16px 16px 40px; }
  .brand span { font-size: 16px; }
  .home-head h1 { font-size: 24px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 16px 12px; }
  .series-hero { grid-template-columns: 120px minmax(0, 1fr); grid-template-rows: none; gap: 0 16px; }
  .series-hero h1 { font-size: 22px; }
  .series-hero .cover { grid-row: auto; }
  .series-hero .desc, .series-hero .actions { grid-column: 1 / -1; }
  .series-edit { grid-template-columns: 1fr; }
  .cover-edit { grid-template-columns: 110px 1fr; align-items: start; }
  .form-grid { grid-template-columns: 1fr; }
  .chapter-list a { padding: 12px 14px; }
  .reader-bar select { max-width: 110px; }
  .panel { padding: 16px; }
}
