/* 15-Puzzle — sliding tile board */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: clamp(28px, 4.4vw, 40px);
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.05;
}
.page-head .sub {
  color: var(--ink-soft);
  margin: 6px 0 0;
  font-size: 14px;
  min-height: 1.4em;
}
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.size-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 600 13px 'Inter', sans-serif;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px;
}
.size-select select {
  font: 600 13px 'Inter', sans-serif;
  color: var(--ink);
  background: transparent;
  border: 0;
  padding: 2px 4px;
  cursor: pointer;
}
.size-select select:focus { outline: none; }

.play {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.chrome {
  display: flex;
  gap: 18px;
  width: 100%;
  max-width: 560px;
  justify-content: center;
  flex-wrap: wrap;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 72px;
  padding: 8px 14px;
  background: var(--bg-2, #f5efe1);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.stat-label {
  font: 600 11px 'Inter', sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.stat-value {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 22px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat-best .stat-value { color: var(--ink); }

.board-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

.board {
  position: relative;
  width: min(100%, 520px);
  aspect-ratio: 1 / 1;
  background: #e8dec5;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: clamp(6px, 1.5vw, 10px);
  box-shadow: inset 0 2px 6px rgba(60, 40, 10, 0.12);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #fbf3df 0%, #f4e8c8 100%);
  border: 1px solid #d9c898;
  border-radius: 10px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.7) inset,
    0 -1px 0 rgba(120, 90, 40, 0.12) inset,
    0 2px 4px rgba(60, 40, 10, 0.12);
  color: var(--accent);
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: clamp(28px, 7vw, 48px);
  letter-spacing: -0.02em;
  cursor: pointer;
  transition: transform 120ms cubic-bezier(0.2, 0.7, 0.2, 1),
    box-shadow 150ms ease,
    background 200ms ease;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.tile:hover {
  background: linear-gradient(180deg, #fef6e3 0%, #f7ecce 100%);
}
.tile:active {
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5) inset,
    0 -1px 0 rgba(120, 90, 40, 0.12) inset,
    0 1px 2px rgba(60, 40, 10, 0.16);
}
.tile.is-correct {
  color: var(--success, #2e7d4f);
}
.tile.is-sliding {
  z-index: 2;
}

/* Solved — wave of gold across the tiles */
@keyframes fp-solved-wave {
  0%   { background-color: var(--tile-bg, #f4e3b2); }
  50%  { background-color: #d5c07d; box-shadow: 0 0 0 2px rgba(213, 192, 125, 0.5); }
  100% { background-color: var(--tile-bg, #f4e3b2); }
}
.board.is-solved .tile {
  animation: fp-solved-wave 900ms ease-out both;
}
.board.is-solved .tile:nth-child(1)  { animation-delay: 0ms; }
.board.is-solved .tile:nth-child(2)  { animation-delay: 40ms; }
.board.is-solved .tile:nth-child(3)  { animation-delay: 80ms; }
.board.is-solved .tile:nth-child(4)  { animation-delay: 120ms; }
.board.is-solved .tile:nth-child(5)  { animation-delay: 160ms; }
.board.is-solved .tile:nth-child(6)  { animation-delay: 200ms; }
.board.is-solved .tile:nth-child(7)  { animation-delay: 240ms; }
.board.is-solved .tile:nth-child(8)  { animation-delay: 280ms; }
.board.is-solved .tile:nth-child(9)  { animation-delay: 320ms; }
.board.is-solved .tile:nth-child(10) { animation-delay: 360ms; }
.board.is-solved .tile:nth-child(11) { animation-delay: 400ms; }
.board.is-solved .tile:nth-child(12) { animation-delay: 440ms; }
.board.is-solved .tile:nth-child(13) { animation-delay: 480ms; }
.board.is-solved .tile:nth-child(14) { animation-delay: 520ms; }
.board.is-solved .tile:nth-child(15) { animation-delay: 560ms; }

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

/* Empty slot — subtly inset */
.empty-slot {
  position: absolute;
  background: rgba(60, 40, 10, 0.08);
  border-radius: 10px;
  box-shadow: inset 0 2px 4px rgba(60, 40, 10, 0.14);
  pointer-events: none;
}

/* Size variants — adjust font sizing */
.board[data-size="3"] .tile { font-size: clamp(36px, 9vw, 60px); }
.board[data-size="4"] .tile { font-size: clamp(28px, 7vw, 48px); }
.board[data-size="5"] .tile { font-size: clamp(22px, 5.5vw, 38px); }

/* Win overlay */
.win-overlay {
  position: fixed; inset: 0; background: rgba(28, 42, 58, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.win-overlay[hidden] { display: none; }
.win-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px 30px; text-align: center; box-shadow: var(--shadow-lift); max-width: 360px;
  width: 100%;
}
.win-card h2 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 32px;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
  color: var(--accent);
}
.win-sub {
  color: var(--ink-soft);
  margin: 0 0 18px;
  font-size: 14px;
}
.win-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin: 0 0 22px;
}
.win-stats div { display: flex; flex-direction: column; align-items: center; }
.win-stats dt {
  font: 600 11px 'Inter', sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 2px;
}
.win-stats dd {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 26px;
  color: var(--accent);
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.aside-info { margin-top: 22px; }
.aside-info details {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
}
.aside-info summary {
  cursor: pointer;
  font: 700 14px 'Inter', sans-serif;
  color: var(--ink);
}
.aside-info .help-body {
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
}
.aside-info .help-body p { margin: 0 0 8px; }
.aside-info .help-body ul { margin: 0; padding-left: 18px; }
.aside-info .help-body li { margin: 4px 0; }

/* Fullscreen tweaks — board fills the viewport nicely */
body[data-fullscreen="true"] .play {
  min-height: calc(100vh - 160px);
  justify-content: center;
}
body[data-fullscreen="true"] .board {
  width: min(92vw, 92vh, 640px);
}

/* Mobile — narrower screens */
@media (max-width: 480px) {
  .play { padding: 12px; gap: 12px; }
  .chrome { gap: 10px; }
  .stat { min-width: 64px; padding: 6px 10px; }
  .stat-value { font-size: 18px; }
  .board { padding: 6px; border-radius: 12px; }
  .tile { border-radius: 8px; }
}
