/* Puzzle game — styled against the site's design tokens (see :root in
   style.css). Reuses .btn, .section-heading, .book-age, and .ink-trail
   from the main stylesheet rather than redefining them. */

.puzzle-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.puzzle-reference:not([hidden]) {
  display: block;
  width: 140px;
  height: auto;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
}

@media (min-width: 820px) {
  .puzzle-layout {
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    gap: 1.75rem;
  }

  .puzzle-reference:not([hidden]) {
    width: 200px;
  }
}

.puzzle-frame {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: 20px;
  width: min(100%, 520px);
  margin: 0 auto;
}

.puzzle-board {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 4px;
  box-sizing: border-box;
  background: var(--ink);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.puzzle-piece {
  border: none;
  padding: 0;
  margin: 0;
  background-repeat: no-repeat;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.puzzle-piece:hover:not(:disabled) {
  filter: brightness(1.08);
}

.puzzle-piece.is-selected {
  outline: 3px solid var(--mustard);
  outline-offset: -3px;
  z-index: 2;
  position: relative;
  transform: scale(1.04);
  box-shadow: 0 6px 14px rgba(38, 50, 74, 0.35);
}

.puzzle-board.is-solved {
  gap: 0;
  padding: 0;
  background: none;
  animation: puzzle-solved-pop 0.5s ease;
}

.puzzle-board.is-solved .puzzle-piece {
  cursor: default;
}

@keyframes puzzle-solved-pop {
  0% { transform: scale(0.96); opacity: 0.6; }
  60% { transform: scale(1.02); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

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

.puzzle-page {
  text-align: center;
  padding-bottom: 3rem;
}

.difficulty-picker {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.75rem;
}

.difficulty-btn.is-active {
  background: var(--coral);
  color: var(--white);
  border-color: var(--coral);
}

.puzzle-status {
  margin-top: 1.25rem;
  font-weight: 700;
  min-height: 1.6em;
}

.puzzle-status.is-solved {
  font-family: var(--font-hand);
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--coral-deep);
  display: inline-block;
  transform: rotate(-1.5deg);
}

.puzzle-actions {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.75rem;
}

.puzzle-error {
  max-width: 34rem;
  margin: 4rem auto;
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--ink-soft);
}

/* ---------- Puzzle library cards ---------- */
.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 28px;
  padding-bottom: 3rem;
}

.puzzle-card {
  background: var(--white);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  text-decoration: none;
  color: var(--ink);
  max-width: 260px;
  justify-self: center;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.puzzle-card:hover, .puzzle-card:focus-visible {
  transform: translateY(-6px) rotate(-0.6deg);
  box-shadow: 0 20px 40px rgba(38, 50, 74, 0.18);
}

.puzzle-card-thumb {
  aspect-ratio: 1 / 1;
  background: var(--paper-shade);
}

.puzzle-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.puzzle-card-info {
  padding: 16px 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-grow: 1;
}

.puzzle-card-info h3 {
  font-size: 1.1rem;
  margin: 0;
}
