/* =========================================================
   Naomie — Système de design (mobile first)
   ========================================================= */

:root {
  /* Couleurs (identité d'origine) */
  --bg1: #fff7c2;
  --bg2: #dffbff;
  --bg3: #ffd9ee;
  --surface: #ffffff;
  --surface-soft: #f7f3ff;
  --pink: #ff7eb6;
  --pink-dark: #f55ca7;
  --purple: #8a7dff;
  --purple-dark: #6f63ee;
  --blue: #60d5ff;
  --blue-dark: #1aa6d9;
  --green: #7fe7b2;
  --green-dark: #22b573;
  --yellow: #ffd75e;
  --red: #ff7a7a;
  --red-dark: #e84d4d;
  --text: #31415a;
  --muted: #5e6d8a;
  --line: rgba(138, 125, 255, 0.16);

  --grad-main: linear-gradient(135deg, var(--pink) 0%, var(--purple) 100%);
  --grad-ok: linear-gradient(135deg, #5fe0a0 0%, #22b573 100%);

  /* Formes */
  --r-sm: 14px;
  --r-md: 20px;
  --r-lg: 26px;
  --r-pill: 999px;

  /* Ombres */
  --shadow-sm: 0 4px 10px rgba(111, 99, 238, 0.1);
  --shadow-md: 0 10px 24px rgba(111, 99, 238, 0.14);
  --shadow-press: 0 2px 0 rgba(111, 99, 238, 0.18);

  /* Espacements */
  --gutter: 16px;
  --gap: 12px;

  /* Typo */
  --font: "Fredoka", "Trebuchet MS", "Arial Rounded MT Bold", Arial, sans-serif;

  /* Tailles tactiles */
  --tap: 52px;

  --ease: cubic-bezier(0.34, 1.4, 0.64, 1);
}

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: linear-gradient(160deg, var(--bg1) 0%, var(--bg2) 50%, var(--bg3) 100%);
  background-attachment: fixed;
  font-family: var(--font);
  font-weight: 500;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

h1,
h2,
p {
  margin: 0;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--purple);
  outline-offset: 3px;
}

/* =========================================================
   Coque d'application
   ========================================================= */

.app {
  height: 100vh;
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- Barre de navigation ---------- */
.appbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px var(--gutter) 6px;
}

.brand {
  display: none;
  font-weight: 700;
  font-size: 1.4rem;
  color: var(--purple-dark);
}

.tabbar {
  display: flex;
  gap: 4px;
  width: 100%;
  max-width: 440px;
  padding: 5px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-md);
}

.tab {
  flex: 1;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.tab-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.tab:active {
  transform: scale(0.95);
}

.tab.is-active {
  background: var(--grad-main);
  color: #fff;
  box-shadow: 0 6px 14px rgba(138, 125, 255, 0.35);
}

/* ---------- Zone des écrans ---------- */
.screens {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: 8px var(--gutter) 14px;
}

.screen {
  display: none;
  height: 100%;
  flex-direction: column;
  gap: var(--gap);
  /* Sécurité : défilement interne si un très petit écran ne suffit pas */
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}

.screen::-webkit-scrollbar {
  display: none;
}

.screen.is-active {
  display: flex;
  animation: screen-in 0.28s ease both;
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.screen-head {
  flex: none;
  text-align: center;
  padding-top: 4px;
}

.screen-head h1 {
  font-size: clamp(1.6rem, 7vw, 2.3rem);
  font-weight: 700;
  line-height: 1.1;
  color: var(--purple-dark);
}

.screen-head p {
  margin-top: 4px;
  font-size: 1.1rem;
  color: var(--muted);
}

.wave {
  display: inline-block;
  transform-origin: 70% 70%;
  animation: wave 2.4s ease-in-out infinite;
}

@keyframes wave {
  0%, 60%, 100% { transform: rotate(0); }
  10%, 30% { transform: rotate(16deg); }
  20%, 40% { transform: rotate(-8deg); }
}

/* =========================================================
   Boutons
   ========================================================= */

.btn {
  min-height: var(--tap);
  padding: 0 22px;
  border: 0;
  border-radius: var(--r-md);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.btn:active {
  transform: translateY(2px) scale(0.97);
}

.btn-primary {
  background: var(--grad-main);
  color: #fff;
  box-shadow: 0 6px 0 #6f63ee, 0 10px 18px rgba(138, 125, 255, 0.3);
}

.btn-primary:active {
  box-shadow: 0 2px 0 #6f63ee;
}

.btn-secondary {
  background: #fff;
  color: var(--purple-dark);
  border: 3px solid var(--yellow);
  box-shadow: 0 5px 0 #f3c742;
}

.btn-secondary:active {
  box-shadow: 0 1px 0 #f3c742;
}

.btn-icon {
  width: var(--tap);
  padding: 0;
  flex: none;
  font-size: 1.4rem;
}

@media (hover: hover) {
  .btn:hover {
    filter: brightness(1.05);
  }
}

/* =========================================================
   Écran : choix du jeu
   ========================================================= */

.game-list {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  max-height: 520px;
}

.game-card {
  --accent: var(--pink);
  --accent-soft: #fff0f7;
  position: relative;
  flex: 1 1 0;
  min-height: 84px;
  max-height: 150px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: 3px solid #fff;
  border-radius: var(--r-lg);
  background: linear-gradient(120deg, #fff 40%, var(--accent-soft) 100%);
  box-shadow: 0 6px 0 var(--accent), var(--shadow-md);
  text-align: left;
  cursor: pointer;
  transition: transform 0.18s var(--ease), box-shadow 0.18s ease;
}

.game-card--memory {
  --accent: var(--blue);
  --accent-soft: #e6f8ff;
}

.game-card--puzzle {
  --accent: #d6d3e8;
  --accent-soft: #f4f3f8;
}

.game-card:active:not(:disabled) {
  transform: translateY(4px) scale(0.98);
  box-shadow: 0 2px 0 var(--accent), var(--shadow-sm);
}

@media (hover: hover) {
  .game-card:hover:not(:disabled) {
    transform: translateY(-3px);
  }
}

.game-card:disabled {
  cursor: default;
  opacity: 0.7;
}

.game-thumb {
  flex: none;
  width: clamp(60px, 20vw, 92px);
  aspect-ratio: 1;
  border-radius: var(--r-md);
  overflow: hidden;
  background: #fff;
  border: 3px solid var(--accent-soft);
  display: grid;
  place-items: center;
}

.game-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.game-thumb--emoji {
  font-size: 2.4rem;
  background: var(--accent-soft);
}

.game-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.game-name {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--purple-dark);
}

.game-desc {
  font-size: 0.95rem;
  color: var(--muted);
  line-height: 1.25;
}

.game-go {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-size: 1.1rem;
  padding-left: 3px;
  box-shadow: var(--shadow-sm);
}

.game-badge {
  flex: none;
  padding: 6px 10px;
  border-radius: var(--r-pill);
  background: #ece9f7;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

/* =========================================================
   Écran : partie
   ========================================================= */

.screen-game {
  position: relative;
  gap: 10px;
}

.hud {
  flex: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.hud-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 52px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid #fff;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}

.hud-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.hud-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
  min-width: 0;
}

.hud-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hud-chip strong {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--purple-dark);
  font-variant-numeric: tabular-nums;
}

.hud-chip--time strong {
  color: var(--red-dark);
}

.hud-chip--time.is-low {
  background: #ffe9e9;
  animation: pulse 1s ease-in-out infinite;
}

.hud-chip.is-bump strong {
  animation: bump 0.35s var(--ease);
}

@keyframes pulse {
  50% { transform: scale(1.05); }
}

@keyframes bump {
  40% { transform: scale(1.35); }
}

/* ---------- Message de feedback (toast) ---------- */
.toast {
  position: absolute;
  top: 66px;
  left: 50%;
  z-index: 5;
  width: max-content;
  max-width: calc(100% - 16px);
  padding: 8px 16px;
  border-radius: var(--r-pill);
  font-weight: 700;
  font-size: 1rem;
  text-align: center;
  color: #fff;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -8px) scale(0.9);
  transition: opacity 0.2s ease, transform 0.25s var(--ease);
}

.toast.success {
  background: var(--green-dark);
  box-shadow: 0 6px 16px rgba(34, 181, 115, 0.35);
}

.toast.error {
  background: var(--red-dark);
  box-shadow: 0 6px 16px rgba(232, 77, 77, 0.35);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

/* ---------- Additions ---------- */
.math-panel,
.memory-panel {
  flex: 1;
  min-height: 0;
  display: none;
  flex-direction: column;
  gap: var(--gap);
}

.app[data-game="math"] .math-panel,
.app[data-game="memory"] .memory-panel {
  display: flex;
}

.question-card {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 14px 12px;
  background: #fff;
  border: 3px solid #fff;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
}

.question-card.is-good {
  animation: good 0.45s ease;
}

.question-card.is-bad {
  animation: shake 0.4s ease;
}

@keyframes good {
  30% {
    border-color: var(--green);
    transform: scale(1.03);
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); border-color: var(--red); }
  40% { transform: translateX(8px); border-color: var(--red); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.level-name {
  padding: 3px 12px;
  border-radius: var(--r-pill);
  background: var(--surface-soft);
  color: var(--purple-dark);
  font-size: 0.85rem;
  font-weight: 700;
}

.question {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 2.5vw, 14px);
  font-size: clamp(2.2rem, 11vw, 3.4rem);
  font-weight: 700;
  line-height: 1.1;
  color: var(--purple-dark);
  font-variant-numeric: tabular-nums;
}

.question .op {
  color: var(--pink-dark);
}

.answer-slot {
  min-width: 2.2ch;
  padding: 0 8px;
  border-radius: var(--r-sm);
  background: #f1f5ff;
  border: 3px dashed #c9d4ff;
  text-align: center;
  color: var(--text);
}

.answer-slot.is-empty {
  color: #b7c2e4;
}

.bonus {
  width: 100%;
  max-width: 320px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.bonus-icon {
  font-size: 1.1rem;
}

.bonus-track {
  flex: 1;
  height: 12px;
  border-radius: var(--r-pill);
  background: #f5e1ec;
  overflow: hidden;
}

#bonus-fill {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--green) 0%, var(--yellow) 60%, var(--pink) 100%);
  transition: width 0.1s linear;
}

#bonus-timer {
  min-width: 3.2em;
  text-align: right;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--pink-dark);
  font-variant-numeric: tabular-nums;
}

.keypad {
  flex: 1;
  min-height: 0;
  max-height: 380px;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(4, minmax(44px, 1fr));
  gap: 10px;
}

.key {
  border: 0;
  border-radius: var(--r-md);
  background: #fff;
  color: var(--purple-dark);
  font-size: clamp(1.5rem, 7vw, 2rem);
  font-weight: 700;
  box-shadow: 0 5px 0 #dcd6ff, var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.15s ease;
}

.key:active,
.key.is-pressed {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #dcd6ff;
  background: #f3f0ff;
}

.key--delete {
  background: #fff6d6;
  color: #c48a00;
  box-shadow: 0 5px 0 #f3d36b, var(--shadow-sm);
}

.key--delete:active,
.key--delete.is-pressed {
  background: #ffeeb0;
  box-shadow: 0 1px 0 #f3d36b;
}

.key--ok {
  background: var(--grad-ok);
  color: #fff;
  box-shadow: 0 5px 0 #179158, var(--shadow-sm);
}

.key--ok:active,
.key--ok.is-pressed {
  background: var(--grad-ok);
  box-shadow: 0 1px 0 #179158;
}

/* ---------- Mémoire ---------- */
.memory-status,
.status-pill {
  flex: none;
  align-self: center;
  padding: 6px 16px;
  border-radius: var(--r-pill);
  background: #fff;
  box-shadow: var(--shadow-sm);
  color: var(--purple-dark);
  font-weight: 700;
  font-size: 1rem;
  text-align: center;
}

.memory-stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
}

.memory-grid {
  --card-size: 72px;
  display: grid;
  grid-template-columns: repeat(var(--memory-columns, 4), var(--card-size));
  grid-auto-rows: var(--card-size);
  gap: var(--memory-gap, 8px);
}

.memory-card {
  position: relative;
  width: var(--card-size);
  height: var(--card-size);
  padding: 0;
  border: 3px solid #fff;
  border-radius: clamp(8px, calc(var(--card-size) * 0.18), 18px);
  background: #fff;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 4px 0 #d8d2ff;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease;
}

.memory-card:active {
  transform: scale(0.94);
}

.memory-card.face-down {
  background: var(--grad-main);
  box-shadow: 0 4px 0 var(--purple-dark);
}

.memory-card.face-down::before {
  content: "?";
  font-size: calc(var(--card-size) * 0.45);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
}

.memory-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.memory-card.revealed,
.memory-card.matched {
  animation: flip 0.28s ease;
}

.memory-card.revealed .memory-image,
.memory-card.matched .memory-image {
  display: block;
}

.memory-card.matched {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(127, 231, 178, 0.5);
  animation: matched 0.45s var(--ease);
  cursor: default;
}

/* Retournement en 2D (scaleX) : évite le bug Safari où une carte
   en rotation 3D avec coins arrondis n'affiche plus son image. */
@keyframes flip {
  from { transform: scaleX(0.1); }
  to { transform: scaleX(1); }
}

@keyframes matched {
  50% { transform: scale(1.12); }
}

/* =========================================================
   Écran : fin de partie
   ========================================================= */

.screen-result {
  justify-content: center;
}

.result-card {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  background: #fff;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  text-align: center;
}

.result-hero {
  font-size: 3.4rem;
  line-height: 1;
  animation: hero 0.6s var(--ease) both;
}

.result-hero img {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: var(--r-md);
}

@keyframes hero {
  from { transform: scale(0.3) rotate(-20deg); opacity: 0; }
}

.result-card h2 {
  font-size: clamp(1.5rem, 6.5vw, 2rem);
  font-weight: 700;
  color: var(--purple-dark);
  line-height: 1.1;
}

.result-game {
  color: var(--muted);
  font-weight: 600;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 340px;
}

.result-stat {
  display: flex;
  flex-direction: column;
  padding: 8px;
  border-radius: var(--r-md);
  background: var(--surface-soft);
}

.result-stat span {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
}

.result-stat strong {
  font-size: 2rem;
  font-weight: 700;
  color: var(--pink-dark);
  line-height: 1.1;
}

.record-banner {
  padding: 6px 14px;
  border-radius: var(--r-pill);
  background: #fff4cf;
  color: #b86e00;
  font-weight: 700;
}

.record-banner.is-record {
  background: var(--yellow);
  color: #6a4300;
  animation: bump 0.6s var(--ease) 0.3s both;
}

.score-form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.score-form label {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.95rem;
  padding-left: 4px;
}

.score-form-row {
  display: flex;
  gap: 8px;
}

.score-form input {
  flex: 1;
  min-width: 0;
  min-height: var(--tap);
  padding: 0 14px;
  border: 3px solid #dfe7ff;
  border-radius: var(--r-md);
  background: #fff;
  font-size: 1.15rem;
  /* ≥16px : évite le zoom automatique d'iOS */
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.score-form input:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 5px rgba(255, 126, 182, 0.15);
}

.save-message {
  padding: 8px 14px;
  border-radius: var(--r-md);
  background: #e3fbef;
  color: #11804f;
  font-weight: 700;
  animation: bump 0.4s var(--ease);
}

.result-actions {
  flex: none;
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
  width: 100%;
  max-width: 420px;
  align-self: center;
  padding-bottom: 6px;
}

/* =========================================================
   Écran : scores
   ========================================================= */

.segmented {
  flex: none;
  display: flex;
  gap: 4px;
  padding: 4px;
  width: 100%;
  max-width: 420px;
  align-self: center;
  background: rgba(255, 255, 255, 0.7);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-sm);
}

.segment {
  flex: 1;
  min-height: 46px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.segment.is-active {
  background: #fff;
  color: var(--purple-dark);
  box-shadow: var(--shadow-sm);
}

.leaderboard {
  flex: none;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 520px;
  align-self: center;
}

.leaderboard li {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 8px 14px 8px 8px;
  background: #fff;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  animation: screen-in 0.3s ease both;
}

.leaderboard li:nth-child(2) { animation-delay: 0.04s; }
.leaderboard li:nth-child(3) { animation-delay: 0.08s; }
.leaderboard li:nth-child(4) { animation-delay: 0.12s; }
.leaderboard li:nth-child(5) { animation-delay: 0.16s; }

.rank {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-soft);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--purple-dark);
}

.lb-name {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.lb-name strong {
  font-weight: 700;
  font-size: 1.1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-name small {
  color: var(--muted);
  font-size: 0.82rem;
}

.lb-score {
  flex: none;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--pink-dark);
  font-variant-numeric: tabular-nums;
}

.lb-score small {
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: 2px;
}

.leaderboard .lb-empty {
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-height: 140px;
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
}

.lb-empty span {
  font-size: 2.4rem;
}

/* =========================================================
   Écran : aide
   ========================================================= */

.help-list {
  flex: none;
  display: grid;
  gap: var(--gap);
  width: 100%;
  max-width: 520px;
  align-self: center;
}

.help-card {
  --accent: var(--pink);
  padding: 14px 16px;
  background: #fff;
  border-radius: var(--r-lg);
  border-left: 8px solid var(--accent);
  box-shadow: var(--shadow-md);
}

.help-card--memory {
  --accent: var(--blue);
}

.help-card h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--purple-dark);
  margin-bottom: 8px;
}

.help-card ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.help-card li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.02rem;
  line-height: 1.25;
}

.help-card li span {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--surface-soft);
  font-size: 1.2rem;
}

/* =========================================================
   Fenêtre de confirmation
   ========================================================= */

.dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: var(--gutter);
  background: rgba(49, 65, 90, 0.4);
  backdrop-filter: blur(3px);
  animation: fade 0.2s ease;
}

.dialog-card {
  width: 100%;
  max-width: 360px;
  padding: 22px 18px 18px;
  background: #fff;
  border-radius: var(--r-lg);
  box-shadow: 0 20px 50px rgba(49, 65, 90, 0.3);
  text-align: center;
  animation: hero 0.35s var(--ease);
}

.dialog-emoji {
  font-size: 3rem;
  line-height: 1;
}

.dialog-card h2 {
  margin: 10px 0 18px;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--purple-dark);
}

.dialog-actions {
  display: grid;
  gap: 12px;
}

@keyframes fade {
  from { opacity: 0; }
}

/* =========================================================
   Petits écrans en hauteur (ex. 360×640, iPhone SE)
   ========================================================= */

@media (max-height: 680px) {
  .appbar {
    padding-top: 8px;
  }

  .tab {
    min-height: 42px;
  }

  .screens {
    padding-top: 6px;
    padding-bottom: 10px;
  }

  .screen-head p {
    font-size: 1rem;
  }

  .hud-chip {
    min-height: 46px;
  }

  .toast {
    top: 58px;
  }

  .question-card {
    padding: 10px 12px;
    gap: 6px;
  }

  .question {
    font-size: clamp(2rem, 10vw, 2.8rem);
  }

  .keypad {
    gap: 8px;
  }

  .result-card {
    gap: 8px;
    padding: 14px;
  }

  .result-hero {
    font-size: 2.6rem;
  }

  .result-stat strong {
    font-size: 1.6rem;
  }
}

/* Grands téléphones : on profite de la hauteur disponible */
@media (min-height: 800px) {
  .game-list {
    max-height: 600px;
  }

  .game-card {
    max-height: 180px;
  }

  .keypad {
    max-height: 460px;
  }

  .question-card {
    padding: 20px 14px 16px;
    gap: 12px;
  }
}

/* =========================================================
   Tablette (tactile, plus d'espace)
   ========================================================= */

@media (min-width: 600px) {
  :root {
    --gutter: 24px;
    --gap: 16px;
    --tap: 58px;
  }

  .appbar {
    padding-top: 16px;
  }

  .tab {
    min-height: 52px;
    font-size: 1.1rem;
  }

  .game-list {
    max-height: 720px;
    width: 100%;
    max-width: 640px;
    align-self: center;
  }

  .game-card {
    max-height: 220px;
  }

  .keypad {
    max-width: 540px;
    max-height: 580px;
    gap: 14px;
  }

  .key {
    font-size: 2.4rem;
  }

  .game-name {
    font-size: 1.6rem;
  }

  .game-desc {
    font-size: 1.05rem;
  }

  .hud {
    width: 100%;
    max-width: 640px;
    align-self: center;
  }

  .hud-chip strong {
    font-size: 1.6rem;
  }

  .question-card {
    width: 100%;
    max-width: 640px;
    align-self: center;
  }

  .question {
    font-size: 4rem;
  }

  .result-card {
    width: 100%;
    max-width: 520px;
    align-self: center;
    padding: 24px;
  }
}

/* =========================================================
   Desktop / paysage large
   ========================================================= */

@media (min-width: 900px) and (min-height: 560px) {
  html {
    font-size: 112.5%;
  }

  .appbar {
    justify-content: space-between;
    padding: 18px var(--gutter) 8px;
  }

  .brand {
    display: block;
    width: 160px;
  }

  .appbar::after {
    content: "";
    width: 160px;
  }

  .screens {
    padding-top: 16px;
    padding-bottom: 24px;
  }

  /* Accueil : cartes en colonnes */
  .game-list {
    flex: none;
    flex-direction: row;
    gap: 24px;
    max-width: 1000px;
    max-height: none;
    margin-top: 2vh;
  }

  .game-card {
    flex-direction: column;
    justify-content: flex-start;
    gap: 12px;
    text-align: center;
    max-height: none;
    padding: 24px 20px 28px;
  }

  .game-thumb {
    width: 100%;
    max-width: 260px;
    aspect-ratio: 4 / 3;
  }

  .game-go {
    width: 56px;
    height: 56px;
    font-size: 1.4rem;
  }

  .game-thumb--emoji {
    font-size: 4rem;
  }

  .game-info {
    align-items: center;
  }

  .game-go,
  .game-badge {
    margin-top: auto;
  }

  /* Partie : question à gauche, clavier à droite */
  .screen-game .hud {
    max-width: 760px;
  }

  .math-panel {
    flex-direction: row;
    align-items: stretch;
    justify-content: center;
    gap: 24px;
  }

  .question-card {
    flex: 1;
    max-width: 520px;
    justify-content: center;
    gap: 22px;
    align-self: stretch;
    margin: 0;
  }

  .question {
    font-size: 4.6rem;
  }

  .keypad {
    flex: none;
    width: 340px;
    max-height: 440px;
    margin: 0;
    align-self: center;
    height: 100%;
  }

  .toast {
    top: 86px;
  }

  .leaderboard li {
    min-height: 64px;
  }

  .help-list {
    grid-template-columns: 1fr 1fr;
    max-width: 860px;
  }
}

/* =========================================================
   Aide : un onglet par jeu sur mobile, tout visible sur desktop
   ========================================================= */

.help-card {
  display: none;
}

.help-card.is-active {
  display: block;
  animation: screen-in 0.25s ease both;
}

.help-card--letters {
  --accent: var(--green-dark);
}

.segment {
  font-size: clamp(0.85rem, 3.6vw, 1rem);
  white-space: nowrap;
}

@media (min-width: 900px) and (min-height: 560px) {
  .help-tabs {
    display: none;
  }

  .help-list {
    grid-template-columns: repeat(3, 1fr);
    max-width: 1000px;
  }

  .help-card {
    display: block;
  }
}

/* =========================================================
   L'Aventure des lettres
   (réutilise .key, .btn, .answer-slot, .result-card,
   .status-pill, .game-go… et les mêmes tokens)
   ========================================================= */

.game-card--letters {
  --accent: var(--green-dark);
  --accent-soft: #e3fbef;
}

.game-thumb--letters {
  display: flex;
  gap: 1px;
  font-size: clamp(1.3rem, 6vw, 1.9rem);
  font-weight: 700;
  line-height: 1;
}

.game-thumb--letters span:nth-child(1) { color: var(--pink-dark); }
.game-thumb--letters span:nth-child(2) { color: var(--purple-dark); transform: translateY(4px); }
.game-thumb--letters span:nth-child(3) { color: var(--green-dark); }

.status-pill {
  animation: screen-in 0.25s ease both;
  max-width: 100%;
  transition: background 0.2s ease, color 0.2s ease;
}

.status-pill.is-success {
  background: var(--green-dark);
  color: #fff;
}

.status-pill.is-error {
  background: var(--red-dark);
  color: #fff;
}

.status-pill.is-bump {
  animation: bump 0.35s var(--ease);
}

.btn {
  white-space: nowrap;
}

/* Lettres mélangées : grande image, cases et tuiles dans la zone du pouce */
.lt-stage--spell .lt-card--small {
  flex: 1 1 auto;
  max-height: none;
}

.lt-stage--spell .lt-card--small .lt-emoji {
  font-size: clamp(3rem, min(26vw, 15vh), 8rem);
}

/* ---------- Carte des étapes ---------- */
.lt-levels {
  flex: none;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 560px;
  align-self: center;
}

.lt-level {
  --accent: var(--pink);
  width: 100%;
  min-height: 66px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 8px 8px;
  border: 3px solid #fff;
  border-radius: var(--r-md);
  background: #fff;
  box-shadow: 0 5px 0 var(--accent), var(--shadow-sm);
  text-align: left;
  cursor: pointer;
  transition: transform 0.18s var(--ease), box-shadow 0.18s ease;
}

.lt-level--2 { --accent: var(--blue); }
.lt-level--3 { --accent: var(--green-dark); }
.lt-level--4 { --accent: var(--yellow); }
.lt-level--5 { --accent: var(--purple); }

.lt-level:active:not(.is-locked) {
  transform: translateY(4px) scale(0.98);
  box-shadow: 0 1px 0 var(--accent);
}

@media (hover: hover) {
  .lt-level:hover:not(.is-locked) {
    transform: translateY(-2px);
  }
}

.lt-level.is-locked {
  --accent: #dcd8ea;
  background: #f6f5fa;
  cursor: default;
}

.lt-level.is-locked .lt-level-title {
  color: var(--muted);
}

.lt-level-badge {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  background: var(--surface-soft);
  font-size: 1.6rem;
}

.lt-level-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lt-level-title {
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--purple-dark);
  line-height: 1.15;
}

.lt-level-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lt-level .game-go {
  width: 40px;
  height: 40px;
  background: var(--accent);
}

.lt-level.is-locked .game-go {
  background: transparent;
  box-shadow: none;
}

.lt-tag {
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--yellow);
  color: #6a4300;
  font-size: 0.75rem;
  font-weight: 700;
}

.lt-stars {
  display: inline-flex;
  gap: 2px;
  font-size: 1.15rem;
  line-height: 1;
}

.lt-star {
  color: #e2def0;
}

.lt-star.is-on {
  color: #ffc21a;
  text-shadow: 0 1px 0 #e0a100;
}

.sound-toggle {
  flex: none;
  align-self: center;
  min-height: 46px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--r-pill);
  background: #fff;
  color: var(--purple-dark);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

.sound-toggle.is-off {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.6);
}

/* ---------- Écran d'exercice ---------- */
.screen-letters-play {
  gap: 10px;
}

.lt-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 640px;
  align-self: center;
}

.lt-bar .btn-icon {
  width: 52px;
  min-height: 52px;
  border-radius: var(--r-md);
}

.lt-progress {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid #fff;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}

.lt-progress-track {
  flex: 1;
  height: 14px;
  border-radius: var(--r-pill);
  background: #f5e1ec;
  overflow: hidden;
}

#lt-progress-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--green) 0%, var(--yellow) 60%, var(--pink) 100%);
  transition: width 0.4s var(--ease);
}

.lt-progress-text {
  font-weight: 700;
  color: var(--purple-dark);
  font-variant-numeric: tabular-nums;
}

#lt-replay.is-speaking {
  animation: pulse 0.8s ease-in-out infinite;
}

.lt-stage {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 640px;
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* Carte image (même style que la carte question des additions) */
.lt-card {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  border: 3px solid #fff;
  border-radius: var(--r-lg);
  background: #fff;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  overflow: hidden;
}

.lt-card.is-speaking,
.lt-listen.is-speaking {
  animation: good 0.6s ease;
}

.lt-card--small {
  flex: 0 1 auto;
  max-height: 22vh;
  padding: 8px;
}

.lt-emoji {
  font-size: clamp(3rem, min(24vw, 14vh), 8rem);
  line-height: 1.1;
}

.lt-card--small .lt-emoji {
  font-size: clamp(2.6rem, min(16vw, 10vh), 5rem);
}

.lt-word {
  font-size: clamp(1.5rem, 7vw, 2.2rem);
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.04em;
}

.lt-word-first {
  display: inline-block;
  color: var(--pink-dark);
}

.lt-word-first.is-hidden {
  min-width: 1.2ch;
  padding: 0 4px;
  border-radius: 10px;
  background: #f1f5ff;
  border: 3px dashed #c9d4ff;
  color: #b7c2e4;
  text-align: center;
}

/* Découvre */
.lt-big {
  display: flex;
  align-items: baseline;
  gap: 0.15em;
  font-size: clamp(4rem, min(28vw, 16vh), 9rem);
  font-weight: 700;
  line-height: 1;
}

.lt-upper {
  color: var(--pink-dark);
  text-shadow: 3px 3px 0 #ffe0ef;
}

.lt-lower {
  color: var(--purple-dark);
  font-size: 0.75em;
  text-shadow: 3px 3px 0 #e8e4ff;
}

.lt-caption {
  font-size: clamp(1.2rem, 5.5vw, 1.7rem);
  font-weight: 600;
  color: var(--text);
}

.lt-caption strong {
  color: var(--pink-dark);
}

.lt-nav {
  flex: none;
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 420px;
}

.lt-next {
  flex: 1;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

/* Choix de réponses (mêmes touches que le pavé des additions) */
.lt-options {
  flex: none;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 420px;
}

.lt-option {
  min-height: clamp(62px, 10.5vh, 96px);
  font-size: clamp(2rem, 9vw, 2.6rem);
}

.lt-option--emoji {
  font-size: clamp(2.2rem, 10vw, 3rem);
}

.lt-option.is-correct {
  background: var(--grad-ok);
  color: #fff;
  box-shadow: 0 5px 0 #179158;
  animation: matched 0.45s var(--ease);
}

.lt-option.is-wrong {
  opacity: 0.35;
  box-shadow: none;
  transform: translateY(4px);
}

.is-shake {
  animation: shake 0.4s ease;
}

/* Cases du mot */
.lt-slots {
  flex: none;
  display: flex;
  justify-content: center;
  gap: 6px;
  width: 100%;
}

.lt-slot {
  width: clamp(40px, 13vw, 64px);
  height: clamp(48px, 15vw, 72px);
  display: grid;
  place-items: center;
  padding: 0;
  font-size: clamp(1.6rem, 8vw, 2.4rem);
  font-weight: 700;
  color: var(--purple-dark);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.lt-slot.is-next {
  border-color: var(--pink);
  background: #fff0f7;
  animation: pulse 1.2s ease-in-out infinite;
}

.lt-slot:not(.is-empty) {
  border-style: solid;
  border-color: var(--green);
  background: #effdf6;
}

.lt-slot.is-filled {
  animation: matched 0.4s var(--ease);
}

.lt-slots.is-correct .lt-slot {
  background: var(--green);
  color: #fff;
}

/* Tuiles de lettres */
.lt-tiles {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 420px;
}

.lt-tile {
  width: clamp(54px, 18vw, 76px);
  height: clamp(54px, 18vw, 76px);
  min-height: 0;
  font-size: clamp(1.7rem, 8vw, 2.3rem);
  transition: opacity 0.2s ease, transform 0.15s ease;
}

.lt-tile.is-used {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.6);
}

.lt-tile.is-hint {
  background: #fff6d6;
  box-shadow: 0 5px 0 #f3d36b, 0 0 0 4px rgba(255, 215, 94, 0.6);
  animation: glow 0.9s ease-in-out infinite;
}

/* Halo sans mouvement : la cible ne bouge pas sous le doigt */
@keyframes glow {
  50% {
    box-shadow: 0 5px 0 #f3d36b, 0 0 0 9px rgba(255, 215, 94, 0.35);
  }
}

/* Écoute */
.lt-listen {
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 24px;
  border: 0;
  border-radius: var(--r-lg);
  background: transparent;
  cursor: pointer;
}

.lt-listen-icon {
  width: clamp(96px, min(34vw, 18vh), 150px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: clamp(2.6rem, min(14vw, 8vh), 4rem);
  background: var(--grad-main);
  box-shadow: 0 6px 0 #6f63ee, 0 12px 24px rgba(138, 125, 255, 0.35);
}

.lt-listen:active .lt-listen-icon {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #6f63ee;
}

.lt-listen-label {
  font-weight: 700;
  color: var(--purple-dark);
}

.lt-hint-btn {
  flex: none;
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.75);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.lt-hint {
  flex: none;
  padding: 4px 18px;
  border-radius: var(--r-md);
  background: #fff;
  box-shadow: var(--shadow-sm);
  font-size: clamp(1.5rem, 7vw, 2rem);
  font-weight: 700;
  color: var(--pink-dark);
  animation: bump 0.4s var(--ease);
}

/* Frise de l'alphabet */
.lt-abc {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 3px;
  width: 100%;
  padding: 8px;
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow-sm);
}

.lt-abc span {
  min-width: 1.15em;
  text-align: center;
  font-size: clamp(0.85rem, 3.6vw, 1.1rem);
  font-weight: 700;
  color: #cfd3e6;
}

.lt-abc .is-current {
  color: var(--purple);
}

.lt-abc .is-done {
  color: var(--green-dark);
}

.lt-stage--alphabet {
  justify-content: center;
  gap: 18px;
}

/* Fin d'étape */
.lt-stage--complete {
  justify-content: center;
}

.lt-complete {
  width: 100%;
  max-width: 520px;
}

.lt-complete-stars {
  display: flex;
  gap: 6px;
  font-size: clamp(2.8rem, 14vw, 4rem);
  line-height: 1;
}

.lt-big-star {
  color: #e2def0;
  animation: hero 0.5s var(--ease) both;
}

.lt-big-star.is-on {
  color: #ffc21a;
  text-shadow: 0 3px 0 #e0a100;
}

.lt-complete-msg {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.lt-complete-actions {
  grid-template-columns: 1fr 1.4fr;
}

/* Onglet Scores */
.leaderboard .lt-total {
  justify-content: center;
  min-height: 48px;
  background: var(--yellow);
  color: #6a4300;
  font-weight: 700;
  font-size: 1.1rem;
}

.lb-score .lt-stars {
  font-size: 1.25rem;
}

/* Étincelles de réussite */
.spark {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  font-size: 1.4rem;
  transform: translate(-50%, -50%);
  animation: spark 0.85s ease-out forwards;
}

@keyframes spark {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.4);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.1);
  }
}

/* Petits écrans en hauteur */
@media (max-height: 680px) {
  .lt-level {
    min-height: 58px;
  }

  .lt-level-badge {
    width: 42px;
    height: 42px;
    font-size: 1.4rem;
  }

  .lt-levels {
    gap: 8px;
  }

  .screen-letters-play,
  .lt-stage {
    gap: 8px;
  }

  .lt-bar .btn-icon,
  .lt-progress {
    min-height: 46px;
  }

  .lt-bar .btn-icon {
    width: 46px;
  }
}

/* Tablette et desktop : 4 choix sur une ligne */
@media (min-width: 600px) {
  .lt-options {
    grid-template-columns: repeat(4, 1fr);
    max-width: 600px;
  }

  .lt-level {
    min-height: 74px;
  }
}

@media (min-width: 900px) and (min-height: 560px) {
  .lt-levels {
    max-width: 640px;
  }

  .lt-bar,
  .lt-stage {
    max-width: 780px;
  }

  .lt-options,
  .lt-tiles {
    max-width: 640px;
  }

  .lt-abc {
    flex-wrap: nowrap;
    justify-content: space-between;
  }
}

/* Origine du classement (partagé / cet appareil) */
.scores-source {
  flex: none;
  align-self: center;
  margin: -4px 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

/* Mouvement réduit */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
