.puzzle-page { background: linear-gradient(180deg, #e7f8ff 0, #fffaf0 360px); min-height: 100vh; }
.puzzle-shell { width: min(1180px, calc(100% - 24px)); margin: 0 auto; padding: 28px 0 60px; }
.puzzle-topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.puzzle-title { text-align: center; flex: 1; }
.puzzle-title h1 { font-size: clamp(1.8rem, 4vw, 3rem); margin: 0; }
.puzzle-title p { margin: 6px 0 0; color: var(--muted); }

.setup-panel, .game-panel {
  background: rgba(255,255,255,.97);
  border-radius: 30px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(82,22,140,.08);
}
.setup-panel { padding: 28px; }
.setup-panel h2 { margin-bottom: 8px; font-size: 1.8rem; }
.setup-panel .intro { color: var(--muted); margin-bottom: 22px; }
.puzzle-gallery { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.puzzle-choice {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  padding: 0;
  border: 4px solid transparent;
  border-radius: 20px;
  background: #e8f5fb;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(51,23,68,.11);
}
.puzzle-choice img { width: 100%; height: 100%; object-fit: cover; }
.puzzle-choice::after { content: "✓"; position: absolute; right: 10px; top: 10px; width: 34px; height: 34px; display: none; place-items: center; border-radius: 50%; background: var(--green); color: #fff; font-weight: 900; box-shadow: 0 5px 14px rgba(0,0,0,.18); }
.puzzle-choice[aria-pressed="true"] { border-color: var(--purple); }
.puzzle-choice[aria-pressed="true"]::after { display: grid; }
.setup-group { margin-top: 24px; }
.setup-label { display: block; margin-bottom: 10px; font-weight: 900; }
.level-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.level-btn {
  min-width: 84px;
  min-height: 52px;
  border: 2px solid #e7d9f0;
  border-radius: 16px;
  background: white;
  color: var(--purple-dark);
  font-weight: 900;
  cursor: pointer;
}
.level-btn[aria-pressed="true"] { color: white; border-color: var(--purple); background: var(--purple); box-shadow: 0 10px 20px rgba(114,39,184,.22); }
.setup-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 26px; }
.setup-actions .primary-btn { flex: 1; min-width: 220px; }

.game-panel { padding: 18px; }
.hud { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px; margin-bottom: 14px; }
.hud-item { padding: 12px 10px; border-radius: 16px; background: #f7f0fb; text-align: center; }
.hud-label { display: block; color: var(--muted); font-size: .76rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.hud-value { display: block; margin-top: 3px; color: var(--purple-dark); font-size: 1.12rem; font-weight: 900; }
.progress-track { height: 13px; border-radius: 999px; background: #ece3f1; overflow: hidden; margin-bottom: 14px; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--pink), var(--yellow)); transition: width .25s ease; }
.board-wrap { position: relative; width: min(100%, 900px); margin: 0 auto; aspect-ratio: 4 / 3; border-radius: 22px; overflow: hidden; background: #d9eef8; box-shadow: inset 0 0 0 5px #fff, 0 13px 30px rgba(42,22,52,.16); }
.puzzle-board { display: grid; width: 100%; height: 100%; touch-action: none; user-select: none; }
.puzzle-tile {
  position: relative;
  border: 1.5px solid rgba(255,255,255,.83);
  background-repeat: no-repeat;
  cursor: grab;
  transition: transform .12s ease, filter .18s ease, box-shadow .12s ease;
}
.puzzle-tile:active { cursor: grabbing; }
.puzzle-tile.selected { z-index: 4; outline: 5px solid var(--yellow); outline-offset: -5px; filter: brightness(1.08); }
.puzzle-tile.correct { box-shadow: inset 0 0 0 3px rgba(73,185,100,.78); }
.drag-ghost { position: fixed; z-index: 3000; pointer-events: none; opacity: .85; border-radius: 12px; box-shadow: 0 18px 40px rgba(0,0,0,.3); transform: translate(-50%,-50%) scale(.88) rotate(2deg); }
.preview-overlay { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(39,18,52,.72); backdrop-filter: blur(5px); }
.preview-overlay[hidden] { display:none; }
.preview-overlay img { width: 92%; max-height: 92%; object-fit: contain; border: 6px solid #fff; border-radius: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.38); }
.game-controls { display: flex; justify-content: center; flex-wrap: wrap; gap: 9px; margin-top: 16px; }
.control-btn { min-height: 48px; padding: 0 15px; border: 0; border-radius: 15px; background: #f1e9f8; color: var(--purple-dark); font-weight: 900; cursor: pointer; }
.control-btn.primary { background: var(--purple); color: white; }
.game-help { margin: 14px auto 0; max-width: 760px; text-align: center; color: var(--muted); font-size: .9rem; }

.win-modal { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 18px; background: rgba(39,17,53,.75); backdrop-filter: blur(12px); }
.win-modal[hidden] { display:none; }
.win-card { width: min(500px,100%); padding: 30px; border-radius: 30px; background: white; text-align: center; box-shadow: 0 30px 90px rgba(0,0,0,.32); }
.win-emoji { font-size: 80px; animation: bounce .8s ease infinite alternate; }
.win-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0; }
.win-stats div { padding: 14px; border-radius: 16px; background: #f6effb; }
.win-stats strong { display:block; font-size: 1.45rem; color: var(--purple-dark); }
.win-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.win-actions > * { flex: 1; min-width: 170px; }
.confetti { position: fixed; top: -20px; z-index: 1200; width: 10px; height: 16px; border-radius: 3px; pointer-events:none; animation: fall var(--dur) linear forwards; }
@keyframes fall { to { transform: translate(var(--drift), 110vh) rotate(720deg); opacity: .9; } }
@keyframes bounce { to { transform: translateY(-12px) scale(1.05); } }

@media (max-width: 760px) {
  .puzzle-shell { width: min(100% - 14px, 700px); padding-top: 12px; }
  .puzzle-topbar { align-items: flex-start; }
  .puzzle-title p { display:none; }
  .setup-panel { padding: 18px 14px; }
  .puzzle-gallery { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; }
  .puzzle-choice { border-radius: 15px; border-width: 3px; }
  .level-grid { display: grid; grid-template-columns: repeat(3,1fr); }
  .level-btn { min-width: 0; }
  .game-panel { padding: 9px; border-radius: 22px; }
  .hud { grid-template-columns: repeat(4,1fr); gap: 5px; }
  .hud-item { padding: 8px 3px; border-radius: 12px; }
  .hud-label { font-size: .61rem; }
  .hud-value { font-size: .95rem; }
  .board-wrap { border-radius: 14px; }
  .game-controls { display: grid; grid-template-columns: repeat(3,1fr); gap: 7px; }
  .control-btn { padding: 0 7px; font-size: .83rem; }
  .game-help { font-size: .8rem; }
}
