/* Primitives du petit train des sons. Utilise uniquement les variables de tokens.css. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
p { margin: 0; }
body {
  margin: 0; background: var(--c-bg); color: var(--c-text);
  font-family: var(--font-ui); font-size: var(--fs-base); line-height: var(--lh-base);
  -webkit-tap-highlight-color: transparent;
}
.read { font-family: var(--font-read); letter-spacing: var(--read-letter-spacing); word-spacing: var(--read-word-spacing); line-height: var(--read-line-height); }
.muted { color: var(--c-text-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--c-focus); outline-offset: 3px; }
h1 { font-size: var(--fs-xl); line-height: var(--lh-xl); font-weight: var(--fw-xl); margin: 0 0 var(--sp-4); }
h2 { font-size: var(--fs-lg); line-height: var(--lh-lg); font-weight: var(--fw-lg); margin: 0 0 var(--sp-4); }
.icon { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Bouton */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--l-touch-min); padding: 0 var(--sp-6); border: 0; border-radius: var(--r-pill);
  font: inherit; font-size: var(--fs-lg); font-weight: 600; cursor: pointer;
  background: var(--c-accent); color: var(--c-on-accent); box-shadow: var(--sh-press);
  transition: transform var(--m-fast) var(--m-ease), box-shadow var(--m-fast) var(--m-ease), background var(--m-fast);
}
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 0 0 transparent; }
.btn--lg { min-height: 72px; padding: 0 var(--sp-7); font-size: var(--fs-xl); }
.btn--reward { background: var(--c-reward); color: var(--c-on-reward); box-shadow: 0 4px 0 #b9831c; }
.btn--secondary { background: var(--c-surface); color: var(--c-text); box-shadow: 0 4px 0 var(--c-border); border: 2px solid var(--c-border); }
.btn--ghost { background: transparent; color: var(--c-accent); box-shadow: none; }
.btn:disabled { background: var(--c-surface-2); color: var(--c-text-muted); box-shadow: none; cursor: not-allowed; }
.btn[aria-busy="true"]::after { content: "…"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* Bouton rond icône */
.icon-btn {
  width: var(--l-touch-min); height: var(--l-touch-min); display: inline-grid; place-items: center;
  border-radius: 50%; border: 2px solid var(--c-border); background: var(--c-surface); color: var(--c-text);
  box-shadow: var(--sh-card); cursor: pointer; padding: 0;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn--listen { background: var(--c-accent); color: var(--c-on-accent); border-color: var(--c-accent); }
.icon-btn--listen[aria-pressed="true"] { animation: pulse 1s var(--m-ease) infinite; }
.icon-btn:disabled { color: var(--c-locked); background: var(--c-surface-2); box-shadow: none; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(31,111,107,.45); } 50% { box-shadow: 0 0 0 12px rgba(31,111,107,0); } }

/* Tuile de réponse */
.tiles { display: flex; flex-wrap: wrap; gap: var(--sp-4); justify-content: center; }
.tile {
  min-width: var(--l-tile-min); min-height: var(--l-tile-min); padding: 0 var(--sp-5);
  display: inline-grid; place-items: center; cursor: pointer;
  background: var(--c-surface); color: var(--c-text); border: 2px solid var(--c-border); border-radius: var(--r-md);
  box-shadow: var(--sh-card);
  font-family: var(--font-read); font-size: var(--fs-word); font-weight: var(--fw-word); letter-spacing: var(--read-letter-spacing);
  transition: transform var(--m-fast) var(--m-ease), background var(--m-fast), border-color var(--m-fast);
}
.tile:active { transform: scale(.96); }
.tile[aria-pressed="true"], .tile.is-selected { border: 3px solid var(--c-accent); background: var(--c-accent-soft); }
.tile.is-right { border: 3px solid var(--c-success); background: var(--c-success-bg); animation: pop var(--m-slow) var(--m-bounce); }
.tile.is-wrong { border: 3px solid var(--c-danger); background: var(--c-danger-bg); animation: shake var(--m-slow) var(--m-ease); }
.tile:disabled { cursor: default; opacity: .75; }
@keyframes pop { 40% { transform: scale(1.08); } }
@keyframes shake { 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }

/* Emplacement */
.slots { display: flex; gap: var(--sp-3); justify-content: center; }
.slot {
  min-width: var(--l-tile-min); height: var(--l-tile-min); border-radius: var(--r-md);
  border: 3px dashed var(--c-border-input); background: transparent; display: grid; place-items: center;
}
.slot.is-over { background: var(--c-accent-soft); border-color: var(--c-accent); }
.slot > .tile { box-shadow: none; }

/* Gare */
.station {
  width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  border: 4px solid var(--c-rail); background: var(--c-surface); color: var(--c-text); font: inherit; font-weight: 700; font-size: var(--fs-lg);
  box-shadow: var(--sh-card); position: relative;
}
.station--open { border-color: var(--c-accent); animation: pulse 1.6s var(--m-ease) infinite; }
.station--locked { color: var(--c-locked); border-color: var(--c-locked); background: var(--c-surface-2); cursor: not-allowed; box-shadow: none; }
.station--depot { border-radius: var(--r-md); background: var(--c-reward); color: var(--c-on-reward); }
.station--depot.station--locked { background: var(--c-surface-2); color: var(--c-locked); }
.station .mini-stars { position: absolute; bottom: -14px; display: flex; gap: 1px; }
.station .mini-stars svg { width: 16px; height: 16px; fill: var(--c-reward); stroke: #b9831c; stroke-width: 1.5; }

/* Progression en wagons */
.progress { display: flex; gap: 6px; }
.progress span { flex: 1; height: 14px; border-radius: 4px; background: var(--c-surface-2); border: 1px solid var(--c-border); }
.progress span.is-done { background: var(--c-accent); border-color: var(--c-accent); }

/* Étoiles et pièces */
.stars { display: flex; gap: var(--sp-2); }
.star { width: 48px; height: 48px; }
.star path { fill: var(--c-surface-2); stroke: var(--c-border-input); stroke-width: 1.5; }
.star.is-on path { fill: var(--c-reward); stroke: #b9831c; }
.stars.is-animated .star.is-on { animation: pop var(--m-slow) var(--m-bounce) both; }
.stars.is-animated .star.is-on:nth-child(2) { animation-delay: 220ms; }
.stars.is-animated .star.is-on:nth-child(3) { animation-delay: 440ms; }
.coins { display: inline-flex; align-items: center; gap: var(--sp-2); font-weight: 700; padding: 4px 14px 4px 4px; border-radius: var(--r-pill); background: var(--c-surface); border: 2px solid var(--c-border); }
.coins::before { content: ""; width: 32px; height: 32px; border-radius: 50%; background: var(--c-reward); box-shadow: inset 0 -3px 0 #b9831c; }

/* Carte / panneau */
.card { background: var(--c-surface); border-radius: var(--r-lg); padding: var(--sp-5); box-shadow: var(--sh-card); }
.card--soft { background: var(--c-accent-soft); box-shadow: none; }

/* Champ */
.field { display: grid; gap: var(--sp-2); }
.field label { font-weight: 600; }
.field input, .field select {
  min-height: var(--l-touch-min); padding: 0 var(--sp-4); font: inherit; color: var(--c-text);
  background: var(--c-surface); border: 2px solid var(--c-border-input); border-radius: var(--r-sm);
}
.field.is-error input { border-color: var(--c-danger); }
.field .error { color: var(--c-danger); font-size: var(--fs-sm); }

/* Interrupteur */
.switch { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); min-height: var(--l-touch-min); }
.switch input { appearance: none; width: 60px; height: 34px; border-radius: 999px; background: var(--c-surface-2); border: 2px solid var(--c-border-input); position: relative; cursor: pointer; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--c-text-muted); transition: transform var(--m-base) var(--m-ease); }
.switch input:checked { background: var(--c-accent); border-color: var(--c-accent); }
.switch input:checked::after { transform: translateX(26px); background: var(--c-on-accent); }
input[type="range"] { width: 100%; accent-color: var(--c-accent); min-height: var(--l-touch-min); }

/* Pavé de la porte parent */
.keypad { display: grid; grid-template-columns: repeat(3, 64px); gap: var(--sp-3); }
.keypad button { height: 64px; border-radius: var(--r-md); border: 2px solid var(--c-border); background: var(--c-surface); font: inherit; font-size: var(--fs-lg); font-weight: 600; color: var(--c-text); cursor: pointer; }
.keypad button:active { background: var(--c-surface-2); }

/* Graphique semaine */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--sp-2); align-items: end; height: 140px; position: relative; }
.week .bar { background: var(--c-accent); border-radius: 6px 6px 0 0; min-height: 4px; }
.week .bar.is-zero { background: var(--c-surface-2); }
.week .goal { position: absolute; left: 0; right: 0; border-top: 2px dashed var(--c-border-input); }
.week-labels { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--sp-2); text-align: center; font-size: var(--fs-sm); color: var(--c-text-muted); }

/* Ligne de compétence */
.skill-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: var(--sp-4); align-items: center; padding: var(--sp-3) 0; border-bottom: 1px solid var(--c-border); }
.skill-row .lvl { font-weight: 700; color: var(--c-accent); }

/* Bannière */
.notice { display: flex; gap: var(--sp-3); align-items: center; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); background: var(--c-accent-soft); }
.notice--ok { background: var(--c-success-bg); color: var(--c-success); }
.notice--warn { background: var(--c-danger-bg); color: var(--c-danger); }

/* Écran de fin */
.overlay { position: fixed; inset: 0; background: rgba(31,42,51,.45); display: grid; grid-template-columns: minmax(0, 420px); justify-content: center; align-items: center; padding: var(--l-gutter); z-index: 10; overflow-y: auto; }
.overlay .card { box-shadow: var(--sh-pop); text-align: center; width: 100%; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-5); justify-items: center; overflow-wrap: anywhere; }
.overlay .card .field, .overlay .card input { width: 100%; min-width: 0; }
