@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:#fff;--ink:#000;--text:#111;--sub:#5e5e5e;--line:#d4d4d4;--guide:#8f8f8f;--frame:#1c1c1c;--band:rgba(0,0,0,.05);--scrim:rgba(255,255,255,.84);--mono:"Plex Mono",monospace;--sans:"Plex Sans",sans-serif}
@media(prefers-color-scheme:dark){:root:not([data-theme=light]){color-scheme:dark;--bg:#000;--ink:#fff;--text:#ededed;--sub:#a6a6a6;--line:#2f2f2f;--guide:#8f8f8f;--frame:#ededed;--band:rgba(255,255,255,.06);--scrim:rgba(0,0,0,.8)}}
:root[data-theme=dark]{color-scheme:dark;--bg:#000;--ink:#fff;--text:#ededed;--sub:#a6a6a6;--line:#2f2f2f;--guide:#8f8f8f;--frame:#ededed;--band:rgba(255,255,255,.06);--scrim:rgba(0,0,0,.8)}

*{box-sizing:border-box;border-radius:0}
html,body{touch-action:manipulation}
body{margin:0;height:100dvh;overflow:hidden;background:var(--bg);color:var(--text);font:16px/1.45 var(--sans);-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}
button,select{font:inherit;color:inherit}
button{cursor:pointer}
button:disabled{opacity:.35;cursor:default}
button:focus-visible,select: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}
kbd{font:500 14px/1 var(--mono)}

.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}
#restart-btn{position:fixed;top:max(0px,env(safe-area-inset-top));left:8px;z-index:2}

/* The board: a grid of squares, with the loop and the pearls drawn over it. */
#board-shell{position:absolute;inset:58px 12px 88px;display:flex;overflow:hidden;touch-action:none;padding:5px}
.board-stage{flex:none;margin:auto;display:flex;flex-direction:column;align-items:center;padding-bottom:56px;position:relative}
.board{position:relative;display:flex;flex-direction:column;flex:none;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;touch-action:none;border:1px solid var(--guide);transition:border-color .6s}
.grid-row{display:flex;flex:none}
.cell{width:var(--cell);height:var(--cell);flex:none;position:relative;border-right:1px solid var(--line);border-bottom:1px solid var(--line);touch-action:none;transition:border-color .6s}
.grid-row:last-child .cell{border-bottom:0}
.cell:last-child{border-right:0}
.cell:focus{outline:none}
.cell:focus-visible{outline:2px solid var(--ink);outline-offset:-4px;z-index:1}
.board.pen .cell:focus-visible{outline:5px double var(--ink);outline-offset:-7px}
/* A branch or a pearl whose own rule is broken: a dashed square, the same in both themes. */
.cell.bad::after{content:'';position:absolute;inset:2px;border:2px dashed var(--ink);pointer-events:none}
/* What a hint rests on. */
.cell.evidence::before{content:'';position:absolute;inset:5px;border:1px dotted var(--guide);pointer-events:none}

.ink{position:absolute;inset:0;width:100%;height:100%;pointer-events:none;overflow:visible}
.ink .seg{stroke:var(--ink);stroke-width:.13;stroke-linecap:round;fill:none}
.ink .black{fill:var(--ink)}
.ink .white{fill:var(--bg);stroke:var(--ink);stroke-width:.075}
.ink .inside{fill:var(--ink);fill-opacity:0;stroke:none;transition:fill-opacity .6s .1s}
/* Hint: a dashed ghost for a segment to draw, a crossed dashed segment for one that has to go. */
.ink .ghost{stroke:var(--ink);stroke-width:.13;stroke-dasharray:.11 .09;stroke-linecap:butt;fill:none;animation:pulse 1.2s 3}
.ink .seg.doomed{stroke-dasharray:.02 .2}
.ink .strike{stroke:var(--ink);stroke-width:.06;stroke-linecap:round;fill:none}
.ink .strike-bg{fill:var(--bg);stroke:var(--ink);stroke-width:.04;animation:pulse 1.2s 3}
@keyframes pulse{50%{opacity:.35}}

/* The payoff arrives at the solve: the grid lets go and the inside of the loop takes a faint tone. */
.board.solved,.board.solved .cell{border-color:transparent}
.board.solved .inside{fill-opacity:.09}

.completion{position:absolute;top:calc(100% - 48px);height:48px;display:flex;justify-content:center}
/* The arrow itself fades in and lifts 4px; the frame owns the container's transform. */
#next-btn{animation:next-reveal .45s .15s both}
.completion[hidden]{display:none}
/* The frame clears borders on its icons, so the box is an outline. */
#next-btn{outline:1px solid var(--ink);outline-offset:-1px}
#next-btn:focus-visible{outline:2px solid var(--ink);outline-offset:2px}
@keyframes next-reveal{from{opacity:0;translate:0 4px}to{opacity:1;translate:0 0}}

#feedback{position:fixed;bottom:60px;left:16px;right:16px;margin:0;text-align:center;color:var(--sub);font:14px/1.3 var(--sans);pointer-events:none}
.toolbar{position:fixed;bottom:max(6px,env(safe-area-inset-bottom));left:8px;right:8px;display:flex;justify-content:space-between}
.toolbar>div{display:flex}
.ib{display:inline-grid;place-items:center;width:48px;height:48px;min-width:48px;min-height:48px;border:0;background:none;padding:12px;color:var(--ink);transition:opacity .15s,transform .1s}
.ib svg{width:24px;height:24px;stroke:currentColor;fill:none;stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round}
.ib:active{transform:scale(.94)}
.toolbar .ib,#restart-btn{color:var(--sub)}
.toolbar .ib:focus-visible,#restart-btn:focus-visible{color:var(--ink)}
@media(hover:hover) and (pointer:fine){.toolbar .ib:hover,#restart-btn:hover{color:var(--ink)}}
header,.toolbar,.toolbar *,button,button *{-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}

.sheet{width:min(32rem,calc(100vw - 16px));max-height:calc(100dvh - 16px);border:1px solid var(--frame);padding:0;background:var(--bg);color:var(--text)}
.sheet[open]{display:flex;flex-direction:column}
.sheet::backdrop{background:var(--scrim)}
.sheet-head{display:flex;justify-content:space-between;align-items:center;padding:8px 16px;gap:12px;flex:none;border-bottom:1px solid var(--line)}
.sheet-head h2{font:500 16px/1.3 var(--mono);margin:0}
.sheet-head form{margin:0}
.sheet-x{width:44px;height:44px;min-width:44px;min-height:44px;padding:10px}
.sheet-body{padding:20px 24px;overflow:auto;min-height:0;overscroll-behavior:contain}
.sheet-body p{max-width:60ch;margin:0 0 16px}
.row{display:flex;align-items:center;justify-content:space-between;gap:12px;min-height:52px;border-bottom:1px solid var(--line)}
.row select{max-width:65%;min-height:44px;background:var(--bg);border:0;padding:4px 8px}
.row button{min-height:44px;background:none;border:0;padding:8px}
.row button:not(:disabled){text-decoration:underline;text-underline-offset:4px}
.sheet-foot{padding:12px 24px;border-top:1px solid var(--line);flex:none;color:var(--sub);font-size:14px}
.sheet-foot a{color:inherit}
.text-action{min-height:44px;padding:8px 12px;border:1px solid var(--line);background:none;font:500 14px/1.3 var(--mono);color:var(--text)}
.controls{border-top:1px solid var(--line);padding-top:16px}
.controls p{margin:0 0 6px}
.help-more{border-top:1px solid var(--line);margin-top:16px;padding-top:4px}
.help-more summary{cursor:pointer;min-height:44px;padding:12px 0;color:var(--sub)}
.help-more summary:focus-visible{outline:2px solid var(--ink);outline-offset:2px}
.help-more p{font-size:14px}
.sheet-body .help-more p:last-child{margin-bottom:0}
@media(max-width:480px){.sheet-head{padding:8px 12px}.sheet-body{padding:16px}}

@media(orientation:landscape) and (max-height:500px){
  #board-shell{inset:6px 72px 12px 60px}
  .readout{left:64px;transform:none}
  .toolbar{left:auto;right:8px;top:12px;bottom:12px;flex-direction:column;width:48px}
  .toolbar>div{flex-direction:column}
  #feedback{left:60px;right:72px;bottom:2px;font-size:12px}
}
@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation:none!important;transition:none!important}}
:root[data-motion=reduce] *,:root[data-motion=reduce] *::before,:root[data-motion=reduce] *::after{animation:none!important;transition:none!important}
@media(forced-colors:active){
  .cell{border-color:GrayText}
  .ink .seg,.ink .ghost,.ink .strike{stroke:CanvasText}
  .ink .black{fill:CanvasText}
  .ink .white{fill:Canvas;stroke:CanvasText}
  .cell.bad::after{border-color:CanvasText}
  .cell:focus-visible{outline-color:Highlight}
  .sheet{border-color:CanvasText}
}
