/* Puzzle Box. Paper and ink, one accent, hairline rules. Luke Steuber. */
@font-face{font-family:"Plex Mono";src:url("fonts/IBMPlexMono-500.woff2") format("woff2");font-weight:500;font-display:swap}
@font-face{font-family:"Plex Sans";src:url("fonts/IBMPlexSans-400.woff2") format("woff2");font-weight:400;font-display:swap}
:root{color-scheme:light;--bg:#f5f1ea;--ink:#262523;--text:#262523;--sub:#5e5a54;--line:#cfcac0;--guide:#8d8a84;--band:rgba(38,37,35,.06);--lit:#fff7e2;--page:#ece7de;--walnut:#5a3d2b;--wood:none;--accent:#d2451e;--mono:"Plex Mono",monospace;--sans:"Plex Sans",system-ui,sans-serif}

*{box-sizing:border-box;border-radius:0}
html,body{touch-action:manipulation}
body{margin:0;height:100dvh;overflow:hidden;background:var(--page) linear-gradient(to bottom,#bcc8d2 0%,#d7dbdb 38%,#e9e5dc 62%,#ece7de 100%) fixed;color:var(--text);font:16px/1.45 var(--sans);-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent;user-select:none;-webkit-user-select:none}
button,select{font:inherit;color:inherit}
button{cursor:pointer}
:focus-visible{outline:2px solid var(--ink);outline-offset:2px}
.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
.ib{width:48px;height:48px;display:inline-grid;place-items:center;background:none;border:0;padding:0;color:var(--ink)}
.ib svg{width:24px;height:24px;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round}
.ib[hidden]{display:none}

.top{position:fixed;top:max(0px,env(safe-area-inset-top));left:8px;z-index:3;height:52px}
#stage{position:absolute;inset:calc(max(0px,env(safe-area-inset-top)) + 52px) 12px calc(max(0px,env(safe-area-inset-bottom)) + 92px)}
#box-view,#panel-view{position:absolute;inset:0;display:flex;align-items:center;justify-content:center}
#box-view[hidden],#panel-view[hidden]{display:none}
#box{width:100%;height:100%;max-width:560px;overflow:visible}
#panel-view{flex-direction:column;gap:12px}
#panel-board svg{display:block;overflow:visible;touch-action:none}

.toolbar{position:fixed;left:0;right:0;bottom:0;padding:0 8px max(8px,env(safe-area-inset-bottom));display:flex;align-items:flex-end;justify-content:space-between;gap:4px;z-index:2}
.tools-left,.tools-right{display:flex;min-width:96px}
.tools-right{justify-content:flex-end}
.tray{display:flex;gap:10px;align-items:center;justify-content:center;flex:1;min-height:64px}
.slot{width:60px;height:60px;border:1px solid var(--line);background:var(--bg);display:grid;place-items:center;padding:0}
.slot svg{width:46px;height:46px;overflow:visible}
.slot.empty{border-style:dashed;cursor:default}
.slot[aria-pressed=true]{border-color:var(--accent);box-shadow:inset 0 0 0 1px var(--accent)}
.slot .part{fill:var(--ink);stroke:none}
.slot .part-line{fill:none;stroke:var(--ink);stroke-width:1.4}

/* The cabinet. */
#box .body{fill:var(--bg);stroke:var(--ink);stroke-width:1.5}
#box .rule{fill:none;stroke:var(--ink);stroke-width:1}
#box .hair{fill:none;stroke:var(--line);stroke-width:1}
#box .guide{fill:none;stroke:var(--guide);stroke-width:1}
#box .dark{fill:var(--ink)}
#box .recess{fill:var(--band);stroke:var(--guide);stroke-width:1}
#box .cut{fill:none;stroke:var(--ink);stroke-width:1;stroke-dasharray:3 2}
#box .seat{fill:var(--bg);stroke:var(--ink);stroke-width:1.2}
#box .accent{fill:var(--accent)}
#box .accent-line{fill:none;stroke:var(--accent);stroke-width:1.6}
#box .hot{cursor:pointer;outline:none}
#box .hot .hit{fill:transparent;stroke:none}
#box .hot:focus-visible .hit{stroke:var(--ink);stroke-width:1.5;stroke-dasharray:4 3}
#box .hot.locked{cursor:default}
#box .grip{fill:none;stroke:var(--ink);stroke-width:1.6;stroke-linecap:round}
#box .fits .hit{stroke:var(--accent);stroke-width:1.6;stroke-dasharray:4 3;animation:breathe 1.6s ease-in-out infinite}
#box .nudge .hit{stroke:var(--guide);stroke-width:1;stroke-dasharray:2 3}
#box .move{transition:transform .55s cubic-bezier(.3,1.35,.5,1)}
#box .slow{transition:transform 1.1s cubic-bezier(.4,0,.2,1)}
#box .fade{transition:opacity .5s ease}
#box .shake{animation:shake .32s ease}
#box text{font-family:var(--mono);font-weight:500;text-anchor:middle;dominant-baseline:central;fill:var(--ink)}

/* Boards, shared by the panels and their small copies on the cabinet. */
.bd .cellbg{fill:var(--bg);stroke:var(--line);stroke-width:1}
.bd .frame{fill:none;stroke:var(--ink);stroke-width:1.5}
.bd .ink{fill:var(--ink)}
.bd .mark{fill:none;stroke:var(--guide);stroke-width:1.4;stroke-linecap:round}
.bd .stroke{fill:none;stroke:var(--ink);stroke-width:2.4;stroke-linecap:round}
.bd .bad{stroke-dasharray:5 4}
.bd .lit{fill:var(--lit)}
.bd .wall{fill:var(--ink)}
.bd .wall-n{fill:var(--bg)}
.bd text{font-family:var(--mono);font-weight:500;text-anchor:middle;dominant-baseline:central;fill:var(--ink)}
.bd .clue-done{fill:var(--guide)}
.bd .vclue{fill:var(--bg);stroke:var(--ink);stroke-width:1.2}
.bd .vclue.bad{stroke-dasharray:3 2}
.bd .vclue.done{stroke:var(--guide)}
.bd .island{fill:var(--bg);stroke:var(--ink);stroke-width:1.5}
.bd .island.done{fill:var(--band);stroke:var(--guide)}
.bd .island.bad{stroke-dasharray:4 3}
.bd .lane{stroke:var(--guide);stroke-width:1;stroke-dasharray:2 4}
.bd .rod{stroke:var(--ink);stroke-width:2.4;stroke-linecap:round}
.bd .post{fill:var(--line);stroke:var(--ink);stroke-width:1}
.bd .post.fixed{fill:var(--ink)}
.bd .post.bad{stroke-dasharray:3 2}
.bd .wallt{fill:var(--ink)}
.bd .floor{fill:var(--bg)}
.bd .cup{fill:var(--bg);stroke:var(--ink);stroke-width:1.5}
.bd .marble{fill:var(--ink)}
.bd .marble-move{transition:transform .16s linear}
.bd .cell{cursor:pointer;outline:none}
.bd .cell .hit{fill:transparent}
.bd .focus{fill:none;stroke:var(--ink);stroke-width:2;stroke-dasharray:4 3;pointer-events:none}
.bd .hint{fill:none;stroke:var(--accent);stroke-width:2.5;pointer-events:none;animation:breathe 1s ease-in-out infinite}
.bd.solved .frame{stroke:var(--ink);stroke-width:3}
.bd .glow{fill:var(--ink)}
#box.finale .bd,#box.finale .recess,#box.finale .hot rect.body,#box.finale .grip{opacity:.28;transition:opacity 1.6s ease .6s}

.tilt-pad{display:grid;grid-template-columns:repeat(3,52px);grid-template-rows:repeat(2,52px);gap:2px}
.tilt-pad[hidden]{display:none}
.tilt-pad button{border:1px solid var(--line);background:none;color:var(--ink);display:grid;place-items:center}
.tilt-pad button svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round}
.tilt-pad .up{grid-column:2}.tilt-pad .left{grid-column:1;grid-row:2}.tilt-pad .down{grid-column:2;grid-row:2}.tilt-pad .right{grid-column:3;grid-row:2}
.tilt-pad button.hinted{border-color:var(--accent);color:var(--accent)}

/* Settings and Help. */
.sheet{border:1px solid var(--ink);background:var(--bg);color:var(--text);padding:0;width:min(420px,calc(100vw - 32px));max-height:80dvh}
.sheet::backdrop{background:rgba(0,0,0,.25)}
.sheet-head{display:flex;align-items:center;justify-content:space-between;padding:4px 4px 0 16px;border-bottom:1px solid var(--line)}
.sheet-head h2{font:500 14px/1 var(--mono);margin:0;letter-spacing:.02em}
.sheet-body{padding:8px 16px 16px}
.row{display:flex;align-items:center;justify-content:space-between;gap:12px;min-height:48px;border-bottom:1px solid var(--line)}
.row select,.row button{background:none;border:1px solid var(--line);padding:6px 10px;min-height:36px}
.help-more summary{cursor:pointer;min-height:40px;display:flex;align-items:center}

@keyframes breathe{0%,100%{opacity:1}50%{opacity:.35}}
@keyframes shake{0%,100%{transform:translateX(0)}25%{transform:translateX(-2px)}75%{transform:translateX(2px)}}
@media(prefers-reduced-motion:reduce){*{animation:none!important;transition:none!important}}
:root[data-motion=reduce] *{animation:none!important;transition:none!important}
@media (min-width:900px){#stage{left:40px;right:40px}}
#box [data-block],#box .slow:not(.hot),#box .fade{pointer-events:none}

/* The 3D cabinet: a canvas with real buttons laid over its parts. */
#box3d{position:fixed;inset:0;width:100vw;height:100dvh;display:block;touch-action:none}
#hots{position:absolute;inset:0;pointer-events:none;overflow:hidden} /* a part swung past the screen edge must not widen the page: phones then lay the whole page out wider and the canvas frames the cabinet off to one side */
.hot3d{position:absolute;pointer-events:auto;cursor:pointer;outline:none;-webkit-tap-highlight-color:transparent}
.hot3d.locked{cursor:default}
.hot3d:focus-visible{outline:none}
:root[data-outlines=on] .hot3d:focus-visible{outline:2px dashed var(--ink);outline-offset:2px} /* the focus ring for keys and switches is a setting, off by default */
.hot3d.fits{outline:2px dashed var(--accent);outline-offset:3px;animation:breathe 1.6s ease-in-out infinite}
.hot3d.nudge{outline:2px dashed #f5f1ea;outline-offset:4px;box-shadow:0 0 0 1px rgba(38,37,35,.55);animation:breathe 1.2s ease-in-out 3}
@media(prefers-reduced-motion:reduce){.hot3d.nudge{animation:none}}
:root[data-motion=reduce] .hot3d.nudge{animation:none}

/* Panel chrome shared by the board ports. */
.panel-readout{position:fixed;top:calc(max(0px,env(safe-area-inset-top)) + 18px);left:50%;transform:translateX(-50%);font:500 13px/1 var(--mono);letter-spacing:.02em;color:var(--sub);font-variant-numeric:tabular-nums;white-space:nowrap;z-index:2}
.panel-readout:empty{display:none}
.panel-feedback{margin:0;min-height:2.9em;max-width:min(30em,92vw);text-align:center;font-size:14px;line-height:1.45;color:var(--sub)}
.panel-tools{display:flex}
#panel-board{display:flex;align-items:center;justify-content:center;max-width:100%}
.ib:disabled{opacity:.35;cursor:default}
#panel-view.done #panel-board,#panel-view.done #tilt-pad{pointer-events:none}

/* Leaning in: the board is an ivory plate on the cabinet's own walnut. */
html.leaning body{background:var(--walnut) var(--wood) center/640px}
html.leaning #panel-board{background:var(--bg);padding:20px;box-shadow:0 0 0 1px rgba(0,0,0,.25),0 10px 28px rgba(20,10,4,.45)}
html.leaning .panel-feedback{color:#f5f1ea}
html.leaning .top .ib,html.leaning .toolbar .ib,html.leaning .panel-readout{color:#f5f1ea}
html.leaning :focus-visible{outline-color:#f5f1ea}
#help-board .rule{margin:0 0 .4em;color:var(--text)}
#help-board .ctl{margin:0 0 1em;padding:0;list-style:none;color:var(--sub);font-size:14px}
#help-board:not([hidden])~p{color:var(--sub);font-size:14px}
.hot3d.away{pointer-events:none}
.slot.replay{border-style:solid;color:var(--ink)}
.finished{display:flex;align-items:center;gap:10px;margin:0;font:500 18px/1 var(--sans);color:var(--ink);animation:finish .6s .2s both} /* the end, said once in a word beside a seal the colour of the disc */
.finished .seal{width:18px;height:18px;border-radius:50%;background:var(--accent)}
@keyframes finish{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}
@media(forced-colors:active){.finished .seal{background:CanvasText;forced-color-adjust:none}}
.slot.replay svg{width:30px;height:30px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
#help-demo{display:flex;gap:8px;justify-content:center;min-height:60px;margin:0 0 .6em}
#help-demo.still{flex-wrap:wrap}
#help-demo.still svg{width:96px;height:48px;border:1px solid var(--line)}
/* In space: the board lies over the cabinet's own canvas, which draws the stars at their real depths. */
html.in-space #panel-board{position:fixed;inset:0;display:block;background:none;padding:0;box-shadow:none}
html.in-space .bx-constellations .night{background:transparent}
html.in-space .panel-feedback{position:fixed;left:50%;transform:translateX(-50%);width:min(30em,92vw);bottom:calc(max(8px,env(safe-area-inset-bottom)) + 60px);pointer-events:none;color:#f5f1ea}
html.sky-flying .toolbar,html.sky-flying .top,html.sky-flying .panel-readout{visibility:hidden}
@media(forced-colors:active){html.in-space .bx-constellations .night{background:Canvas}} /* high contrast: the system ground over the sky, so the marks keep their contrast */
