:root {
  --bg: #EEF1F6;
  --surface: #FFFFFF;
  --surface-2: #E2E7F0;
  --text: #1B2236;
  --muted: #5A6683;
  --line: #CDD4E1;
  --star: #9A7200;
  --focus: #2F6FE4;
  --tint: #5A6683;
  --radius-card: 6px;
  --radius-ui: 999px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1B2236;
    --surface: #252E47;
    --surface-2: #2F3956;
    --text: #EDF0F6;
    --muted: #9AA6C0;
    --line: #3A4566;
    --star: #F2C14E;
    --focus: #8DB4FF;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1B2236; --surface: #252E47; --surface-2: #2F3956; --text: #EDF0F6;
  --muted: #9AA6C0; --line: #3A4566; --star: #F2C14E; --focus: #8DB4FF; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.55 "Zen Kaku Gothic New", system-ui, sans-serif;
}
img { display: block; max-width: 100%; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* --- login ----------------------------------------------------------------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-box { max-width: 26rem; }
.login h1 { font-size: 2.25rem; line-height: 1.15; margin: 0 0 .5rem; letter-spacing: -.01em; }
.login p { color: var(--muted); margin: 0 0 1.5rem; }
.login-msg { min-height: 1.5em; color: var(--text); }
.gbtn { min-height: 44px; }

/* --- cabecera --------------------------------------------------------------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; white-space: nowrap; font-size: 1.05rem; }
.views { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.views::-webkit-scrollbar { display: none; }
.views a {
  text-decoration: none; padding: 6px 12px; border-radius: var(--radius-ui);
  color: var(--muted); white-space: nowrap; font-weight: 500;
}
.views a[aria-current="page"] { background: var(--text); color: var(--bg); }
@media (max-width: 640px) {
  .top { flex-wrap: wrap; gap: 8px; }
  .views { order: 3; flex-basis: 100%; }
  .brand { flex: 1; }
}

.ghost, .primary {
  border-radius: var(--radius-ui); padding: 7px 14px; cursor: pointer; font-weight: 500;
  border: 1px solid var(--line); background: transparent; min-height: 40px;
}
.primary { background: var(--star); border-color: var(--star); color: #1B2236; }
:root[data-theme="dark"] .primary, :root:not([data-theme="light"]) .primary { color: #1B2236; }

/* --- lista ------------------------------------------------------------------ */
main { padding: 16px max(16px, env(safe-area-inset-left)) 64px; max-width: 1400px; margin: 0 auto; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search { flex: 1 1 260px; }
.search input {
  width: 100%; min-height: 42px; padding: 8px 14px; border-radius: var(--radius-ui);
  border: 1px solid var(--line); background: var(--surface);
}
.filters {
  margin-top: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface);
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 16px; align-items: end;
}
.filters label { display: grid; gap: 4px; font-size: .875rem; color: var(--muted); }
.filters select, .filters input[type="number"] {
  min-height: 38px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text);
}
.filters .check { display: flex; gap: 8px; align-items: center; color: var(--text); }
.count { color: var(--muted); font-size: .9rem; margin: 14px 0 10px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px 14px; }
@media (max-width: 420px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 14px 10px; } }
.card {
  --tint: var(--muted);
  display: flex; flex-direction: column; text-decoration: none; color: inherit;
  background: var(--surface); border-radius: var(--radius-card); overflow: hidden;
  border-bottom: 4px solid var(--tint);
}
.card .poster { aspect-ratio: 2 / 3; background: var(--surface-2); position: relative; }
.card .poster img { width: 100%; height: 100%; object-fit: cover; }
.card .score {
  position: absolute; left: 6px; top: 6px; padding: 1px 8px; border-radius: var(--radius-ui);
  background: rgba(16, 20, 33, .78); color: #F2C14E; font-weight: 700; font-size: .875rem;
}
.card .flag {
  position: absolute; right: 6px; top: 6px; padding: 1px 8px; border-radius: var(--radius-ui);
  background: rgba(16, 20, 33, .78); color: #EDF0F6; font-size: .75rem;
}
.card .meta { padding: 8px 10px 10px; display: grid; gap: 2px; }
.card .t { font-weight: 500; font-size: .92rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .s { color: var(--muted); font-size: .8rem; }
.empty { padding: 40px 0; color: var(--muted); max-width: 40rem; }

/* --- ficha ------------------------------------------------------------------ */
.detail {
  --tint: #5A6683;
  width: min(1100px, 100vw); max-width: 100vw; max-height: 100dvh; height: 100dvh;
  margin: 0 auto; padding: 0; border: 0; background: var(--bg); color: var(--text);
}
@media (min-width: 900px) { .detail { height: calc(100dvh - 48px); margin-top: 24px; border-radius: 12px; } }
.detail::backdrop { background: rgba(10, 13, 22, .7); }
#detail-body { height: 100%; overflow-y: auto; overscroll-behavior: contain; }
.hero { position: relative; min-height: 220px; background: var(--tint); overflow: hidden; }
.hero .banner { width: 100%; height: 260px; object-fit: cover; opacity: .85; }
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to bottom, transparent 30%, var(--bg) 100%);
}
.close {
  position: absolute; top: 12px; left: 12px; z-index: 2; min-height: 40px;
  background: rgba(16, 20, 33, .7); color: #EDF0F6; border: 0; border-radius: var(--radius-ui); padding: 6px 14px; cursor: pointer;
}
/* El título japonés, en vertical y en mincho, es la firma visual de la ficha. */
.ja {
  position: absolute; right: 18px; top: 18px; z-index: 2; margin: 0;
  writing-mode: vertical-rl; font-family: "Zen Old Mincho", serif; font-weight: 700;
  font-size: clamp(1.6rem, 4vw, 2.6rem); line-height: 1.1; letter-spacing: .08em;
  color: #fff; text-shadow: 0 2px 12px rgba(0, 0, 0, .45);
  max-height: calc(100% - 36px); overflow: hidden; white-space: nowrap;
}
.head { display: grid; grid-template-columns: 180px 1fr; gap: 22px; padding: 0 24px; margin-top: -120px; position: relative; z-index: 1; }
.head .cover { border-radius: 6px; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); border-bottom: 5px solid var(--tint); }
.head h2 { font-size: clamp(1.5rem, 3vw, 2.1rem); line-height: 1.2; margin: 120px 0 4px; letter-spacing: -.01em; }
.head .en { color: var(--muted); margin: 0 0 12px; }
.facts { display: flex; flex-wrap: wrap; gap: 18px 28px; margin: 0; }
.facts div { display: grid; }
.facts dt { color: var(--muted); font-size: .8rem; }
.facts dd { margin: 0; font-weight: 700; font-size: 1.15rem; }
.facts .big dd { color: var(--star); font-size: 1.6rem; line-height: 1.1; }
@media (max-width: 640px) {
  .head { grid-template-columns: 110px 1fr; gap: 14px; padding: 0 16px; margin-top: -70px; }
  .head h2 { margin-top: 74px; font-size: 1.3rem; }
  .ja { font-size: 1.5rem; right: 12px; }
  .hero .banner { height: 180px; }
}
.body { padding: 20px 24px 48px; display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 32px; }
@media (max-width: 900px) { .body { grid-template-columns: 1fr; padding: 16px; } }
.body h3 { font-size: 1.1rem; margin: 28px 0 10px; }
.body h3:first-child { margin-top: 0; }
.synopsis { white-space: pre-line; max-width: 68ch; }
.notice { padding: 10px 14px; border-left: 4px solid var(--tint); background: var(--surface); border-radius: 0 8px 8px 0; margin: 0 0 16px; }
.notice a { font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.chips li, .chips a {
  padding: 3px 10px; border-radius: var(--radius-ui); background: var(--surface); border: 1px solid var(--line);
  font-size: .85rem; text-decoration: none;
}
.chips .spoiler { filter: blur(4px); }
.chips .spoiler.shown { filter: none; }
.linklike { background: none; border: 0; padding: 0; color: var(--focus); cursor: pointer; text-decoration: underline; font-size: .9rem; }
.trailer { aspect-ratio: 16 / 9; width: 100%; border: 0; border-radius: 8px; background: #000; }
.rel { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.rel li { display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: center; }
.rel img, .rel .ph { width: 44px; height: 62px; object-fit: cover; border-radius: 4px; background: var(--surface-2); }
.rel .k { color: var(--muted); font-size: .8rem; }
.rel .seen { color: var(--star); font-size: .8rem; }
.chars { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.char { display: grid; grid-template-columns: 48px 1fr; gap: 10px; align-items: center; background: var(--surface); border-radius: 8px; padding: 6px; }
.char img { width: 48px; height: 64px; object-fit: cover; border-radius: 4px; }
.char .v { color: var(--muted); font-size: .85rem; }
.side dl { margin: 0; display: grid; gap: 10px; }
.side dt { color: var(--muted); font-size: .8rem; }
.side dd { margin: 0; }
.dist { display: grid; gap: 4px; }
.dist .row { display: grid; grid-template-columns: 22px 1fr 44px; gap: 8px; align-items: center; font-size: .82rem; }
.dist .bar { height: 10px; border-radius: 3px; background: var(--tint); min-width: 2px; }
.dist .pct { color: var(--muted); text-align: right; }
.themes-list { margin: 0; padding-left: 1.1rem; }
.themes-list li { margin-bottom: 4px; }

/* --- calendario --------------------------------------------------------------- */
.cal h2, .stats h2 { font-size: 1.5rem; margin: 8px 0 4px; }
.cal .lead, .stats .lead { color: var(--muted); margin: 0 0 20px; }
.day { margin-bottom: 22px; }
.day h3 { font-size: 1rem; margin: 0 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.day.today h3 { color: var(--star); }
.ep {
  --tint: var(--muted);
  display: grid; grid-template-columns: 52px 1fr auto; gap: 12px; align-items: center;
  padding: 6px 0; text-decoration: none; color: inherit;
}
.ep img, .ep .ph { width: 52px; height: 72px; object-fit: cover; border-radius: 4px; border-left: 4px solid var(--tint); background: var(--surface-2); }
.ep .t { font-weight: 500; }
.ep .s { color: var(--muted); font-size: .85rem; }
.ep .time { font-weight: 700; font-variant-numeric: tabular-nums; }
.tag-mine { display: inline-block; margin-left: 6px; padding: 0 8px; border-radius: var(--radius-ui); background: var(--star); color: #1B2236; font-size: .75rem; font-weight: 700; }
.cal-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 40px; }
@media (max-width: 900px) { .cal-cols { grid-template-columns: 1fr; gap: 16px; } }

/* --- estadísticas --------------------------------------------------------------- */
.kpis { display: flex; flex-wrap: wrap; gap: 28px 44px; margin: 0 0 28px; }
.kpis div { display: grid; }
.kpis dt { color: var(--muted); font-size: .85rem; order: 2; }
.kpis dd { margin: 0; font-size: 2rem; font-weight: 700; line-height: 1.1; }
.gbars { display: grid; gap: 6px; max-width: 640px; }
.gbars .row { display: grid; grid-template-columns: 130px 1fr 88px; gap: 10px; align-items: center; font-size: .9rem; }
.gbars .bar { height: 12px; border-radius: 3px; background: var(--star); }
.gbars .n { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
table.runs { border-collapse: collapse; width: 100%; max-width: 900px; font-size: .88rem; }
.runs th, .runs td { text-align: left; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.runs th { color: var(--muted); font-weight: 500; }
.runs .bad { color: #E5484D; font-weight: 700; }
.runs code { font-size: .8rem; word-break: break-word; color: var(--muted); }
.scroll { overflow-x: auto; }
