/* Jigsaw Puzzle — game styles (builds on /assets/site.css and /assets/fun.css) */
[hidden] { display: none !important; }

/* ---------- menu ---------- */
.menu-main { padding: 28px 0 60px; }
.menu-head { text-align: center; max-width: 660px; margin: 0 auto 22px; }
.menu-head h1 { font-size: clamp(2.3rem, 7vw, 3.6rem); margin-bottom: .15em; }
.menu-head p { color: var(--ink-soft); font-weight: 700; }
.menu-head b { color: var(--ink); }
.menu-music {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 4px;
  font: 800 .95rem var(--font-body); color: var(--ink); cursor: pointer;
  background: var(--card); border: 0; border-radius: 999px; padding: 8px 16px; box-shadow: 0 3px 0 rgba(59,42,30,.12);
}
.menu-music svg { width: 20px; height: 20px; }
.music-toggle .mt-slash { display: none; }
.music-toggle[aria-pressed="false"] .mt-slash { display: inline; }
.music-toggle[aria-pressed="false"] { opacity: .75; }

.levels { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-bottom: 30px; }
.level {
  font: inherit; cursor: pointer; border: 3px solid transparent; background: var(--card); color: var(--ink); border-radius: 20px;
  padding: 10px 22px 12px; min-width: 160px; text-align: center; box-shadow: 0 4px 0 rgba(59,42,30,.12);
  display: flex; flex-direction: column; align-items: center; line-height: 1.15;
}
.level b { font-family: var(--font-display); font-size: 1.25rem; }
.level small { color: var(--ink-soft); font-weight: 700; }
.lv-stars { color: var(--yellow-deep); font-size: 1.2rem; letter-spacing: 2px; }
.level[aria-checked="true"] { border-color: var(--red); background: #fff3d6; box-shadow: 0 4px 0 var(--red-deep); }

.pick-title { text-align: center; font-size: 1.8rem; margin-bottom: 16px; }
.scene-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.scene-card {
  font: inherit; color: inherit; text-align: left; cursor: pointer; padding: 0; border: 0; position: relative;
  background: var(--card); border-radius: 20px; overflow: hidden; box-shadow: var(--shadow);
}
.scene-card img { width: 100%; height: auto; aspect-ratio: 3 / 2; object-fit: cover; }
.scene-card .pcs {   /* little jigsaw badge */
  position: absolute; top: 10px; left: 10px; background: rgba(255,250,240,.95); color: var(--ink); border-radius: 999px;
  padding: 3px 10px 3px 8px; font: 800 .82rem var(--font-body); box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.scene-card .sc-body { padding: 10px 14px 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.scene-card b { font-family: var(--font-display); font-size: 1.15rem; line-height: 1.1; display: block; }
.scene-card small { color: var(--ink-soft); font-weight: 700; font-size: .8rem; }
.sc-stars { white-space: nowrap; font-size: 1.15rem; letter-spacing: 1px; color: #e3d3b4; }
.sc-stars .on { color: var(--yellow); text-shadow: 0 1px 0 var(--yellow-deep); }
.total-stars { text-align: center; font-weight: 800; color: var(--ink-soft); margin-top: 28px; }
@media (max-width: 520px) {
  .scene-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .scene-card b { font-size: 1rem; }
  .scene-card .sc-body { flex-direction: column; align-items: flex-start; padding: 8px 10px 10px; }
  .level { min-width: 0; flex: 1 1 0; padding: 8px 6px 10px; }
  .level b { font-size: 1.05rem; }
  .level small { font-size: .72rem; }
}

/* ---------- play ---------- */
#play { position: relative; isolation: isolate; height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; background: var(--paper); }
#play > :not(.ambient) { position: relative; z-index: 1; }
.ambient { position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.amb-img { position: absolute; inset: -15%; background: center / cover no-repeat; opacity: 0; transition: opacity 1s;
  filter: blur(26px) saturate(1.35); animation: ambDrift 40s ease-in-out infinite alternate; }
.amb-img.on { opacity: 1; }
@keyframes ambDrift { from { transform: scale(1.02) translate(-3%, -2%); } to { transform: scale(1.15) translate(3%, 2%); } }
.ambient::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 50%, rgba(255,248,230,.2) 0%, rgba(255,246,225,.5) 65%, rgba(255,242,215,.72) 100%); }
.amb-stars i { position: absolute; left: var(--x); top: var(--y); z-index: 1; font-style: normal; font-size: var(--s); line-height: 1; color: #fff;
  text-shadow: 0 0 6px #ffd23f, 0 0 14px rgba(255,190,40,.9); opacity: 0; animation: ambTwinkle var(--t) ease-in-out infinite; animation-delay: var(--d); }
@keyframes ambTwinkle { 0%, 100% { opacity: 0; transform: scale(.4); } 50% { opacity: 1; transform: scale(1) rotate(45deg); } }

.toolbar { flex: none; display: flex; align-items: center; gap: 8px; padding: 8px max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left)); }
.toolbar:has(.progress) { min-height: 84px; align-items: flex-start; }
.tb-btn {
  flex: none; height: 46px; min-width: 46px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--card); color: var(--ink); box-shadow: 0 3px 0 rgba(59,42,30,.15);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 11px; font: 800 1rem var(--font-body);
}
.tb-btn svg { width: 24px; height: 24px; }
.tb-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(59,42,30,.15); }
.tb-btn.hint { background: var(--yellow); box-shadow: 0 3px 0 var(--yellow-deep); }
.tb-btn.peek { background: #dff0ff; box-shadow: 0 3px 0 #9cc6ea; }
.tb-btn.peek.on { background: #2f5fb3; color: #fff; }
#soundBtn .snd-off { display: none; }
#soundBtn[aria-pressed="false"] .snd-on { display: none; }
#soundBtn[aria-pressed="false"] .snd-off { display: block; }
.tb-title { flex: 1; min-width: 0; text-align: center; }
.progress { display: inline-flex !important; align-items: center; gap: 8px; margin-top: 6px !important; background: rgba(255,250,240,.92);
  border-radius: 999px; padding: 3px 12px 3px 6px; box-shadow: 0 2px 8px rgba(59,42,30,.15); }
.progress .bar { width: 110px; height: 12px; border-radius: 999px; background: #eadcc0; overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, #7ed957, #2fbf4a); transition: width .5s cubic-bezier(.3,1.4,.5,1); }
.progress b { font: 800 .95rem var(--font-body); color: var(--ink); min-width: 3.4em; }
@media (max-width: 619px) {
  .tb-label { display: none; }
  .tb-btn { padding: 0 9px; height: 42px; min-width: 42px; }
  .toolbar:has(.progress) { min-height: 0; }
  .toolbar .tb-title { display: flex; justify-content: center; align-items: center; gap: 8px; flex-wrap: wrap; }
  .progress { margin-top: 0 !important; }
  .progress .bar { width: 70px; }
}

/* board + tray: side by side on wide screens, board on top on tall ones (sizes set by jigsaw.js) */
.playarea { flex: 1; min-height: 0; display: flex; gap: 14px; padding: 4px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
.playarea.tall { flex-direction: column; gap: 10px; }
.board-wrap { position: relative; z-index: 2; flex: none; display: grid; place-items: center; }
.tray { position: relative; z-index: 1; }
.board {
  position: relative; width: var(--bw, 600px); height: var(--bh, 400px); border-radius: 10px;
  background: #f3e6c8; box-shadow: 0 0 0 5px #fff, 0 16px 40px rgba(59,42,30,.35);
  touch-action: manipulation; cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.board .ghost, .board .full { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 10px; pointer-events: none; }
.board .ghost { opacity: .07; filter: saturate(.6); transition: opacity .8s ease, filter .8s; }   /* almost clear */
.board.peeking .ghost { opacity: .4; }                                /* Peek: a washed-out view */
.board.showall .ghost { opacity: 1; filter: none; }                   /* the start: the whole picture */
.board .full { opacity: 0; transition: opacity 1.2s ease; }
.board.done .full { opacity: 1; }
.slots { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.slots path { fill: rgba(255,255,255,.08); stroke: rgba(255,255,255,.95); stroke-width: 2; stroke-dasharray: 7 6; vector-effect: non-scaling-stroke; transition: opacity .5s; }
.slots path.filled { opacity: 0; }
.slots path.glow { fill: rgba(255,214,70,.45); stroke: #ffb800; stroke-width: 4; stroke-dasharray: none; animation: slotGlow 1s ease-in-out infinite alternate; }
@keyframes slotGlow { from { fill: rgba(255,214,70,.2); } to { fill: rgba(255,214,70,.65); } }
.slots path.wrong { fill: rgba(227,50,31,.3); stroke: #e3321f; stroke-dasharray: none; }
.board.done .slots { opacity: 0; transition: opacity .6s; }
.placed { position: absolute; inset: 0; pointer-events: none; }
.placed canvas { position: absolute; }
.placed canvas.snapped { animation: snapGlow .7s ease-out; }
@keyframes snapGlow { 0% { filter: brightness(1.6) drop-shadow(0 0 10px #fff6b0); } 100% { filter: none; } }
.board.done .placed { opacity: 0; transition: opacity 1.2s ease .2s; }
.board .shine { position: absolute; inset: 0; border-radius: 10px; overflow: hidden; pointer-events: none; }
.board .shine::after { content: ""; position: absolute; top: -20%; bottom: -20%; width: 35%; left: -60%; transform: skewX(-18deg);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.75), transparent); opacity: 0; }
.board.done .shine::after { opacity: 1; animation: shineSweep 1.4s ease-in-out .5s forwards; }
@keyframes shineSweep { to { left: 130%; } }
.board.done { animation: doneGlow 2s ease .3s; }
@keyframes doneGlow { 40% { box-shadow: 0 0 0 5px #fff, 0 0 0 14px rgba(255,210,63,.8), 0 16px 60px rgba(255,190,40,.8); } }

.tray {
  flex: 1; min-width: 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-wrap: wrap; align-content: flex-start; justify-content: center; gap: 4px 6px; padding: 10px 6px 20px;
  border-radius: 22px; background: rgba(255,250,240,.55); box-shadow: inset 0 0 0 3px rgba(255,255,255,.8), 0 6px 20px rgba(59,42,30,.12);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.tp {   /* a piece waiting in the tray */
  position: relative; flex: none; width: var(--pw); height: var(--ph); cursor: grab; touch-action: none;
  border: 0; padding: 0; background: none; transform: rotate(var(--rot, 0deg)); transition: transform .25s cubic-bezier(.3,1.5,.5,1);
  -webkit-tap-highlight-color: transparent;
}
.tp canvas { width: 100%; height: 100%; display: block; pointer-events: none; filter: drop-shadow(0 3px 3px rgba(59,42,30,.35)); }
@media (hover: hover) { .tp:hover { transform: translateY(-4px) scale(1.06); } }
.tp.sel { transform: translateY(-6px) scale(1.14); z-index: 2; }
.tp.sel canvas { filter: drop-shadow(0 0 0 #fff) drop-shadow(0 0 4px #fff) drop-shadow(0 0 10px #ffb800) drop-shadow(0 8px 10px rgba(59,42,30,.35)); animation: selBob 1.1s ease-in-out infinite; }
@keyframes selBob { 50% { transform: translateY(-3px); } }
.tp.gone { visibility: hidden; }
.tp.nudge { animation: nudgeHop .7s cubic-bezier(.3,1.6,.5,1); }
@keyframes nudgeHop { 35% { translate: 0 -14px; } }
.tp.bounce { animation: bounceBack .5s cubic-bezier(.3,1.6,.5,1); }
@keyframes bounceBack { 30% { scale: 1.2; } }
.flying { position: fixed; z-index: 40; pointer-events: none; transform-origin: 0 0; filter: drop-shadow(0 10px 14px rgba(59,42,30,.4)); }
.dragging { position: fixed; z-index: 45; pointer-events: none; filter: drop-shadow(0 14px 16px rgba(59,42,30,.45)); }
body.holding, body.holding .board, body.holding .tp { cursor: grabbing; }

.toast {
  position: absolute; left: 50%; top: 8px; transform: translateX(-50%); z-index: 3; margin: 0; white-space: nowrap;
  background: rgba(255,250,240,.96); color: var(--ink); font-weight: 800; font-size: .95rem;
  padding: 8px 16px; border-radius: 999px; box-shadow: 0 4px 14px rgba(0,0,0,.2); transition: opacity .3s; pointer-events: none;
}
.toast:empty { opacity: 0; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; font: 800 1.4rem var(--font-display); color: var(--ink-soft); z-index: 4; }

/* ---------- win ---------- */
.win { position: fixed; inset: 0; z-index: 50; background: rgba(40, 24, 10, .45); display: grid; place-items: center; padding: 16px; animation: fade .3s; }
@keyframes fade { from { opacity: 0; } }
.win-card { background: var(--card); border-radius: 30px; padding: 26px 26px 22px; text-align: center; width: min(440px, 100%);
  box-shadow: 0 10px 0 rgba(59,42,30,.18), 0 30px 60px rgba(0,0,0,.25); animation: pop .5s cubic-bezier(.3,1.6,.5,1); }
@keyframes pop { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.win-card h2 { font-size: 2.2rem; margin: 4px 0 2px; color: var(--red); }
.win-card p { font-weight: 700; color: var(--ink-soft); }
.win-stars { font-size: 3.4rem; line-height: 1; letter-spacing: 6px; }
.win-stars span { color: #eadcc0; display: inline-block; }
.win-stars span.on { color: var(--yellow); text-shadow: 0 3px 0 var(--yellow-deep); animation: pop .5s cubic-bezier(.3,1.8,.5,1) both; }
.win-stars span.on:nth-child(2) { animation-delay: .25s; }
.win-stars span.on:nth-child(3) { animation-delay: .5s; }
.win-buttons { display: flex; flex-direction: column; gap: 12px; align-items: stretch; margin-top: 8px; }
.win-links { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; }
.btn-link { background: none; border: 0; font: 800 1rem var(--font-body); color: var(--ink-soft); cursor: pointer; padding: 6px; text-decoration: underline; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }