:root {
  color-scheme: light;
  --color-bg: #f4f5f7;
  --color-surface: #ffffff;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-tile: #3b82f6;
  --color-tile-text: #ffffff;
  --color-text: #1f2937;
  --color-muted: #6b7280;
  --color-border: #e5e7eb;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 24px 16px 48px;
  background: var(--color-bg);
  color: var(--color-text);
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.app__header {
  text-align: center;
}

.app__header h1 {
  margin: 0 0 4px;
  font-size: 1.75rem;
}

.app__subtitle {
  margin: 0;
  color: var(--color-muted);
  font-size: 0.9rem;
}

.stats {
  display: flex;
  justify-content: space-around;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 12px 16px;
}

.stats__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stats__label {
  font-size: 0.75rem;
  color: var(--color-muted);
}

.stats__value {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.board-wrapper {
  display: flex;
  justify-content: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 6px;
  width: min(100%, 360px);
  aspect-ratio: 1 / 1;
  background: var(--color-border);
  padding: 6px;
  border-radius: 16px;
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  background: var(--color-tile);
  color: var(--color-tile-text);
  cursor: pointer;
  transition: transform 0.08s ease, background-color 0.15s ease;
}

.tile:hover {
  background: var(--color-primary-dark);
}

.tile:active {
  transform: scale(0.96);
}

.tile--blank {
  background: transparent;
  cursor: default;
  box-shadow: none;
}

/* タイル移動時のポップアニメーション（再生成されたDOM要素に付与し、挿入と同時に再生される） */
@keyframes tile-pop {
  0% {
    transform: scale(0.82);
  }
  60% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

.tile--moved {
  animation: tile-pop 0.18s ease-out;
}

/* クリア時の祝福演出（拡大縮小＋色変化） */
@keyframes board-celebrate {
  0%,
  100% {
    transform: scale(1);
  }
  20% {
    transform: scale(1.05);
  }
  40% {
    transform: scale(0.97);
  }
  60% {
    transform: scale(1.03);
  }
  80% {
    transform: scale(0.99);
  }
}

@keyframes tile-celebrate-color {
  0%,
  100% {
    background: var(--color-tile);
  }
  50% {
    background: #f59e0b;
  }
}

.board--celebrate {
  animation: board-celebrate 0.7s ease-in-out;
}

.board--celebrate .tile:not(.tile--blank) {
  animation: tile-celebrate-color 0.7s ease-in-out;
}

.controls {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.button {
  appearance: none;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.95rem;
  cursor: pointer;
}

.button--primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.button--primary:hover {
  background: var(--color-primary-dark);
}

.ranking {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 16px;
}

.ranking h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.ranking__list {
  margin: 0;
  padding: 0 0 0 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}

.ranking__empty {
  list-style: none;
  color: var(--color-muted);
  margin-left: -1.25rem;
}

.ranking__row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.ranking__row-name {
  font-weight: 600;
}

.ranking__row-meta {
  color: var(--color-muted);
}

.clear-dialog {
  border: none;
  border-radius: 16px;
  padding: 24px;
  max-width: 320px;
  width: 90%;
}

.clear-dialog::backdrop {
  background: rgba(15, 23, 42, 0.5);
}

.clear-form__label {
  display: block;
  margin: 12px 0 4px;
  font-size: 0.85rem;
  color: var(--color-muted);
}

#player-name {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 1rem;
}

.clear-form__actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.clear-form__error {
  color: #dc2626;
  font-size: 0.85rem;
  min-height: 1.2em;
  margin: 8px 0 0;
}
