/* Audioguida cripta di Sant'Agnese in Agone
   Tema scuro e caldo, alto contrasto: si legge bene al buio e non abbaglia.
   Pensata per il telefono e per chi legge con fatica: nessun testo sotto i 16px,
   comandi principali da almeno 56px. Stile da guida a stampa: filetti al posto dei
   riquadri, didascalie in corsivo, l'oro solo per ciò che si tocca per ascoltare. */

:root {
  --bg: #100e0c;
  --surface: #1c1815;
  --surface-2: #26201b;
  --line: #3a3027;
  --line-strong: #4a3d2e;
  --text: #f3ead8;
  --text-soft: #d6cab2;
  --muted: #c4b69e;
  --accent: #c8a256;
  --accent-edge: #e2c78a;
  --accent-ink: #1a1408;
  --ok: #9dc08b;
  --warn: #e0a96d;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --gutter: 20px;
  --radius: 8px;
  --bar-h: 152px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

/* L'attributo hidden vince sempre, anche su elementi con display impostato. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 18px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) max(var(--gutter), env(safe-area-inset-right)) 0 max(var(--gutter), env(safe-area-inset-left));
}

h1, h2 { font-family: var(--serif); font-weight: 600; margin: 0; }
h1:focus { outline: none; }
p { margin: 0; }
img { display: block; max-width: 100%; }
svg { width: 24px; height: 24px; flex: none; }

a { color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 8px; }

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }

/* Didascalia: corsivo, come nelle guide a stampa. */
.label {
  font-family: var(--serif);
  font-style: italic;
  font-size: 19px;
  line-height: 1.3;
  color: var(--muted);
}

.badge {
  margin-top: 10px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  color: var(--warn);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  text-decoration: none;
  font-size: 17px;
  white-space: nowrap;
}
.chip svg { width: 20px; height: 20px; color: var(--muted); }

.button {
  min-height: 56px;
  padding: 0 24px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 18px;
  font-weight: 700;
}

.link-button {
  margin-top: 6px;
  padding: 10px 0;
  border: 0;
  background: none;
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--muted);
  text-underline-offset: 4px;
  font-size: 17px;
  text-align: left;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: transparent;
}
.icon-button svg { width: 32px; height: 32px; }

/* ---------- Scelta lingua ---------- */

.lang-view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 40px 0;
  text-align: center;
}
.lang-mark { font: 600 32px/1.1 var(--serif); margin: 0; }
.lang-view .label { margin-top: 6px; }
.lang-rule { width: 48px; height: 1px; margin: 28px auto; border: 0; background: var(--line-strong); }
.lang-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 28px;
  font-size: 28px;
  line-height: 1.3;
}
.lang-title span:not(:first-child) { color: var(--muted); font-size: 20px; font-weight: 400; }
.lang-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.lang-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 68px;
  padding: 0 20px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--serif);
  font-size: 26px;
  text-align: left;
}
.lang-option[aria-pressed="true"] { border-color: var(--text); }
.lang-option svg { width: 28px; height: 28px; }

/* ---------- Password d'accesso ---------- */

.gate-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.gate-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 28px;
  line-height: 1.3;
}
.gate-title svg { width: 28px; height: 28px; color: var(--muted); }
.gate-input {
  width: 100%;
  min-height: 60px;
  padding: 0 18px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 22px;
}
.gate-input::placeholder { color: var(--muted); opacity: .7; }
.gate-input:focus { outline: none; border-color: var(--accent); }
.gate-error { color: var(--warn); font-size: 18px; }

/* ---------- Home ---------- */

.home-header { padding: 16px 0 22px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.home-header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.home-title { margin-top: 14px; font-size: clamp(32px, 9.5vw, 42px); line-height: 1.1; }

.download:empty { display: none; }
.download { margin-bottom: 8px; }

/* Avvisi: un filetto colorato a sinistra, niente riquadri. */
.notice {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0 4px 18px;
  border-left: 3px solid var(--line-strong);
  color: var(--text-soft);
  font-size: 18px;
}
.notice-title { color: var(--text); font-weight: 700; font-size: 19px; display: flex; justify-content: space-between; gap: 12px; }
.notice-small { font-size: 16px; color: var(--muted); margin-top: 6px; }
.notice-ok { border-left-color: var(--ok); }
.notice-ok .notice-title { color: var(--ok); }
.notice-warn { border-left-color: var(--warn); }
.notice-warn .notice-title, .notice-warn > p { color: var(--warn); }
.notice-warn .button { align-self: flex-start; }

.progress { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: inherit; transition: width .3s ease; }
.pct { font-variant-numeric: tabular-nums; }

/* Elenco degli ambienti: foto, poi numero grande e titolo sul fondo pieno,
   così il testo resta leggibile qualunque sia la foto. */
.cards { list-style: none; margin: 0; padding: 0; }
.cards li { border-top: 1px solid var(--line); }
.cards li:last-child { border-bottom: 1px solid var(--line); }
.card {
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: baseline;
  gap: 0 14px;
  padding: 22px 0 24px;
  text-decoration: none;
}
.card-img {
  grid-column: 1 / -1;
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  margin-bottom: 16px;
  border-radius: 4px;
  background: var(--surface);
}
.card-num { font: 600 42px/1 var(--serif); font-variant-numeric: lining-nums; }
.card-text { display: grid; gap: 6px; }
.card-title { font-size: 27px; line-height: 1.15; }
.card-meta { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 17px; }
.card-meta svg { width: 20px; height: 20px; }
.card:active .card-title { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 5px; }

/* Accesso discreto all'area riservata (pannello di amministrazione). */
.home-footer { display: flex; justify-content: center; padding: 16px 0 calc(24px + env(safe-area-inset-bottom)); }
.lock-link {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%;
  color: var(--muted); opacity: .45;
}
.lock-link svg { width: 18px; height: 18px; }
.lock-link:hover, .lock-link:focus-visible { opacity: 1; }

/* ---------- Ambiente ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 calc(-1 * var(--gutter));
  padding: calc(6px + env(safe-area-inset-top)) 12px 6px 6px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar-tools { display: flex; align-items: center; gap: 8px; }
.text-size { display: flex; gap: 6px; }
.text-button {
  width: 52px;
  height: 48px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font: 600 21px/1 var(--serif);
}

.cover { margin: 16px 0 0; border-radius: 4px; overflow: hidden; aspect-ratio: 3 / 2; background: var(--surface); }
.cover img { width: 100%; height: 100%; object-fit: cover; }

.audio-missing { margin-top: 16px; }

.section-label { margin-top: 24px; }

.reading {
  --text-scale: 1;
  margin-top: 6px;
  max-width: 34em;
  font-size: calc(26px * var(--text-scale));
  line-height: 1.5;
  overflow-wrap: break-word;
  hyphens: auto;
  -webkit-hyphens: auto;
  hyphenate-limit-chars: 9 4 4;
  -webkit-hyphenate-limit-before: 4;
  -webkit-hyphenate-limit-after: 4;
}
.reading-title { font-size: 1.3em; line-height: 1.15; margin-bottom: .75em; hyphens: manual; }
.reading p { margin: 0 0 .9em; color: var(--text); transition: color .4s ease, border-color .4s ease; }
/* Con i tempi dei paragrafi: quello in lettura è pieno e segnato a sinistra. */
.reading.has-cues p { color: var(--text-soft); padding-left: 14px; border-left: 3px solid transparent; }
.reading.has-cues p.is-current { color: var(--text); border-left-color: var(--accent); }

.next-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 84px;
  margin-top: 12px;
  padding: 20px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-decoration: none;
}
.next-card > span { display: grid; gap: 4px; }
.next-title { font-family: var(--serif); font-size: 24px; line-height: 1.2; font-weight: 600; }
.next-card svg { width: 30px; height: 30px; }

/* Spazio in fondo: permette all'ultima riga di arrivare all'altezza di lettura. */
.scroll-room { height: calc(62dvh); }

.follow-chip {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-h) + 14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 6;
  min-height: 52px;
  padding: 0 22px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 18px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .45);
}
.follow-chip[hidden] { display: none; }

.player-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  padding: 10px max(var(--gutter), env(safe-area-inset-left)) calc(12px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-right));
  background: var(--surface);
  border-top: 1px solid var(--line-strong);
}
.player-bar[hidden] { display: none; }
.seek-row, .controls { max-width: 600px; margin: 0 auto; }
.seek-row { display: flex; align-items: center; gap: 12px; }
.time { font-size: 17px; color: var(--text); font-variant-numeric: tabular-nums; min-width: 46px; }
.time-total { text-align: right; }

.seek {
  --pct: 0%;
  flex: 1;
  height: 44px;
  margin: 0;
  background: transparent;
  accent-color: var(--accent);
  -webkit-appearance: none;
  appearance: none;
}
.seek::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(var(--accent), var(--accent)) 0 / var(--pct) 100% no-repeat, var(--line-strong);
}
.seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
}
.seek::-moz-range-track { height: 8px; border-radius: 999px; background: var(--line-strong); }
.seek::-moz-range-progress { height: 8px; border-radius: 999px; background: var(--accent); }
.seek::-moz-range-thumb { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); border: 3px solid var(--surface); }

.controls { display: flex; align-items: center; justify-content: center; gap: 28px; margin-top: 4px; }
.play-button {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border: 2px solid var(--accent-edge);
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
}
.play-button svg { width: 36px; height: 36px; }

/* ---------- Varie ---------- */

.toast {
  position: fixed;
  left: 50%;
  top: calc(12px + env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 20;
  width: min(92vw, 480px);
  min-height: 56px;
  padding: 14px 18px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 18px;
  text-align: center;
}
.toast[hidden] { display: none; }

.fatal { padding: 40px 0; color: var(--warn); text-align: center; }

.loading { min-height: 100dvh; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
