/* Styles communs à toute l'application. Chaque exercice a sa propre feuille
   dans son dossier, chargée à l'ouverture de l'exercice.

   Couleurs tirées du logo (public/assets/logo.svg) :
   bleu canard #05687C pour les boutons et les éléments actifs,
   orange #FA903E pour les accents. */

:root {
  --brand: #05687c;        /* bleu canard du logo : boutons, liens, sélection */
  --brand-dark: #034b59;   /* ombre portée des boutons */
  --brand-light: #a7d3dc;
  --brand-soft: #e3f1f4;
  --accent: #fa903e;       /* orange du logo : accents, décor */
  --accent-strong: #e0701f; /* orange lisible sur fond blanc (texte en gras) */
  --accent-soft: #fff1e4;
  --danger: #c2401b;       /* erreurs, alertes */
  --danger-soft: #fdeee9;
  --ink: #17343b;
  --ink-soft: #56707a;
  --sky: #d3ecf0;
  --paper: #ffffff;
  --ok: #3aa45b;           /* réussite */
  --ok-dark: #2f8a4b;
  --ok-soft: #dcf3e2;
  --ok-ink: #1f6b38;
  --danger-ink: #9c3414;
  --danger-strong: #b3261e;
  --line: #d6e4e8;
  --radius: 18px;
  font-family: 'Nunito', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; }

body {
  min-height: 100dvh;
  background: linear-gradient(180deg, var(--sky) 0%, #eef7f8 45%, #fff4ea 100%) fixed;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--brand); outline-offset: 3px; }

.screen { max-width: 980px; margin: 0 auto; padding: 16px; }

.hero { text-align: center; padding: 18px 0 8px; }
.hero h1 { font-size: clamp(2rem, 6vw, 3rem); font-weight: 900; margin: 0; letter-spacing: -0.5px; }
.hero p { color: var(--ink-soft); margin: 6px 0 0; font-size: 1.05rem; }

.warn { background: #fff3cd; border-radius: 12px; padding: 12px 16px; }
.foot { text-align: center; color: var(--ink-soft); font-size: 0.85rem; }

.panel {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
  margin: 14px 0;
  box-shadow: 0 2px 0 rgba(35, 50, 74, 0.06), 0 8px 24px rgba(35, 50, 74, 0.06);
}
.panel h2 { font-size: 1.15rem; margin: 0 0 12px; font-weight: 800; display: flex; justify-content: space-between; align-items: baseline; }
.panel h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); margin: 16px 0 8px; }
.count { font-size: 0.9rem; color: var(--ink-soft); font-weight: 600; }
.hint { min-height: 1.4em; margin: 12px 0 0; color: #9a5b00; font-size: 0.95rem; }

/* --- Boutons ------------------------------------------------------- */

.btn-go {
  display: block;
  width: 100%;
  max-width: 420px;
  margin: 20px auto;
  padding: 16px 24px;
  font-size: 1.4rem;
  font-weight: 900;
  color: #fff;
  background: var(--brand);
  border: 0;
  border-radius: 999px;
  box-shadow: 0 6px 0 var(--brand-dark);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn-go:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 var(--brand-dark); }

.btn-secondary {
  display: block;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding: 12px 24px;
  font-weight: 800;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: #fff;
}

.btn-back {
  border: 0;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
}

.btn-link { background: none; border: 0; padding: 8px 0 0; color: var(--brand); font-weight: 700; text-decoration: underline; }

/* --- Choix segmentés et pastilles ------------------------------------ */

.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button {
  flex: 1;
  min-width: 64px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: #f6f9fc;
  font-weight: 800;
}
.seg button[aria-pressed='true'] { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: #f6f9fc;
  font-weight: 700;
  font-size: 0.9rem;
}
.chip:hover { border-color: #b8c7d6; }

/* --- Sélecteur d'animaux (référentiel des phonèmes) ------------------ */

.animal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.animal {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px;
  border-radius: 14px;
  border: 3px solid var(--line);
  background: #fff;
  transition: transform 0.12s, border-color 0.12s;
}
.animal img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; }
.animal-name { font-weight: 800; font-size: 0.95rem; }
.animal-sound { font-size: 0.8rem; color: var(--ink-soft); font-weight: 700; }
.animal[aria-pressed='true'] { border-color: var(--brand); background: var(--brand-soft); transform: translateY(-2px); }
.animal[aria-pressed='true']::after {
  content: '✓';
  position: absolute;
  top: -8px;
  right: -8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 900;
}

/* --- Barre de progression ---------------------------------------- */

.h-bar { display: block; height: 10px; min-width: 60px; border-radius: 99px; background: #edf1f5; overflow: hidden; }
.h-bar i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }

/* --- Cartes d'exercices ----------------------------------------------- */

.game-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin: 16px 0; }
.game-card {
  width: 100%;
  border: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 14px;
  background: var(--paper);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
  box-shadow: 0 2px 0 rgba(35, 50, 74, 0.06), 0 8px 24px rgba(35, 50, 74, 0.08);
  transition: transform 0.12s;
}
.game-card:hover { transform: translateY(-2px); }
.game-card img { width: 96px; height: 96px; object-fit: cover; border-radius: 14px; flex: none; }
.game-card-body { display: flex; flex-direction: column; gap: 2px; }
.game-card-skill { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--brand); font-weight: 800; }
.game-card-title { font-size: 1.3rem; font-weight: 900; }
.game-card-tagline { color: var(--ink-soft); }
.game-card-last { font-size: 0.85rem; color: var(--ink-soft); margin-top: 4px; }

a.btn-go { text-align: center; text-decoration: none; }
.game-card[aria-pressed='true'] { box-shadow: 0 0 0 4px var(--brand), 0 8px 24px rgba(35, 50, 74, 0.08); }
.game-card:disabled { cursor: default; }

/* --- Accueil public ------------------------------------------------- */

.hero-img { width: 110px; height: 110px; }
.home { max-width: 640px; }
/* Logo : ses contre-formes sont blanches, on le pose donc toujours sur du blanc. */
.logo-card { display: inline-block; margin: 0; padding: 18px 28px; background: #fff; border-radius: 26px; box-shadow: 0 8px 24px rgba(5, 104, 124, 0.12); }
.logo-card img { display: block; width: min(320px, 70vw); height: auto; }
.home .hero p { margin-top: 14px; }
.home-panel { text-align: center; }
.home-panel p { color: var(--ink-soft); }
.home-panel .btn-go { margin-bottom: 4px; }

/* --- Espace patient ------------------------------------------------- */

.play-center { max-width: 480px; text-align: center; padding-top: 32px; }
.play-center h1 { font-size: clamp(2rem, 7vw, 2.6rem); font-weight: 900; margin: 6px 0; }
.play-mascot { width: 120px; height: 120px; }
.play-lead { font-size: 1.2rem; color: var(--ink-soft); margin: 0 0 18px; }

.year-display { display: flex; justify-content: center; gap: 10px; margin: 0 auto 6px; }
.year-display span {
  width: 58px; height: 72px;
  display: grid; place-items: center;
  font-size: 2.4rem; font-weight: 900;
  background: #fff; border-radius: 14px;
  border: 3px dashed #c4d2df;
}
.year-display span.filled { border: 3px solid var(--brand); }
.year-display.shake { animation: shake 0.45s; }
.year-msg { min-height: 1.5em; color: var(--danger); font-weight: 700; margin: 6px 0 12px; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 320px; margin: 0 auto; }
.keypad button {
  height: 66px;
  border: 0; border-radius: 16px;
  background: #fff;
  font-size: 1.8rem; font-weight: 900;
  box-shadow: 0 5px 0 #d3dde7;
}
.keypad button:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 #d3dde7; }
.keypad .key-ok { background: var(--ok); color: #fff; box-shadow: 0 5px 0 var(--ok-dark); }

.play-hub .game-cards { grid-template-columns: 1fr; max-width: 560px; margin: 16px auto; }
.play-hub .hero .btn-switch { display: inline-block; margin-top: 4px; font-size: 0.9rem; color: var(--ink-soft); }
.play-hub .foot { font-size: 1.05rem; }
.play-hub .foot .btn-link { font-weight: 800; }
.play-card { padding: 18px; }
.play-card img { width: 110px; height: 110px; }
.play-card .game-card-body { flex: 1; }
.play-go {
  flex: none; width: 60px; height: 60px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand); color: #fff; font-size: 1.6rem;
  box-shadow: 0 4px 0 var(--brand-dark);
}

/* --- Animations communes --------------------------------------------- */

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(9px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(4px); }
}

@keyframes pop { 0% { transform: scale(0.92); } 60% { transform: scale(1.04); } 100% { transform: scale(1); } }

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

/* --- Replay : halo à l'endroit de chaque toucher (commun à tous les exercices) --- */
.tap-halo {
  position: absolute; z-index: 5; pointer-events: none;
  width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%;
  border: 5px solid var(--halo, var(--brand));
  background: color-mix(in srgb, var(--halo, var(--brand)) 25%, transparent);
  animation: tap-halo 1.1s cubic-bezier(0.3, 1.6, 0.5, 1) forwards;
}
.tap-halo.ok { --halo: var(--ok); }
.tap-halo.ko { --halo: var(--danger); }
.tap-halo.ignored { --halo: #e2a400; }
.tap-halo.button { --halo: var(--brand); }
.tap-halo.miss { --halo: #8a97a8; }
@keyframes tap-halo {
  0% { transform: scale(0.2); opacity: 1; }
  35% { transform: scale(1.15); opacity: 1; }
  55% { transform: scale(0.85); }
  75% { transform: scale(1.05); opacity: 0.9; }
  100% { transform: scale(1); opacity: 0; }
}

/* ------------------------------------------------------------------ */
/* Accessibilité (js/core/a11y.js pose les attributs data-a11y-* sur <html>) */
/* ------------------------------------------------------------------ */

html[data-a11y-text='large'] { font-size: 118%; }
html[data-a11y-text='xlarge'] { font-size: 136%; }

html[data-a11y-font='legible'] { font-family: 'Atkinson Hyperlegible', 'Verdana', system-ui, sans-serif; }
html[data-a11y-font='dyslexia'] { font-family: 'Lexend', 'Verdana', system-ui, sans-serif; }
html[data-a11y-font='dyslexia'] body { letter-spacing: 0.03em; word-spacing: 0.12em; line-height: 1.6; }
html[data-a11y-spacing='wide'] body { letter-spacing: 0.06em; word-spacing: 0.18em; line-height: 1.8; }

html[data-a11y-contrast='high'] {
  --ink: #000;
  --ink-soft: #1e2d32;
  --line: #5b6d73;
  --brand: #00495a;
  --brand-dark: #002f3a;
  --brand-soft: #d2e9ee;
  --accent-strong: #a84a00;
  --sky: #ffffff;
}
html[data-a11y-contrast='high'] body { background: #fff; }
html[data-a11y-contrast='high'] .panel,
html[data-a11y-contrast='high'] .game-card,
html[data-a11y-contrast='high'] .choice,
html[data-a11y-contrast='high'] .tir-target,
html[data-a11y-contrast='high'] .tir-word { box-shadow: 0 0 0 2px var(--ink); }

/* Daltonisme : juste / faux en bleu et orange (palette Okabe-Ito), au lieu de vert et rouge. */
html[data-a11y-colors='cvd'] {
  --ok: #0072b2;
  --ok-dark: #005488;
  --ok-soft: #d6eaf6;
  --ok-ink: #00466f;
  --danger: #d55e00;
  --danger-soft: #fbe4d3;
  --danger-ink: #8a3c00;
  --danger-strong: #b34f00;
}

html[data-a11y-motion='reduce'] *,
html[data-a11y-motion='reduce'] *::before,
html[data-a11y-motion='reduce'] *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

/* Roue crantée, en haut à droite de chaque écran. */
.a11y-cog {
  position: fixed; top: 10px; right: 12px; z-index: 40;
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.9); color: var(--brand);
  box-shadow: 0 2px 8px rgba(23, 52, 59, 0.18);
}
.a11y-cog svg { width: 26px; height: 26px; }
.a11y-cog:hover { color: var(--brand-dark); }
.has-a11y .topbar, .has-a11y .pro-bar { padding-right: 64px; }

.a11y-overlay { position: fixed; inset: 0; z-index: 60; background: rgba(23, 52, 59, 0.5); display: grid; place-items: center; padding: 16px; }
.a11y-panel {
  width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow: auto;
  background: #fff; color: var(--ink); border-radius: 22px; padding: 18px 20px; text-align: left;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.a11y-panel header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.a11y-panel h2 { margin: 0; font-size: 1.25rem; font-weight: 900; }
.a11y-close { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--brand-soft); font-weight: 900; }
.a11y-who { margin: 4px 0 8px; color: var(--ink-soft); }
.a11y-panel fieldset { border: 0; padding: 0; margin: 14px 0 0; }
.a11y-panel legend { font-weight: 800; margin-bottom: 6px; padding: 0; }
.a11y-panel .seg button { flex: 1; min-width: 100px; }
.a11y-help { margin: 6px 0 0; font-size: 0.88rem; color: var(--ink-soft); }
.a11y-panel footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.a11y-done {
  border: 0; border-radius: 999px; padding: 10px 22px; font-weight: 800; color: #fff;
  background: var(--brand); box-shadow: 0 3px 0 var(--brand-dark);
}
