/* A chronicler's archive under two moons: crimson Iothas (#dc143c) and silver Dener (#c0c0c0).
   Text uses the nearest shades that stay readable (4.5:1) on each theme; the moons themselves stay pure. */
:root {
  --bg: #ebece6; --surface: #f6f6f1; --ink: #1e2130; --muted: #5d6273; --line: #cfd1c6;
  --iothas: #b0102f; --dener: #696969; --dener-soft: #e3e3e3; --iothas-soft: #f5dce1;
  --ok: #3f6b4b; --warn: #8a6a1c;
  --f-display: 'IM Fell English SC', 'Iowan Old Style', Georgia, serif;
  --f-body: 'Spectral', Georgia, 'Times New Roman', serif;
  --f-ui: 'Alegreya Sans SC', 'Gill Sans', 'Trebuchet MS', sans-serif;
  --shadow: 0 1px 2px rgba(30,33,48,.08), 0 6px 18px rgba(30,33,48,.07);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #12131b; --surface: #1b1d28; --ink: #e7e4da; --muted: #9fa3b3; --line: #2d3040;
  --iothas: #ee4466; --dener: #c0c0c0; --dener-soft: #2a2b31; --iothas-soft: #3d1520;
  --ok: #7fb48c; --warn: #d6b25a; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35); color-scheme: dark;
} }
:root[data-theme="dark"] {
  --bg: #12131b; --surface: #1b1d28; --ink: #e7e4da; --muted: #9fa3b3; --line: #2d3040;
  --iothas: #ee4466; --dener: #c0c0c0; --dener-soft: #2a2b31; --iothas-soft: #3d1520;
  --ok: #7fb48c; --warn: #d6b25a; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 16px; line-height: 1.55; }
body.locked { overflow: hidden; }
a { color: var(--iothas); }
:focus-visible { outline: 2px solid var(--dener); outline-offset: 2px; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 max(16px, env(safe-area-inset-right, 0px)) 64px max(16px, env(safe-area-inset-left, 0px)); }

/* Top bar */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding: 14px 0 0; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--f-display); font-size: 1.25rem; color: var(--ink); text-decoration: none; padding-bottom: 10px; }
.moons { display: inline-flex; gap: 4px; }
.moons i { display: block; width: 11px; height: 11px; border-radius: 50%; }
.moons i:first-child { background: #dc143c; }
.moons i:last-child { background: #c0c0c0; }
.nav { display: flex; gap: 2px; margin-left: auto; }
.nav a { font-family: var(--f-ui); font-size: 1.05rem; letter-spacing: .04em; color: var(--muted); text-decoration: none; padding: 6px 12px 9px; border-bottom: 3px solid transparent; }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--iothas); }
.nav a.dm { color: var(--warn); }
.nav a.dm[aria-current="page"] { border-bottom-color: var(--warn); }

/* Type */
h1 { font-family: var(--f-display); font-weight: 400; font-size: clamp(1.9rem, 5vw, 2.8rem); line-height: 1.08; margin: 0; text-wrap: balance; }
h2 { font-family: var(--f-display); font-weight: 400; font-size: 1.5rem; line-height: 1.15; margin: 0 0 10px; }
h3 { font-family: var(--f-ui); font-weight: 700; letter-spacing: .08em; font-size: .85rem; color: var(--dener); margin: 0 0 8px; }
.lede { max-width: 65ch; color: var(--muted); margin: 6px 0 0; }
.meta { font-family: var(--f-ui); font-size: .82rem; color: var(--muted); letter-spacing: .03em; margin-top: 2px; }
.crumbs { font-family: var(--f-ui); letter-spacing: .04em; font-size: .9rem; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--muted); }
section.block { margin-top: 30px; }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: 10px; padding: 28px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-family: var(--f-display); font-weight: 400; font-size: 1.4rem; margin-bottom: 4px; }

/* Search */
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: var(--surface); box-shadow: var(--shadow); }
.search:focus-within { border-color: var(--dener); box-shadow: 0 0 0 3px var(--dener-soft); }
.search input { border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 1.05rem; padding: 12px 2px; width: 100%; outline: none; }
.results { display: grid; gap: 18px; margin-top: 18px; }
.mention { padding: 8px 0; border-bottom: 1px solid var(--line); }
.mention b { font-weight: 600; }
.mention span { color: var(--muted); }

/* Chips and tabs */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-family: var(--f-ui); font-size: .92rem; letter-spacing: .03em; border: 1px solid var(--line); background: transparent; color: var(--ink); border-radius: 999px; padding: 4px 12px; cursor: pointer; text-decoration: none; }
.chip .n { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: 4px; }
.chip[aria-current="page"], .chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chip[aria-current="page"] .n, .chip[aria-pressed="true"] .n { color: inherit; opacity: .7; }

/* Entry cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.group + .group { margin-top: 26px; }
.group h3 { display: flex; gap: 8px; align-items: baseline; }
.group h3 .n { color: var(--muted); font-weight: 500; }
.card { display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: start; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px; color: inherit; text-decoration: none; min-width: 0; transition: transform .12s ease, border-color .12s ease; }
.card:hover { transform: translateY(-1px); border-color: var(--dener); }
.card .name { font-weight: 600; line-height: 1.25; overflow-wrap: break-word; }
.mono { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-family: var(--f-display); font-size: 1.4rem; background: var(--dener-soft); color: var(--ink); overflow: hidden; border: 1px solid var(--line); flex: none; }
.mono img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 18%; }
.mono.t-facción { background: var(--surface); }
.mono.t-facción img { object-fit: contain; padding: 3px; }
.mono.t-PJ, .mono.t-compañero { background: var(--iothas-soft); }
.card .mono { width: 96px; height: 120px; border-radius: 8px; font-size: 1.9rem; } /* 4:5, like the portraits */
.card .mono.t-facción { height: 96px; }
.party { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; } /* 8 player characters: 4 + 4 */
.party .card { align-items: center; }
.companions { margin: 12px 0 0; }
.companions .meta { display: inline; }

/* Home */
.hero { padding: 10px 0 4px; }
.hero .eyebrow, .episode-hero .eyebrow { font-family: var(--f-ui); color: var(--iothas); letter-spacing: .06em; }
.hero h1 { font-size: clamp(2.3rem, 7vw, 3.6rem); }
.arcs { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x proximity; }
.arc { flex: 1 0 150px; scroll-snap-align: start; display: grid; gap: 2px; align-content: start; background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--dener); border-radius: 8px; padding: 10px 12px; color: inherit; text-decoration: none; }
.arc:hover { border-color: var(--dener); }
.arc.current { border-top-color: var(--iothas); }
.arc .name { font-weight: 600; line-height: 1.25; }
.arc-group { margin-top: 26px; scroll-margin-top: 12px; }
.arc-group h2 .meta { display: inline; font-size: .85rem; }
select.region { font: inherit; font-family: var(--f-ui); font-size: .92rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; margin-left: auto; }

/* Badges: state (alive or not) and stance (towards the party) never share a style */
.pills { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.pill { font-family: var(--f-ui); font-size: .75rem; letter-spacing: .04em; border-radius: 4px; padding: 1px 7px; border: 1px solid var(--line); color: var(--muted); }
.pill.state { border-style: dashed; }
.pill.state.muerto, .pill.state.destruido { color: var(--iothas); border-color: var(--iothas); }
.pill.state.desaparecido { color: var(--warn); border-color: var(--warn); }
.pill.stance.aliado { border-color: var(--ok); color: var(--ok); }
.pill.stance.enemigo { background: var(--iothas-soft); border-color: var(--iothas); color: var(--iothas); }
.pill.stance.ambiguo { border-color: var(--warn); color: var(--warn); }

/* Episodes */
.thumb { position: relative; display: block; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; background: var(--dener-soft); border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb::after { content: ""; position: absolute; left: 50%; top: 50%; width: 64px; height: 44px; margin: -22px 0 0 -32px; border-radius: 12px; background: rgba(0,0,0,.65) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 7l8 5-8 5z' fill='white'/%3E%3C/svg%3E") center / 28px no-repeat; }
.episode-hero { display: grid; grid-template-columns: minmax(0, 420px) 1fr; gap: 22px; align-items: start; }
.summary p { margin: 0 0 10px; max-width: 70ch; }
.summary + .btn { margin-top: 6px; }
.points { margin: 0; padding-left: 20px; display: grid; gap: 6px; max-width: 75ch; }
.ep-list { display: grid; gap: 10px; }
.ep-row { display: grid; grid-template-columns: 120px 1fr; gap: 14px; align-items: center; color: inherit; text-decoration: none; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.ep-row:hover { border-color: var(--dener); }
.ep-row .thumb { border-radius: 6px; }
.ep-row .thumb::after { display: none; }
.ep-row .title { font-weight: 600; line-height: 1.25; }
.pager { display: flex; justify-content: space-between; gap: 10px; margin-top: 28px; font-family: var(--f-ui); letter-spacing: .04em; }

/* Entry page */
.entry-head { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; }
.entry-head .mono { width: 96px; height: 96px; font-size: 2rem; }
.entry-head.with-portrait { align-items: end; gap: 24px; }
.portrait { display: block; width: 260px; aspect-ratio: 4 / 5; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: var(--dener-soft); box-shadow: var(--shadow); }
.portrait img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 20%; display: block; }
.portrait.t-facción { aspect-ratio: 1; width: 200px; background: var(--surface); }
.portrait.t-facción img { object-fit: contain; padding: 14px; }
.alias { font-style: italic; color: var(--muted); }
.entry-body { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 32px; margin-top: 24px; align-items: start; }
.segment { display: grid; gap: 4px; margin-bottom: 18px; }
.segment .r { font-family: var(--f-ui); letter-spacing: .06em; font-size: .8rem; color: var(--dener); }
.segment p { margin: 0; max-width: 68ch; font-size: 1.03rem; }
.segment.latest p { font-size: 1.08rem; }
.aside { display: grid; gap: 22px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: .95rem; margin: 0; }
.facts dt { font-family: var(--f-ui); color: var(--muted); letter-spacing: .03em; }
.facts dd { margin: 0; }
.eps { display: flex; flex-wrap: wrap; gap: 5px; }
.epn { font-family: var(--f-ui); font-variant-numeric: tabular-nums; font-size: .85rem; border: 1px solid var(--iothas); color: var(--iothas); border-radius: 4px; padding: 1px 7px; min-width: 2.2em; text-align: center; text-decoration: none; }
.rels { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.rels a { font-weight: 600; text-decoration: none; }
.rels a:hover { text-decoration: underline; }
.rels span { color: var(--muted); }

/* DM desk */
.session { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px 18px; box-shadow: var(--shadow); display: grid; gap: 12px; }
.session h1 input { font: inherit; width: 3.2em; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 0 6px; }
.session > .meta { margin: 0; }
.queue { display: grid; gap: 8px; }
.qrow { display: grid; grid-template-columns: auto 48px 1fr auto; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--bg); }
.qrow.done { opacity: .65; }
.qrow input[type="checkbox"] { width: 20px; height: 20px; }
.qrow img { width: 48px; height: 60px; object-fit: cover; border-radius: 6px; background: var(--dener-soft); }
.qrow .name { font-weight: 600; }
.qrow .ctx { font-size: .88rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qrow .ctx.warn { color: var(--warn); }
.dmnote { font-family: var(--f-ui); letter-spacing: .03em; font-size: .88rem; color: var(--warn); border: 1px dashed var(--warn); border-radius: 8px; padding: 8px 12px; margin: 0; }
.controls { display: grid; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin: 14px 0 18px; box-shadow: var(--shadow); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.controls .search { flex: 1 1 260px; box-shadow: none; background: var(--bg); }
.count { font-family: var(--f-ui); color: var(--muted); font-size: .9rem; }
.epbox { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-family: var(--f-ui); letter-spacing: .03em; }
.epbox input { width: 5.5em; font: inherit; font-family: var(--f-body); color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.dmgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.dcard { display: grid; grid-template-columns: 72px 1fr; gap: 12px; align-items: start; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: pointer; color: inherit; font: inherit; min-width: 0; }
.dcard:hover { border-color: var(--warn); }
.dcard.pub { border-left: 4px solid var(--ok); }
.dcard img { width: 72px; height: 90px; object-fit: cover; border-radius: 6px; display: block; background: var(--dener-soft); }
.dcard .name { font-weight: 600; }
.dcard .ctx { font-size: .88rem; color: var(--muted); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.pill.pub { border-color: var(--ok); color: var(--ok); }
.pill.link { border-color: var(--dener); color: var(--dener); }
.pill.review { border-color: var(--warn); color: var(--warn); }
.flink { font-family: var(--f-ui); font-size: .8rem; letter-spacing: .03em; border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px; background: transparent; color: var(--iothas); cursor: pointer; text-decoration: none; }
.scrim { position: fixed; inset: 0; background: rgba(10,12,20,.45); z-index: 20; }
.panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(580px, 100%); background: var(--surface); z-index: 21; box-shadow: -10px 0 30px rgba(0,0,0,.25); display: flex; flex-direction: column; border-left: 1px solid var(--line); }
.panel .head { padding: calc(18px + env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px)) 14px 22px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center; }
.panel h2 { font-size: 1.8rem; margin: 0; text-wrap: balance; }
.panel .body { padding: 18px 22px calc(28px + env(safe-area-inset-bottom, 0px)); overflow-y: auto; display: grid; gap: 18px; align-content: start; }
.close { border: 1px solid var(--line); background: transparent; color: var(--ink); border-radius: 8px; width: 38px; height: 38px; cursor: pointer; font-size: 1.2rem; align-self: start; }
.dmhero { display: grid; grid-template-columns: 120px 1fr; gap: 14px; align-items: start; }
.dmhero img { width: 120px; height: 150px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 3px; font-family: var(--f-ui); font-size: .85rem; letter-spacing: .03em; color: var(--muted); }
.form label.tog { display: flex; gap: 8px; align-items: center; color: var(--ink); cursor: pointer; }
.form label.tog input { width: auto; }
.form input, .form textarea, .form select { font: inherit; font-family: var(--f-body); font-size: .98rem; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
.form textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.acts { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { display: inline-block; font-family: var(--f-ui); letter-spacing: .04em; font-size: .98rem; border-radius: 8px; padding: 8px 14px; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; }
.btn.pri { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--iothas); border-color: var(--iothas); }
.btn:disabled { opacity: .55; cursor: wait; }
.dmsheet { font-size: .94rem; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.dmsheet summary { cursor: pointer; font-family: var(--f-ui); letter-spacing: .04em; }
.dmsheet ul { margin: 4px 0; padding-left: 20px; }
.dmtools { border-top: 1px dashed var(--warn); padding-top: 14px; }
.dmtools h3 { color: var(--warn); }

.site-footer { margin-top: 48px; padding-top: 14px; border-top: 1px solid var(--line); font-family: var(--f-ui); letter-spacing: .04em; color: var(--muted); font-size: .9rem; }
.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--surface); font-family: var(--f-ui); letter-spacing: .03em; padding: 9px 16px; border-radius: 8px; z-index: 40; max-width: calc(100% - 32px); }

@media (max-width: 760px) {
  .episode-hero, .entry-body { grid-template-columns: 1fr; }
  .entry-head .mono { width: 72px; height: 72px; font-size: 1.6rem; }
  .entry-head.with-portrait { grid-template-columns: 1fr; gap: 14px; }
  .portrait { width: min(320px, 100%); }
  .portrait.t-facción { width: 160px; }
  .ep-row { grid-template-columns: 96px 1fr; }
  .nav { margin-left: 0; width: 100%; }
  .brand { padding-bottom: 0; }
  .form .two { grid-template-columns: 1fr; }
  .dmhero { grid-template-columns: 90px 1fr; }
  .dmhero img { width: 90px; height: 112px; }
  .qrow { grid-template-columns: auto 40px 1fr; }
  .party { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .party .card { grid-template-columns: 56px 1fr; gap: 10px; }
  .party .card .mono { width: 56px; height: 70px; font-size: 1.4rem; }
  .qrow .btn { grid-column: 2 / -1; justify-self: start; }
}
@media (prefers-reduced-motion: reduce) { .card { transition: none; } }
.companions .pill { margin-left: 6px; vertical-align: 1px; }
