/* ──────────────────────────────────────────────────────────────
   Calame — liseuse, portrait 480×800
   Hiérarchie de l'écran de lecture : l'illustration domine, le texte
   vit sous elle, les deux choix sont empilés en bas à portée des
   pouces. Voir PLAN.md § Décisions de design.
   ────────────────────────────────────────────────────────────── */

.calame-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0 18px 12px;
  position: relative;
  overflow: hidden;
}

/* ── Sections ── */

.section {
  display: none;
  width: 100%;
  height: 100%;
  min-height: 0;
  flex-direction: column;
}

.section.active {
  display: flex;
}

/* ── Liste des histoires ── */

.list-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 8px;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: var(--tap-min);
  padding: 14px 18px;
  background: var(--card-bg);
  border: 1px solid var(--edge);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  width: 100%;
  font-family: var(--font-family);
  font-size: 19px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.list-item:active {
  background: var(--card-raised);
}

.list-item--new {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-accent);
  font-weight: 700;
  font-size: 21px;
  justify-content: center;
}

.list-item--new:active {
  background: var(--primary-hover);
}

.list-item-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.list-item-row .list-item--story {
  flex: 1;
}

.list-item-action {
  flex-shrink: 0;
  width: 56px;
  border: 1px solid var(--edge);
  border-radius: var(--card-radius);
  background: var(--card-raised);
  color: var(--text-secondary);
  font-family: var(--font-family);
  font-size: 20px;
  cursor: pointer;
}

.list-item-action:active {
  background: var(--edge);
}

.list-item-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.list-item-title {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item-meta {
  font-size: 14px;
  color: var(--text-secondary);
}

.list-item-status {
  flex-shrink: 0;
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 20px;
  font-weight: 700;
}

.list-item-status--active {
  background: rgba(127, 160, 122, 0.22);
  color: #4E6B4A;
}

.list-item-status--completed {
  background: var(--card-raised);
  color: var(--text-secondary);
}

/* ── Filtres de langue ── */

.filter-row {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  padding-bottom: 10px;
}

.filter-btn {
  min-height: 44px;
  padding: 8px 18px;
  border: 1px solid var(--edge);
  border-radius: 16px;
  background: var(--card-bg);
  color: var(--text-secondary);
  font-family: var(--font-family);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.filter-btn--active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-accent);
}

/* ── Choix de l'univers ──
   Grille 3×3. Les tuiles portent surtout leur icône : le libellé est
   là pour l'adulte, Noé reconnaît le dessin. */

.theme-board {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 1fr;
  gap: 12px;
  padding-bottom: 8px;
}

.theme-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--card-bg);
  border: 1px solid var(--edge);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  font-family: var(--font-family);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  padding: 6px;
  text-align: center;
}

.theme-card:active {
  background: var(--card-raised);
}

.theme-card-emoji {
  font-size: 40px;
  line-height: 1;
}

/* ── Reprendre ── */

.resume-body {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.resume-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
}

.action-btn {
  min-height: var(--tap-min);
  border: 1px solid var(--edge);
  border-radius: var(--card-radius);
  background: var(--card-bg);
  color: var(--text);
  font-family: var(--font-family);
  font-size: var(--font-size-button);
  font-weight: 700;
  cursor: pointer;
  padding: 14px 20px;
}

.action-btn:active {
  background: var(--card-raised);
}

.action-btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-accent);
}

.action-btn--primary:active {
  background: var(--primary-hover);
}

/* ── Contenus centrés (chargement, erreur) ── */

.centered-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
}

/* Illustrations de Diam's (erreur, liste vide, fin), produites le
   2026-09-21 et détourées sur fond transparent par scripts/prepare-art.py
   — elles se posent donc aussi bien sur --bg que sur --surface.

   Sans modificateur, le bloc ne réserve rien : #loading-art n'a pas
   d'illustration et l'écran de chargement ne doit pas garder un trou de
   240px. C'est aussi le mode de défaillance prévu dans PLAN.md — une
   image absente laisse l'écran compréhensible au lieu de le trouer. */
.state-art {
  width: 0;
  height: 0;
}

/* 240px est une taille souhaitée, pas un plancher : surtout PAS de
   `flex-shrink: 0` ici. L'écran de fin empile l'illustration, un texte de
   2 à 4 phrases et le badge FIN dans une `.ending-body` de hauteur fixe ;
   avec une fin longue, une illustration non compressible sort par le haut
   (mesuré à -38px) et pousse le badge dans la rangée de boutons.
   `background-size: contain` préserve le ratio quand elle rétrécit. */
.state-art--error,
.state-art--ending,
.state-art--empty,
.state-art[style*="background-image"] {
  width: 240px;
  height: 240px;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}

.state-art--error { background-image: url('../assets/mascotte/erreur.webp'); }
.state-art--ending { background-image: url('../assets/mascotte/fin.webp'); }
.state-art--empty { background-image: url('../assets/mascotte/vide.webp'); }

/* Liste vide. Le bloc est centré dans ce qui reste sous le bouton
   « Nouvelle histoire », qui demeure la seule sortie de l'écran. */
.list-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 12px 8px;
}

.list-empty-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-secondary);
  text-align: center;
}

.loading-dots {
  display: flex;
  gap: 10px;
}

.loading-dots span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  animation: pulse 1.2s ease-in-out infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.15s; }
.loading-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

.loading-text,
.error-text {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 0 12px;
}

.error-text {
  color: var(--text);
}

/* ── Lecture ── */

.reading-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  flex-shrink: 0;
}

.volume-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 18px;
  background: var(--card-raised);
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
}

.icon-btn:active {
  background: var(--edge);
}

.icon-btn--sm {
  width: 44px;
  height: 44px;
  font-size: 20px;
}

/* L'illustration domine. Le cadre garde sa hauteur même vide, pour
   qu'aucun décalage ne survienne quand l'image arrive : l'enfant vise
   déjà un bouton à ce moment-là. */
.illustration-wrap {
  flex: 1 1 auto;
  min-height: 0;
  border-radius: var(--card-radius);
  overflow: hidden;
  background: var(--card-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: breathe 3.5s ease-in-out infinite;
}

/* Dès qu'une image est là, le cadre cesse de respirer. */
.illustration-wrap:has(.illustration-img[src]) {
  animation: none;
  background: var(--card-bg);
}

@keyframes breathe {
  0%, 100% { background-color: var(--card-raised); }
  50% { background-color: var(--edge); }
}

.illustration-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 320ms ease-in;
}

.illustration-img[src] {
  opacity: 1;
}

.story-text {
  flex: 0 0 auto;
  max-height: 200px;
  overflow-y: auto;
  padding: 14px 4px 10px;
  font-size: var(--font-size-story);
  font-weight: 400;
  line-height: 1.4;
  color: var(--text);
}

.story-text--long {
  font-size: 23px;
}

.story-text--very-long {
  font-size: 20px;
  line-height: 1.35;
}

/* ── Bas d'écran ── */

.bottom-controls {
  flex-shrink: 0;
  padding-top: 8px;
}

.nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.nav-btn {
  flex: 1;
  min-height: 60px;
  border: 1px solid var(--edge);
  border-radius: var(--card-radius);
  background: var(--card-bg);
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
}

.nav-btn:active:not(:disabled) {
  background: var(--card-raised);
}

.nav-btn:disabled {
  opacity: 0.35;
}

.nav-page {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* Les deux choix sont EMPILÉS, pas côte à côte : leur largeur double,
   ils descendent à portée des pouces, et la position devient un repère
   aussi fort que la couleur — ce qui compte, le bleu et l'ambre étant
   proches en clarté. */
.choice-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.choice-btn {
  min-height: var(--tap-min);
  border: none;
  border-radius: var(--card-radius);
  font-family: var(--font-family);
  font-size: var(--font-size-button);
  font-weight: 700;
  color: var(--on-accent);
  cursor: pointer;
  padding: 12px 18px;
  transition: transform 90ms ease, opacity 200ms ease;
}

.choice-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.choice-btn--a {
  background: var(--choice-a);
}

.choice-btn--a:active:not(:disabled) {
  background: var(--choice-a-active);
}

.choice-btn--b {
  background: var(--choice-b);
}

.choice-btn--b:active:not(:disabled) {
  background: var(--choice-b-active);
}

/* Attente d'une page : le choix retenu reste marqué, l'autre s'efface.
   Le geste de l'enfant est acquitté tout de suite, alors que la page
   met 3 à 10 secondes à arriver. */
.choice-btn--chosen {
  outline: 4px solid var(--text);
  outline-offset: -4px;
}

.choice-btn--faded {
  opacity: 0.25;
}

.choice-btn:disabled {
  cursor: default;
}

/* Pendant l'attente, l'illustration de la page quittée reste affichée,
   atténuée : il n'y a jamais d'écran vide. */
.reading--waiting .illustration-wrap {
  opacity: 0.45;
  transition: opacity 260ms ease;
}

.reading--waiting .story-text {
  opacity: 0.4;
}

/* ── Fin d'histoire ──
   C'est un moment, pas une page comme les autres. */

.ending-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
}

.ending-body .story-text {
  max-height: none;
  text-align: center;
}

.ending-badge {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--text-secondary);
  border: 2px solid var(--edge);
  border-radius: 999px;
  padding: 8px 22px;
}

/* ── Batterie ── */

.battery-indicator {
  font-variant-numeric: tabular-nums;
}
