/* ============================================================================
   Jigsaw — focused clubhouse play screen (gamesy). Wraps engine.js; the .jig-*
   hooks + element IDs are required by the engine + orchestrator. Difficulty is
   chosen in the lobby, so there's no start-overlay picker here — the page
   auto-starts / auto-resumes the chosen band. Mode accent via --c on .sp-page.
   ============================================================================ */

/* Full-width like the lobby (no max-width cap) — the jigsaw stage wants every
   pixel. The other play pages stay capped in their own stylesheets. */
.sp-page { width: 100%; margin: 0; color: #2b2620;
  font-family: Georgia, 'Times New Roman', serif; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.sp-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sp-back { font-family: system-ui, sans-serif; font-weight: 700; font-size: 16px; letter-spacing: 1px; color: var(--c, #1f4a33); text-decoration: none; }
.sp-back:hover { filter: brightness(1.12); }
.sp-header-actions { display: flex; gap: 10px; }
.sp-iconbtn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid #d8cdb2; background: #fffdf7; color: #4a443b; font-size: 15px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 1px 2px rgba(60,50,30,.06); transition: background .12s; }
.sp-iconbtn:hover { background: #f3ecd9; }
.sp-iconbtn.on { background: var(--c, #4e7d3a); color: #fff; border-color: var(--c, #4e7d3a); }
.sp-dd { position: relative; }
.sp-dd-panel { position: absolute; top: calc(100% + 6px); right: 0; min-width: 200px; background: #fffdf7; border: 1px solid #e6ddc6; border-radius: 10px; box-shadow: 0 8px 24px rgba(40,30,15,.18); padding: 8px; z-index: 30; display: none; }
.sp-dd.open .sp-dd-panel { display: block; }
.sp-dd-item { display: flex; align-items: center; width: 100%; padding: 10px; background: none; border: 0; border-radius: 7px; font-family: system-ui, sans-serif; font-size: 14px; color: #2b2620; cursor: pointer; text-decoration: none; text-align: left; }
.sp-dd-item:hover { background: #f3ecd9; }

/* ── Toolbar ────────────────────────────────────────────────────────────── */
.jig-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; padding: 12px 16px; border: 1px solid #e0d4b6; border-radius: 12px; background: linear-gradient(180deg, #fffdf8, #faf4e6); margin: 0 0 14px; box-shadow: inset 0 1px 0 #fff, 0 1px 2px rgba(60,50,30,.07); font-family: system-ui, sans-serif; }
.jig-toolbar .grp { display: inline-flex; align-items: center; gap: 8px; padding-right: 14px; border-right: 1px solid #ece3cb; }
.jig-toolbar .grp:last-of-type { border-right: 0; }
.jig-toolbar .grp .lbl { color: #7a7468; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; }
.jig-toolbar .grp.grow { flex: 1; min-width: 200px; }
.jig-toolbar .grp.grow .jig-progress { flex: 1; min-width: 90px; margin: 0; }
.jig-toolbar .badge { font-family: system-ui, sans-serif; font-weight: 700; font-size: 12px; letter-spacing: .6px; color: #fff; padding: 6px 13px; border-radius: 8px; background: linear-gradient(180deg, color-mix(in srgb, var(--c, #4e7d3a), #fff 16%), var(--c, #4e7d3a)); box-shadow: 0 2px 5px rgba(60,50,30,.18), inset 0 1px 0 rgba(255,255,255,.25); white-space: nowrap; }
.jig-toolbar .timer { font-family: Georgia, serif; font-weight: 700; font-size: 19px; }
.jig-toolbar .timer .clk { min-width: 56px; display: inline-block; }
.jig-toolbar .val { font-family: Georgia, serif; font-weight: 700; font-size: 13px; color: #4a443b; }
.jig-toolbar button.tbtn { appearance: none; background: #fffdf7; border: 1px solid #e6ddc6; border-radius: 8px; color: #4a443b; padding: 7px 11px; cursor: pointer; font: 600 11px system-ui, sans-serif; letter-spacing: .04em; text-transform: uppercase; box-shadow: 0 1px 2px rgba(60,50,30,.05); transition: background .12s, color .12s; }
.jig-toolbar button.tbtn:hover { background: #f3ecd9; }
.jig-toolbar button.tbtn.on { background: var(--c, #4e7d3a); color: #fff; border-color: var(--c, #4e7d3a); }
.jig-toolbar button.tbtn-icon { font-size: 14px; padding: 6px 9px; letter-spacing: 0; }

.jig-progress { height: 8px; background: #efe7d3; border-radius: 5px; position: relative; overflow: hidden; }
.jig-progress .fill { height: 100%; background: var(--c, #4e7d3a); width: 0; transition: width .4s; }

.jig-edges-toggle { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font: 600 10.5px system-ui, sans-serif; letter-spacing: .04em; text-transform: uppercase; color: #4a443b; }
.jig-edges-toggle input { width: 15px; height: 15px; margin: 0; cursor: pointer; accent-color: var(--c, #4e7d3a); }
.jig-edges-toggle:hover { color: var(--c, #4e7d3a); }

.jig-bgcolors { display: flex; gap: 6px; }
.jig-bgcolors button { appearance: none; width: 24px; height: 24px; border-radius: 6px; cursor: pointer; border: 1px solid #d8cdb2; background-size: cover; }
.jig-bgcolors button.on { border: 2px solid #2b2620; box-shadow: 0 0 0 2px #fffdf7 inset; }
.jig-bgcolors button[data-bg="paper"] { background: #f3ecd9; }
.jig-bgcolors button[data-bg="green"] { background: linear-gradient(180deg, #adb98a, #8ca06a); }
.jig-bgcolors button[data-bg="ink"]   { background: linear-gradient(180deg, #2a221a, #1a140c); }
.jig-bgcolors button[data-bg="wood"]  { background: linear-gradient(180deg, #8a6a3a, #6a4a1a); }

/* Sort dropdown */
.jig-sort-wrap { position: relative; display: inline-block; }
.jig-sort-menu { position: absolute; top: calc(100% + 4px); left: 0; z-index: 5000; min-width: 160px; background: #fffdf7; border: 1px solid #e6ddc6; border-radius: 10px; box-shadow: 0 8px 24px rgba(40,30,15,.18); padding: 4px; }
.jig-sort-menu[hidden] { display: none; }
.jig-sort-menu button { appearance: none; display: block; width: 100%; padding: 9px 12px; background: transparent; border: none; border-radius: 7px; cursor: pointer; text-align: left; font: 600 11.5px system-ui, sans-serif; text-transform: uppercase; letter-spacing: .06em; color: #2b2620; }
.jig-sort-menu button:hover { background: #f3ecd9; }
.jig-sort-wrap.fs .jig-sort-menu { background: #2b2620; border-color: rgba(240,228,190,.35); bottom: calc(100% + 4px); top: auto; }
.jig-sort-wrap.fs .jig-sort-menu button { color: #f3ecd9; }
.jig-sort-wrap.fs .jig-sort-menu button:hover { background: #463d30; }

/* ── Stage ──────────────────────────────────────────────────────────────── */
/* Match the stage to the puzzle IMAGE ratio (7:4 — images are 1792×1024) so
   the picture fills the frame instead of letterboxing. 7:4 is wide+short, so a
   full-width stage still fits the viewport height (no scroll); only on very
   wide screens does the height cap kick in and centre it. */
/* Velvet gold-edged frame — the clubhouse premium treatment. The engine's
   #stage (.jig-stage-inner) is inset:0 so it sits INSIDE this border; the frame
   never overlaps the play area. Stripped in fullscreen (see .is-fullscreen). */
.jig-stage { position: relative; box-sizing: border-box; background: #f3ecd9; border: 9px solid #2b231a; border-radius: 15px; overflow: hidden; aspect-ratio: 7 / 4; width: min(100%, calc((100vh - 200px) * 7 / 4)); margin: 0 auto; touch-action: none;
  background-image: radial-gradient(rgba(27,20,8,.07) 1px, transparent 1.2px), linear-gradient(180deg, #f3ecd9 0%, #e7dcc0 100%); background-size: 4px 4px, auto; box-shadow: inset 0 0 0 1.5px #b08a35, 0 0 0 1px #1b150d, 0 12px 28px rgba(40,30,15,.3); }
.jig-stage[data-bg="green"] { background-image: radial-gradient(rgba(20,30,10,.18) 1px, transparent 1.4px), linear-gradient(180deg, #adb98a 0%, #8ca06a 100%); }
.jig-stage[data-bg="ink"]   { background-image: radial-gradient(rgba(255,255,255,.08) 1px, transparent 1.2px), linear-gradient(180deg, #2a221a 0%, #1a140c 100%); }
.jig-stage[data-bg="wood"]  { background-image: repeating-linear-gradient(90deg, rgba(60,40,20,.08) 0 2px, transparent 2px 8px), linear-gradient(90deg, #8a6a3a 0%, #6a4a1a 100%); }
.jig-stage-inner { position: absolute; inset: 0; }
.jig-stage canvas.gameCanvas { display: none; }
.jig-stage canvas.polypiece { cursor: default; }
.jig-stage canvas.polypiece.moving { transition: top 1s, left 1s; }

.jig-ref-overlay { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 80%; max-height: 80%; opacity: 0; visibility: hidden; pointer-events: none; z-index: 650; border: 1px solid #2b2620; border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.4); transition: opacity .2s; }
.jig-ref-overlay.show { opacity: .85; visibility: visible; }

/* Fullscreen */
body.jig-fs-active { overflow: hidden; }
.jig-stage.is-fullscreen { position: fixed !important; inset: 0 !important; width: auto !important; margin: 0 !important; z-index: 9999; aspect-ratio: auto !important; border: none !important; border-radius: 0 !important; box-shadow: none !important; }
.jig-fs-bar { position: absolute; left: 0; right: 0; bottom: 0; z-index: 800; display: none; align-items: center; gap: 12px; padding: 9px 14px; background: rgba(27,20,8,.82); color: #f3ecd9; font-family: system-ui, sans-serif; font-size: 12.5px; backdrop-filter: blur(4px); transform: translateY(100%); transition: transform .25s ease; }
.jig-stage.is-fullscreen .jig-fs-bar { display: flex; }
.jig-stage.is-fullscreen.fsbar-open .jig-fs-bar { transform: translateY(0); }

/* Peek handle — toggles the slide-away bar; carries the live progress %. */
.jig-fs-handle { display: none; }
.jig-stage.is-fullscreen .jig-fs-handle { display: inline-flex; align-items: center; gap: 8px; position: absolute; left: 50%; transform: translateX(-50%); bottom: 0; z-index: 802; padding: 4px 16px 5px; border: 0; border-radius: 11px 11px 0 0; background: rgba(27,20,8,.82); color: #f3ecd9; font: 600 11px system-ui, sans-serif; cursor: pointer; backdrop-filter: blur(4px); transition: bottom .25s ease; }
.jig-stage.is-fullscreen.fsbar-open .jig-fs-handle { bottom: 46px; }
.jig-fs-handle .chev { font-size: 9px; line-height: 1; transition: transform .25s ease; }
.jig-stage.is-fullscreen.fsbar-open .jig-fs-handle .chev { transform: rotate(180deg); }
.jig-fs-handle-pct b { color: #e9c463; font-family: Georgia, serif; }
.jig-fs-bar .fs-stats { display: flex; align-items: center; gap: 14px; margin-left: auto; margin-right: auto; }
.jig-fs-bar .fs-stats b { color: #e9c463; font-family: Georgia, serif; font-size: 14px; }
.jig-fs-bar button { appearance: none; background: transparent; border: 1px solid rgba(240,228,190,.4); border-radius: 7px; color: #f3ecd9; padding: 6px 11px; cursor: pointer; font: 600 10.5px system-ui, sans-serif; text-transform: uppercase; letter-spacing: .06em; }
.jig-fs-bar button:hover { background: #f3ecd9; color: #2b2620; }
.jig-fs-bar button.on { background: #e9c463; color: #2b2620; border-color: #e9c463; }

/* ── Completion modal ───────────────────────────────────────────────────── */
.jig-done-backdrop { position: fixed; inset: 0; background: rgba(27,20,8,.55); display: flex; align-items: center; justify-content: center; z-index: 10000; padding: 20px; }
.jig-done-backdrop.hidden { display: none; }
.jig-done { background: #fffdf7; border: 1px solid #e6ddc6; border-radius: 16px; box-shadow: 0 20px 50px rgba(0,0,0,.4); padding: 34px 36px 26px; max-width: 460px; width: 100%; text-align: center; position: relative; animation: jig-pop .3s ease-out; }
@keyframes jig-pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.jig-done .stamp { display: inline-block; font-family: 'Alfa Slab One', Georgia, serif; font-weight: 400; font-size: 34px; letter-spacing: .5px; color: #b0832a; border: 3px solid #c79a3a; border-radius: 10px; padding: 12px 28px 8px; transform: rotate(-3deg); margin-bottom: 12px; box-shadow: 0 3px 10px rgba(120,90,30,.18); }
.jig-done .sub { font-family: Georgia, serif; font-style: italic; font-size: 16px; color: #4a443b; margin-bottom: 18px; }
.jig-done .stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 14px 0 22px; border-top: 1px solid #e6ddc6; border-bottom: 1px solid #e6ddc6; padding: 14px 0; }
.jig-done .stat { padding: 0 8px; border-right: 1px solid #e6ddc6; }
.jig-done .stat:last-child { border-right: none; }
.jig-done .stat .n { font-family: Georgia, serif; font-weight: 700; font-size: 24px; color: #2b2620; line-height: 1; display: block; }
.jig-done .stat .lbl { font-family: system-ui, sans-serif; text-transform: uppercase; letter-spacing: .08em; font-size: 9.5px; color: #7a7468; margin-top: 4px; }
.jig-done .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.jig-done .actions button, .jig-done .actions a { font: 700 12px system-ui, sans-serif; text-transform: uppercase; letter-spacing: .04em; padding: 11px 18px; border-radius: 9px; cursor: pointer; border: 1px solid #2f6e42; text-decoration: none; color: #2f6e42; background: #fffdf7; display: inline-flex; align-items: center; }
.jig-done .actions button.primary { background: #2f6e42; color: #fff; }
.jig-done .actions button.primary:hover { filter: brightness(1.08); }
.jig-done .actions a:hover, .jig-done .actions button:hover { filter: brightness(1.04); }

/* Solved chip */
.jig-solved-chip { position: fixed; right: 20px; bottom: 20px; z-index: 9500; display: flex; align-items: center; gap: 12px; background: #fffdf7; border: 1px solid #e6ddc6; border-radius: 12px; box-shadow: 0 6px 18px rgba(60,50,30,.22); padding: 10px 12px 10px 14px; font-family: Georgia, serif; font-size: 13px; animation: jig-chip-in .25s ease-out; }
.jig-solved-chip.hidden { display: none; }
@keyframes jig-chip-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.jig-solved-chip .chip-stamp { font-family: Georgia, serif; font-weight: 700; font-size: 16px; color: #2f6e42; line-height: 1; border: 2px solid #2f6e42; border-radius: 6px; padding: 5px 8px; transform: rotate(-3deg); }
.jig-solved-chip .chip-meta { display: flex; flex-direction: column; line-height: 1.25; }
.jig-solved-chip .chip-time { font-family: Georgia, serif; font-weight: 700; color: #2b2620; }
.jig-solved-chip .chip-level { font-family: system-ui, sans-serif; text-transform: uppercase; letter-spacing: .08em; font-size: 9.5px; color: #7a7468; }
.jig-solved-chip button { appearance: none; background: var(--c, #2f6e42); color: #fff; border: none; border-radius: 7px; padding: 7px 12px; font: 700 10.5px system-ui, sans-serif; text-transform: uppercase; letter-spacing: .06em; cursor: pointer; }
.jig-solved-chip button:hover { filter: brightness(1.08); }
.jig-solved-chip .chip-close { background: transparent; color: #9a9182; padding: 0 2px; font-size: 18px; letter-spacing: 0; }
.jig-solved-chip .chip-close:hover { color: #2b2620; filter: none; }

/* Confetti + toast */
.jig-confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 9999; }
.jig-confetti span { position: absolute; top: -10px; width: 8px; height: 14px; opacity: .9; animation: jig-fall 2.6s linear forwards; }
@keyframes jig-fall { to { transform: translateY(110vh) rotate(720deg); opacity: 0; } }
.jig-toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); background: #6a7a2a; color: #fff; font: 700 11.5px system-ui, sans-serif; text-transform: uppercase; letter-spacing: .12em; padding: 10px 18px; border-radius: 8px; box-shadow: 0 6px 16px rgba(60,50,30,.3); z-index: 9500; pointer-events: none; animation: jig-toast-pop 2.6s ease-out forwards; }
@keyframes jig-toast-pop { 0% { opacity: 0; transform: translate(-50%, 16px); } 12% { opacity: 1; transform: translate(-50%, 0); } 85% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -10px); } }

/* Tips modal reuses .jig-done-backdrop / .jig-done shells. */
.jig-tips-list { font-family: Georgia, serif; font-size: 14px; line-height: 1.55; color: #2b2620; list-style: none; padding: 0; margin: 0 0 20px; text-align: left; }
.jig-tips-list li { padding: 9px 0; border-bottom: 1px solid #efe7d3; }
.jig-tips-list li:last-child { border-bottom: none; }
.jig-tips-list b { color: var(--c, #2f6e42); }
.jig-tips-list kbd { font-family: ui-monospace, monospace; background: #f3ecd9; border: 1px solid #e6ddc6; border-radius: 4px; padding: 1px 5px; font-size: 11px; }

/* ── Phone launch gate — tap to play in fullscreen + landscape ────────────────
   Hidden by default; the script removes [hidden] only on phones. Portrait shows
   the rotate prompt, landscape shows the play button (toggled by orientation). */
.jig-gate { position: fixed; inset: 0; z-index: 10000; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; background: #1d2b22; color: #f0e9d4; }
.jig-gate[hidden] { display: none; }
.jig-gate-rotate, .jig-gate-play { display: none; flex-direction: column; align-items: center; gap: 12px; }
@media (orientation: portrait)  { .jig-gate .jig-gate-rotate { display: flex; } }
@media (orientation: landscape) { .jig-gate .jig-gate-play   { display: flex; } }
.jig-gate-rotate svg { color: var(--c, #2F6EA3); animation: jig-gate-wobble 2.4s ease-in-out infinite; }
.jig-gate-title { margin: 0; font-family: 'Times New Roman', Georgia, serif; font-weight: 700; font-size: 23px; color: #fff; }
.jig-gate-sub { margin: 0; max-width: 300px; font-size: 13.5px; line-height: 1.45; color: #b9c4ad; }
.jig-gate-play { background: none; border: 0; color: inherit; cursor: pointer; padding: 26px 44px; border-radius: 16px; }
.jig-gate-play:active { background: rgba(255,255,255,.07); }
.jig-gate-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: #9fb094; }
.jig-gate-cta { font-family: 'Times New Roman', Georgia, serif; font-weight: 700; font-size: 32px; color: #fff; }
.jig-gate-note { font-size: 11.5px; letter-spacing: .1em; text-transform: uppercase; color: #b9c4ad; }
@keyframes jig-gate-wobble { 0%, 55%, 100% { transform: rotate(0deg); } 20%, 40% { transform: rotate(90deg); } }
