/* =============================================================
   MOTAMORPHOSE — écran de partie : HUD, chaîne, tuiles, clavier
   ============================================================= */

.screen--game {
  position: relative;
  gap: 8px;
  min-height: 0;
  padding-bottom: calc(var(--safe-bottom) + 8px);
  /* Grille : la chaîne prend exactement l'espace restant, le clavier reste collé en bas. */
  display: grid;
  grid-template-rows: auto auto minmax(56px, 1fr) auto;
  align-content: stretch;
  /* Sur les écrans très bas (paysage de téléphone), on autorise le défilement. */
  overflow-y: auto;
}

.screen--game > * {
  min-height: 0;
}

.game__top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.game__title {
  flex: 1;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

/* --------------------------------- HUD ------------------------------ */
.game__hud {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.hud__pair {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.hud__label {
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
}

.hud__value {
  font-size: 1.12rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud__value--target {
  background: var(--grad-target);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hud__arrow {
  font-size: 1.1rem;
  color: var(--text-faint);
  flex: none;
}

.hud__meta {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
}

.hud__meta b {
  color: var(--text);
  font-weight: 800;
  font-family: var(--font-mono);
}

.progress {
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.progress__fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: var(--grad-primary);
  transition: width 420ms var(--ease-out);
  box-shadow: 0 0 12px rgba(20, 224, 200, 0.6);
}

/* -------------------------------- Chaîne ---------------------------- */
.chain {
  min-height: 56px;
  /* Les mots s'empilent vers le bas : le dernier reste au plus près du clavier. */
  justify-content: flex-end;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px 2px 10px;
  scroll-behavior: smooth;
  mask-image: linear-gradient(180deg, transparent 0, #000 18px, #000 calc(100% - 12px), transparent 100%);
}

.chain-row {
  display: flex;
  align-items: center;
  gap: 8px;
  animation: row-in 320ms var(--ease-out) both;
}

.chain-row__index {
  width: 20px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-faint);
  text-align: right;
  flex: none;
}

.chain-row__tiles {
  display: flex;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

.chain-row--start .tile {
  border-color: rgba(110, 161, 255, 0.45);
}

.chain-row--target .tile {
  border-color: rgba(255, 200, 80, 0.55);
  box-shadow: 0 0 0 1px rgba(255, 200, 80, 0.3), 0 8px 24px rgba(255, 150, 60, 0.22);
}

.chain-row--ghost {
  opacity: 0.45;
  margin-top: 4px;
}

.chain-row--ghost .tile {
  border-style: dashed;
  background: rgba(255, 217, 61, 0.08);
}

.chain-row--current .tile {
  border-color: rgba(20, 224, 200, 0.55);
}

/* -------------------------------- Tuiles ---------------------------- */
.tile {
  --tile-size: clamp(34px, 9.4vw, 46px);
  width: var(--tile-size);
  height: var(--tile-size);
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--grad-tile);
  border: 1px solid var(--border);
  font-size: calc(var(--tile-size) * 0.48);
  font-weight: 900;
  letter-spacing: 0.02em;
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 6px 16px rgba(4, 2, 16, 0.28);
  position: relative;
  transition: transform 180ms var(--ease-spring), background 200ms, box-shadow 200ms,
    border-color 200ms;
  user-select: none;
}

.tile--changed {
  background: linear-gradient(160deg, rgba(20, 224, 200, 0.34), rgba(43, 108, 255, 0.28));
  border-color: rgba(20, 224, 200, 0.7);
  color: #eafffb;
  box-shadow: 0 0 0 1px rgba(20, 224, 200, 0.4), 0 0 20px rgba(20, 224, 200, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  animation: tile-flip 460ms var(--ease-spring);
}

.tile--target {
  background: linear-gradient(160deg, rgba(255, 217, 61, 0.32), rgba(255, 138, 61, 0.3));
  border-color: rgba(255, 200, 80, 0.7);
  color: #fff6d8;
}

.tile--empty {
  background: rgba(255, 255, 255, 0.04);
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.16);
  color: var(--text-faint);
  box-shadow: none;
}

.tile--pop {
  animation: tile-pop 260ms var(--ease-spring);
}

.chain-row--error {
  animation: shake 420ms var(--ease-out);
}

/* ------------------------- Zone de saisie --------------------------- */
.input-zone {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 2px;
  flex: none;
}

.input-preview {
  display: flex;
  gap: 5px;
  justify-content: center;
  min-height: 44px;
  align-items: center;
}

.input-preview .tile {
  --tile-size: clamp(34px, 9.4vw, 48px);
  border-color: var(--border-strong);
}

.input-preview .tile--caret {
  border-color: var(--turquoise);
  box-shadow: 0 0 0 2px rgba(20, 224, 200, 0.35), 0 0 24px rgba(20, 224, 200, 0.3);
  animation: caret-pulse 1.4s ease-in-out infinite;
}

.input-preview .tile--invalid {
  border-color: rgba(255, 92, 108, 0.8);
  color: #ffb3bd;
  animation: shake 380ms var(--ease-out);
}

/* ------------------------------- Clavier ---------------------------- */
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  user-select: none;
}

.keyboard[hidden] {
  display: none;
}

.keyboard__row {
  display: flex;
  gap: 5px;
  justify-content: center;
}

.key {
  flex: 1 1 0;
  min-width: 0;
  max-width: 52px;
  height: clamp(36px, 9.2vw, 46px);
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: clamp(0.86rem, 3.6vw, 1rem);
  font-weight: 800;
  color: var(--text);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.22), 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform 90ms var(--ease-out), background 140ms, box-shadow 140ms;
}

.key:active,
.key--pressed {
  transform: translateY(2px) scale(0.97);
  background: var(--surface-3);
  box-shadow: inset 0 0 0 1px rgba(20, 224, 200, 0.5);
}

.key--wide {
  flex: 1.6 1 0;
  max-width: 74px;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.key--accent {
  background: rgba(43, 108, 255, 0.24);
  border-color: rgba(43, 108, 255, 0.4);
}

.key--enter {
  background: var(--grad-primary);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 16px rgba(70, 46, 220, 0.4);
}

.game__actions {
  display: flex;
  gap: 8px;
  flex: none;
}

.game__actions .btn {
  padding-left: 12px;
  padding-right: 12px;
  min-height: 46px;
}

/* ------------------------------- Pause ------------------------------ */
.pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(8, 3, 22, 0.78);
  backdrop-filter: blur(10px);
  animation: fade-in 200ms both;
  padding: 20px;
}

.pause-overlay[hidden] {
  display: none;
}

.pause-overlay__card {
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  padding: 24px;
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, var(--violet-700), var(--violet-800));
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
}

.pause-overlay__card h2 {
  font-size: 1.2rem;
  font-weight: 800;
}

/* Panneau de progression multijoueur */
.race {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  max-height: 132px;
  overflow-y: auto;
}

.race__row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.76rem;
  font-weight: 700;
}

.race__name {
  width: 76px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
}

.race__bar {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.race__bar span {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--grad-rose);
  transition: width 420ms var(--ease-out);
}

.race__value {
  width: 34px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-faint);
}

.race__row--me .race__name {
  color: var(--turquoise);
}
