body.app-page--tool-jigsaw{height:100dvh;min-width:320px;overflow:hidden;overscroll-behavior:none}
body.app-page--tool-jigsaw .site-footer{display:none}
body.app-page--tool-jigsaw #main{height:calc(100dvh - var(--px-header-height,64px));min-height:0}
.jigsaw-page{box-sizing:border-box;display:grid;grid-template-rows:auto auto minmax(0,1fr);gap:5px;width:100%;height:100%;max-width:none;margin:0;padding:7px 8px calc(80px + env(safe-area-inset-bottom));overflow:hidden;color:var(--ink,#252820)}
.jigsaw-heading{min-width:0;padding-right:84px}.jigsaw-heading h1{margin:0;font-size:clamp(1rem,2.4vw,1.3rem);line-height:1.15}.jigsaw-heading p{margin:2px 0 0;color:#586052;font-size:.74rem}
.jigsaw-status{min-height:1em;margin:0;color:#485044;font-size:.75rem;line-height:1.25;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.jigsaw-setup{box-sizing:border-box;align-self:start;display:grid;gap:9px;width:min(100%,480px);max-height:calc(100% - 10px);min-height:0;margin:8px auto;padding:13px;overflow-y:auto;overscroll-behavior:contain;border:1px solid #d5d9cf;border-radius:16px;background:#fff}
.jigsaw-field{display:grid;gap:4px;font-size:.84rem;font-weight:700}.jigsaw-field select,.jigsaw-field input[type=file]{box-sizing:border-box;width:100%;min-height:44px;padding:8px 10px;border:1px solid #c5cbbd;border-radius:10px;background:#fff;color:inherit;font:inherit;font-weight:400}.jigsaw-field select{height:44px;min-height:44px;padding-right:30px;appearance:none;-webkit-appearance:none;background-image:linear-gradient(45deg,transparent 50%,#586052 50%),linear-gradient(135deg,#586052 50%,transparent 50%);background-position:calc(100% - 15px) 50%,calc(100% - 10px) 50%;background-size:5px 5px;background-repeat:no-repeat}
.jigsaw-setup__actions{display:flex;align-items:center;justify-content:center;flex-wrap:wrap;gap:7px}.jigsaw-setup button,.jigsaw-play button{box-sizing:border-box;min-width:44px;min-height:44px;padding:7px 10px;border:1px solid #c5cbbd;border-radius:12px;background:#fff;color:inherit;font:inherit;font-size:.8rem;cursor:pointer;touch-action:manipulation}
.jigsaw-setup #jigsaw-start{border-color:#49643c;background:#49643c;color:#fff;font-weight:700}.jigsaw-setup button:disabled,.jigsaw-play button:disabled{opacity:.48;cursor:default}.jigsaw-help,.jigsaw-piece-count{margin:0;color:#586052;font-size:.78rem;line-height:1.45}
body.arc-jigsaw .jigsaw-setup.arc-panel .jigsaw-help{color:#c2cbd0}
.jigsaw-play{box-sizing:border-box;position:relative;display:grid;grid-template-rows:44px minmax(0,1fr) 74px;gap:4px;min-width:0;min-height:0;height:100%;overflow:hidden}
.jigsaw-source-label{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
.jigsaw-workspace-tools{position:relative;z-index:2;display:flex;align-items:center;justify-content:flex-start;gap:4px;min-width:0;min-height:44px}
.jigsaw-workspace-tools button{flex:none;width:44px;height:44px;padding:2px;font-size:.72rem;white-space:nowrap}.jigsaw-workspace-tools #jigsaw-rotate{font-size:1.2rem}
.jigsaw-workspace-tools #jigsaw-preview-toggle img{display:block;width:24px;height:24px;margin:auto;object-fit:contain}
.jigsaw-workspace-tools #jigsaw-preview-toggle[aria-pressed="true"]{border-color:#49643c;background:#e5eddf}
.jigsaw-workspace-tools #jigsaw-selection{min-width:0;margin-left:auto;color:#586052;font-size:.7rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.jigsaw-workspace{position:relative;box-sizing:border-box;min-width:0;min-height:0;overflow:hidden;touch-action:none;border:1px solid #d8ddd3;border-radius:14px;background-color:#f3f5f0;background-image:radial-gradient(#cdd3c7 1px,transparent 1px);background-size:18px 18px;outline:none}
.jigsaw-workspace:focus-visible{outline:3px solid #335cbe;outline-offset:2px}.jigsaw-board{position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:none;image-rendering:pixelated}
.jigsaw-preview{position:fixed;top:calc(var(--px-header-height,64px) + max(8px,env(safe-area-inset-top)));right:max(12px,env(safe-area-inset-right));z-index:70;box-sizing:border-box;display:flex;flex-direction:column;width:min(180px,calc(100vw - 24px));max-height:calc(100dvh - var(--px-header-height,64px) - 100px);padding:6px;border:1px solid rgba(67,79,61,.24);border-radius:12px;background:rgba(255,255,250,.97);box-shadow:0 5px 18px rgba(31,43,28,.2);pointer-events:auto}
.jigsaw-preview[hidden]{display:none!important}
.jigsaw-preview__head{display:flex;align-items:center;justify-content:space-between;gap:6px;min-height:44px;margin-bottom:4px;color:#394332;font-size:.7rem;font-weight:800;cursor:grab;touch-action:none;user-select:none;-webkit-user-select:none}
.jigsaw-preview__head:active{cursor:grabbing}
.jigsaw-preview__head button{flex:none;width:44px;min-width:44px;height:44px;min-height:44px;padding:0;border:0;border-radius:8px;background:transparent;color:inherit;font:inherit;font-size:1.15rem;line-height:1;cursor:pointer;touch-action:manipulation}
.jigsaw-preview__head:focus-visible{outline:3px solid #335cbe;outline-offset:2px}
.jigsaw-preview__head{flex:none}
.jigsaw-preview__canvas{display:block;flex:0 1 auto;min-height:0;width:100%;max-height:min(24dvh,150px);height:auto;object-fit:contain;image-rendering:pixelated;pointer-events:none}
.jigsaw-tray{box-sizing:border-box;display:flex;align-items:center;gap:8px;width:100%;min-width:0;height:74px;overflow-x:auto;overflow-y:hidden;padding:2px 3px 5px;overscroll-behavior-x:contain;touch-action:pan-x;scrollbar-width:thin}
.jigsaw-piece{box-sizing:border-box;display:grid;place-items:center;flex:0 0 64px;width:64px;height:64px;padding:4px;border:1px solid #c5cbbd;border-radius:10px;background:#fff;color:inherit;cursor:pointer;touch-action:pan-x;user-select:none;-webkit-user-select:none}
.jigsaw-piece[aria-pressed=true],.jigsaw-piece.is-selected{border-color:#a77400;box-shadow:0 0 0 2px #ffe5a1;background:#fffaf0}.jigsaw-piece:active{transform:translateY(1px) scale(.98);filter:brightness(.97)}.jigsaw-piece canvas{display:block;max-width:52px;max-height:52px;image-rendering:pixelated;pointer-events:none}.jigsaw-workspace[data-jigsaw-selected=true]{cursor:grab}.jigsaw-workspace[data-jigsaw-dragging=true]{cursor:grabbing}.jigsaw-complete{position:absolute;left:50%;bottom:4px;z-index:3;transform:translateX(-50%);width:max-content;max-width:calc(100% - 16px);margin:0;padding:4px 8px;border-radius:10px;background:#e5eddf;color:#31482a;font-size:.78rem;font-weight:700;text-align:center}.jigsaw-page :focus-visible{outline:3px solid #335cbe;outline-offset:2px}.jigsaw-page [hidden]{display:none!important}.jigsaw-sr-only{position:absolute!important;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
body.app-page--tool-jigsaw[data-jigsaw-playing="true"] .jigsaw-page{grid-template-rows:minmax(0,1fr);padding-top:4px}
body.app-page--tool-jigsaw[data-jigsaw-playing="true"] .jigsaw-heading,body.app-page--tool-jigsaw[data-jigsaw-playing="true"] #jigsaw-status{display:none}
@media(max-width:380px){.jigsaw-page{padding-right:6px;padding-left:6px}.jigsaw-heading p{font-size:.69rem}.jigsaw-workspace-tools{gap:3px}.jigsaw-workspace-tools button{width:44px;min-width:44px;padding:1px;font-size:.65rem}.jigsaw-workspace-tools #jigsaw-selection{display:none}.jigsaw-piece{flex-basis:60px;width:60px;height:60px}.jigsaw-tray{height:70px}}
@media(orientation:landscape) and (max-height:520px){.jigsaw-page{grid-template-rows:auto minmax(0,1fr);padding:4px 6px calc(74px + env(safe-area-inset-bottom));gap:3px}.jigsaw-heading{display:none}.jigsaw-setup{align-self:stretch;height:100%;max-height:100%;margin:0 auto;padding:9px;gap:6px}.jigsaw-setup__actions{position:sticky;bottom:0;z-index:2;padding:6px 0;background:#fff}.jigsaw-field select,.jigsaw-field input[type=file]{min-height:44px}.jigsaw-tray{height:64px}}
@media(max-height:420px){.jigsaw-play{grid-template-rows:44px minmax(0,1fr) 48px;gap:2px}.jigsaw-tray{height:48px}.jigsaw-piece{flex-basis:44px;width:44px;height:44px;padding:2px}.jigsaw-piece canvas{max-width:36px;max-height:36px}}
@media(orientation:portrait) and (max-height:600px){.jigsaw-heading p,.jigsaw-help{display:none}.jigsaw-page{gap:3px}.jigsaw-setup{gap:6px;margin:4px auto;padding:9px}}
@media(prefers-reduced-motion:reduce){.jigsaw-page button,.jigsaw-workspace{animation:none!important;transition:none!important}}
.app-page--tool-jigsaw.arc-jigsaw .jigsaw-piece:active{transform:translateY(1px) scale(.98)}
@media(orientation:landscape) and (max-height:520px) and (min-width:540px){.app-page--tool-jigsaw.arc-jigsaw .arc-hud{width:min(300px,calc(100% - 310px));box-sizing:border-box}}
@media(orientation:landscape) and (max-height:520px) and (max-width:539px){.app-page--tool-jigsaw.arc-jigsaw .jigsaw-play{grid-template-rows:auto 44px minmax(0,1fr) 50px}.app-page--tool-jigsaw.arc-jigsaw .arc-hud{position:static;width:auto}}
.jigsaw-workspace-tools{overflow-x:auto;scrollbar-width:none;overscroll-behavior-x:contain}.jigsaw-workspace-tools::-webkit-scrollbar{display:none}
#jigsaw-hint{position:relative;flex:none;width:44px;height:44px;padding:1px;font-size:.57rem;font-weight:800;white-space:nowrap}
#jigsaw-tray .jigsaw-piece.is-hint-target{border-color:#ffd35a;box-shadow:0 0 0 3px rgba(255,211,90,.72),0 3px 0 rgba(0,0,0,.28);background:#fff9df}

/* Keep the board primary: common actions stay visible, the rest open on demand. */
.jigsaw-workspace-tools{overflow:visible;z-index:6}
.jigsaw-workspace-tools #jigsaw-selection{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
.jigsaw-more{position:relative;flex:none}
.jigsaw-more>summary{box-sizing:border-box;display:grid;place-items:center;width:44px;height:44px;border:1px solid #c5cbbd;border-radius:14px;background:#fff;color:#17232d;cursor:pointer;list-style:none;touch-action:manipulation}
.jigsaw-more>summary::-webkit-details-marker{display:none}
.jigsaw-more>summary svg{width:23px;height:23px;fill:currentColor}
.jigsaw-more>summary:focus-visible{outline:3px solid #335cbe;outline-offset:2px}
.jigsaw-more[open]>summary{background:#ffd35a;border-color:#b88f1d}
.jigsaw-more__menu{position:absolute;top:calc(100% + 8px);right:0;z-index:10;display:grid;grid-template-columns:repeat(3,44px);gap:6px;padding:8px;border:1px solid #374858;border-radius:16px;background:#15202b;box-shadow:0 10px 28px #0005}
.jigsaw-workspace-tools .jigsaw-more__menu #jigsaw-new{grid-column:1/-1;width:100%;min-height:44px}

/* Tools live in the shared icon header. The board keeps the space they freed. */
body.app-page--tool-jigsaw[data-jigsaw-playing="true"] .jigsaw-play{grid-template-rows:minmax(0,1fr) 74px!important}
body.app-page--tool-jigsaw .jigsaw-play>.arc-hud,body.app-page--tool-jigsaw .jigsaw-play>.arc-win{display:none!important}
body.app-page--tool-jigsaw .jigsaw-workspace-tools{position:absolute;width:1px;height:1px;min-height:0;padding:0;overflow:hidden;clip-path:inset(50%)}
body.app-page--tool-jigsaw .jigsaw-workspace{grid-row:1}
body.app-page--tool-jigsaw .jigsaw-tray{grid-row:2}
body.app-page--tool-jigsaw[data-tool-result-open] .px-tool-header-slot{visibility:hidden}
@media(max-height:420px){body.app-page--tool-jigsaw[data-jigsaw-playing="true"] .jigsaw-play{grid-template-rows:minmax(0,1fr) 48px!important}}
@media(orientation:landscape) and (max-height:520px) and (min-width:540px){
  body.app-page--tool-jigsaw[data-jigsaw-playing="true"] .jigsaw-play{grid-template-rows:minmax(0,1fr)!important;grid-template-areas:"work tray"!important}
}

/* Reference window: image aspect is computed independently of its 44px controls. */
body.app-page--tool-jigsaw .px-site-header #jigsaw-preview-toggle{position:relative;background:#fff;color:#17232d;border:2px solid #657383;min-width:44px;min-height:44px}
body.app-page--tool-jigsaw .px-site-header #jigsaw-preview-toggle svg{fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
body.app-page--tool-jigsaw .px-site-header #jigsaw-preview-toggle[aria-pressed="true"]{background:#ffd35a;color:#17232d;border-color:#6e5510}
.jigsaw-preview-indicator{display:none;position:absolute;right:1px;bottom:0;font-size:11px;font-weight:900;line-height:14px}
#jigsaw-preview-toggle[aria-pressed="true"] .jigsaw-preview-indicator{display:block}
.jigsaw-preview{max-height:none;gap:4px;touch-action:none;overflow:visible}
.jigsaw-preview__head{height:44px;min-height:44px;margin:0;font-size:12px}
.jigsaw-preview__head button{background:#edf0e7;border:1px solid #8a9681;color:#253221}
.jigsaw-preview__canvas{flex:none;align-self:center;max-height:none;object-fit:fill}
.jigsaw-preview__foot{display:flex;align-items:center;justify-content:space-between;gap:4px;flex:none;height:44px;color:#394332;font-size:11px;font-variant-numeric:tabular-nums}
#jigsaw-preview-resize{box-sizing:border-box;flex:none;width:44px;min-width:44px;height:44px;min-height:44px;padding:8px;border:1px solid #657383;border-radius:8px;background:#fff;color:#17232d;cursor:nwse-resize;touch-action:none;transition:background-color .14s,border-color .14s,box-shadow .14s}
#jigsaw-preview-resize svg{display:block;width:26px;height:26px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
#jigsaw-preview-resize:hover{border-color:#6e5510;background:#fff0bf}
#jigsaw-preview-resize:active{border-color:#6e5510;background:#ffd35a;box-shadow:inset 0 1px 3px #6e551044}
#jigsaw-preview-resize:focus-visible,#jigsaw-preview-close:focus-visible{outline:3px solid #335cbe;outline-offset:2px}
.jigsaw-preview[data-preview-gesture]{border-color:#335cbe;box-shadow:0 0 0 2px #335cbe55,0 5px 18px #1f2b1c33}
body.app-page--tool-jigsaw .jigsaw-more__menu{grid-template-columns:minmax(0,1fr);width:212px;max-width:calc(100vw - 32px);gap:8px}
body.app-page--tool-jigsaw .jigsaw-more__menu button{box-sizing:border-box;min-height:44px;border:1px solid #657383;border-radius:10px;background:#fff;color:#17232d;font-size:13px;padding:8px}
body.app-page--tool-jigsaw .jigsaw-more__menu button:disabled{background:#263442;color:#adbac5;border-color:#41515f;cursor:default}
body.app-page--tool-jigsaw .jigsaw-more__menu #jigsaw-fit{display:flex;align-items:center;justify-content:space-between;gap:8px;width:100%}
#jigsaw-view-scale{font-variant-numeric:tabular-nums;font-size:11px}
.jigsaw-more__pages{display:grid;grid-template-columns:44px minmax(0,1fr) 44px;gap:6px;align-items:center;text-align:center;color:#fff;font-size:13px;font-variant-numeric:tabular-nums}
body.app-page--tool-jigsaw .jigsaw-more__menu #jigsaw-new{width:100%}
