:root {
  color-scheme: light;
  --paper: #f5f1e8;
  --ink: #171717;
  --muted: #68645d;
  --line: #d7d0c2;
  --accent: #8c1d2c;
  --panel: #fffdf8;
  --shadow: 0 22px 70px rgba(31, 25, 17, .16);
}
* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: radial-gradient(circle at 50% 0, #fffdf7, var(--paper) 48rem); font: 16px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input { font: inherit; }
button { color: inherit; }
.topbar { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right)); border-bottom: 1px solid var(--line); background: rgba(245,241,232,.92); backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 10; }
.brand { min-width: 0; display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-family: Georgia, serif; font-weight: 700; }
.brand-copy { min-width: 0; display: grid; line-height: 1.12; }
.brand-copy strong, .brand-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-copy strong { font-size: 15px; letter-spacing: .045em; }
.brand-copy small { margin-top: 3px; color: var(--muted); font: 12px system-ui, sans-serif; }
.brand-mark { flex: 0 0 auto; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; color: #fff; background: var(--accent); font: 700 14px Georgia, serif; letter-spacing: .05em; }
.header-actions, .language { display: flex; align-items: center; gap: 7px; }
.text-button, .lang-button, .close-button { border: 0; background: transparent; cursor: pointer; }
.text-button { padding: 9px 10px; }
.lang-button { min-width: 42px; padding: 8px; border-radius: 999px; color: var(--muted); font-size: 13px; font-weight: 750; }
.lang-button.active { color: #fff; background: var(--ink); }
.reader-shell { display: grid; place-items: start center; padding: clamp(14px, 3vw, 30px) 12px 36px; }
.reader { width: min(100%, 1180px); }
.stage { position: relative; width: min(100%, 720px); aspect-ratio: 2 / 3; max-height: calc(100svh - 185px); margin: 0 auto; overflow: hidden; background: #151515; box-shadow: var(--shadow); touch-action: pan-y; transition: width .2s ease, aspect-ratio .2s ease; }
.stage img, .stage video { display: none; width: 100%; height: 100%; object-fit: contain; background: #111; }
.stage img.visible, .stage video.visible { display: block; }
.loading, .missing { position: absolute; inset: 0; display: grid; place-content: center; gap: 8px; padding: 30px; text-align: center; color: #eee; background: linear-gradient(145deg, #171717, #2c2723); }
.loading[hidden], .missing[hidden] { display: none; }
.missing span { color: #bbb; font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.replay { position: absolute; right: 16px; bottom: 16px; border: 1px solid rgba(255,255,255,.5); border-radius: 999px; padding: 10px 14px; color: #fff; background: rgba(0,0,0,.66); cursor: pointer; }
.reader-controls { display: grid; grid-template-columns: 64px minmax(100px, 1fr) 64px; align-items: center; gap: 10px; width: min(100%, 420px); margin: 18px auto 0; }
.nav-button, .counter { min-height: 48px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; box-shadow: 0 5px 18px rgba(30,25,20,.06); }
.nav-button { border-radius: 50%; font: 32px/1 Georgia, serif; }
.nav-button:disabled { opacity: .25; cursor: default; }
.counter { border-radius: 999px; font-weight: 750; }
.hint { margin: 12px 0 0; color: var(--muted); text-align: center; font-size: 13px; }
.transcript { width: min(100%, 720px); margin: 18px auto 0; padding: 12px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.transcript summary { cursor: pointer; font-weight: 750; }
.transcript div { padding-top: 10px; white-space: pre-line; }
.index-dialog { width: min(calc(100% - 24px), 620px); max-height: min(84vh, 760px); border: 0; border-radius: 20px; padding: 0; color: var(--ink); background: var(--panel); box-shadow: 0 28px 100px rgba(0,0,0,.35); }
.index-dialog::backdrop { background: rgba(20,17,13,.62); backdrop-filter: blur(5px); }
.dialog-head { display: flex; justify-content: space-between; gap: 20px; padding: 24px 24px 16px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 2px 0 0; font: 700 clamp(22px,5vw,32px) Georgia,serif; }
.eyebrow { margin: 0; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.close-button { align-self: start; width: 42px; height: 42px; border-radius: 50%; background: #eee8dc; font-size: 27px; }
.resume-card { margin: 18px 24px 8px; padding: 15px 16px; border-radius: 13px; background: #eee8dc; }
.resume-card button { margin-top: 9px; border: 0; border-radius: 999px; padding: 9px 13px; color: #fff; background: var(--accent); cursor: pointer; }
.section-list { margin: 8px 0 0; padding: 0 24px; list-style: none; overflow: auto; }
.section-list button { width: 100%; display: grid; grid-template-columns: 54px 1fr; gap: 12px; padding: 15px 2px; border: 0; border-bottom: 1px solid var(--line); text-align: left; background: transparent; cursor: pointer; }
.section-page { color: var(--accent); font-weight: 800; }
.section-name { font-family: Georgia,serif; font-size: 18px; }
.jump-form { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 18px 24px 24px; }
.jump-form > div { display: flex; }
.jump-form input { width: 82px; border: 1px solid var(--line); border-radius: 9px 0 0 9px; padding: 9px; }
.jump-form button { border: 0; border-radius: 0 9px 9px 0; padding: 9px 13px; color: #fff; background: var(--ink); cursor: pointer; }
@media (max-width: 540px) {
  .topbar { min-height: 56px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand-copy { max-width: 34vw; }
  .reader-shell { padding-top: 8px; }
  .stage { max-height: calc(100svh - 165px); }
  .hint { display: none; }
  .jump-form { align-items: flex-start; flex-direction: column; }
}
@media (min-width: 541px) and (max-width: 1024px) {
  .reader-shell { padding-inline: 22px; }
  .stage { max-height: calc(100svh - 190px); }
}
@media (min-width: 1200px) {
  .stage { max-height: calc(100svh - 200px); }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

html, body {
  background: #000;
  color: #fff;
}

.topbar {
  background: #111;
  border-bottom-color: #333;
}

.brand-copy small, .hint {
  color: #bbb;
}

.nav-button, .counter {
  background: #222;
  color: #fff;
  border-color: #555;
}

/* Testata illustrata: titolo a tutta larghezza, comandi sulla riga sotto. */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.topbar { flex-direction: column; justify-content: center; gap: 2px; padding: 6px 12px 4px; }
.brand { width: 100%; justify-content: center; }
.brand-banner { display: block; max-width: 100%; width: auto; height: auto; max-height: 105px; object-fit: contain; }
.header-actions { width: 100%; justify-content: center; gap: 18px; }
@media (max-width: 540px) {
  .topbar { position: relative; padding: 4px 6px 2px; gap: 0; }
  .brand-banner { width: 100%; max-height: none; }
  .header-actions { justify-content: space-evenly; gap: 4px; }
  .text-button, .lang-button { min-height: 40px; }
}

/* Testata della storia in continuità con la vignetta; comandi sotto il contatore. */
.reader-shell { padding-top: 0; }
.story-banner { width: min(100%, 720px); margin: 0 auto; line-height: 0; }
.story-banner img { display: block; width: 100%; height: auto; }
.page-count { display: block; margin: 9px auto 0; padding: 2px 14px; border: 0; background: transparent; color: #ddd; font-size: 13px; font-weight: 700; cursor: pointer; }
.reader-controls { grid-template-columns: 48px minmax(0, 1fr) 48px; width: min(100%, 430px); gap: 7px; margin-top: 3px; }
.reader-controls .nav-button { min-height: 44px; }
.center-controls { display: grid; grid-template-columns: 1fr 1.4fr 1fr; align-items: center; min-height: 44px; border: 1px solid #555; border-radius: 999px; background: #222; overflow: hidden; }
.center-controls button { min-width: 0; min-height: 42px; padding: 4px; color: #fff; text-align: center; font-size: 12px; text-transform: uppercase; }
.center-controls .lang-button { border-radius: 999px; }
.center-controls .lang-button.active { background: #eee; color: #111; }
.center-controls .text-button { font-weight: 750; }
@media (max-width: 540px) {
  .reader-shell { padding: 0 0 28px; }
  .reader { width: 100%; }
  .story-banner { width: 100%; }
  .reader-controls { padding: 0 8px; }
  .stage { max-height: calc(100svh - 165px); }
}

/* Pulsante sovrapposto alla JPG delle sole pagine elencate in
   config.js > manualVideoPages. [hidden] lo rimuove dalle altre pagine. */
.play-video { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 2; white-space: nowrap; border: 1px solid rgba(255,255,255,.7); border-radius: 999px; padding: 12px 18px; color: #fff; background: rgba(0,0,0,.82); font-weight: 750; cursor: pointer; }
.play-video[hidden] { display: none; }

/* Tablet, iPad A16 compreso: riserva spazio per testata, numero e pulsanti.
   Applica la stessa misura in verticale e orizzontale, senza deformare le tavole. */
@media (hover: none) and (pointer: coarse) and (min-width: 541px) {
  .stage {
    max-height: max(220px, calc(100svh - 300px));
  }
}
