/* =========================================================
   Doigts Magiques — styles
   Thème : ciel doux / corail / menthe (ludique, lisible)
   ========================================================= */

:root {
  /* Couleurs de base */
  --bg-1: #dff3ff;
  --bg-2: #e8faf3;
  --bg-3: #fff6e8;
  --surface: rgba(255, 255, 255, 0.82);
  --ink: #1a2b3c;
  --ink-soft: #3d556c;
  --muted: #6a8299;
  --line: rgba(26, 43, 60, 0.12);
  --accent: #ff6b4a;
  --accent-dark: #e24f2e;
  --success: #1faa6e;
  --warn: #e8a317;
  --danger: #d64545;
  --shadow: 0 10px 30px rgba(26, 43, 60, 0.1);
  --radius: 18px;
  --font-display: "Trebuchet MS", "Segoe UI", Verdana, sans-serif;
  --font-body: "Segoe UI", "Trebuchet MS", Verdana, sans-serif;
  --font-mono: "Consolas", "Courier New", monospace;

  /* Couleurs des doigts (partagées clavier + mains) */
  --finger-pinky-l: #ff6b6b;
  --finger-ring-l: #ffa94d;
  --finger-middle-l: #fcc419;
  --finger-index-l: #51cf66;
  --finger-thumb: #74c0fc;
  --finger-index-r: #339af0;
  --finger-middle-r: #f06595;
  --finger-ring-r: #ff8787;
  --finger-pinky-r: #20c997;

  --key-bg: #ffffff;
  --key-text: #1a2b3c;
  --palm: #ffd8a8;
  --finger-idle: #ffec99;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, var(--bg-1), transparent 60%),
    radial-gradient(900px 500px at 90% 0%, var(--bg-3), transparent 55%),
    linear-gradient(165deg, var(--bg-1), var(--bg-2) 45%, var(--bg-3));
  line-height: 1.45;
  overflow-x: hidden;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: #fff;
  padding: 0.75rem 1rem;
  z-index: 1000;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
}

/* Décor de fond */
.bg-shapes {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(2px);
  opacity: 0.35;
}

.blob-1 {
  width: 280px;
  height: 280px;
  background: #7ad7ff;
  top: 12%;
  left: -80px;
  animation: floaty 12s ease-in-out infinite;
}

.blob-2 {
  width: 220px;
  height: 220px;
  background: #ffb4a2;
  top: 55%;
  right: -60px;
  animation: floaty 15s ease-in-out infinite reverse;
}

.blob-3 {
  width: 160px;
  height: 160px;
  background: #b2f2bb;
  bottom: 8%;
  left: 30%;
  animation: floaty 18s ease-in-out infinite;
}

@keyframes floaty {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-18px);
  }
}

/* En-tête */
.top-bar {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.top-bar .main-nav {
  margin-left: auto;
}

.xp-float {
  display: none !important;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

a.brand-home-link {
  text-decoration: none;
  color: inherit;
  border-radius: 10px;
  outline-offset: 3px;
}

a.brand-home-link:hover .brand-title {
  color: var(--accent, #ff6b4a);
}

a.brand-home-link:focus-visible {
  outline: 2px solid var(--accent, #339af0);
}

/* Titres de vue : focus programmatique uniquement (tabindex=-1), sans contour */
h1[tabindex="-1"]:focus,
h2[tabindex="-1"]:focus,
.level-name[tabindex="-1"]:focus {
  outline: none;
}

.brand-mark {
  display: inline-flex;
  line-height: 0;
}

.brand-mark svg {
  display: block;
}

.brand-title,
.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 3vw, 2rem);
  letter-spacing: -0.02em;
  color: var(--ink);
  font-weight: 700;
  line-height: 1.1;
}

.player-strip[hidden] {
  display: none !important;
}

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  max-width: 100%;
  min-width: 0;
  justify-content: center;
}

.stat {
  background: var(--surface);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  min-width: 5.5rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stat-value {
  display: block;
  font-weight: 700;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

/* Navigation principale */
.main-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  justify-content: center;
  flex: 1 1 14rem;
  max-width: 100%;
  min-width: 0;
}

/* Commun bouton + ancre (Jeux) : même boîte, même axe vertical */
.nav-link {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  margin: 0;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-weight: 700;
  font-size: 0.86rem;
  line-height: 1.2;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  vertical-align: middle;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
  background: color-mix(in srgb, #fff 70%, transparent);
  color: var(--ink);
}

.nav-link.is-active {
  background: #fff;
  border-color: var(--line);
  color: var(--accent-dark);
  box-shadow: 0 2px 8px rgba(26, 43, 60, 0.08);
}

/* Écran Accueil */
.learn-home {
  position: relative;
  z-index: 2;
  max-width: 880px;
  margin: 0 auto 2rem;
  padding: 0.5rem 1.25rem 2.5rem;
}

.home-page {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.home-hero {
  text-align: center;
  padding: 0.5rem 0 0.25rem;
}

.home-hero-visual {
  display: flex;
  justify-content: center;
  margin-bottom: 0.85rem;
}

.home-hero-keyboard {
  width: min(280px, 72vw);
  height: auto;
  filter: drop-shadow(0 10px 18px rgba(26, 43, 60, 0.12));
}

.hk-body {
  fill: #fff;
  stroke: var(--ink);
  stroke-width: 2.5;
}

.hk-keys rect {
  fill: #eef6fb;
  stroke: color-mix(in srgb, var(--ink) 18%, transparent);
  stroke-width: 1.2;
}

.hk-keys .hk-accent {
  fill: color-mix(in srgb, var(--accent) 35%, #fff);
}

.hk-keys .hk-accent-2 {
  fill: color-mix(in srgb, var(--success) 28%, #fff);
}

.hk-keys .hk-space {
  fill: color-mix(in srgb, var(--finger-thumb) 45%, #fff);
}

.hk-spark {
  fill: var(--accent);
  opacity: 0.85;
}

@media (prefers-reduced-motion: no-preference) {
  .hk-spark-1 {
    animation: home-spark 2.8s ease-in-out infinite;
  }
  .hk-spark-2 {
    animation: home-spark 3.4s ease-in-out infinite 0.4s;
  }
  .hk-spark-3 {
    animation: home-spark 3s ease-in-out infinite 0.9s;
  }
  .home-cta {
    animation: home-cta-pulse 2.6s ease-in-out infinite;
  }
}

@keyframes home-spark {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.85);
  }
  50% {
    opacity: 1;
    transform: scale(1.15);
  }
}

@keyframes home-cta-pulse {
  0%,
  100% {
    box-shadow: 0 6px 0 rgba(226, 79, 46, 0.28);
  }
  50% {
    box-shadow: 0 6px 0 rgba(226, 79, 46, 0.28), 0 0 0 8px color-mix(in srgb, var(--accent) 12%, transparent);
  }
}

.home-title {
  margin: 0 0 0.45rem;
  font-family: var(--font-display);
  font-size: clamp(2rem, 5.5vw, 2.85rem);
  letter-spacing: -0.03em;
  line-height: 1.08;
  color: var(--ink);
}

.home-promise {
  margin: 0 auto 0.55rem;
  max-width: 28rem;
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 2.8vw, 1.45rem);
  font-weight: 700;
  color: var(--accent-dark);
  line-height: 1.3;
}

.home-lead {
  margin: 0 auto 1.15rem;
  max-width: 32rem;
  color: var(--ink-soft);
  font-size: clamp(0.98rem, 2.2vw, 1.08rem);
}

.home-cta {
  min-width: min(16rem, 100%);
  font-size: 1.12rem;
  padding: 0.95rem 1.6rem;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: 2px solid color-mix(in srgb, var(--accent-dark) 70%, #000);
  box-shadow: 0 6px 0 rgba(226, 79, 46, 0.28);
}

.btn-primary:hover {
  background: var(--accent-dark);
}

.home-section-title {
  margin: 0 0 0.55rem;
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 2.5vw, 1.35rem);
}

.home-section-title--subtle {
  font-size: 1.05rem;
  color: var(--ink-soft);
}

.home-config {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.15rem;
  box-shadow: 0 8px 22px rgba(26, 43, 60, 0.06);
}

.home-config-hint {
  margin: 0 0 0.85rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.home-config-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem 1rem;
}

.home-config-field {
  margin: 0;
  min-width: 0;
}

.home-activities {
  scroll-margin-top: 1rem;
}

.home-activity-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.home-activity-card {
  appearance: none;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 18px;
  padding: 1.05rem 1rem 1.1rem;
  min-height: 8.5rem;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 6px 16px rgba(26, 43, 60, 0.05);
}

.home-activity-card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
  box-shadow: var(--shadow);
}

.home-activity-card:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.home-activity-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}

.home-activity-card.is-recommended {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  background: linear-gradient(165deg, #fff 55%, color-mix(in srgb, var(--accent) 8%, #fff));
}

.home-activity-card--wide {
  grid-column: 1 / -1;
  min-height: auto;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
}

.home-activity-card--wide .home-activity-desc {
  flex: 1 1 12rem;
}

.home-activity-badge {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #fff;
  background: var(--accent);
  border-radius: 999px;
  padding: 0.28rem 0.55rem;
  max-width: 46%;
  overflow-wrap: anywhere;
  line-height: 1.2;
}

.home-activity-icon {
  display: inline-flex;
  color: var(--accent-dark);
  margin-bottom: 0.15rem;
}

.home-activity-name {
  display: block;
  font-weight: 800;
  font-size: 1.08rem;
  line-height: 1.25;
  padding-right: 4.5rem;
  overflow-wrap: anywhere;
}

.home-activity-card:not(.is-recommended) .home-activity-name {
  padding-right: 0;
}

.home-activity-desc {
  display: block;
  color: var(--ink-soft);
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.home-reassure {
  padding: 0.25rem 0.15rem 0;
}

.home-reassure-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.45rem;
}

.home-reassure-list li {
  position: relative;
  padding: 0.55rem 0.75rem 0.55rem 2rem;
  background: color-mix(in srgb, #fff 70%, transparent);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.home-reassure-list li::before {
  content: "";
  position: absolute;
  left: 0.75rem;
  top: 50%;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--success);
  transform: translateY(-50%);
}

.learn-home-title {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3vw, 2rem);
}

.learn-home-lead {
  margin: 0 0 1.25rem;
  color: var(--muted);
}

.learn-mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  gap: 0.65rem;
  margin-bottom: 1.25rem;
}

.learn-mode-card {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 16px;
  padding: 1.1rem 0.85rem;
  cursor: pointer;
  text-align: center;
  font: inherit;
  font-weight: 800;
  color: var(--ink);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.learn-mode-card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: var(--shadow);
}

.learn-mode-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}

.learn-resume-block {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

.learn-last-activity {
  margin: 0;
  color: var(--ink-soft);
  font-weight: 600;
}

.learn-library-link {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--accent-dark);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  padding: 0.25rem 0;
}

@media (max-width: 720px) {
  .home-config-grid,
  .home-activity-grid {
    grid-template-columns: 1fr;
  }

  .home-activity-card--wide {
    flex-direction: column;
    align-items: flex-start;
  }

  .home-activity-name {
    padding-right: 0;
  }

  .home-activity-card.is-recommended .home-activity-badge {
    position: static;
    max-width: 100%;
    margin-bottom: 0.15rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hk-spark-1,
  .hk-spark-2,
  .hk-spark-3,
  .home-cta {
    animation: none !important;
  }

  .home-activity-card,
  .btn {
    transition: none;
  }
}

.exercise-mode-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
  margin: 0.5rem auto 0;
  padding: 0 1.25rem;
  min-width: 0;
}

.mode-tab {
  appearance: none;
  border: 1px solid var(--line);
  background: color-mix(in srgb, #fff 75%, transparent);
  color: var(--ink-soft);
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
}

.mode-tab:hover {
  color: var(--ink);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
}

.mode-tab.is-active {
  background: #fff;
  color: var(--accent-dark);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent);
}

.settings-screen,
.progress-screen {
  position: relative;
  z-index: 2;
  max-width: 720px;
  margin: 0 auto 2rem;
  padding: 0.75rem 1.25rem 2rem;
}

.settings-title {
  margin: 0 0 1rem;
  font-family: var(--font-display);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.settings-grid .field {
  min-width: 0;
  max-width: 100%;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.settings-note {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Bandeau joueur — motivation légère */
.player-strip {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  margin: 0 1.25rem 0.75rem;
  padding: 0.55rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 4px 16px rgba(26, 43, 60, 0.06);
}

.player-achievements-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.player-achievements-btn:hover {
  background: color-mix(in srgb, var(--accent) 12%, #fff);
  transform: translateY(-1px);
}

.player-xp-block {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1 1 12rem;
  min-width: 10rem;
}

.player-level-pill {
  font-weight: 800;
  font-size: 0.82rem;
  color: var(--accent-dark);
  white-space: nowrap;
}

.xp-track {
  flex: 1;
  height: 0.45rem;
  background: color-mix(in srgb, var(--line) 80%, #fff);
  border-radius: 999px;
  overflow: hidden;
}

.xp-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #51cf66, #339af0);
  border-radius: inherit;
  transition: width 0.45s ease;
}

.player-xp-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.player-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.player-chip {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-soft);
  background: color-mix(in srgb, var(--bg-1) 55%, #fff);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.28rem 0.65rem;
}

.player-chip.complete {
  background: color-mix(in srgb, var(--success) 18%, #fff);
  color: var(--success);
}

.xp-float {
  position: fixed;
  top: 5.5rem;
  right: 1.5rem;
  z-index: 40;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  font-size: 0.9rem;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.xp-float.show {
  opacity: 1;
  transform: translateY(0);
}

/* Succès (achievements) */
.achievements-screen {
  position: relative;
  z-index: 2;
  max-width: 720px;
  margin: 0 auto 2rem;
  padding: 0.5rem 1.25rem 2rem;
}

.achievements-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.35rem;
}

.achievements-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 3vw, 1.85rem);
}

.achievements-lead {
  margin: 0 0 1.25rem;
  color: var(--muted);
}

.achievements-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  gap: 0.55rem;
  margin-bottom: 1.25rem;
}

.achievements-stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.7rem 0.8rem;
  text-align: center;
}

.achievements-stat-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.achievements-stat-value {
  display: block;
  margin-top: 0.2rem;
  font-size: 1.2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.achievements-daily {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  margin-bottom: 1.25rem;
}

.achievements-daily h3 {
  margin: 0 0 0.45rem;
  font-size: 1rem;
}

.achievements-daily-list {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--ink-soft);
}

.achievements-daily-note {
  margin: 0.55rem 0 0;
  font-weight: 700;
  color: var(--success);
}

.achievements-section {
  margin-bottom: 1.35rem;
}

.achievements-section h3 {
  margin: 0 0 0.55rem;
  font-size: 1.05rem;
}

.achievements-badges {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 0.55rem;
}

.badge-card {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.75rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  min-height: 6.2rem;
}

.badge-card.locked {
  opacity: 0.45;
  filter: grayscale(0.35);
}

.badge-icon {
  font-size: 1.35rem;
  line-height: 1.2;
}

.badge-title {
  font-weight: 800;
  font-size: 0.88rem;
}

.badge-desc {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.3;
}

.achievements-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.achievements-list li {
  padding: 0.55rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-weight: 600;
}

.achievements-empty {
  color: var(--muted);
  font-weight: 500;
}

body.view-achievements .library-screen,
body.view-achievements #exercise-root,
body.view-achievements .text-play-screen,
body.view-achievements .text-result-screen,
body.view-achievements .learn-home,
body.view-achievements #path-screen,
body.view-achievements .progress-screen,
body.view-achievements .settings-screen {
  display: none !important;
}

body.view-learn #exercise-root,
body.view-learn #path-screen,
body.view-learn #library-screen,
body.view-learn #text-play-screen,
body.view-learn #text-result-screen,
body.view-learn #progress-screen,
body.view-learn #achievements-screen,
body.view-learn #settings-screen,
body.view-learn #training-result-screen {
  display: none !important;
}

body.view-path #learn-home,
body.view-path #exercise-root,
body.view-path #library-screen,
body.view-path #text-play-screen,
body.view-path #text-result-screen,
body.view-path #progress-screen,
body.view-path #achievements-screen,
body.view-path #settings-screen,
body.view-path #training-result-screen {
  display: none !important;
}

body.view-exercise #learn-home,
body.view-exercise #path-screen,
body.view-exercise #library-screen,
body.view-exercise #progress-screen,
body.view-exercise #achievements-screen,
body.view-exercise #settings-screen {
  display: none !important;
}

body.view-progress #learn-home,
body.view-progress #path-screen,
body.view-progress #exercise-root,
body.view-progress #library-screen,
body.view-progress #achievements-screen,
body.view-progress #settings-screen {
  display: none !important;
}

body.view-settings #learn-home,
body.view-settings #path-screen,
body.view-settings #exercise-root,
body.view-settings #library-screen,
body.view-settings #progress-screen,
body.view-settings #achievements-screen {
  display: none !important;
}

@media (max-width: 720px) {
  .top-bar {
    flex-direction: column;
    align-items: center;
    gap: 0.65rem;
  }

  .top-bar .main-nav {
    margin-left: auto;
    margin-right: auto;
  }

  .main-nav {
    flex: 0 0 auto;
    width: auto;
    max-width: min(100%, 18.5rem);
    justify-content: center;
    align-items: center;
    align-content: center;
    flex-wrap: wrap;
    overflow-x: visible;
    overflow-y: visible;
    padding-bottom: 0;
  }

  .nav-link {
    flex: 0 0 auto;
    align-self: center;
    height: auto;
    width: auto;
    min-height: 44px;
    font-size: 0.8rem;
    padding: 0.45rem 0.75rem;
  }

  .stats-bar {
    justify-content: center;
  }
}

/* Contenu principal */
.main {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 0.5rem 1.25rem 1rem;
}

.word-section {
  text-align: center;
  margin-bottom: 0.75rem;
}

.level-name {
  margin: 0 0 0.35rem;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.95rem;
}

.word-display {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
  gap: 0.12rem;
  min-height: 0;
  max-height: calc(2 * 1.25em + 0.9rem);
  padding: 0.4rem 0.75rem;
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: clamp(1.55rem, 4.8vw, 2.45rem);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.06em;
  user-select: none;
}

/* Affichage phrases — typographie de lecture, pas d’espacement « lettres » */
.phrase-display {
  display: block;
  width: 100%;
  max-width: 42rem;
  margin: 0 auto;
  min-height: 0;
  max-height: calc(2 * 1.55em + 0.85rem);
  padding: 0.45rem 0.9rem;
  overflow: hidden;
  font-family: Georgia, "Palatino Linotype", "Times New Roman", serif;
  font-size: clamp(1.05rem, 2.6vw, 1.45rem);
  font-weight: 500;
  line-height: 1.55;
  letter-spacing: normal;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-wrap: break-word;
  user-select: none;
}

/* Critique : display:flex/block ne doit jamais écraser [hidden] */
.word-display[hidden],
.phrase-display[hidden],
.text-display[hidden],
[data-exercise-block][hidden] {
  display: none !important;
}

.phrase-display .ch {
  display: inline;
  border-radius: 3px;
  transition: background 0.12s ease, color 0.12s ease;
}

.phrase-display .ch.done {
  color: var(--success);
}

.phrase-display .ch.current {
  background: var(--accent);
  color: #fff;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

.phrase-display .ch.current.cursor {
  animation: phrase-caret 1s steps(1) infinite;
}

.phrase-display .ch.space.current {
  padding: 0 0.12em;
}

@keyframes phrase-caret {
  50% {
    box-shadow: inset 0 -2px 0 transparent;
  }
}

.phrase-display.shake-mild {
  animation: shake-mild 0.35s ease;
}

@keyframes shake-mild {
  0%,
  100% {
    transform: translateX(0);
  }
  30% {
    transform: translateX(-4px);
  }
  60% {
    transform: translateX(4px);
  }
}

.phrase-display.success-pop {
  animation: success-pop 0.55s ease;
}

.key.shift-key {
  min-width: 4.2rem;
  font-size: 0.78rem;
  text-transform: none;
}

.key.active.shift-key {
  z-index: 3;
}


.letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0.85em;
  padding: 0.05em 0.05em;
  border-radius: 10px;
  color: var(--ink);
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.letter.done {
  color: var(--success);
}

.letter.current {
  background: var(--accent);
  color: #fff;
  transform: translateY(-3px) scale(1.08);
  box-shadow: 0 6px 0 rgba(226, 79, 46, 0.35);
}

.letter.space-char::before {
  content: "␣";
  opacity: 0.55;
}

.word-display.shake {
  animation: shake 0.4s ease;
}

.word-display.success-pop {
  animation: success-pop 0.55s ease;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-8px);
  }
  40% {
    transform: translateX(8px);
  }
  60% {
    transform: translateX(-5px);
  }
  80% {
    transform: translateX(5px);
  }
}

@keyframes success-pop {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

.feedback {
  min-height: 1.5rem;
  margin: 0.35rem 0;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent-dark);
}

.activity-pause-banner {
  margin: 0.25rem 0 0.5rem;
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent, #339af0) 12%, white);
  border: 1px solid color-mix(in srgb, var(--accent, #339af0) 35%, transparent);
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
}

.adaptation-notice {
  margin: 0.35rem 0 0.15rem;
  padding: 0.55rem 0.75rem;
  border-radius: 0.45rem;
  font-size: clamp(0.9rem, 2.2vw, 1.05rem);
  font-weight: 600;
  line-height: 1.45;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

.adaptation-notice.is-info {
  background: color-mix(in srgb, var(--accent, #2a6f97) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent, #2a6f97) 35%, transparent);
  color: var(--ink);
}

.adaptation-notice.is-error {
  background: color-mix(in srgb, var(--danger, #b33) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger, #b33) 40%, transparent);
  color: var(--ink);
  font-weight: 700;
}

.feedback.good {
  color: var(--success);
}

.instruction {
  margin: 0.2rem 0 0;
  font-size: clamp(0.98rem, 2.2vw, 1.25rem);
  font-weight: 700;
  color: var(--ink);
}

/* Clavier */
.keyboard-section {
  margin: 0 auto 0.55rem;
  width: 100%;
  max-width: 56rem;
  overflow-x: auto;
}

.keyboard {
  --kb-cols: 60;
  --kb-rows: 5;
  --key-h: 2.7rem;
  --kb-gap: 0.28rem;
  display: grid;
  grid-template-columns: repeat(var(--kb-cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--kb-rows), var(--key-h));
  gap: var(--kb-gap);
  align-items: stretch;
  width: 100%;
  min-width: 0;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  box-sizing: border-box;
}

.keyboard-row {
  display: contents;
}

.key {
  --key-color: var(--muted);
  --key-w: 1;
  position: relative;
  min-width: 0;
  height: auto;
  min-height: 0;
  padding: 0.15rem 0.2rem;
  border: 2px solid color-mix(in srgb, var(--key-color) 35%, transparent);
  border-radius: 8px;
  background: var(--key-bg);
  color: var(--key-text);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: clamp(0.55rem, 1.55vw, 0.95rem);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 0 color-mix(in srgb, var(--key-color) 40%, #ccc);
  transition: transform 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
  user-select: none;
  box-sizing: border-box;
}

.key.wide,
.key.mod-key,
.key.shift-key {
  font-size: clamp(0.45rem, 1.2vw, 0.78rem);
}

.key.space {
  min-width: 0;
}

/* Entrée ISO : une seule touche logique, silhouette en L */
.key.enter-key.enter-iso {
  z-index: 2;
  align-self: stretch;
  border-radius: 8px;
  clip-path: polygon(
    38% 0%,
    100% 0%,
    100% 100%,
    0% 100%,
    0% 52%,
    38% 52%
  );
}

.key.enter-key.enter-ansi {
  border-radius: 8px;
}

.key-legend {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.05;
  gap: 0.05rem;
  pointer-events: none;
}

.key-legend .pri {
  font-weight: 800;
}

.key-legend .sec {
  font-size: 0.68em;
  font-weight: 600;
  opacity: 0.72;
}

.key .dot {
  position: absolute;
  bottom: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--key-color);
  opacity: 0.85;
}

.key.active {
  background: var(--key-color);
  color: #fff;
  transform: translateY(-3px) scale(1.06);
  box-shadow: 0 6px 0 color-mix(in srgb, var(--key-color) 70%, #000);
  z-index: 2;
}

.key.active .key-legend .sec {
  opacity: 0.9;
}

.key.pressed {
  transform: translateY(2px);
  box-shadow: 0 1px 0 color-mix(in srgb, var(--key-color) 40%, #ccc);
}

/* Couleurs par doigt sur les touches */
.key.finger-pinky-l {
  --key-color: var(--finger-pinky-l);
}
.key.finger-ring-l {
  --key-color: var(--finger-ring-l);
}
.key.finger-middle-l {
  --key-color: var(--finger-middle-l);
}
.key.finger-index-l {
  --key-color: var(--finger-index-l);
}
.key.finger-thumb {
  --key-color: var(--finger-thumb);
}
.key.finger-index-r {
  --key-color: var(--finger-index-r);
}
.key.finger-middle-r {
  --key-color: var(--finger-middle-r);
}
.key.finger-ring-r {
  --key-color: var(--finger-ring-r);
}
.key.finger-pinky-r {
  --key-color: var(--finger-pinky-r);
}

/* Mains — sous le clavier, jamais superposées aux touches */
.hands-section {
  text-align: center;
  margin-top: 0;
  margin-bottom: 0.65rem;
}

.hands-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(0.75rem, 5vw, 3rem);
  flex-wrap: wrap;
}

.hand-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.hand-svg {
  width: min(180px, 40vw);
  height: auto;
  filter: drop-shadow(0 8px 12px rgba(26, 43, 60, 0.12));
}

.palm {
  fill: var(--palm);
  stroke: #e8a87c;
  stroke-width: 3;
}

.finger rect {
  fill: var(--finger-idle);
  stroke: #e8b86d;
  stroke-width: 2.5;
  transition: fill 0.18s ease, stroke 0.18s ease, filter 0.18s ease;
}

.finger.active rect {
  filter: drop-shadow(0 0 6px rgba(255, 107, 74, 0.45));
  stroke: #fff;
  stroke-width: 3.5;
}

/* Couleurs actives des doigts */
.hand-left .finger-pinky.active rect {
  fill: var(--finger-pinky-l);
}
.hand-left .finger-ring.active rect {
  fill: var(--finger-ring-l);
}
.hand-left .finger-middle.active rect {
  fill: var(--finger-middle-l);
}
.hand-left .finger-index.active rect {
  fill: var(--finger-index-l);
}
.hand-left .finger-thumb.active rect,
.hand-right .finger-thumb.active rect {
  fill: var(--finger-thumb);
}
.hand-right .finger-index.active rect {
  fill: var(--finger-index-r);
}
.hand-right .finger-middle.active rect {
  fill: var(--finger-middle-r);
}
.hand-right .finger-ring.active rect {
  fill: var(--finger-ring-r);
}
.hand-right .finger-pinky.active rect {
  fill: var(--finger-pinky-r);
}

.hand-label {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}

.finger-hint {
  margin: 0.75rem 0 0;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--ink);
  min-height: 1.5rem;
}

/* Stats détaillées */
.detail-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
  margin: 1rem 0 0.5rem;
}

.detail-stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.65rem 0.5rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.detail-label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.15rem;
}

.detail-stat span:last-child {
  font-weight: 800;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

/* Contrôles */
.controls {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto 2rem;
  padding: 0 1.25rem;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 10.5rem;
  flex: 1 1 10.5rem;
  max-width: 16rem;
}

/* Légendes secondaires masquées déjà gérées en responsive */

.field-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.ch.linebreak,
.ch.linebreak-marker {
  display: inline;
  color: #1a7a4c;
  font-weight: 800;
  white-space: nowrap;
}

.ch.linebreak.current,
.ch.linebreak-marker.current {
  outline: 2px solid #1a7a4c;
  border-radius: 4px;
  padding: 0 0.12rem;
}

.library-card-warn {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: #a33;
}

.library-card-adapt {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--ink-muted, #4a5d6e);
}

.library-card.incompatible {
  opacity: 0.88;
}

.field select {
  appearance: none;
  background: var(--surface)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%233d556c' d='M0 0l6 8 6-8z'/%3E%3C/svg%3E")
    no-repeat right 0.9rem center;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 2.2rem 0.7rem 0.9rem;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.field select:focus {
  outline: 3px solid color-mix(in srgb, var(--accent) 50%, transparent);
  outline-offset: 2px;
}

.btn {
  border: none;
  border-radius: 14px;
  padding: 0.8rem 1.15rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
  transition: transform 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

.btn:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.btn:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--line);
  box-shadow: 0 3px 0 rgba(26, 43, 60, 0.08);
}

.btn-secondary:hover {
  background: #f4fbff;
}

.btn-secondary[aria-pressed="false"] {
  opacity: 0.85;
}

.btn-danger {
  background: #fff5f5;
  color: var(--danger);
  border: 2px solid color-mix(in srgb, var(--danger) 35%, transparent);
}

.btn-danger:hover {
  background: #ffe3e3;
}

.hint-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.5rem 0 0;
}

/* Crédit auteur — bas de page, non fixe */
.site-credit {
  position: relative;
  z-index: 0;
  max-width: 40rem;
  margin: 1.75rem auto 2rem;
  padding: 0 1.25rem 0.5rem;
  text-align: center;
  pointer-events: none;
}

.site-credit p {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--ink-soft);
  opacity: 0.85;
}

/* Overlay Bravo */
.success-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(26, 43, 60, 0.25);
  z-index: 50;
  pointer-events: none;
}

.success-overlay[hidden] {
  display: none;
}

.success-text {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 10vw, 4.5rem);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 6px 0 rgba(31, 170, 110, 0.55);
  background: var(--success);
  padding: 0.6rem 1.4rem;
  border-radius: 24px;
  animation: success-pop 0.55s ease;
}

/* Modes d'aide */
body.mode-intermediate .hands-section,
body.mode-intermediate .instruction,
body.mode-intermediate .finger-hint {
  display: none;
}

body.mode-expert .keyboard-section,
body.mode-expert .hands-section,
body.mode-expert .instruction,
body.mode-expert .finger-hint {
  display: none;
}

/* Responsive */
@media (max-width: 720px) {
  .top-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .stats-bar {
    justify-content: center;
  }

  .keyboard {
    --key-h: 1.9rem;
  }

  .key {
    font-size: clamp(0.42rem, 2.4vw, 0.7rem);
    padding: 0.05rem;
    border-radius: 6px;
  }

  .key-legend .sec,
  .key-legend .tert {
    display: none;
  }

  .key.wide,
  .key.mod-key,
  .key.shift-key {
    font-size: clamp(0.38rem, 2vw, 0.58rem);
  }

  .key.space {
    min-width: 28%;
  }

  .key .dot {
    width: 4px;
    height: 4px;
    bottom: 2px;
  }

  .detail-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .buttons .btn {
    flex: 1 1 calc(50% - 0.75rem);
  }

  .field {
    min-width: calc(50% - 0.75rem);
    max-width: none;
  }
}

@media (max-width: 420px) {
  .keyboard {
    --key-h: 2rem;
    --kb-gap: 0.22rem;
    padding: 0.65rem;
  }

  .key {
    font-size: 0.75rem;
    border-radius: 7px;
  }

  .key .dot {
    width: 5px;
    height: 5px;
    bottom: 3px;
  }
}

/* Accessibilité : réduire les animations */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .blob {
    animation: none;
  }

  .phrase-display .ch.current.cursor {
    animation: none;
  }
}

/* =========================================================
   Mode Textes — bibliothèque, lecture, résultats
   ========================================================= */

body.view-library #exercise-root,
body.view-library #text-play-screen,
body.view-library #text-result-screen,
body.view-library #learn-home,
body.view-library #path-screen,
body.view-library #progress-screen,
body.view-library #achievements-screen,
body.view-library #settings-screen,
body.view-library #training-result-screen {
  display: none !important;
}

body.view-library #library-screen {
  display: block;
}

body.view-text-play #library-screen,
body.view-text-play #text-result-screen,
body.view-text-play #learn-home,
body.view-text-play #path-screen,
body.view-text-play #progress-screen,
body.view-text-play #achievements-screen,
body.view-text-play #settings-screen {
  display: none !important;
}

body.view-text-play #text-play-screen,
body.view-text-play #exercise-root {
  display: block;
}

body.view-text-play #exercise-mode-bar,
body.view-text-play #exercise-controls {
  display: none !important;
}

body.view-text-result #library-screen,
body.view-text-result #exercise-root,
body.view-text-result #text-play-screen,
body.view-text-result #learn-home,
body.view-text-result #path-screen,
body.view-text-result #progress-screen,
body.view-text-result #achievements-screen,
body.view-text-result #settings-screen {
  display: none !important;
}

body.view-text-result #text-result-screen {
  display: flex;
}

.library-screen {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 0.5rem 1.25rem 2rem;
}

.library-title {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 4vw, 2rem);
  color: var(--ink);
  text-align: center;
}

.library-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  margin-bottom: 1.25rem;
}

.library-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 1rem;
}

.library-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.library-card-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--ink);
  line-height: 1.3;
}

.library-card-author {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.library-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.library-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg-1) 60%, #fff);
  border: 1px solid var(--line);
  color: var(--ink-soft);
}

.library-badge.progress-new {
  background: #e8faf3;
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
}

.library-badge.progress-in_progress {
  background: #fff6e8;
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 35%, transparent);
}

.library-badge.progress-done {
  background: #e8faf3;
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
}

.library-card-stats {
  margin: 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.library-card-source {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.library-card .btn {
  margin-top: auto;
  align-self: flex-start;
}

.text-play-screen {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 0.25rem 1.25rem 0;
}

.text-meta-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
  margin-bottom: 0.75rem;
}

.text-meta-info {
  flex: 1 1 12rem;
  min-width: 0;
}

.text-play-title {
  margin: 0 0 0.2rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--ink);
}

.text-play-author,
.text-play-part {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.text-meta-stats {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.text-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.text-display {
  max-width: 48rem;
  max-height: calc(2 * 1.55em + 1rem);
  overflow: hidden;
  text-align: left;
  padding: 0.55rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.text-display p {
  margin: 0 0 0.55em;
}

.text-display p:last-child {
  margin-bottom: 0;
}

body.view-text-play .word-display,
body.view-text-play #word-heading.level-name {
  display: none;
}

body.view-text-play .detail-stats .detail-stat:first-child {
  display: none;
}

.text-result-screen {
  position: relative;
  z-index: 1;
  min-height: 60vh;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1.25rem 2rem;
}

.text-result-card {
  width: min(100%, 480px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.text-result-heading {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--ink);
}

.text-result-title {
  margin: 0 0 1rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.text-result-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
  margin: 0 0 1rem;
  text-align: center;
}

.text-result-stats div {
  background: color-mix(in srgb, var(--bg-1) 50%, #fff);
  border-radius: 12px;
  padding: 0.55rem 0.4rem;
}

.text-result-stats dt {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.text-result-stats dd {
  margin: 0.15rem 0 0;
  font-size: 1.25rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.text-result-error-keys {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.text-result-best {
  margin: 0 0 1rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.text-result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

/* Panneau de progression (entraînement) */
.progress-panel {
  margin: 1rem 0 0.5rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.progress-panel-title {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--ink);
}

.progress-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.progress-stat {
  text-align: center;
  padding: 0.45rem 0.35rem;
  background: color-mix(in srgb, var(--bg-1) 45%, #fff);
  border-radius: 12px;
}

.progress-label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.1rem;
}

.progress-value {
  font-weight: 800;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.progress-hint {
  margin: 0.35rem 0;
  font-size: 0.88rem;
  color: var(--ink-soft);
  line-height: 1.4;
}

.progress-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.progress-grid-cell {
  min-width: 2.1rem;
  padding: 0.25rem 0.35rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.progress-grid-cell .pg-char {
  display: block;
  font-size: 0.95rem;
  line-height: 1.1;
}

.progress-grid-cell .pg-pct {
  display: block;
  font-size: 0.65rem;
  color: var(--muted);
  font-weight: 600;
}

.progress-grid-cell.pg-low {
  background: color-mix(in srgb, var(--danger) 12%, #fff);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
}

.progress-grid-cell.pg-mid {
  background: color-mix(in srgb, var(--warn) 12%, #fff);
}

.progress-grid-cell.pg-high {
  background: color-mix(in srgb, var(--success) 12%, #fff);
}

.progress-dev-link {
  display: block;
  margin: 0.65rem auto 0;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
}

.progress-dev-link:hover {
  color: var(--ink-soft);
}

body.view-training-result #library-screen,
body.view-training-result #exercise-root,
body.view-training-result #text-play-screen,
body.view-training-result #text-result-screen {
  display: none !important;
}

body.view-training-result #training-result-screen {
  display: flex;
}

.training-result-advice {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  color: var(--ink);
  line-height: 1.45;
}

@media (max-width: 520px) {
  .progress-summary {
    grid-template-columns: 1fr;
  }
}

/* Screen-reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.section-header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin-bottom: 0.5rem;
}

.progress-lead,
.achievements-lead {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.achievements-work-btn {
  appearance: none;
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.nav-link:focus-visible,
.mode-tab:focus-visible,
.learn-mode-card:focus-visible,
.btn:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 70%, #fff);
  outline-offset: 2px;
}

/* ---- Responsive navigation & views ---- */
@media (max-width: 1440px) {
  .main-nav {
    gap: 0.3rem;
  }
}

@media (max-width: 1024px) {
  .top-bar {
    gap: 0.75rem;
  }

  .brand h1 {
    font-size: clamp(1.2rem, 2.5vw, 1.7rem);
  }

  .stats-bar .stat {
    min-width: 3.5rem;
  }

  .exercise-mode-bar {
    gap: 0.35rem;
  }
}

@media (max-width: 768px) {
  .top-bar {
    flex-direction: column;
    align-items: center;
    padding: 0.65rem 0.85rem;
    gap: 0.65rem;
  }

  .brand {
    justify-content: center;
    width: 100%;
  }

  .top-bar .main-nav {
    margin-left: auto;
    margin-right: auto;
  }

  .main-nav {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    align-content: center;
    width: auto;
    max-width: min(100%, 18.5rem);
    overflow-x: visible;
    overflow-y: visible;
    gap: 0.35rem 0.4rem;
    padding: 0;
    row-gap: 0.35rem;
  }

  .nav-link {
    flex: 0 0 auto;
    align-self: center;
    height: auto;
    width: auto;
    max-width: none;
    min-height: 44px;
    font-size: 0.8rem;
    padding: 0.45rem 0.75rem;
    line-height: 1.2;
  }

  .nav-link.is-active {
    /* pilule intrinsèque — jamais stretch */
    align-self: center;
  }

  .stats-bar {
    justify-content: center;
    gap: 0.4rem;
  }

  .player-strip {
    margin: 0 0.65rem 0.55rem;
    padding: 0.45rem 0.65rem;
  }

  .learn-home,
  .library-screen,
  .progress-screen,
  .settings-screen,
  .achievements-screen {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  .learn-mode-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .exercise-mode-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    padding: 0 0.75rem;
    -webkit-overflow-scrolling: touch;
  }

  .mode-tab {
    flex: 0 0 auto;
    min-height: 2.35rem;
    padding: 0.45rem 0.8rem;
    font-size: 0.78rem;
  }

  .hands-wrap {
    gap: 0.5rem;
  }

  .hand-svg {
    width: min(42vw, 9.5rem);
    height: auto;
  }
}

@media (max-width: 430px) {
  .brand h1 {
    font-size: 1.25rem;
  }

  .stat-label {
    font-size: 0.65rem;
  }

  .stat-value {
    font-size: 0.95rem;
  }

  .word-display {
    font-size: clamp(1.25rem, 5.5vw, 1.75rem);
    max-height: calc(2 * 1.25em + 0.7rem);
    padding: 0.35rem 0.45rem;
  }

  .phrase-display,
  .text-display {
    font-size: clamp(0.98rem, 4.2vw, 1.25rem);
    max-height: calc(2 * 1.5em + 0.7rem);
    padding: 0.35rem 0.55rem;
  }

  .keyboard {
    --key-h: 1.75rem;
    --kb-gap: 0.18rem;
    padding: 0.35rem;
  }

  .key {
    min-width: 0;
  }

  .controls-row.buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
  }

  .controls-row.buttons .btn {
    width: 100%;
  }
}

@media (max-width: 390px) {
  .nav-link {
    font-size: 0.75rem;
    padding: 0.42rem 0.6rem;
    min-height: 44px;
  }

  .learn-mode-card {
    padding: 0.85rem 0.55rem;
    font-size: 0.9rem;
  }

  .mode-tab {
    font-size: 0.72rem;
    padding: 0.4rem 0.65rem;
  }

  .hand-svg {
    width: min(40vw, 8.5rem);
  }
}

@media (max-width: 360px) {
  .top-bar {
    padding: 0.5rem 0.55rem;
    align-items: center;
  }

  .player-strip {
    margin-inline: 0.45rem;
  }

  .main-nav {
    gap: 0.3rem;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    max-width: min(100%, 15.75rem);
  }

  .nav-link {
    font-size: 0.72rem;
    padding: 0.4rem 0.55rem;
    min-height: 44px;
    height: auto;
    width: auto;
    flex: 0 0 auto;
    align-self: center;
  }

  .learn-mode-grid {
    gap: 0.45rem;
  }

  .section-header-row {
    flex-direction: column;
    align-items: stretch;
  }

  .section-header-row .btn {
    width: 100%;
  }
}

@media (max-width: 320px) {
  html,
  body {
    overflow-x: hidden;
    max-width: 100%;
  }

  .brand {
    max-width: 100%;
    min-width: 0;
  }

  .brand-mark svg {
    width: 28px;
    height: 22px;
  }

  .brand h1 {
    font-size: 1.1rem;
  }

  .stats-bar {
    gap: 0.3rem;
  }

  .stats-bar .stat {
    flex: 1 1 calc(50% - 0.3rem);
    min-width: 0;
    text-align: center;
  }

  .nav-link {
    font-size: 0.7rem;
    padding: 0.4rem 0.5rem;
    min-height: 44px;
    height: auto;
    width: auto;
    flex: 0 0 auto;
    align-self: center;
  }

  .word-display,
  .phrase-display,
  .text-display {
    font-size: 1.05rem;
    letter-spacing: 0.02em;
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .instruction {
    font-size: 0.88rem;
  }

  .keyboard-section {
    margin-inline: 0;
    padding-inline: 0.15rem;
    max-width: 100%;
  }

  .keyboard {
    --key-h: 1.55rem;
    max-width: 100%;
  }

  .key {
    border-radius: 4px;
    font-size: clamp(0.36rem, 2.8vw, 0.55rem);
  }

  .key-legend .sec,
  .key-legend .tert {
    display: none;
  }

  .hands-section {
    padding-inline: 0.25rem;
    max-width: 100%;
  }

  .hand-svg {
    width: min(38vw, 7.5rem);
  }

  .detail-stats {
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
    font-size: 0.8rem;
  }

  .library-filters {
    flex-direction: column;
  }

  .library-filters .field {
    width: 100%;
  }

  .controls {
    padding-inline: 0.5rem;
    max-width: 100%;
    box-sizing: border-box;
  }

  .hint-footer {
    font-size: 0.75rem;
  }

  .site-credit {
    margin: 1.25rem auto 1.5rem;
    padding-inline: 1rem;
  }

  .site-credit p {
    font-size: 0.72rem;
  }
}


/* =========================================================
   Parcours progressif
   ========================================================= */

.path-screen {
  position: relative;
  z-index: 2;
  max-width: 760px;
  margin: 0 auto 2rem;
  padding: 0.75rem 1.25rem 2.5rem;
}

.path-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.55rem, 3.5vw, 2.1rem);
}

.path-lead {
  margin: 0.35rem 0 0.45rem;
  color: var(--ink-soft);
  font-size: 1.05rem;
}

.path-session-note,
.path-config-summary {
  margin: 0.25rem 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
}

.path-reset-banner {
  margin: 0.65rem 0;
  padding: 0.65rem 0.8rem;
  border-radius: 12px;
  background: color-mix(in srgb, var(--warn) 16%, #fff);
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.path-lesson-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.path-lesson-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.95rem 1rem;
  display: grid;
  gap: 0.35rem;
}

.path-lesson-item.is-locked {
  opacity: 0.72;
}

.path-lesson-item.is-done {
  border-color: color-mix(in srgb, var(--success) 45%, var(--line));
}

.path-lesson-status {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.path-lesson-item.is-unlocked .path-lesson-status {
  color: var(--accent-dark);
}

.path-lesson-item.is-done .path-lesson-status {
  color: var(--success);
}

.path-lesson-item-title {
  margin: 0;
  font-size: 1.12rem;
  overflow-wrap: anywhere;
}

.path-lesson-item-desc,
.path-lesson-item-keys {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.path-lesson-btn {
  justify-self: start;
  min-height: 44px;
  margin-top: 0.25rem;
}

.path-lesson-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.path-lesson-chrome {
  margin-bottom: 0.75rem;
}

.path-lesson-meta {
  margin: 0 0 0.45rem;
  font-weight: 700;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.path-lesson-actions,
.path-result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.path-discover-panel,
.path-result-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem 1.05rem;
  margin-bottom: 0.85rem;
}

.path-discover-title {
  margin: 0 0 0.35rem;
  font-size: 1.2rem;
}

.path-discover-desc {
  margin: 0 0 0.65rem;
  color: var(--ink-soft);
}

.path-discover-keys {
  margin: 0 0 1rem;
  padding-left: 1.1rem;
  font-weight: 600;
}

.path-result-message {
  margin: 0 0 0.75rem;
  font-weight: 800;
  font-size: 1.08rem;
  overflow-wrap: anywhere;
}

/* Découverte parcours : marque pédagogique faible (≠ indication active) */
.key.path-new:not(.active) {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent);
  background: color-mix(in srgb, var(--accent) 8%, #fff);
}

/* L’attendu (.active) prime toujours sur le marquage path-new */
.key.path-new.active {
  background: var(--key-color);
  color: #fff;
  transform: translateY(-3px) scale(1.06);
  box-shadow: 0 6px 0 color-mix(in srgb, var(--key-color) 70%, #000);
  z-index: 2;
}

@media (max-width: 720px) {
  .path-screen {
    padding-inline: 0.85rem;
  }

  .path-lesson-actions .btn,
  .path-result-actions .btn {
    width: 100%;
  }
}

/* Hauteur limitée : garder clavier + mains visibles (sans superposer les mains) */
@media (max-height: 800px) {
  .word-section {
    margin-bottom: 0.45rem;
  }

  .word-display {
    font-size: clamp(1.35rem, 3.8vw, 2rem);
    max-height: calc(2 * 1.22em + 0.7rem);
    padding: 0.3rem 0.65rem;
  }

  .phrase-display,
  .text-display {
    font-size: clamp(0.98rem, 2.2vw, 1.28rem);
    line-height: 1.45;
    max-height: calc(2 * 1.45em + 0.65rem);
    padding: 0.35rem 0.75rem;
  }

  .instruction {
    font-size: clamp(0.92rem, 1.8vw, 1.1rem);
  }

  .keyboard {
    --key-h: 2.25rem;
    --kb-gap: 0.22rem;
    padding: 0.5rem;
  }

  .keyboard-section {
    margin-bottom: 0.35rem;
  }

  .hands-section {
    margin-bottom: 0.4rem;
  }

  .hand-svg {
    width: min(150px, 34vw);
  }
}

@media (max-height: 720px) {
  .detail-stats {
    margin-bottom: 0.35rem;
  }

  .word-display {
    font-size: clamp(1.2rem, 3.2vw, 1.7rem);
  }

  .phrase-display,
  .text-display {
    font-size: clamp(0.92rem, 2vw, 1.15rem);
    line-height: 1.4;
    max-height: calc(2 * 1.4em + 0.55rem);
  }

  .keyboard {
    --key-h: 2rem;
    padding: 0.4rem;
  }

  .hand-svg {
    width: min(128px, 30vw);
  }

  .hands-wrap {
    gap: clamp(0.5rem, 3vw, 1.5rem);
  }
}

@media (max-height: 650px) {
  .word-section {
    margin-bottom: 0.3rem;
  }

  .level-name {
    font-size: 0.85rem;
    margin-bottom: 0.2rem;
  }

  .word-display {
    font-size: clamp(1.1rem, 2.8vw, 1.5rem);
    max-height: calc(2 * 1.2em + 0.5rem);
    padding: 0.25rem 0.5rem;
  }

  .phrase-display,
  .text-display {
    font-size: clamp(0.88rem, 1.8vw, 1.05rem);
    max-height: calc(2 * 1.35em + 0.45rem);
    padding: 0.28rem 0.55rem;
  }

  .instruction {
    font-size: 0.9rem;
  }

  .keyboard {
    --key-h: 1.75rem;
    --kb-gap: 0.16rem;
    padding: 0.3rem;
  }

  .hand-svg {
    width: min(110px, 26vw);
  }

  .hand-label {
    font-size: 0.78rem;
  }
}

/*
 * Exercice / texte : prioriser clavier + mains dans le viewport.
 * Compacte le chrome (profil, onglets, stats) sans superposer les mains.
 */
@media (max-height: 720px) {
  body.view-exercise .profile-bar,
  body.view-text-play .profile-bar {
    padding: 0.15rem 0.55rem 0.25rem;
    gap: 0.3rem 0.45rem;
  }

  body.view-exercise .profile-chip,
  body.view-exercise .profile-manage-btn,
  body.view-text-play .profile-chip,
  body.view-text-play .profile-manage-btn {
    min-height: 36px;
    padding-top: 0.2rem;
    padding-bottom: 0.2rem;
    font-size: 0.82rem;
  }

  body.view-exercise .profile-chip-initial,
  body.view-text-play .profile-chip-initial {
    width: 1.55rem;
    height: 1.55rem;
    font-size: 0.85rem;
  }

  body.view-exercise .exercise-mode-bar,
  body.view-text-play .exercise-mode-bar {
    margin-top: 0.2rem;
    gap: 0.3rem;
  }

  body.view-exercise .mode-tab,
  body.view-text-play .mode-tab {
    min-height: 0;
    padding: 0.28rem 0.6rem;
    font-size: 0.74rem;
  }

  body.view-exercise .hand-svg,
  body.view-text-play .hand-svg {
    width: min(100px, 24vw);
  }

  body.view-exercise .finger-hint,
  body.view-text-play .finger-hint {
    min-height: 0;
    font-size: 0.78rem;
    margin: 0.1rem 0 0;
  }

  body.view-exercise .detail-stats,
  body.view-text-play .detail-stats {
    margin: 0.35rem 0 0.25rem;
    gap: 0.35rem;
  }

  body.view-exercise .detail-stat,
  body.view-text-play .detail-stat {
    padding: 0.35rem 0.35rem;
    border-radius: 10px;
  }

  body.view-exercise .detail-stat span:last-child,
  body.view-text-play .detail-stat span:last-child {
    font-size: 1rem;
  }

  body.view-exercise .controls,
  body.view-text-play .controls {
    margin-bottom: 0.75rem;
  }
}

@media (max-height: 650px) {
  body.view-exercise .top-bar,
  body.view-text-play .top-bar {
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
    gap: 0.35rem;
  }

  body.view-exercise .nav-link,
  body.view-text-play .nav-link {
    min-height: 36px;
    padding: 0.3rem 0.55rem;
    font-size: 0.74rem;
  }

  body.view-exercise .hand-svg,
  body.view-text-play .hand-svg {
    width: min(88px, 22vw);
  }

  body.view-exercise .hands-section,
  body.view-text-play .hands-section {
    margin-bottom: 0.25rem;
  }

  body.view-exercise .keyboard,
  body.view-text-play .keyboard {
    --key-h: 1.55rem;
    --kb-gap: 0.12rem;
    padding: 0.25rem;
  }
}

/* Mobile étroit + hauteur limitée : nav moins haute en exercice */
@media (max-width: 768px) and (max-height: 760px) {
  body.view-exercise .top-bar,
  body.view-text-play .top-bar {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    padding: 0.35rem 0.5rem;
    gap: 0.3rem 0.45rem;
  }

  body.view-exercise .brand,
  body.view-text-play .brand {
    width: auto;
  }

  body.view-exercise .brand-title,
  body.view-text-play .brand-title {
    font-size: 0.95rem;
  }

  body.view-exercise .top-bar .main-nav,
  body.view-text-play .top-bar .main-nav {
    max-width: 100%;
    margin: 0;
    gap: 0.25rem;
    row-gap: 0.25rem;
  }

  body.view-exercise .nav-link,
  body.view-text-play .nav-link {
    min-height: 34px;
    padding: 0.28rem 0.5rem;
    font-size: 0.7rem;
  }

  body.view-exercise .hand-svg,
  body.view-text-play .hand-svg {
    width: min(32vw, 5.75rem);
  }
}

/* Suivi de frappe : pas d’animation de scroll (scrollTop immédiat) */
@media (prefers-reduced-motion: reduce) {
  .word-display,
  .phrase-display,
  .text-display {
    scroll-behavior: auto;
  }
}

/* ---- Profils enfants (local) ---- */
.profile-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.45rem 0.65rem;
  padding: 0.35rem 0.85rem 0.55rem;
  max-width: 100%;
  box-sizing: border-box;
}

.profile-chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.35rem 0.85rem 0.35rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  max-width: min(100%, 16rem);
}

.profile-chip:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 70%, #fff);
  outline-offset: 2px;
}

.profile-chip-initial {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  flex: 0 0 auto;
}

.profile-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-manage-btn {
  width: fit-content;
  max-width: 100%;
  min-height: 44px;
  height: auto;
  padding: 0.4rem 1rem;
  margin: 0;
  flex: 0 0 auto;
  align-self: center;
  box-sizing: border-box;
  white-space: nowrap;
}

.profile-storage-warning {
  margin: 0 0.85rem 0.5rem;
  padding: 0.55rem 0.85rem;
  border-radius: 12px;
  background: color-mix(in srgb, #fcc419 35%, #fff);
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 600;
  text-align: center;
}

.profiles-screen {
  position: relative;
  z-index: 2;
  max-width: 40rem;
  margin: 0 auto 2rem;
  padding: 0.75rem 1.25rem 2rem;
}

.profiles-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 3vw, 1.85rem);
}

.profiles-lead,
.profiles-gate-note {
  color: var(--ink-soft);
  font-weight: 600;
}

.profiles-gate-note {
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 12%, #fff);
  border: 1px solid var(--line);
}

.profiles-section-title {
  margin: 1.25rem 0 0.55rem;
  font-size: 1.1rem;
}

.profile-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.profile-form input[type="text"] {
  width: 100%;
  min-height: 44px;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  box-sizing: border-box;
}

.profile-form-error {
  margin: 0;
  color: #c92a2a;
  font-weight: 700;
}

.profile-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.profiles-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.profile-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.profile-item.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}

.profile-item-main {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1 1 10rem;
  min-width: 0;
}

.profile-item-name {
  font-weight: 800;
  overflow-wrap: anywhere;
}

.profile-item-badge {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--accent-dark);
}

.profile-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.profile-item-actions .btn {
  min-height: 44px;
}

.profile-reset-stats-btn {
  font-size: 0.9rem;
}

.profile-reset-success {
  margin: 1rem 0 0;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: color-mix(in srgb, #51cf66 18%, white);
  color: var(--ink);
  border: 1px solid color-mix(in srgb, #51cf66 40%, transparent);
}

.profile-reset-dialog {
  width: min(28rem, calc(100vw - 2rem));
  max-width: 100%;
  padding: 0;
  border: 2px solid color-mix(in srgb, var(--danger) 55%, transparent);
  border-radius: var(--radius);
  background: #fff8f8;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.profile-reset-dialog::backdrop {
  background: rgba(26, 43, 60, 0.45);
}

.profile-reset-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.25rem;
}

.profile-reset-title {
  margin: 0;
  font-size: 1.25rem;
  color: var(--danger);
}

.profile-reset-desc,
.profile-reset-name-line {
  margin: 0;
  color: var(--ink);
  line-height: 1.45;
}

.profile-reset-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: flex-end;
  margin-top: 0.35rem;
}

.btn-danger-solid {
  background: var(--danger);
  color: #fff;
  border: 2px solid var(--danger);
}

.btn-danger-solid:hover:not(:disabled) {
  filter: brightness(0.95);
}

.btn-danger-solid:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.path-lesson-item.is-last {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.path-lesson-last-tag {
  display: inline-block;
  margin-left: 0.35rem;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--accent-dark);
}

body.view-profiles #learn-home,
body.view-profiles #path-screen,
body.view-profiles #exercise-root,
body.view-profiles #library-screen,
body.view-profiles #progress-screen,
body.view-profiles #achievements-screen,
body.view-profiles #settings-screen,
body.view-profiles #training-result-screen,
body.view-profiles #text-play-screen,
body.view-profiles #text-result-screen {
  display: none !important;
}

body.view-learn #profiles-screen,
body.view-path #profiles-screen,
body.view-exercise #profiles-screen,
body.view-progress #profiles-screen,
body.view-settings #profiles-screen,
body.view-achievements #profiles-screen,
body.view-library #profiles-screen {
  display: none !important;
}

@media (max-width: 768px) {
  .profile-bar {
    padding-inline: 0.65rem;
    justify-content: center;
  }

  /* Compact centré — ne pas étirer sur toute la largeur */
  .profile-manage-btn {
    width: fit-content;
    max-width: 100%;
    min-height: 44px;
    padding: 0.4rem 0.95rem;
    white-space: normal;
    text-align: center;
  }

  .profile-chip {
    max-width: 100%;
  }
}

@media (max-width: 280px) {
  .profile-manage-btn {
    width: 100%;
    white-space: normal;
  }
}

/* ---- Étoiles de précision (parcours) ---- */
.path-stars-total {
  margin: 0.15rem 0 0.55rem;
  font-weight: 800;
  color: var(--accent-dark);
  text-align: center;
}

.path-stars {
  display: inline-flex;
  gap: 0.2rem;
  align-items: center;
  line-height: 1;
}

.path-lesson-stars {
  display: flex;
  margin: 0.15rem 0 0.45rem;
}

.path-star {
  font-size: 1.15rem;
  font-weight: 700;
}

.path-star.is-filled {
  color: #e67700;
}

.path-star.is-empty {
  color: color-mix(in srgb, var(--muted) 70%, #fff);
  opacity: 0.85;
}

.path-result-stars {
  display: flex;
  justify-content: center;
  margin: 0.35rem 0 0.55rem;
}

.path-result-stars-row {
  font-size: 1.35rem;
}

.path-result-best-note {
  margin: 0 0 0.75rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-align: center;
}

@media (prefers-reduced-motion: no-preference) {
  .path-stars.is-celebrate .path-star.is-filled {
    animation: path-star-pop 0.45s ease-out both;
  }

  .path-stars.is-celebrate .path-star.is-filled:nth-child(2) {
    animation-delay: 0.06s;
  }

  .path-stars.is-celebrate .path-star.is-filled:nth-child(3) {
    animation-delay: 0.12s;
  }
}

@keyframes path-star-pop {
  0% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  70% {
    transform: scale(1.18);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .path-stars.is-celebrate .path-star {
    animation: none;
  }
}

/* --- Games hub + Laser Letters --- */
.games-hub {
  position: relative;
  z-index: 2;
  max-width: 56rem;
  margin: 0 auto;
  padding: 1rem 0 2rem;
}

.games-hub-title {
  margin: 0 0 0.4rem;
  font-size: clamp(1.5rem, 3vw, 2rem);
  color: var(--ink);
}

.games-hub-lead {
  margin: 0 0 1.25rem;
  color: var(--muted);
  max-width: 36rem;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 1rem;
}

.game-card {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 1.1rem 1.15rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.game-card:hover {
  border-color: color-mix(in srgb, var(--accent, #e85d4c) 45%, var(--line));
  transform: translateY(-2px);
}

.game-card-icon {
  color: var(--accent, #e85d4c);
}

.game-card-name {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--ink);
}

.game-card-desc {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.4;
}

.game-card-cta {
  margin-top: 0.35rem;
  font-weight: 700;
  color: var(--accent, #e85d4c);
}

.laser-letters-screen {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 56rem;
  margin: 0 auto;
  padding: 0.5rem 0 1.5rem;
  min-height: min(70vh, 36rem);
}

.laser-letters-screen[hidden] {
  display: none !important;
}

.ll-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.ll-top-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.ll-sound-btn {
  font-size: 0.85rem;
  padding: 0.35rem 0.7rem;
  min-height: 2rem;
}

.ll-title {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 1.85rem);
  color: var(--ink);
}

.ll-hud,
.ll-best-line {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.ll-stage {
  position: relative;
  flex: 1;
  min-height: 22rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 88%, white);
  box-shadow: var(--shadow);
  overflow: hidden;
}

#laser-letters-canvas {
  display: block;
  width: 100%;
  height: min(62vh, 28rem);
  touch-action: none;
}

.ll-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1.25rem;
  text-align: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(2px);
}

.ll-panel[hidden] {
  display: none !important;
}

.ll-panel-title {
  margin: 0;
  font-size: 1.45rem;
  color: var(--ink);
}

.ll-panel-lead {
  margin: 0;
  max-width: 28rem;
  color: var(--muted);
  line-height: 1.45;
}

.ll-stats {
  list-style: none;
  margin: 0;
  padding: 0;
  color: var(--ink);
  line-height: 1.6;
}

.ll-error {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent, #e85d4c) 18%, white);
  color: #9b2c1f;
  font-weight: 700;
  z-index: 2;
}

a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

@media (max-width: 420px) {
  #laser-letters-canvas {
    height: min(55vh, 22rem);
  }

  .ll-stage {
    min-height: 18rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ll-panel,
  .game-card {
    backdrop-filter: none;
    transition: none;
  }
}

/* ---- Compte (optionnel) ---- */
.account-screen {
  max-width: 40rem;
  margin: 0 auto;
  padding: 1rem 1.25rem 2.5rem;
}
.account-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.account-title {
  margin: 0;
  font-size: clamp(1.4rem, 3vw, 1.85rem);
}
.account-lead {
  color: var(--muted);
  margin: 0 0 1rem;
  line-height: 1.45;
}
.account-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem 1.1rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 4px 16px rgba(26, 43, 60, 0.05);
}
.account-section-title {
  margin: 1rem 0 0.65rem;
  font-size: 1.05rem;
}
.account-panel > .account-section-title:first-child {
  margin-top: 0;
}
.account-form {
  display: grid;
  gap: 0.75rem;
}
.account-form .field {
  display: grid;
  gap: 0.3rem;
}
.account-form input {
  min-height: 44px;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
}
.account-error {
  margin: 0 0 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  background: color-mix(in srgb, #e03131 12%, #fff);
  color: #9b2c1f;
  font-weight: 600;
}
.account-actions-row,
.account-inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.btn.btn-link {
  background: transparent;
  border: none;
  color: var(--accent-dark);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  min-height: 44px;
  padding: 0.35rem 0.5rem;
}
.account-google-btn {
  margin-top: 0.25rem;
  width: 100%;
  max-width: 22rem;
  justify-content: center;
  min-height: 44px;
}
.account-billing {
  margin: 1rem 0 0.5rem;
  padding-top: 0.25rem;
}
.account-billing-benefits {
  margin: 0.35rem 0 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
  max-width: 36rem;
}
.account-verify-banner {
  margin: 0.85rem 0 0.5rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--accent-dark) 35%, var(--line));
  background: color-mix(in srgb, var(--accent, #1f6f5b) 10%, #fff);
}
.account-verify-banner p {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
  line-height: 1.45;
}
.account-verify-banner .btn {
  min-height: 44px;
}
.account-auth-divider::before,
.account-auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.account-import-list {
  display: grid;
  gap: 0.45rem;
  margin: 0.75rem 0;
}
.account-import-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  font-weight: 600;
}
.account-conflict {
  margin: 0.75rem 0;
  padding: 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, #fcc419 18%, #fff);
}
.account-sync-badge {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line) 55%, #fff);
}
.account-sync-badge[data-state="ok"] {
  color: #2b8a3e;
}
.account-sync-badge[data-state="error"],
.account-sync-badge[data-state="conflict"] {
  color: #9b2c1f;
}
.account-sync-badge[data-state="syncing"] {
  color: var(--accent-dark);
}
.footer-account-link {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  padding: 0.25rem;
  min-height: 44px;
}
.footer-account-link:hover,
.footer-account-link:focus-visible {
  color: var(--ink);
  text-decoration: underline;
}
body.view-account #learn-home,
body.view-account #path-screen,
body.view-account #exercise-root,
body.view-account #library-screen,
body.view-account #progress-screen,
body.view-account #achievements-screen,
body.view-account #settings-screen,
body.view-account #profiles-screen,
body.view-account #training-result-screen,
body.view-account #text-play-screen,
body.view-account #text-result-screen {
  display: none !important;
}

