/* =========================================================
   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;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-mark {
  display: inline-flex;
  line-height: 0;
}

.brand-mark svg {
  display: block;
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 3vw, 2rem);
  letter-spacing: -0.02em;
  color: var(--ink);
}

.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;
  gap: 0.35rem;
  justify-content: center;
  flex: 1 1 14rem;
  max-width: 100%;
  min-width: 0;
}

.nav-link {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-weight: 700;
  font-size: 0.86rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
  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 Apprendre */
.learn-home {
  position: relative;
  z-index: 2;
  max-width: 720px;
  margin: 0 auto 2rem;
  padding: 0.75rem 1.25rem 2rem;
}

.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;
  margin-bottom: 1rem;
}

.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;
}

.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;
}

.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 .progress-screen,
body.view-achievements .settings-screen {
  display: none !important;
}

body.view-learn #exercise-root,
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-exercise #learn-home,
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 #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 #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: stretch;
  }

  .main-nav {
    justify-content: flex-start;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 0.15rem;
    -webkit-overflow-scrolling: touch;
  }

  .nav-link {
    flex: 0 0 auto;
    font-size: 0.8rem;
    padding: 0.38rem 0.65rem;
  }

  .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: 1.25rem;
}

.level-name {
  margin: 0 0 0.5rem;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.95rem;
}

.word-display {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.15rem;
  min-height: 4.5rem;
  padding: 0.75rem 1rem;
  font-family: var(--font-mono);
  font-size: clamp(2.2rem, 7vw, 3.6rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  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: 4.5rem;
  padding: 0.85rem 1.1rem;
  font-family: Georgia, "Palatino Linotype", "Times New Roman", serif;
  font-size: clamp(1.2rem, 3.2vw, 1.75rem);
  font-weight: 500;
  line-height: 1.75;
  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);
}

.feedback.good {
  color: var(--success);
}

.instruction {
  margin: 0.25rem 0 0;
  font-size: clamp(1.05rem, 2.5vw, 1.35rem);
  font-weight: 700;
  color: var(--ink);
}

/* Clavier */
.keyboard-section {
  margin: 0 auto 1.25rem;
  width: 100%;
  max-width: 56rem;
  overflow-x: auto;
}

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  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: flex;
  flex-wrap: nowrap;
  gap: 0.28rem;
  justify-content: center;
  width: 100%;
}

.key {
  --key-color: var(--muted);
  --key-w: 1;
  position: relative;
  flex: var(--key-w) 1 0;
  min-width: 0;
  height: 2.7rem;
  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 {
  flex: 7 1 0;
  min-width: 30%;
}

.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 */
.hands-section {
  text-align: center;
  margin-bottom: 1rem;
}

.hands-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(1rem, 6vw, 4rem);
  flex-wrap: wrap;
}

.hand-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.hand-svg {
  width: min(200px, 42vw);
  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.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;
  }

  .key {
    height: 1.9rem;
    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 {
    padding: 0.65rem;
    gap: 0.3rem;
  }

  .keyboard-row {
    gap: 0.22rem;
  }

  .key {
    min-width: 1.55rem;
    height: 2rem;
    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 #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 #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 #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: min(40vh, 320px);
  overflow-y: auto;
  text-align: left;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.text-display p {
  margin: 0 0 0.85em;
}

.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: stretch;
    padding: 0.65rem 0.85rem;
    gap: 0.5rem;
  }

  .brand {
    justify-content: center;
  }

  .main-nav {
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 0.3rem;
    padding: 0.15rem 0.1rem 0.35rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .nav-link {
    flex: 0 0 auto;
    font-size: 0.78rem;
    padding: 0.42rem 0.7rem;
    min-height: 2.25rem;
  }

  .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,
  .phrase-display,
  .text-display {
    font-size: clamp(1.15rem, 6.5vw, 1.55rem);
    padding-inline: 0.25rem;
  }

  .keyboard {
    gap: 0.18rem;
    padding: 0.35rem;
  }

  .key {
    height: 1.75rem;
    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.72rem;
    padding: 0.4rem 0.55rem;
  }

  .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;
  }

  .player-strip {
    margin-inline: 0.45rem;
  }

  .main-nav {
    gap: 0.2rem;
  }

  .nav-link {
    font-size: 0.68rem;
    padding: 0.38rem 0.48rem;
  }

  .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.65rem;
    padding: 0.36rem 0.42rem;
    min-height: 2.1rem;
  }

  .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 {
    max-width: 100%;
  }

  .key {
    height: 1.55rem;
    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;
  }
}

