* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --ink: #2b2a26;
  --paper: #faf7f0;
  --card: #ffffff;
  --accent: #b23a2f;      /* rosso Roma */
  --accent-soft: #f6e3e0;
  --hl: #ffd54d;          /* evidenziazione karaoke */
  --past: #8a8377;
  --line: #e5ded2;
  --ok: #2e7d32;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.5;
}
#topbar {
  background: var(--card);
  border-bottom: 2px solid var(--line);
  padding: 14px 20px 0;
  text-align: center;
}
.brand { font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
#topbar h1 { font-size: 1.35rem; margin: 2px 0 10px; font-weight: 700; }
#stepper { display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; }
.step[hidden] { display: none; }
.step {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; padding: 6px 10px 10px; cursor: default;
  color: var(--past); font-family: inherit;
}
.step .dot {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--line); color: var(--past); font-weight: 700; font-size: .95rem;
}
.step .lbl { font-size: .72rem; }
.step.done .dot { background: var(--ok); color: #fff; }
.step.done { color: var(--ok); cursor: pointer; }
.step.cur .dot { background: var(--accent); color: #fff; }
.step.cur { color: var(--accent); font-weight: 700; }

main { max-width: 760px; margin: 0 auto; padding: 18px 16px 60px; }
.view[hidden] { display: none; }
.instr {
  background: var(--accent-soft); border-left: 4px solid var(--accent);
  padding: 12px 14px; border-radius: 8px; margin-bottom: 18px; font-size: .98rem;
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 22px; }
.card.center { text-align: center; }
.cover { margin-bottom: 18px; }
.cover img {
  display: block; width: 100%; max-height: 320px; object-fit: cover;
  border-radius: 12px; border: 1px solid var(--line);
}
.reader {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 26px 28px; font-family: Georgia, "Times New Roman", serif;
  font-size: 1.32rem; line-height: 1.7;
}
.reader p { margin-bottom: 14px; }
.reader p.dialog { padding-left: 18px; font-style: italic; }
.spk-label {
  font-style: normal; font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: .68em; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; margin-right: 8px; user-select: none;
}
.spk-c0 .spk-label { color: #b23a2f; }
.spk-c1 .spk-label { color: #1f6e6b; }
.spk-c2 .spk-label { color: #715ba0; }
.spk-c3 .spk-label { color: #a05c1f; }
.tok { border-radius: 5px; padding: 1px 2px; }
.tok.cur { background: var(--hl); }
.tok.past { color: var(--past); }
.gloss, .demo-gloss {
  text-decoration: underline dotted var(--accent) 2px;
  text-underline-offset: 4px; cursor: pointer;
}
.gloss:hover { background: var(--accent-soft); border-radius: 5px; }
.gloss.seen { text-decoration-color: var(--ok); }

.btnrow { display: flex; justify-content: center; gap: 10px; margin-top: 20px; }
.btnrow.wrap { flex-wrap: wrap; }
.btn {
  font-family: inherit; font-size: 1rem; padding: 10px 18px;
  border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--card); color: var(--ink); cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { font-size: 1.1rem; padding: 13px 24px; }
.btn.tiny { font-size: .8rem; padding: 5px 10px; margin-top: 10px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.rec-on { background: #c62828; border-color: #c62828; color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { filter: brightness(1.25); } }
.hint { font-size: .88rem; color: var(--past); margin-top: 12px; text-align: center; }
.speed { display: flex; align-items: center; gap: 6px; font-size: .95rem; }

.s3-progress { text-align: center; font-size: .85rem; color: var(--past); margin-bottom: 8px; }
.s3-speaker { text-align: center; font-weight: 700; color: var(--accent); margin-bottom: 10px; font-size: .95rem; }
.s3-sentence {
  font-family: Georgia, serif; font-size: 1.6rem; line-height: 1.7;
  text-align: center; min-height: 120px; display: flex; align-items: center; justify-content: center;
  flex-wrap: wrap; gap: 2px; padding: 10px 0;
}
.s3-sentence .tok { cursor: pointer; }
.s3-sentence .tok:hover { background: var(--accent-soft); }

.gloss-pop {
  position: fixed; z-index: 50; max-width: 320px; width: calc(100vw - 32px);
  background: var(--card); border: 2px solid var(--accent); border-radius: 14px;
  padding: 16px; box-shadow: 0 12px 32px rgba(0,0,0,.18);
}
.gloss-pop[hidden] { display: none; }
.gp-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
#gp-word { font-weight: 700; font-size: 1.15rem; color: var(--accent); }
#gp-close { background: none; border: none; font-size: 1rem; cursor: pointer; color: var(--past); }
.gp-icon { font-size: 2.6rem; text-align: center; margin: 8px 0; }
.gp-def { font-size: 1rem; }
.gp-tr { margin-top: 8px; font-size: .95rem; color: var(--past); font-style: italic; }
.endemoji { font-size: 3.2rem; margin-bottom: 8px; }

@media (max-width: 560px) {
  .reader { font-size: 1.15rem; padding: 18px; }
  .s3-sentence { font-size: 1.3rem; }
  .step .lbl { display: none; }
}

/* I controlli audio stanno SOPRA il testo e restano agganciati in alto durante
   lo scorrimento del karaoke: pausa e avvio sempre raggiungibili.
   :not([hidden]) è essenziale: senza, l'id vincerebbe su .view[hidden]
   e le sezioni non attive resterebbero visibili. */
#view-2:not([hidden]), #view-4:not([hidden]), #view-5:not([hidden]) { display: flex; flex-direction: column; }
#view-2 .instr, #view-4 .instr, #view-5 .instr { order: -2; }
#view-2 .btnrow, #view-4 .btnrow, #view-5 .btnrow,
#view-5 #s5-status { order: -1; margin-top: 0; margin-bottom: 14px; }
#view-2 .btnrow, #view-4 .btnrow, #view-5 .btnrow {
  position: sticky; top: 0; z-index: 40;
  background: var(--paper); padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

/* Tasto "Esci dalla lezione" — una volta sola, nella barra del menu */
#topbar { position: relative; }
.exit-btn {
  position: absolute; top: 12px; right: 14px;
  background: var(--card); border: 1.5px solid var(--accent); border-radius: 10px;
  color: var(--accent); font-size: .9rem; font-weight: 600; padding: 6px 14px;
  cursor: pointer; font-family: inherit;
}
.exit-btn:hover { background: var(--accent); color: #fff; }
.step.free { cursor: pointer; }
@media (max-width: 560px) { .exit-btn { top: 8px; right: 8px; padding: 3px 8px; } }

/* Tappa 6: domande di comprensione */
.qq { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 14px; }
.qq .qtext { font-weight: 700; margin-bottom: 12px; }
.opt {
  display: block; width: 100%; text-align: left; font-family: inherit; font-size: 1rem;
  background: var(--paper); border: 1.5px solid var(--line); border-radius: 10px;
  padding: 10px 14px; margin-bottom: 8px; cursor: pointer;
}
.opt:hover { border-color: var(--accent); }
.opt.sel { border-color: #5b87ad; background: #e9f2f9; font-weight: 600; }
.opt.right { border-color: var(--ok); background: #e6f2e6; font-weight: 700; }
.opt.wrong { border-color: #c62828; background: #fbe9e7; }
.opt:disabled { cursor: default; opacity: 1; }
.qwhy { font-size: .9rem; color: var(--past); margin-top: 8px; border-left: 3px solid var(--ok); padding-left: 10px; }
.quiz-result { text-align: center; font-size: 1.15rem; font-weight: 700; margin-top: 16px; }

/* Tappa 7: matching del vocabolario (PD-M1: due colonne con intestazioni,
   divisore centrale con badge ⇄, hint dinamico che guida i due click) */
.match-hint { text-align: center; font-weight: 600; color: var(--accent); margin-bottom: 14px; min-height: 1.4em; }
.match-wrap { display: flex; gap: 0; align-items: stretch; }
.match-col { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.match-head {
  text-align: center; font-size: .78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--past); padding-bottom: 2px;
}
.match-divider { display: flex; align-items: center; padding: 0 8px; }
.match-badge {
  width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 1.1rem; border: 1.5px solid var(--accent);
}
.m-item {
  display: flex; align-items: center; gap: 8px; text-align: left;
  font-family: inherit; font-size: 1rem; line-height: 1.35;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 10px;
  padding: 10px 12px; cursor: pointer;
}
.m-word { font-weight: 700; font-family: Georgia, "Times New Roman", serif; font-size: 1.08rem; }
.m-item:hover:not(:disabled) { border-color: var(--accent); }
.m-item.sel { border-color: #5b87ad; background: #e9f2f9; }
/* PD-M2: le coppie abbinate si numerano su entrambi i lati */
.m-item.ok { border-color: var(--ok); background: #e6f2e6; cursor: default; }
.m-num {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--ok); color: #fff; font-size: .8rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
/* PD-M3: errore = flash rosso */
.m-item.flash { animation: mflash .45s; }
@keyframes mflash { 0%, 60% { border-color: #c62828; background: #fbe9e7; } }
.m-item:disabled { opacity: 1; }

/* Tappa 8: memory delle flashcard (PD-G1: coppie termine/significato) */
.mem-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.mem-card {
  position: relative; min-height: 92px; border-radius: 12px; cursor: pointer;
  font-family: inherit; font-size: .95rem; line-height: 1.3; padding: 10px 8px;
  background: var(--accent); border: 1.5px solid var(--accent);
  display: flex; align-items: center; justify-content: center; text-align: center;
}
.mem-card::before {
  content: "?"; position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; font-size: 1.9rem; font-weight: 700; color: #fff;
}
.mem-card .mem-txt { visibility: hidden; }
.mem-card.rev, .mem-card.found { background: var(--card); cursor: default; }
.mem-card.rev::before, .mem-card.found::before,
.mem-card.open::before, .mem-card.okpair::before { content: none; }
.mem-card.rev .mem-txt, .mem-card.found .mem-txt { visibility: visible; }
.mem-card.rev { border-color: #5b87ad; }
.mem-card.found { border-color: var(--ok); background: #e6f2e6; }
.mem-a.rev .mem-txt, .mem-a.found .mem-txt { font-family: Georgia, "Times New Roman", serif; font-weight: 700; font-size: 1.05rem; }

/* PD-U8: layout mobile */
@media (max-width: 560px) {
  .m-item { font-size: .88rem; padding: 8px 8px; }
  .m-word { font-size: .95rem; }
  .match-divider { padding: 0 4px; }
  .match-badge { width: 26px; height: 26px; font-size: .9rem; }
  .mem-grid { grid-template-columns: repeat(3, 1fr); }
  .mem-card { min-height: 84px; font-size: .82rem; }
}

/* ---- PD-U8 · fascia del tasto «Esci» (25/08/2026) -------------------------
   .exit-btn è in position:absolute: non occupa spazio nel flusso, così il
   brand — centrato e a piena larghezza — gli finiva sotto. Rilevato in QA sul
   pilota Core Engineering B1 M1, ma NON è il difetto di un generatore: il
   blocco #topbar/.brand è identico in tutti i sorgenti, e a 375px collidevano
   TUTTI i corsi del catalogo. Soglie misurate (larghezza sotto la quale il
   brand entra nel tasto): 439px «Italiano medico B1» … 642px «English for
   Sport and Exercise Science B1».

   Due regimi, perché l'etichetta cambia molto di larghezza da lingua a lingua
   (✕ Exit 60px … ✕ Verlassen 100px) e la sola spaziatura orizzontale
   strozzerebbe il brand sui telefoni:
     · fino a 700px la barra riserva al tasto una FASCIA VERTICALE — il brand
       resta a piena larghezza e centrato, e la correzione non dipende
       dall'etichetta né dalla lingua;
     · oltre i 700px lo spazio orizzontale c'è: si tiene il testo fuori dalla
       zona del tasto conservando il centraggio. A 1280px la regola è un
       no-op (altezza e centraggio identici a prima della correzione).
   PD-U6 invariato: il tasto resta una sola volta, in alto a destra.        */
@media (max-width: 560px) { #topbar { padding-top: 42px; } }
@media (min-width: 561px) and (max-width: 700px) { #topbar { padding-top: 52px; } }
@media (min-width: 701px) { #topbar .brand, #topbar h1 { padding-left: 130px; padding-right: 130px; } }
/* ---- fine PD-U8 ---------------------------------------------------------- */

/* ==========================================================================
   MOTORE PREGHIERE v2 — TRE TAPPE (02/09/2026)
   Si appende al CSS base del motore lettura (by-syllabus/A2.1/sorgente-lettura-01).
   Vincolo PD-U8a rispettato: nessuna shorthand `padding` su #topbar .brand / h1.
   ========================================================================== */

/* --- 1. neutralizza le regole sticky del motore a cinque tappe -------------
   Là la tappa 2 era «ascolta tutto» e la sua .btnrow stava agganciata in alto.
   Qui la tappa 2 è la ripetizione frase per frase: i comandi stanno DENTRO la
   scheda della frase, e se non si spengono finiscono in cima allo schermo. */
#view-2:not([hidden]) { display: block; }
#view-2 .instr { order: 0; }
#view-2 .btnrow {
  position: static; order: 0; margin-top: 18px; margin-bottom: 0;
  background: none; padding: 0; border-bottom: none;
}

/* --- 2. fascia «che cosa puoi fare in questa tappa» (PD-L5c) --------------- */
.cando {
  background: var(--accent-soft);
  /* proprietà logiche, non «left»: in arabo la fascia è a destra e la barra
     colorata deve stare dal lato da cui si comincia a leggere */
  border-inline-start: 4px solid var(--accent);
  border-radius: 8px; padding: 12px 16px; margin-bottom: 16px; font-size: .95rem;
}
.cando-h { font-weight: 700; margin-bottom: 6px; }
.cando ul { margin: 0; padding-inline-start: 20px; }
.cando li { margin: 3px 0; }
.cando-note { margin-top: 8px; font-size: .88rem; font-style: italic; color: #8a4a42; }

/* --- 3. barra audio delle tappe 1 e 3 -------------------------------------
   Agganciata in alto sopra il testo: nella tappa 1 si ascolta seguendo con gli
   occhi, nella 3 si legge insieme alla voce — in tutti e due i casi il comando
   serve prima del testo, non dopo. */
.audiobar { background: var(--paper); padding: 10px 0 8px; }
.audiobar.at-top {
  position: sticky; top: 0; z-index: 40;
  border-bottom: 1px solid var(--line); margin-bottom: 14px;
}
.audiobar .btnrow { margin-top: 0; row-gap: 8px; }
.audiobar .btn { font-size: .95rem; padding: 8px 14px; }

/* --- 3b. PD-U14: barra di scorrimento lineare ------------------------------
   Si clicca dentro per andare avanti e indietro, si trascina la manopola, e i
   tacchetti segnano l'inizio di ogni frase. La spunta «voce più lenta» sta
   SOTTO il play: è un modo di ascoltare, quindi appartiene al pulsante che
   avvia l'ascolto (committente, 01/09/2026). */
.player {
  display: flex; align-items: flex-start; gap: 12px;
  margin-top: 4px; text-align: left;
}
.play-col { flex: none; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.play-col .play-btn { width: 100%; }
.play-col .speed { font-size: .85rem; }
.bar-line { flex: 1 1 auto; display: flex; align-items: center; gap: 12px; min-height: 42px; }
.play-btn { min-width: 132px; flex: none; }
.tnow, .ttot {
  font-size: .82rem; color: var(--past); font-variant-numeric: tabular-nums;
  flex: none; min-width: 38px;
}
.ttot { text-align: right; }
.track {
  position: relative; flex: 1 1 auto; height: 24px; cursor: pointer;
  touch-action: none; -webkit-tap-highlight-color: transparent;
}
/* PD-U14c: la riga vera è sottile, ma la zona cliccabile è alta 24 px */
.track::before {
  content: ""; position: absolute; left: 0; right: 0; top: 9px; height: 6px;
  background: var(--line); border-radius: 3px;
}
.fill {
  position: absolute; left: 0; top: 9px; height: 6px; width: 0;
  background: var(--accent); border-radius: 3px; pointer-events: none;
}
.handle {
  position: absolute; top: 4px; left: 0; width: 16px; height: 16px;
  margin-left: -8px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--card);
  box-shadow: 0 1px 4px rgba(0,0,0,.28); pointer-events: none;
}
.track:hover .handle, .track:focus-visible .handle { transform: scale(1.18); }
.track.dragging .handle { transform: scale(1.3); }
.track:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
/* PD-U14a: i tacchetti stanno SOPRA il riempimento (nel markup vengono dopo) */
.ticks { position: absolute; left: 0; right: 0; top: 9px; height: 6px; pointer-events: none; }
.ticks i {
  position: absolute; top: 0; width: 1px; height: 6px;
  background: var(--card); opacity: .9;
}
.player-extra { margin-top: 10px; }
@media (prefers-reduced-motion: reduce) { .handle { transition: none; } }

/* --- 4. tappa 2: la frase corrente e i suoi comandi ------------------------
   Anche qui la spunta «voce più lenta» sta sotto il pulsante che fa suonare la
   frase, come nelle tappe 1 e 3: una sola grammatica in tutte e tre. */
#view-2 .btnrow.wrap { align-items: flex-start; }
#view-2 .play-col { min-width: 170px; }
.s3-sentence { min-height: 96px; }
.s3-sentence .tok.cur { background: var(--hl); }
#s2-sentence .tok { cursor: pointer; }
#s2-progress { margin-bottom: 4px; }

@media (max-width: 560px) {
  .audiobar .btn { font-size: .9rem; padding: 7px 11px; }
  .cando { font-size: .9rem; }
  .player { flex-direction: column; gap: 6px; }
  .play-col { width: 100%; }
  .bar-line { width: 100%; }
  #view-2 .play-col { width: 100%; min-width: 0; }
}

/* --- Adattamento arabo (RTL) --- */
@font-face {
  font-family: "Scheherazade New";
  src: url("ScheherazadeNew-Regular.ttf") format("truetype");
  font-display: swap;
}
.reader, .s3-sentence, #gp-word {
  font-family: "Scheherazade New", "Noto Naskh Arabic", "Amiri", Georgia, serif;
}
.reader { font-size: 1.75rem; line-height: 2.3; }
.reader p.dialog { padding-left: 0; padding-right: 18px; font-style: normal; }
.reader p.dialog .spk-label { margin-right: 0; margin-left: 8px; }
.s3-sentence { font-size: 2.1rem; line-height: 2.1; }
#gp-word { font-size: 1.6rem; }
@media (max-width: 560px) {
  .reader { font-size: 1.4rem; }
  .s3-sentence { font-size: 1.6rem; }
}
