/* Hkayti — système de design v1 (hkayti_docs/14-design-system.md, fiche « Hkayti_Design_System_v1.pdf »).
   Toutes les valeurs viennent des tokens : couleurs, typographie, grille de 4 dp, rayons, élévations, animations. */

/* --- Polices (OFL, intégrées pour fonctionner hors connexion) ------------------------------ */
@font-face { font-family: "Baloo 2"; font-weight: 600; font-display: swap; src: url("../fonts/baloo-2-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Baloo 2"; font-weight: 700; font-display: swap; src: url("../fonts/baloo-2-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Nunito Sans"; font-weight: 400; font-display: swap; src: url("../fonts/nunito-sans-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Nunito Sans"; font-weight: 700; font-display: swap; src: url("../fonts/nunito-sans-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Baloo Bhaijaan 2"; font-weight: 700; font-display: swap; src: url("../fonts/baloo-bhaijaan-2-arabic-700-normal.woff2") format("woff2"); unicode-range: U+0600-06FF; }

/* --- Tokens --------------------------------------------------------------------------------- */
:root {
  /* Couleurs */
  --night: #11182E;
  --indigo: #252B4A;
  --indigo-hover: #2E355A;
  --slate: #273047;
  --slate-disabled: #41475B;
  --gold: #F2D58A;
  --gold-pressed: #E3C574;
  --lavender: #C9B9F0;
  --ivory: #F8F4E9;
  --muted: #B8BED2;
  --success: #77CDA0;
  --error: #E78A9B;
  --error-pressed: #D97A8C;
  --border: rgba(201, 185, 240, .22);

  /* Typographie */
  --font-title: "Baloo 2", "Nunito Sans", system-ui, sans-serif;
  --font-body: "Nunito Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-arabic: "Baloo Bhaijaan 2", "Baloo 2", sans-serif;

  /* Grille de 4 dp */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 20px; --space-6: 24px;
  --space-8: 32px; --space-10: 40px; --space-12: 48px; --space-16: 64px;
  --screen-margin: 20px;
  --card-padding: 16px;
  --control: 48px;

  /* Rayons */
  --radius-sm: 8px; --radius-md: 12px; --radius-lg: 20px; --radius-xl: 28px; --radius-pill: 999px;

  /* Élévations : discrètes, la séparation vient d'abord des couleurs et des bordures */
  --elev-1: 0 2px 6px rgba(0, 0, 0, .18);
  --elev-2: 0 4px 12px rgba(0, 0, 0, .24);
  --elev-3: 0 8px 24px rgba(0, 0, 0, .32);

  /* Animations */
  --dur-press: 120ms; --dur-screen: 220ms; --dur-appear: 400ms; --dur-breathe: 3000ms;
  --ease: cubic-bezier(.2, 0, 0, 1);
}

/* --- Base ----------------------------------------------------------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  background: var(--night); color: var(--ivory);
  font: 400 16px/24px var(--font-body);
  -webkit-font-smoothing: antialiased;
}
main { max-width: 480px; margin: 0 auto; padding: var(--space-4) var(--screen-margin) var(--space-12); }
section { animation: appear var(--dur-screen) var(--ease); }
@keyframes appear { from { opacity: 0; } to { opacity: 1; } }
[hidden] { display: none !important; }

h1, h2, h3 { font-family: var(--font-title); margin: 0; color: var(--ivory); }
.display { font: 700 32px/40px var(--font-title); }
h1, .h1 { font: 700 28px/36px var(--font-title); }
h2, .h2 { font: 700 24px/32px var(--font-title); }
h3, .h3 { font: 600 20px/28px var(--font-title); }
p { margin: 0; }
.caption { font-size: 14px; line-height: 20px; color: var(--muted); }
.muted { color: var(--muted); }
.gold { color: var(--gold); }
.stack > * + * { margin-top: var(--space-4); }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: var(--space-8) 0 var(--space-3); }
img, svg { display: block; max-width: 100%; }

:focus-visible { outline: 2px solid var(--lavender); outline-offset: 2px; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }

/* --- Boutons -------------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--control); padding: 0 var(--space-6); border-radius: var(--radius-pill);
  font: 700 16px/20px var(--font-body); transition: background var(--dur-press) var(--ease), transform var(--dur-press) var(--ease);
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn-primary { width: 100%; min-height: 52px; background: var(--gold); color: var(--night); }
.btn-primary:active:not(:disabled) { background: var(--gold-pressed); }
.btn-primary:disabled { background: var(--slate-disabled); color: var(--muted); }
.btn-secondary { background: transparent; color: var(--ivory); border: 1.5px solid var(--lavender); }
.btn-secondary:active:not(:disabled) { background: var(--indigo-hover); }
.btn-secondary:disabled { opacity: .5; }
.btn-secondary[aria-pressed="true"] { background: var(--lavender); color: var(--night); }
.btn-danger { background: var(--error); color: var(--night); }
.btn-danger:active { background: var(--error-pressed); }
.btn-block { width: 100%; }
.btn-small { min-height: 40px; padding: 0 var(--space-4); font-size: 14px; }
.link { color: var(--gold); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; min-height: var(--control); }

.icon-btn {
  width: var(--control); height: var(--control); border-radius: 50%; flex: none;
  display: grid; place-items: center; color: var(--ivory);
}
.icon-btn:active { background: var(--indigo); }
.icon-btn svg { width: 24px; height: 24px; }

/* Barre du haut : retour + titre */
.topbar { display: flex; align-items: center; gap: var(--space-2); min-height: 56px; margin: 0 calc(-1 * var(--space-3)) var(--space-4); }
.topbar h1 { font-size: 22px; line-height: 28px; flex: 1; }

/* --- Champs --------------------------------------------------------------------------------- */
.field { display: block; margin-bottom: var(--space-4); }
.field > .label { display: block; font-size: 14px; line-height: 20px; color: var(--muted); margin-bottom: var(--space-2); }
.input {
  display: flex; align-items: center; gap: var(--space-3); min-height: 52px; padding: 0 var(--space-4);
  background: var(--slate); border: 1.5px solid var(--border); border-radius: var(--radius-md);
  transition: border-color var(--dur-press) var(--ease);
}
.input:focus-within { border: 2px solid var(--lavender); }
.input.invalid { border-color: var(--error); }
.input svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.input input { flex: 1; min-width: 0; height: 48px; background: none; border: 0; outline: none; color: var(--ivory); font: inherit; }
.input input::placeholder { color: var(--muted); opacity: .7; }
.field-error { color: var(--error); font-size: 14px; line-height: 20px; margin-top: var(--space-2); }

.check { display: flex; gap: var(--space-3); align-items: flex-start; min-height: var(--control); padding: var(--space-2) 0; cursor: pointer; }
.check input { appearance: none; width: 24px; height: 24px; flex: none; margin: 0; border: 2px solid var(--lavender); border-radius: 6px; display: grid; place-items: center; }
.check input:checked { background: var(--gold); border-color: var(--gold); }
.check input:checked::after { content: ""; width: 12px; height: 6px; border: 2.5px solid var(--night); border-top: 0; border-right: 0; transform: translateY(-2px) rotate(-45deg); }
.check input:focus-visible { outline: 2px solid var(--lavender); outline-offset: 3px; }

/* Sélecteur segmenté (âge…) */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: var(--space-2); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; align-items: center; justify-content: center; min-height: var(--control); border-radius: var(--radius-pill);
  background: var(--slate); color: var(--ivory); font-weight: 700; cursor: pointer; border: 1.5px solid transparent;
}
.segmented input:checked + span { background: var(--gold); color: var(--night); }
.segmented input:focus-visible + span { outline: 2px solid var(--lavender); outline-offset: 2px; }

.error-text { color: var(--error); margin: var(--space-2) 0 var(--space-4); }

/* --- Cartes --------------------------------------------------------------------------------- */
.card { background: var(--indigo); border-radius: var(--radius-lg); border: 1.5px solid var(--border); box-shadow: var(--elev-1); }
button.card { text-align: left; transition: background var(--dur-press) var(--ease); width: 100%; }
button.card:active { background: var(--indigo-hover); }
.card.selected, .card[aria-pressed="true"] { border: 2px solid var(--gold); }

/* Carte d'histoire */
.story-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.story-card { overflow: hidden; display: flex; flex-direction: column; }
.story-card .cover { aspect-ratio: 4 / 3; width: 100%; object-fit: cover; background: var(--slate); }
.story-card .body { padding: var(--space-3) var(--space-3) var(--space-4); }
.story-card .title { font: 700 15px/20px var(--font-body); color: var(--ivory); }
.story-card .meta { font-size: 13px; line-height: 18px; color: var(--muted); margin-top: var(--space-1); }

/* Reprendre */
.resume-card { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); }
.resume-card .cover { width: 88px; height: 66px; border-radius: var(--radius-md); object-fit: cover; flex: none; }
.resume-card .info { flex: 1; min-width: 0; }
.resume-card .title { font-weight: 700; line-height: 20px; }
.resume-card .meta { font-size: 13px; color: var(--muted); margin: 2px 0 var(--space-2); }
.resume-card .play-mini { width: 44px; height: 44px; border-radius: 50%; background: var(--gold); color: var(--night); display: grid; place-items: center; flex: none; }
.resume-card .play-mini svg { width: 18px; height: 18px; margin-left: 2px; }
.track { height: 6px; border-radius: 3px; background: var(--slate); overflow: hidden; }
.track > div { height: 100%; background: var(--lavender); border-radius: 3px; }

/* Carrousel des favoris */
.carousel { display: flex; gap: var(--space-3); overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 calc(-1 * var(--screen-margin)); padding: 0 var(--screen-margin) var(--space-2); scrollbar-width: none; }
.carousel::-webkit-scrollbar { display: none; }
.carousel .tile { flex: none; width: 108px; scroll-snap-align: start; border-radius: var(--radius-md); overflow: hidden; border: 1.5px solid var(--border); }
.carousel .tile img { aspect-ratio: 1; width: 100%; object-fit: cover; }

/* Premium */
.premium-card { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-4); margin-top: var(--space-6); border: 1.5px dashed rgba(242, 213, 138, .55); }
.premium-card .crown { width: 52px; height: 52px; border-radius: 50%; background: var(--night); display: grid; place-items: center; flex: none; color: var(--gold); }
.premium-card .crown svg { width: 28px; height: 28px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .08em; background: var(--gold); color: var(--night); border-radius: var(--radius-pill); padding: 1px 10px; }
.premium-card .title { font: 700 16px/22px var(--font-body); margin: var(--space-1) 0 2px; }
.premium-card:disabled { opacity: .85; }

/* --- Avatars & profils ---------------------------------------------------------------------- */
.avatar { display: block; border-radius: 50%; overflow: hidden; flex: none; background: var(--slate); }
.avatar svg { width: 100%; height: 100%; }
.avatar-64 { width: 64px; height: 64px; } .avatar-40 { width: 40px; height: 40px; } .avatar-96 { width: 96px; height: 96px; }

.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.profile-card { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); padding: var(--space-5) var(--space-3); }
.profile-card .name { font: 700 18px/24px var(--font-title); }
.profile-card .age { font-size: 14px; color: var(--muted); }

.avatar-picker { display: flex; gap: var(--space-2); justify-content: center; flex-wrap: wrap; margin: var(--space-3) 0 var(--space-6); }
.avatar-picker label { position: relative; }
.avatar-picker input { position: absolute; opacity: 0; pointer-events: none; }
.avatar-picker .avatar { width: 44px; height: 44px; border: 2px solid transparent; cursor: pointer; }
.avatar-picker input:checked + .avatar { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(242, 213, 138, .25); }
.avatar-picker input:focus-visible + .avatar { outline: 2px solid var(--lavender); outline-offset: 2px; }
.avatar-hero { display: flex; justify-content: center; }

/* Cartes de voix : dimensions identiques */
.voice-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }
.voice-card { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-2); padding: var(--space-3) var(--space-2); cursor: pointer; position: relative; }
.voice-card input { position: absolute; opacity: 0; pointer-events: none; }
.voice-card:has(input:checked) { border: 2px solid var(--gold); }
.voice-card:has(input:focus-visible) { outline: 2px solid var(--lavender); outline-offset: 2px; }
.voice-card .portrait { width: 52px; height: 52px; }
.voice-card .name { font-weight: 700; font-size: 14px; line-height: 18px; }
.voice-card .desc { font-size: 12px; line-height: 16px; color: var(--muted); flex: 1; }
.voice-card .listen { min-height: 36px; padding: 0 var(--space-3); font-size: 12px; border-width: 1px; }
.voice-card .check-mark { position: absolute; top: 6px; right: 6px; width: 18px; height: 18px; border-radius: 50%; background: var(--gold); color: var(--night); display: none; place-items: center; }
.voice-card:has(input:checked) .check-mark { display: grid; }
.voice-card .check-mark svg { width: 12px; height: 12px; }

/* --- En-tête de l'accueil --------------------------------------------------------------------- */
.home-header { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-2); }
.home-header .who { flex: 1; min-width: 0; }
.home-header .avatar-btn { border-radius: 50%; }
.pill-small { display: inline-flex; align-items: center; min-height: 32px; padding: 0 var(--space-3); margin-top: var(--space-1); border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--indigo); font-size: 13px; color: var(--muted); }

/* --- Connexion -------------------------------------------------------------------------------- */
.auth-hero { text-align: center; margin: calc(-1 * var(--space-4)) calc(-1 * var(--screen-margin)) 0; }
.auth-hero img { width: 100%; max-height: 190px; object-fit: cover; }
.logo { font: 700 52px/52px var(--font-title); color: var(--gold); letter-spacing: -.01em; margin-top: var(--space-2); }
.logo-ar { font: 700 26px/34px var(--font-arabic); color: var(--gold); opacity: .9; }
.tagline { color: var(--ivory); margin: var(--space-2) 0 var(--space-6); }
.auth-town { margin: var(--space-8) calc(-1 * var(--screen-margin)) calc(-1 * var(--space-12)); opacity: .9; }
.privacy { font-size: 13px; line-height: 18px; color: var(--muted); text-align: center; margin-top: var(--space-4); }
.center { text-align: center; }

/* --- Lecteur (l'écran le plus sombre) ------------------------------------------------------- */
#view-play { margin: calc(-1 * var(--space-4)) calc(-1 * var(--screen-margin)) 0; padding: 0 var(--screen-margin); background: linear-gradient(#0C1122, var(--night) 60%); min-height: 100dvh; }
.player-cover { margin: 0 calc(-1 * var(--screen-margin)); height: 35vh; min-height: 200px; max-height: 320px; position: relative; }
.player-cover img { width: 100%; height: 100%; object-fit: cover; }
.player-cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 55%, #0C1122); }
.player-cover .topbar { position: absolute; top: 0; left: 0; right: 0; margin: 0; padding: var(--space-2) var(--space-2); z-index: 1; }
.player-cover .topbar .icon-btn { background: rgba(17, 24, 46, .55); }
.player-head { text-align: center; margin-top: var(--space-2); }
.player-head h1 { font-size: 26px; line-height: 32px; }
.player-head .meta { font-size: 14px; color: var(--muted); margin-top: var(--space-1); }
.phase { min-height: 24px; margin-top: var(--space-3); color: var(--lavender); font-style: italic; text-align: center; }

.play-btn {
  width: 80px; height: 80px; border-radius: 50%; margin: var(--space-4) auto 0;
  display: grid; place-items: center; background: var(--gold); color: var(--night); box-shadow: var(--elev-2);
  transition: background var(--dur-press) var(--ease), transform var(--dur-press) var(--ease);
}
.play-btn:active { background: var(--gold-pressed); transform: scale(.97); }
.play-btn:focus-visible { outline: 3px solid var(--lavender); outline-offset: 4px; }
.play-btn svg { width: 34px; height: 34px; }
.play-btn #icon-play { margin-left: 4px; }

.progress { position: relative; height: 6px; margin: var(--space-6) 0 var(--space-2); border-radius: 3px; background: var(--slate); }
.progress #bar { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--lavender); border-radius: 3px; }
.progress #bar::after { content: ""; position: absolute; right: -7px; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 50%; background: var(--lavender); }
.progress.pre-roll { animation: breathe var(--dur-breathe) ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .55; } }
.times { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }

.player-actions { display: flex; justify-content: center; gap: var(--space-8); margin-top: var(--space-6); }
.round-action { display: flex; flex-direction: column; align-items: center; gap: var(--space-1); min-width: 64px; }
.round-action .ring {
  width: 52px; height: 52px; border-radius: 50%; border: 1.5px solid var(--border); background: var(--indigo);
  display: grid; place-items: center; color: var(--ivory); transition: background var(--dur-press) var(--ease);
}
.round-action .ring svg { width: 22px; height: 22px; }
.round-action:active .ring { background: var(--indigo-hover); }
.round-action[aria-pressed="true"] .ring { border-color: var(--gold); color: var(--gold); }
.round-action .label { font-size: 13px; line-height: 16px; }
.round-action .action-state { font-size: 12px; line-height: 16px; color: var(--lavender); min-height: 16px; }

.read-text { text-align: center; margin-top: var(--space-4); }
.read-text summary { display: inline-flex; min-height: var(--control); align-items: center; color: var(--lavender); font-weight: 700; cursor: pointer; list-style: none; text-decoration: underline; text-underline-offset: 3px; }
.read-text summary::-webkit-details-marker { display: none; }
.story-text { text-align: left; white-space: pre-wrap; color: var(--ivory); opacity: .88; background: var(--indigo); border-radius: var(--radius-lg); padding: var(--space-4); margin-top: var(--space-2); }
.notes { margin-top: var(--space-4); display: grid; gap: var(--space-2); }
.note { display: flex; gap: var(--space-2); align-items: flex-start; font-size: 13px; line-height: 18px; color: var(--muted); }
.note svg { width: 16px; height: 16px; flex: none; margin-top: 1px; color: var(--lavender); }
.player-footer { display: grid; gap: var(--space-3); margin: var(--space-6) 0 var(--space-8); }

/* --- Réglages ---------------------------------------------------------------------------------- */
.account { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4); }
.list { display: grid; gap: var(--space-2); }
.list-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); }
.list-row .info { flex: 1; min-width: 0; }
.list-row .name { font-weight: 700; }
.list-row .meta { font-size: 13px; color: var(--muted); }
.row-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.text-btn { min-height: 36px; padding: 0 var(--space-2); font-size: 14px; font-weight: 700; color: var(--lavender); }
.text-btn.danger { color: var(--error); }
.data-block { padding: var(--space-2) var(--space-4); }
.data-block .text-row { display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: 52px; font-weight: 700; }
.data-block .text-row + .text-row { border-top: 1px solid var(--border); }
.data-block .text-row svg { width: 20px; height: 20px; }
.data-block .danger { color: var(--error); }

/* --- États (chargement, vide, erreur) -------------------------------------------------------- */
.state { display: flex; flex-direction: column; align-items: center; text-align: center; padding: var(--space-12) var(--space-4) var(--space-8); }
.state img { width: 200px; height: 170px; margin-bottom: var(--space-6); }
.state h2 { font-size: 22px; line-height: 28px; }
.state p { color: var(--muted); margin: var(--space-2) 0 var(--space-6); max-width: 300px; }
.state .btn { min-width: 200px; }
.dots { display: flex; gap: 6px; margin-top: var(--space-4); }
.dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--lavender); animation: breathe 1.6s ease-in-out infinite; }
.dots span:nth-child(2) { animation-delay: .25s; } .dots span:nth-child(3) { animation-delay: .5s; }
.empty-inline { padding: var(--space-6) var(--space-4); }
.empty-inline img { width: 150px; height: 128px; margin-bottom: var(--space-4); }

/* --- Formulaire Premium (conservé) ----------------------------------------------------------- */
fieldset { border: 0; padding: 0; margin: 0 0 var(--space-5); }
legend { font-weight: 700; margin-bottom: var(--space-2); }
.choices { display: grid; gap: var(--space-2); grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.choices.inline { grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); }
.choice { display: flex; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; min-height: var(--control); padding: var(--space-2) var(--space-3); background: var(--slate); border-radius: var(--radius-md); cursor: pointer; border: 1.5px solid transparent; }
.choice input:checked + span { border-color: var(--gold); color: var(--gold); }
.panel { background: var(--indigo); border-radius: var(--radius-lg); padding: var(--space-8) var(--space-5); text-align: center; }

/* --- Mouvement réduit : aucune animation décorative --------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
