* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, sans-serif;
  padding: 2rem;
  background: #1b1f2a;
  color: #f2f2f2;
}

.layout {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 2rem;
}

.game-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.game-history {
  width: min(100%, 18rem);
  background: #262b3a;
  border-radius: 0.75rem;
  padding: 1rem 1.25rem;
}

.game-history h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.game-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: #c7c9d1;
}

.game-history-list li {
  padding: 0.4rem 0.5rem;
  border-radius: 0.4rem;
  background: #1b1f2a;
}

.game-history-list li.is-empty {
  color: #8b8fa3;
  font-style: italic;
  background: transparent;
  padding-left: 0;
}

.status {
  font-size: 1.25rem;
  font-weight: bold;
}

.moves {
  font-size: 1rem;
  color: #c7c9d1;
}

.difficulty {
  display: flex;
  gap: 0.5rem;
}

.difficulty button {
  font-size: 1rem;
  font-family: inherit;
  padding: 0.4rem 1rem;
  border-radius: 0.5rem;
  border: 2px solid transparent;
  cursor: pointer;
  background: #3a3f51;
  color: #f2f2f2;
}

.difficulty button:hover {
  background: #4c5268;
}

.difficulty button:focus-visible {
  outline: 2px solid #f2f2f2;
  outline-offset: 2px;
}

.difficulty button.is-active {
  border-color: #f2c94c;
  background: #4c5268;
  font-weight: bold;
}

.game-mode {
  display: flex;
  gap: 0.5rem;
}

.game-mode button {
  font-size: 1rem;
  font-family: inherit;
  padding: 0.4rem 1rem;
  border-radius: 0.5rem;
  border: 2px solid transparent;
  cursor: pointer;
  background: #3a3f51;
  color: #f2f2f2;
}

.game-mode button:hover {
  background: #4c5268;
}

.game-mode button:focus-visible {
  outline: 2px solid #f2f2f2;
  outline-offset: 2px;
}

.game-mode button.is-active {
  border-color: #f2c94c;
  background: #4c5268;
  font-weight: bold;
}

.players-scoreboard {
  display: flex;
  gap: 1.5rem;
  font-size: 1rem;
  color: #c7c9d1;
}

.players-scoreboard[hidden] {
  display: none;
}

.lan-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  max-width: 32rem;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  background: #262b3a;
  color: #c7c9d1;
  text-align: center;
}

.lan-panel[hidden] {
  display: none;
}

.lan-message {
  margin: 0;
  font-size: 1rem;
}

.lan-message.is-error {
  color: #eb5757;
  font-weight: bold;
}

.lan-address {
  margin: 0;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 1.05rem;
  color: #f2c94c;
  word-break: break-all;
}

.lan-address[hidden] {
  display: none;
}

.lan-actions {
  display: flex;
  gap: 0.5rem;
}

.lan-button {
  font-size: 0.9rem;
  font-family: inherit;
  padding: 0.35rem 0.9rem;
  border-radius: 0.5rem;
  border: none;
  cursor: pointer;
  background: #4c5268;
  color: #f2f2f2;
}

.lan-button:hover {
  background: #5c6380;
}

.lan-button:focus-visible {
  outline: 2px solid #f2f2f2;
  outline-offset: 2px;
}

.lan-button[hidden] {
  display: none;
}

/* Plateau inactif : ce n'est pas le tour de ce joueur (FR-006). */
.board.is-locked {
  opacity: 0.55;
}

.board.is-locked .tile {
  cursor: not-allowed;
}

.players-scoreboard .player {
  padding: 0.4rem 0.75rem;
  border-radius: 0.5rem;
}

.players-scoreboard .player.is-active-player {
  background: #3a3f51;
  color: #f2c94c;
  font-weight: bold;
}

.sound-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  color: #c7c9d1;
}

.sound-controls input[type='range'] {
  accent-color: #f2c94c;
  cursor: pointer;
}

.sound-controls button {
  font-size: 0.9rem;
  font-family: inherit;
  padding: 0.4rem 0.9rem;
  border-radius: 0.5rem;
  border: 2px solid transparent;
  cursor: pointer;
  background: #3a3f51;
  color: #f2f2f2;
}

.sound-controls button:hover {
  background: #4c5268;
}

.sound-controls button:focus-visible {
  outline: 2px solid #f2f2f2;
  outline-offset: 2px;
}

.sound-controls button.is-muted {
  border-color: #f2c94c;
  background: #4c5268;
  font-weight: bold;
}

.best-score {
  font-size: 1rem;
  font-weight: bold;
  color: #f2c94c;
}

.restart {
  font-size: 1rem;
  font-family: inherit;
  padding: 0.5rem 1.25rem;
  border-radius: 0.5rem;
  border: none;
  cursor: pointer;
  background: #4c5268;
  color: #f2f2f2;
}

.restart:hover {
  background: #5c6380;
}

.restart:focus-visible {
  outline: 2px solid #f2f2f2;
  outline-offset: 2px;
}

.board {
  --cols: 4;
  display: grid;
  gap: 0.5rem;
  width: min(94vw, calc(var(--cols) * 4.5rem));
  margin-inline: auto;
}

.tile {
  aspect-ratio: 1;
  width: 100%;
  font-size: clamp(1rem, 4vw, 1.75rem);
  border-radius: 0.5rem;
  border: none;
  padding: 0;
  cursor: pointer;
  background: transparent;
  perspective: 800px;
  transition: transform 0.1s ease;
}

.tile:hover:not([disabled]) {
  transform: scale(1.03);
}

.tile[disabled] {
  cursor: default;
}

.tile-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.5s ease;
}

.tile.is-revealed .tile-inner,
.tile.is-matched .tile-inner {
  transform: rotateY(180deg);
}

.tile-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
  backface-visibility: hidden;
}

.tile-face--back {
  background: #3a3f51;
}

.tile-face--front {
  background: #f2f2f2;
  color: #1b1f2a;
  transform: rotateY(180deg);
}

.tile.is-matched .tile-face--front {
  background: #4caf7d;
  color: #0b2417;
}

@keyframes tile-shake {
  0%, 100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-6px);
  }
  40% {
    transform: translateX(5px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(3px);
  }
}

.tile.is-shaking {
  animation: tile-shake 0.4s ease;
}

@media (prefers-reduced-motion: reduce) {
  .tile.is-shaking {
    animation: none;
  }
}
