/* ===== Variables de thème ===== */
:root {
  --app-font-family: Verdana, Geneva, sans-serif;

  --color-bg: #fef6e4;
  --color-bg-alt: #ffffff;
  --color-text: #2b2d42;
  --color-primary: #ff6b6b;
  --color-primary-dark: #e85555;
  --color-secondary: #4ecdc4;
  --color-accent: #ffd166;
  --color-success: #6bcf6b;
  --color-warning: #f4a259;
  --color-card-shadow: rgba(43, 45, 66, 0.12);
  --color-border: #f0dfc4;

  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

/* Un seul fichier (Regular) déclaré : le navigateur "fabrique" lui-même le gras
   à partir de cette police (font-synthesis). Si tu obtiens un jour un vrai
   fichier OpenDyslexic-Bold.otf, ajoute un second @font-face avec
   font-weight: bold et src pointant vers ce fichier — mais ne le fais QUE si
   le fichier existe réellement dans /fonts, sinon le gras casse à nouveau. */
@font-face {
  font-family: 'OpenDyslexic';
  src: url('../fonts/OpenDyslexic-Regular.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

html[data-theme="dark"] {
  --color-bg: #1b1b2f;
  --color-bg-alt: #262640;
  --color-text: #f2f2f7;
  --color-primary: #ff8787;
  --color-primary-dark: #ff6b6b;
  --color-secondary: #5fe0d6;
  --color-accent: #ffd97d;
  --color-success: #7be07b;
  --color-warning: #ffb877;
  --color-card-shadow: rgba(0, 0, 0, 0.4);
  --color-border: #3a3a5c;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--app-font-family);
  background: var(--color-bg);
  color: var(--color-text);
  transition: background 0.3s ease, color 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}

#app-root {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  min-height: 100vh;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ===== Écran d'accueil ===== */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-title {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  margin: 8px 0;
}

.home-subtitle {
  font-size: 1.1rem;
  opacity: 0.85;
  margin-top: 0;
}

.icon-btn {
  background: var(--color-bg-alt);
  border: 2px solid var(--color-border);
  border-radius: 50%;
  width: 52px;
  height: 52px;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px var(--color-card-shadow);
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.game-card {
  background: var(--color-bg-alt);
  border: none;
  border-radius: var(--radius-lg);
  padding: 24px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  box-shadow: 0 6px 16px var(--color-card-shadow);
  min-height: 130px;
  transition: transform 0.15s ease;
}

.game-card:active { transform: scale(0.96); }

.game-icon { font-size: 2.6rem; }
.game-title { font-size: 1.1rem; font-weight: bold; text-align: center; }

.settings-link {
  display: block;
  margin: 24px auto 0;
}

/* ===== Boutons génériques ===== */
.btn-primary, .btn-secondary {
  border-radius: var(--radius-md);
  padding: 14px 22px;
  font-size: 1.05rem;
  font-weight: bold;
  border: none;
  min-height: 48px;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
  box-shadow: 0 6px 14px var(--color-card-shadow);
}
.btn-primary:disabled {
  background: var(--color-border);
  color: var(--color-text);
  opacity: 0.6;
  cursor: not-allowed;
}
.btn-primary:not(:disabled):active { background: var(--color-primary-dark); }

.btn-secondary {
  background: var(--color-bg-alt);
  color: var(--color-text);
  border: 2px solid var(--color-border);
}

.btn-back {
  background: none;
  border: none;
  color: var(--color-text);
  font-size: 1rem;
  padding: 8px 4px;
  margin-bottom: 8px;
  opacity: 0.75;
}

/* ===== Écran de config du jeu ===== */
.screen-title { font-size: clamp(1.4rem, 3.5vw, 2rem); margin-bottom: 4px; }
.screen-subtitle { opacity: 0.8; margin-top: 0; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin: 20px 0;
}

.level-card {
  background: var(--color-bg-alt);
  border: 3px solid transparent;
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 4px 12px var(--color-card-shadow);
  min-height: 110px;
}

.level-card.selected { border-color: var(--color-secondary); }
.level-card:disabled { opacity: 0.5; cursor: not-allowed; }

.level-name { font-size: 1.1rem; font-weight: bold; }
.level-hint { opacity: 0.7; font-size: 0.95rem; }
.level-record { color: var(--color-warning); font-weight: bold; font-size: 0.95rem; }
.level-warning { color: var(--color-primary); font-size: 0.85rem; }

.speed-control {
  background: var(--color-bg-alt);
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 16px 0 24px;
  box-shadow: 0 4px 12px var(--color-card-shadow);
}
.speed-control input[type="range"] { width: 100%; margin-top: 10px; }
.speed-labels { display: flex; justify-content: space-between; font-size: 0.85rem; opacity: 0.7; margin-top: 4px; }

.btn-start { width: 100%; }

/* ===== Carte d'info (jeu Mots en Syllabes) ===== */
.info-card {
  background: var(--color-bg-alt);
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 16px 0;
  box-shadow: 0 4px 12px var(--color-card-shadow);
}
.info-card p { margin: 6px 0; }
.btn-small { padding: 8px 14px; font-size: 0.9rem; min-height: auto; }

/* ===== Compte à rebours ===== */
.countdown-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}
.countdown-number {
  font-size: clamp(3rem, 15vw, 6rem);
  font-weight: bold;
  color: var(--color-secondary);
  animation: pop 0.6s ease;
}

@keyframes pop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

/* ===== Écran de jeu ===== */
.play-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.timer-bar-track {
  flex: 1;
  background: var(--color-border);
  border-radius: 999px;
  height: 16px;
  overflow: hidden;
}
.timer-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-secondary), var(--color-accent));
  width: 100%;
  transition: width 0.2s linear;
  border-radius: 999px;
}

.score-badge {
  background: var(--color-bg-alt);
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: bold;
  font-size: 1.1rem;
  box-shadow: 0 4px 10px var(--color-card-shadow);
  white-space: nowrap;
}

.stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 22vh;
}

.target-display {
  font-size: 4.5rem; /* ajusté dynamiquement en JS selon la longueur du mot */
  font-weight: bold;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.15s ease, transform 0.15s ease;
  background: var(--color-bg-alt);
  border-radius: var(--radius-lg);
  padding: 20px 40px;
  box-shadow: 0 8px 20px var(--color-card-shadow);
  max-width: 92vw;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}
.target-display.visible {
  opacity: 1;
  transform: scale(1);
}

.choices-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

.choice-btn {
  background: var(--color-bg-alt);
  border: 3px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  font-size: 1.5rem; /* ajusté dynamiquement en JS selon la longueur du mot */
  font-weight: bold;
  min-height: 64px;
  width: 100%;
  box-shadow: 0 4px 10px var(--color-card-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}
.choice-btn:active:not(:disabled) { transform: scale(0.95); }
.choice-btn:disabled { cursor: default; }

.choice-correct {
  background: var(--color-success) !important;
  border-color: var(--color-success) !important;
  color: #143d14;
}
.choice-wrong {
  background: var(--color-warning) !important;
  border-color: var(--color-warning) !important;
  color: #4a2c00;
}

.floating-feedback {
  position: fixed;
  left: 50%;
  bottom: 10%;
  transform: translateX(-50%);
  background: var(--color-bg-alt);
  color: var(--color-text);
  padding: 12px 22px;
  border-radius: 999px;
  box-shadow: 0 6px 16px var(--color-card-shadow);
  font-weight: bold;
  animation: floatUp 0.7s ease forwards;
  z-index: 10;
}
.feedback-good { color: var(--color-success); }
.feedback-soft { color: var(--color-warning); }

@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, 10px); }
  20% { opacity: 1; transform: translate(-50%, 0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -10px); }
}

/* ===== Jeu Mots en Syllabes ===== */
.syllable-pair {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  justify-content: center;
  gap: 20px;
  margin: 30px 0;
}

.pair-column {
  background: var(--color-bg-alt);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 20px var(--color-card-shadow);
  padding: 18px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  flex: 1 1 260px;
  max-width: 420px;
}

.pair-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.6;
  font-weight: bold;
}

.word-whole, .word-split {
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  max-width: 100%;
}

.word-whole { color: var(--color-text); }
.word-split { color: var(--color-secondary); }

.btn-next {
  display: block;
  margin: 10px auto 0;
  min-width: 220px;
}

/* Sur petit écran, on empile les deux colonnes au lieu de forcer la même ligne */
@media (max-width: 560px) {
  .syllable-pair { flex-direction: column; align-items: stretch; }
  .pair-column { max-width: none; }
}

/* ===== Écran de fin ===== */
.end-screen { text-align: center; padding-top: 20px; }
.end-level-label { opacity: 0.75; margin-top: -4px; }
.end-score {
  font-size: clamp(3.5rem, 16vw, 6rem);
  font-weight: bold;
  color: var(--color-primary);
  margin: 10px 0 0;
}
.end-score-label { margin-top: 0; opacity: 0.85; }
.end-record { font-weight: bold; color: var(--color-warning); }
.end-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 320px;
  margin: 24px auto 0;
}

/* ===== Réglages ===== */
.settings-section {
  background: var(--color-bg-alt);
  border-radius: var(--radius-md);
  padding: 18px;
  margin-bottom: 20px;
  box-shadow: 0 4px 12px var(--color-card-shadow);
}
.settings-section h3 { margin-top: 0; }

.font-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.font-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--color-border);
}
.font-option.selected { border-color: var(--color-secondary); }
.font-option input { width: 20px; height: 20px; }

.settings-hint { font-size: 0.9rem; opacity: 0.75; }

.import-block { margin: 14px 0; display: flex; flex-direction: column; gap: 8px; }
.import-block label { font-weight: bold; font-size: 0.95rem; }
.import-block textarea, .import-block input[type="file"] {
  font-family: var(--app-font-family);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--color-bg);
  color: var(--color-text);
}
.import-feedback { font-weight: bold; min-height: 1.2em; }

/* ===== Responsive : tablette / grands écrans ===== */
@media (min-width: 700px) {
  .end-actions { flex-direction: row; justify-content: center; max-width: none; }
  .end-actions button { flex: 1; max-width: 220px; }
}

/* iPad / tactile : cibles plus grandes, pas d'effets hover-only */
@media (pointer: coarse) {
  .choice-btn, .level-card, .btn-primary, .btn-secondary, .game-card {
    min-height: 56px;
  }
}
