/* Three themes: the paper default, a plain white one, and the dark one.
   The dark block is written twice on purpose — once for "the system says dark
   and the reader has not chosen otherwise", once for an explicit choice — so a
   [data-theme] pick always wins over prefers-color-scheme. */
:root {
  color-scheme: light;
  --bg: #f6f1e4;
  --bg-card: #fffdf7;
  --ink: #2b2417;
  --ink-soft: #7a6b52;
  --rule: #ddd0b4;
  --accent: #8c2f21;
  --shadow: 0 1px 2px rgba(43, 36, 23, .06), 0 8px 24px rgba(43, 36, 23, .08);
}
/* Plain white: same ink, the paper tint taken out. */
:root[data-theme="white"] {
  color-scheme: light;
  --bg: #ffffff;
  --bg-card: #ffffff;
  --ink: #23201b;
  --ink-soft: #6f6a61;
  --rule: #e3e0d9;
  --accent: #8c2f21;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="paper"]):not([data-theme="white"]) {
    color-scheme: dark;
    --bg: #14110c;
    --bg-card: #1e1a13;
    --ink: #ece3d2;
    --ink-soft: #a2937a;
    --rule: #3a3226;
    --accent: #e0734f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14110c;
  --bg-card: #1e1a13;
  --ink: #ece3d2;
  --ink-soft: #a2937a;
  --rule: #3a3226;
  --accent: #e0734f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }

/* ---------- index ---------- */
.home { max-width: 46rem; margin: 0 auto; padding: 3rem 1.25rem 4rem; }
.masthead { display: flex; align-items: center; gap: 1rem; margin-bottom: 2rem; }
/* Sized to the h1's own line, so the portrait never makes the masthead taller.
   Height is explicit and overflow clipped so a failed load falls back to an
   empty circle rather than a block of alt text that reflows the whole header. */
.portrait {
  flex: none; width: clamp(2.6rem, 9vw, 3.8rem); height: clamp(2.6rem, 9vw, 3.8rem);
  overflow: hidden; object-fit: cover; object-position: 50% 18%;
  border-radius: 50%; border: 1px solid var(--rule); box-shadow: var(--shadow);
  filter: saturate(.9);
}
.home h1 { font-size: clamp(2.2rem, 8vw, 3.4rem); margin: 0; letter-spacing: .02em; line-height: 1.05; }
.home .author { color: var(--ink-soft); font-style: italic; margin: .3rem 0 0; font-size: .9rem; }
.credit { margin: 2.5rem 0 0; color: var(--ink-soft); font-size: .72rem; text-align: center; }
.resume {
  display: block; padding: .9rem 1.1rem; margin-bottom: 2rem; border-radius: .6rem;
  background: var(--accent); color: #fff; text-decoration: none; box-shadow: var(--shadow);
}
/* Without this the display above would defeat the hidden attribute, and the
   link would show even for a reader who has never opened a canto. */
.resume[hidden] { display: none; }
.resume small { display: block; opacity: .85; }
/* minmax(0,1fr) stops the grid column from sizing to the full incipit, which
   would push the row wider than the viewport instead of truncating it. */
.cantos {
  list-style: none; padding: 0; margin: 0; display: grid; gap: .75rem;
  grid-template-columns: minmax(0, 1fr);
}
.cantos li { min-width: 0; }
.cantos a {
  display: flex; align-items: baseline; gap: .9rem; padding: 1rem 1.1rem; min-width: 0;
  background: var(--bg-card); border: 1px solid var(--rule); border-radius: .6rem;
  text-decoration: none; color: inherit; box-shadow: var(--shadow);
}
.cantos a:hover { border-color: var(--accent); }
.cantos .num {
  font-size: 1.5rem; color: var(--accent); min-width: 3.2rem; flex: none;
  font-variant-caps: small-caps; letter-spacing: .04em;
}
/* The opening verse identifies the canto far better than repeating its number. */
.cantos .incipit {
  font-style: italic; color: var(--ink-soft); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cantos .meta { margin-left: auto; padding-left: .8rem; color: var(--ink-soft); font-size: .85rem; flex: none; }

/* ---------- reader ---------- */
.reader { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.bar {
  display: flex; align-items: center; gap: .75rem;
  padding: .7rem 1rem; border-bottom: 1px solid var(--rule);
  font-size: .82rem; color: var(--ink-soft); flex: none;
}
.bar a { text-decoration: none; }
.bar .mark {
  flex: none; color: var(--accent); font-size: .95rem; letter-spacing: .08em;
  font-variant-caps: small-caps; border-left: 1px solid var(--rule); padding-left: .75rem;
}
.bar .incipit {
  font-style: italic; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
@media (max-width: 30rem) { .bar .incipit { display: none; } }
.bar .pos { margin-left: auto; font-variant-numeric: tabular-nums; }
.bar button {
  font: inherit; color: inherit; background: none; cursor: pointer;
  border: 1px solid var(--rule); border-radius: .35rem; padding: .2rem .55rem;
}
.progress { height: 2px; background: var(--rule); flex: none; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.track {
  flex: 1; display: flex; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.track::-webkit-scrollbar { display: none; }
.page {
  flex: 0 0 100%; width: 100%; height: 100%; scroll-snap-align: center; scroll-snap-stop: always;
  display: flex; align-items: center; justify-content: center; padding: 1.5rem 1.25rem;
}
.estrofe {
  width: min(34rem, 100%); background: var(--bg-card); border: 1px solid var(--rule);
  border-radius: .8rem; box-shadow: var(--shadow); padding: clamp(1.4rem, 5vw, 2.4rem);
  max-height: 100%; overflow-y: auto;
}
.estrofe .n {
  font-size: .78rem; letter-spacing: .18em; color: var(--accent);
  text-transform: uppercase; margin-bottom: 1rem;
}
.estrofe p {
  margin: 0; white-space: pre-line; line-height: 1.85;
  font-size: clamp(1.02rem, 3.9vw, 1.2rem);
}
.hint { text-align: center; color: var(--ink-soft); font-size: .75rem; padding: .55rem; flex: none; }
.nav-zone {
  position: fixed; top: 3.2rem; bottom: 2.2rem; width: 18%; cursor: pointer; z-index: 2;
  border: 0; background: transparent; -webkit-tap-highlight-color: transparent;
}
.nav-zone.prev { left: 0; }
.nav-zone.next { right: 0; }
.msg { padding: 2rem 1.25rem; text-align: center; color: var(--ink-soft); }
.msg code { color: var(--ink); }

/* ---------- theme switch ---------- */
.theme {
  font: inherit; color: inherit; background: none; cursor: pointer;
  border: 1px solid var(--rule); border-radius: .35rem; padding: .2rem .55rem;
  font-size: .78rem; line-height: 1.6; white-space: nowrap;
}
.theme:hover { border-color: var(--accent); color: var(--accent); }
.bar .theme { flex: none; }
.home .theme { position: absolute; top: 1rem; right: 1.25rem; }
.home { position: relative; }
