/* Yoto Studio — système visuel.
   Fond crème, aplats colorés, coins très arrondis, grandes cibles tactiles.
   Un seul thème assumé : la palette est chaude et claire, un mode sombre la
   dénaturerait. */

:root {
  color-scheme: light;

  --bg: #f5ead8;
  --surface: #ebddc5;
  --paper: #f9f4ed;
  --ink: #201e1d;
  --divider: color-mix(in srgb, #201e1d 16%, transparent);

  /* Aplats de couleur et leur encre associée, toujours utilisés par paire. */
  --sun: oklch(0.87 0.155 88);    --sun-ink: oklch(0.38 0.09 78);
  --coral: oklch(0.74 0.17 32);   --coral-ink: oklch(0.37 0.12 32);
  --berry: oklch(0.68 0.16 355);  --berry-ink: oklch(0.36 0.13 355);
  --teal: oklch(0.78 0.11 195);   --teal-ink: oklch(0.36 0.08 205);
  --grass: oklch(0.8 0.145 140);  --grass-ink: oklch(0.36 0.1 145);
  --sky: oklch(0.8 0.1 245);      --sky-ink: oklch(0.36 0.1 260);

  --neutral-100: #f9f4ed;
  --neutral-200: #eee7db;
  --neutral-300: #dcd3c4;
  --neutral-600: #82796a;
  --neutral-700: #645c50;
  --neutral-800: #474238;
  --neutral-900: #2e2b25;

  --accent: var(--coral-ink);
  --accent-soft: var(--coral);

  --font-heading: "Caprasimo", Georgia, serif;
  --font-body: "Figtree", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  --space-1: 4.4px;  --space-2: 8.8px;  --space-3: 13.2px;
  --space-4: 17.6px; --space-6: 26.4px; --space-8: 35.2px;

  --radius-md: 16px;
  --radius-lg: 28px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px color-mix(in srgb, #2e2b25 14%, transparent);
  --shadow-md: 0 3px 10px color-mix(in srgb, #2e2b25 16%, transparent);
  --shadow-lg: 0 12px 32px color-mix(in srgb, #2e2b25 22%, transparent);
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 var(--font-body);
  padding-bottom: 70px;
  overflow-x: hidden;
}

h1, h2, h3 {
  font-family: var(--font-heading);
  font-weight: 400;
  line-height: 1.12;
  letter-spacing: -0.015em;
  margin: 0 0 var(--space-2);
  text-wrap: pretty;
}
h1 { font-size: clamp(30px, 5vw, 42px); }
h2 { font-size: 23px; }
h3 { font-size: 19px; }
p { margin: 0 0 var(--space-3); }
a { color: var(--coral-ink); text-underline-offset: 3px; }
a:hover { filter: brightness(1.2); }
.muted { color: var(--neutral-700); font-size: 14px; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--coral-ink); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--sun) 60%, transparent); }

/* ── En-tête ───────────────────────────────────────────────────────────── */

header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-3);
  padding: var(--space-3) clamp(16px, 4vw, 52px);
  background: var(--sun);
  border-bottom: 5px solid var(--coral);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.brand { display: flex; align-items: center; gap: var(--space-3); margin-right: auto;
         text-decoration: none; color: inherit; }
.brand-badge {
  width: 44px; height: 44px; flex: 0 0 auto;
  border-radius: var(--radius-pill); background: var(--coral-ink);
  color: var(--neutral-100); display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
}
.brand-name { display: block; font-family: var(--font-heading); font-size: 24px; line-height: 1.05; }
.brand-tag { display: block; font-size: 12.5px; color: var(--sun-ink); }

nav { display: flex; flex-wrap: wrap; gap: var(--space-2); }
nav a {
  min-height: 44px; display: flex; align-items: center;
  padding: 0 var(--space-4); border-radius: var(--radius-pill);
  border: 2px solid var(--coral); background: var(--neutral-100);
  color: var(--coral-ink); font-weight: 700; font-size: 14.5px;
  text-decoration: none;
}
nav a:hover { filter: brightness(0.96); }
nav a[aria-current="page"] {
  background: var(--coral-ink); border-color: var(--coral-ink); color: var(--neutral-100);
}

main { max-width: 1100px; margin: 0 auto; padding: clamp(20px, 3vw, 44px) clamp(16px, 4vw, 52px); }

/* ── Blocs ─────────────────────────────────────────────────────────────── */

.panel {
  background: var(--paper);
  border-radius: calc(var(--radius-lg) * 1.15);
  padding: clamp(18px, 2.5vw, 28px);
  margin-bottom: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.panel.narrow { max-width: 460px; }

/* Bandeau d'accueil, avec ses disques décoratifs. */
.hero {
  position: relative; overflow: hidden;
  background: var(--teal); color: var(--teal-ink);
  border-radius: var(--radius-lg);
  padding: clamp(20px, 3vw, 34px);
  margin-bottom: var(--space-6);
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-4);
}
.hero::before, .hero::after {
  content: ""; position: absolute; border-radius: var(--radius-pill); opacity: .85;
}
.hero::before { right: -40px; top: -50px; width: 190px; height: 190px; background: var(--sun); }
.hero::after { right: 110px; bottom: -58px; width: 120px; height: 120px; background: var(--coral); }
/* z-index explicite : ::before et ::after sont positionnés et peints après les enfants,
   donc `position: relative` seul les laisserait passer par-dessus les boutons. */
.hero > * { position: relative; z-index: 1; }
.hero h1 { margin: 0; max-width: 13ch; }
.hero p { margin: 0 0 8px; max-width: 34ch; font-size: 15.5px; }
.hero .button { margin-left: auto; }

.alert {
  border-radius: var(--radius-lg); padding: var(--space-3) var(--space-4);
  font-size: 15px; display: flex; align-items: center; gap: var(--space-3);
  flex-wrap: wrap; margin-bottom: var(--space-4);
}
.alert.ok { background: var(--grass); color: var(--grass-ink); }
.alert.error { background: var(--coral); color: var(--coral-ink); }
.alert-text { color: var(--coral-ink); font-weight: 700; }

/* ── Contrôles ─────────────────────────────────────────────────────────── */

label { display: block; font-size: 13px; margin-bottom: 5px; color: var(--neutral-700); }

input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 16px;
  font: inherit; font-size: 15px; color: var(--ink);
  background: var(--surface);
  border: 2px solid transparent; border-radius: var(--radius-pill);
  margin-bottom: var(--space-4);
}
input:hover, select:hover { border-color: var(--coral); }
input:focus-visible, select:focus-visible { border-color: var(--coral-ink); outline-offset: 0; }
input[type="file"] { padding: 10px 14px; border-radius: var(--radius-md); }
select { appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--neutral-700) 50%),
                    linear-gradient(135deg, var(--neutral-700) 50%, transparent 50%);
  background-position: calc(100% - 21px) 21px, calc(100% - 16px) 21px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
  padding-right: 44px; }

button, .button {
  font: inherit; font-family: var(--font-body); font-weight: 700; font-size: 15px;
  min-height: 50px; padding: 0 var(--space-6);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--neutral-900); color: var(--neutral-100);
  border: none; border-radius: var(--radius-pill);
  cursor: pointer; text-decoration: none;
}
button:hover, .button:hover { background: var(--coral-ink); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:disabled:hover { background: var(--neutral-900); }

button.link {
  min-height: 44px; padding: 0 var(--space-3);
  background: transparent; color: var(--coral-ink);
  font-weight: 700; font-size: 14px; text-decoration: underline;
}
button.link:hover { background: color-mix(in srgb, var(--coral) 30%, transparent); }

form.inline { display: inline-flex; gap: var(--space-2); align-items: center; margin: 0;
              flex-wrap: wrap; }
form.inline input, form.inline select { margin: 0; width: auto; min-width: 190px; }

progress {
  width: 100%; height: 14px; margin-top: var(--space-2);
  border: none; border-radius: var(--radius-pill); overflow: hidden;
  background: var(--surface); accent-color: var(--coral-ink);
}
progress::-webkit-progress-bar { background: var(--surface); border-radius: var(--radius-pill); }
progress::-webkit-progress-value { background: var(--coral-ink); border-radius: var(--radius-pill); }
progress::-moz-progress-bar { background: var(--coral-ink); border-radius: var(--radius-pill); }

/* ── Onglets ───────────────────────────────────────────────────────────── */

.tabs { margin: var(--space-4) 0 var(--space-2); }
.tablist {
  display: inline-flex; gap: 6px; padding: 5px; margin-bottom: var(--space-4);
  background: var(--surface); border-radius: var(--radius-pill);
}
.tablist [role="tab"] {
  min-height: 44px; padding: 0 var(--space-4);
  background: transparent; color: var(--neutral-800);
  font-size: 14.5px; border-radius: var(--radius-pill);
}
.tablist [role="tab"]:hover { background: var(--neutral-200); }
.tablist [role="tab"][aria-selected="true"] { background: var(--coral-ink); color: var(--neutral-100); }
.tabs:not(.is-enhanced) .tablist { display: none; }
.tabs:not(.is-enhanced) .tabpanel + .tabpanel { margin-top: var(--space-6); }
.tabpanel > p.muted:last-child { margin-bottom: 0; }

/* ── Tableaux ──────────────────────────────────────────────────────────── */

/* La première colonne absorbe l'espace disponible, les autres restent compactes et
   se calent à droite : sans ça les cellules se tassent à gauche et laissent un vide. */
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th, td { white-space: nowrap; }
/* Une part généreuse pour le titre, sans lui donner tout : la mise en page automatique
   répartit ensuite le reste entre les colonnes, au lieu de les tasser à gauche. */
th:first-child, td:first-child { width: 30%; white-space: normal; }
th:last-child, td:last-child { text-align: right; padding-right: 0; }
th:last-child form, td:last-child form { justify-content: flex-end; }
/* Dans une cellule, le formulaire ne doit pas se casser sur deux lignes : la mise en page
   automatique du tableau lui accordera la largeur nécessaire s'il refuse de se replier. */
td form.inline { flex-wrap: nowrap; }
td form.inline input { min-width: 0; width: 19ch; }
th {
  text-align: left; font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  font-weight: 700; color: var(--neutral-700);
  padding: 0 var(--space-3) var(--space-2) 0; border-bottom: 1px solid var(--divider);
}
td {
  padding: var(--space-3) var(--space-3) var(--space-3) 0;
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 8%, transparent);
  vertical-align: middle;
}
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--ink) 4%, transparent); }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
  background: var(--surface); padding: 3px 9px; border-radius: var(--radius-pill);
}

/* ── Bouton en cours de traitement ─────────────────────────────────────── */

button.is-busy { position: relative; padding-left: 46px; opacity: .9; cursor: progress; }
button.is-busy::before {
  content: ""; position: absolute; left: 20px; top: 50%;
  width: 14px; height: 14px; margin-top: -7px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--neutral-100) 35%, transparent);
  border-top-color: var(--neutral-100);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { button.is-busy::before { animation-duration: 2.4s; } }

/* ── Grille des cartes ─────────────────────────────────────────────────── */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(256px, 1fr));
  gap: var(--space-4);
}

.story-card {
  display: flex; flex-direction: column; gap: var(--space-3);
  background: var(--fill); color: var(--fill-ink);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.story-card:hover { box-shadow: var(--shadow-md); }

.story-head { display: flex; align-items: center; gap: var(--space-3); }
.story-title {
  font-family: var(--font-heading); font-size: 20px; line-height: 1.15;
  color: inherit; text-decoration: none; text-wrap: pretty;
}
.story-title:hover { text-decoration: underline; }
.story-meta { font-size: 13.5px; opacity: .78; margin-top: 4px; }

/* Vignette : 64 pixels sur fond sombre, comme l'écran du lecteur. */
.icon-tile {
  width: 72px; height: 72px; flex: 0 0 auto;
  border-radius: var(--radius-md); background: var(--neutral-900);
  padding: 6px; display: grid;
  grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); gap: 1px;
  box-shadow: var(--shadow-sm);
}
.icon-tile span { border-radius: 2px; }

.story-status { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.chip {
  font-size: 12.5px; font-weight: 700;
  padding: 4px 12px; border-radius: var(--radius-pill);
  background: var(--fill-ink); color: var(--neutral-100);
}
.chip.pale { background: var(--neutral-100); color: var(--neutral-800); }
.story-when { font-size: 13px; opacity: .75; }

.story-actions { display: flex; gap: var(--space-2); margin-top: auto; }
.story-actions .button { flex: 1; min-height: 46px; padding: 0 var(--space-4); }
.story-actions .btn-round { flex: 0 0 auto; }
.btn-round {
  width: 46px; height: 46px; flex: 0 0 auto; padding: 0; min-height: 0;
  border-radius: var(--radius-pill);
  border: 2px solid var(--neutral-900); background: transparent; color: var(--neutral-900);
}
.btn-round:hover { background: var(--neutral-900); color: var(--neutral-100); }
a.btn-round { display: grid; place-items: center; }

/* Tuile d'ajout, volontairement en pointillés : ce n'est pas encore une carte. */
.new-card {
  min-height: 196px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: var(--space-2);
  border: 4px dashed var(--coral); border-radius: var(--radius-lg);
  background: var(--neutral-100); color: var(--coral-ink);
  font-family: var(--font-heading); font-size: 19px; text-decoration: none;
}
.new-card:hover { background: var(--sun); border-color: var(--coral-ink); }
.new-card span {
  width: 56px; height: 56px; border-radius: var(--radius-pill);
  background: var(--coral); color: var(--neutral-100);
  display: grid; place-items: center;
}

/* ── Émulateur de lecteur ──────────────────────────────────────────────── */

.back {
  display: inline-block; margin-bottom: var(--space-3);
  font-weight: 700; font-size: 14px; text-decoration: none;
}
.back:hover { text-decoration: underline; }

.player-layout {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(272px, 1fr));
  gap: clamp(22px, 3vw, 46px); align-items: start;
}

/* Le boîtier : coins très ronds, écran sombre, deux molettes. */
.player-body {
  width: min(330px, 84vw); margin: 0 auto;
  display: flex; flex-direction: column; gap: 18px;
  background: var(--berry); border: 5px solid var(--berry-ink);
  border-radius: 46px; padding: 24px;
  box-shadow: var(--shadow-lg);
}
.player-screen {
  aspect-ratio: 1; border-radius: 24px; background: var(--neutral-900); padding: 16px;
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  gap: 3px;
}
.player-screen span { border-radius: 3px; }
.player-screen.is-playing { animation: pl-glow 2.4s ease-in-out infinite; }
@keyframes pl-glow {
  0%, 100% { box-shadow: inset 0 0 0 0 transparent; }
  50% { box-shadow: inset 0 0 32px color-mix(in srgb, var(--sun) 30%, transparent); }
}

.player-bar { display: flex; align-items: center; gap: 14px; }
.player-knob {
  width: 28px; height: 28px; flex: 0 0 auto;
  border-radius: var(--radius-pill); background: var(--sun);
}
.player-track {
  flex: 1; height: 12px; border-radius: var(--radius-pill);
  background: var(--berry-ink); overflow: hidden; cursor: pointer;
}
.player-track span {
  display: block; height: 100%; width: 0;
  background: var(--neutral-100); border-radius: var(--radius-pill);
}
.player-now {
  text-align: center; font-weight: 700; font-size: 14px;
  color: var(--berry-ink); min-height: 20px;
}

/* Liste des pistes */
.pl-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.pl-track {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 10px 14px; border-radius: var(--radius-lg); background: var(--surface);
}
.pl-track.is-current { background: var(--sun); }
.pl-play {
  width: 44px; height: 44px; min-height: 0; flex: 0 0 auto; padding: 0;
  border-radius: var(--radius-pill); background: var(--neutral-900); color: var(--neutral-100);
  display: grid; place-items: center;
}
.pl-play .pl-num { font-size: 14px; }
.pl-play .pl-glyph { display: none; font-size: 13px; }
.pl-track:hover .pl-play:not(:disabled) .pl-num,
.pl-track.is-current .pl-play .pl-num { display: none; }
.pl-track:hover .pl-play:not(:disabled) .pl-glyph,
.pl-track.is-current .pl-play .pl-glyph { display: block; }
.pl-name { flex: 1; min-width: 0; font-weight: 700; font-size: 15.5px; }
.pl-dur { font-size: 13.5px; color: var(--neutral-700); }

/* ── Zone de suppression ───────────────────────────────────────────────── */

/* Discrète par défaut : l'action est rare et irréversible, elle ne doit pas
   attirer l'œil autant que le reste de la page. */
.panel.danger { background: transparent; box-shadow: none; border: 2px dashed var(--divider); }
.panel.danger h2 { font-size: 19px; }
button.danger { background: transparent; color: var(--coral-ink); border: 2px solid var(--coral); }
button.danger:hover { background: var(--coral-ink); color: var(--neutral-100); border-color: var(--coral-ink); }

/* Case à cocher d'une action destructive : lisible, avec une vraie cible tactile. */
.check {
  display: flex; align-items: flex-start; gap: var(--space-3);
  margin-bottom: var(--space-4); padding: var(--space-3) var(--space-4);
  background: color-mix(in srgb, var(--coral) 22%, transparent);
  border-radius: var(--radius-lg);
  font-size: 14px; line-height: 1.5; color: var(--ink); cursor: pointer;
}
.check input {
  width: 22px; height: 22px; min-height: 0; flex: 0 0 auto; margin: 1px 0 0;
  accent-color: var(--coral-ink); cursor: pointer;
}
.check code { background: color-mix(in srgb, var(--neutral-100) 70%, transparent); }

/* ── Studio d'enregistrement ───────────────────────────────────────────── */

.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--space-4); }

textarea {
  border-radius: var(--radius-lg); resize: vertical; line-height: 1.55;
  min-height: 110px; padding: var(--space-4);
}

.chapters { list-style: none; margin: 0 0 var(--space-6); padding: 0;
            display: flex; flex-direction: column; gap: var(--space-4); }

.chapter {
  background: var(--paper); border-radius: calc(var(--radius-lg) * 1.15);
  padding: clamp(18px, 2.5vw, 26px); box-shadow: var(--shadow-sm);
}
.chapter[data-recorded="1"] { background: color-mix(in srgb, var(--grass) 28%, var(--paper)); }

.chapter-head { display: flex; align-items: baseline; gap: var(--space-3); flex-wrap: wrap; }
.chapter-head h2 { margin: 0; font-size: 21px; }
.chapter-state { font-size: 13px; color: var(--neutral-700); margin-left: auto; }

/* Le texte est là pour être lu à voix haute : plus grand, plus aéré que du texte d'interface. */
.chapter-text {
  margin: var(--space-3) 0 var(--space-4);
  font-size: 17px; line-height: 1.75; white-space: pre-wrap;
  max-width: 62ch;
}

.chapter-actions { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.chapter-actions button { min-width: 172px; }
.rec-start.is-recording { background: var(--coral-ink); }
.rec-start.is-recording::after {
  content: ""; width: 10px; height: 10px; border-radius: var(--radius-pill);
  background: var(--neutral-100); animation: rec-pulse 1.1s ease-in-out infinite;
}
@keyframes rec-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .rec-start.is-recording::after { animation: none; } }

.rec-timer {
  font-family: ui-monospace, Menlo, monospace; font-size: 17px; font-weight: 700;
  color: var(--coral-ink); min-width: 52px;
}
.rec-preview { height: 40px; max-width: 260px; flex: 1; }

.hero-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-left: auto; }
.button.ghost {
  background: transparent; color: var(--teal-ink); border: 2px solid var(--teal-ink);
}
.button.ghost:hover { background: var(--teal-ink); color: var(--neutral-100); }

/* Déconnexion de l'application : présente en permanence, mais sans concurrencer la navigation. */
.logout { margin: 0; }
.logout button {
  width: 44px; height: 44px; min-height: 0; padding: 0;
  border-radius: var(--radius-pill); border: 2px solid transparent;
  background: transparent; color: var(--sun-ink);
}
.logout button:hover { background: var(--coral-ink); color: var(--neutral-100); }

/* Écran de connexion : rien d'autre à l'écran, la mire se place au centre.
   La hauteur retranchée correspond à l'en-tête et au rembourrage bas du corps. */
main.centered {
  display: grid; place-items: center;
  min-height: 100vh; padding-block: var(--space-6);
}
main.centered .panel { width: 100%; margin: 0 0 70px; text-align: center; }
main.centered .brand-badge {
  margin: 0 auto var(--space-3); width: 56px; height: 56px;
}
main.centered .panel label { text-align: left; }
main.centered .panel button { width: 100%; }

/* ── Page de présentation ──────────────────────────────────────────────── */

.landing { max-width: 1100px; margin: 0 auto; padding: clamp(24px, 4vw, 56px) clamp(16px, 4vw, 52px); }
.landing .hero { align-items: center; }
.landing .hero h1 { font-size: clamp(38px, 7vw, 62px); max-width: none; }
.landing .hero p { max-width: 40ch; }
.landing .story-card h2 { margin: 0 0 var(--space-2); font-size: 22px; }
.landing .story-card p { font-size: 14.5px; line-height: 1.6; }
.landing-note { margin-top: var(--space-8); text-align: center; }

/* La page publique n'a pas d'en-tête : elle se cale en haut, pas au centre. */
main.centered:has(.landing) { min-height: 0; align-items: start; }
