/* layout: full-screen canvas, slim top bar, one scrolling tool row at the bottom, slide-up panels */
:root{--bg:#f3f5f4;--surface:#ffffff;--ink:#17211f;--soft:#5c6b68;--rule:#d5ddda;--branch:#1d5c73;--fruit:#9a3b12;--accent:#0f6b5c;--on-accent:#fff;--mark:#ffe58a;--neuron:15,107,92;
--read:"Noto Serif",Georgia,"Times New Roman",serif;--ui:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;color-scheme:light}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]){--bg:#0e1514;--surface:#17211f;--ink:#e6eeeb;--soft:#8fa29d;--rule:#2b3a37;--branch:#8fd0e6;--fruit:#ffb27a;--accent:#5fd1b8;--on-accent:#05211b;--mark:#6b5710;--neuron:95,209,184;color-scheme:dark}}
:root[data-theme="dark"]{--bg:#0e1514;--surface:#17211f;--ink:#e6eeeb;--soft:#8fa29d;--rule:#2b3a37;--branch:#8fd0e6;--fruit:#ffb27a;--accent:#5fd1b8;--on-accent:#05211b;--mark:#6b5710;--neuron:95,209,184;color-scheme:dark}
*{box-sizing:border-box}
[hidden]{display:none!important}
html,body{height:100%;margin:0;overflow:hidden;overscroll-behavior:none}
body{background:var(--bg);color:var(--ink);font:14px/1.4 var(--ui)}
#app{position:relative;height:100%;display:flex;flex-direction:column}
button,select,input,textarea{font:inherit;color:inherit}
button{background:none;border:0;border-radius:8px;padding:0 11px;min-height:40px;min-width:40px;cursor:pointer;white-space:nowrap}
button:focus-visible,select:focus-visible,input:focus-visible,textarea:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
button.on,button.primary{background:var(--accent);color:var(--on-accent)}
button:disabled{opacity:.35;cursor:default}
header{display:flex;align-items:center;gap:2px;padding:4px 8px;border-bottom:1px solid var(--rule);background:var(--bg);z-index:3}
#wsname{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;text-align:left;font-weight:600}
#viewport{position:relative;flex:1;min-height:0;overflow:hidden;touch-action:none;cursor:grab}
#neurons{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}
#world{position:absolute;left:0;top:0;width:0;height:0;transform-origin:0 0}
#links{position:absolute;left:0;top:0;width:1px;height:1px;overflow:visible}
#links path{fill:none}
#links .line{stroke:var(--soft);stroke-width:1.5}
#links .hit{stroke:transparent;stroke-width:18;cursor:pointer;pointer-events:stroke}
#links g.sel .line{stroke:var(--accent);stroke-width:3}
#links circle{fill:var(--soft)}

.item{position:absolute;width:max-content;cursor:auto}
.item .body{font-family:var(--ui);font-size:var(--fs,16px);line-height:var(--lh,1.55);text-align:var(--al,left);color:var(--branch);overflow-wrap:anywhere;outline:none;min-height:1.5em;-webkit-user-select:text;user-select:text}
.item .body p,.item .body div,.item .body h1,.item .body h2,.item .body h3{margin:0 0 var(--pg,.35em)}
.item .body h1{font-size:1.5em;line-height:1.25}.item .body h2{font-size:1.28em;line-height:1.3}.item .body h3{font-size:1.1em}
.item .body ul,.item .body ol{margin:0 0 var(--pg,.35em);padding-left:1.4em}
.item .body blockquote{margin:0 0 0 1.6em;padding:0;border:0}
.item.k-source .body{font-family:var(--read);font-size:var(--fs,19px);color:var(--ink)}
.item.r-fruit .body{color:var(--fruit);font-family:var(--read);font-style:italic}
.item .tag{position:absolute;left:0;bottom:100%;font-size:10px;font-weight:700;color:var(--soft);pointer-events:none;white-space:nowrap}
.item.r-fruit .tag{color:var(--fruit)}
mark{background:var(--mark);color:inherit;border-radius:2px}
.anchor{border-bottom:2px dotted var(--accent)}
.item .outline{position:absolute;left:0;top:0;width:1px;height:1px;overflow:visible;pointer-events:none}
.item .outline polygon{fill:none;stroke:var(--accent);stroke-width:1.2;stroke-dasharray:4 3;stroke-linejoin:round}
.item.picked .outline polygon{stroke:var(--fruit);stroke-width:2;stroke-dasharray:none}
.item .handle{display:none;position:absolute;z-index:2;touch-action:none;-webkit-user-select:none;user-select:none;align-items:center;justify-content:center;font-size:13px;transform:translate(-50%,-50%)}
.item.sel .handle{display:flex}
.handle.move{width:44px;height:28px;border-radius:14px;background:var(--accent);color:var(--on-accent);cursor:move;margin-left:14px}
.handle.edge{width:30px;height:30px}
.handle.edge::before{content:"";border-radius:3px;background:var(--accent)}
.handle.left,.handle.right{cursor:ew-resize}
.handle.left::before,.handle.right::before{width:6px;height:24px}
.handle.top,.handle.bottom{cursor:ns-resize}
.handle.top::before,.handle.bottom::before{width:24px;height:6px}
.item .body[contenteditable="true"]{min-width:180px}
.gone{visibility:hidden}
::highlight(tts-s){background-color:rgba(var(--neuron),.16)}
::highlight(tts){background-color:var(--accent);color:var(--on-accent)}
#grip{position:absolute;z-index:4;width:104px;padding:0;background:var(--accent);color:var(--on-accent);border-radius:20px;touch-action:none;-webkit-user-select:none;user-select:none;cursor:move}
#player{border-top:1px solid var(--rule);background:var(--surface);z-index:3}
#voice{max-width:170px}
.bar>span:not(.sep){flex:0 0 auto;padding:0 6px;color:var(--soft)}
.item .fold{display:none}
.item.collapsed .body{display:none}
.item.collapsed .fold{display:block;color:var(--branch);cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:240px;text-align:left;padding:0;min-height:30px}
.item.collapsed.r-fruit .fold{color:var(--fruit)}
.item.collapsed .handle.edge{display:none}

#hint{position:absolute;left:16px;right:16px;top:34%;text-align:center;color:var(--soft);pointer-events:none;font-family:var(--read);font-size:18px}
#hint button{pointer-events:auto;margin-top:12px;border:1px solid var(--rule);font:14px var(--ui);color:var(--ink)}
#toast{position:absolute;left:12px;right:12px;bottom:10px;margin:auto;max-width:460px;display:flex;align-items:center;gap:8px;padding:6px 8px 6px 14px;background:var(--surface);border:1px solid var(--rule);border-radius:12px;z-index:5;box-shadow:0 4px 18px rgba(0,0,0,.18)}
#toast span{flex:1;min-width:0}
footer{border-top:1px solid var(--rule);background:var(--surface);z-index:3}
.bar{display:flex;gap:2px;overflow-x:auto;padding:5px 8px;scrollbar-width:none;align-items:center}
.bar::-webkit-scrollbar{display:none}
.bar .sep{flex:0 0 1px;height:22px;background:var(--rule);margin:0 5px}
.bar button,.bar select{flex:0 0 auto}
.bar select{min-height:40px;background:var(--surface);border:1px solid var(--rule);border-radius:8px}

#panel{position:absolute;inset:0;z-index:10;background:var(--bg);display:flex;flex-direction:column}
#panel .phead{display:flex;align-items:center;gap:6px;padding:6px 10px;border-bottom:1px solid var(--rule)}
#panel h2{flex:1;font-size:16px;margin:0}
#pbody{flex:1;overflow:auto;padding:18px 18px 48px;-webkit-user-select:text;user-select:text}
.page{max-width:65ch;margin:0 auto;display:flex;flex-direction:column;gap:14px}
.page h3{margin:18px 0 0;font-size:13px;color:var(--accent);border-bottom:1px solid var(--rule);padding-bottom:4px}
.page .read{font-family:var(--read);font-size:16px;line-height:1.65;overflow-wrap:anywhere}
.page .read p,.page .read div{margin:0 0 .4em}
.page .muted{color:var(--soft)}
.row{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
.row button,.choice{border:1px solid var(--rule)}
.choice{display:block;width:100%;text-align:left;padding:12px 14px;white-space:normal}
.choice small{display:block;color:var(--soft)}
.page textarea,.page input[type=text],.page select{width:100%;background:var(--surface);border:1px solid var(--rule);border-radius:10px;padding:12px}
.page textarea{min-height:34vh;font:16px/1.6 var(--read);resize:vertical}
.page textarea.short{min-height:90px}
.card{background:var(--surface);border:1px solid var(--rule);border-radius:14px;padding:22px 18px;font:18px/1.55 var(--read);overflow-wrap:anywhere;white-space:pre-wrap}
.hit-yes{color:var(--accent)}.hit-no{color:var(--fruit)}
.timer{font-variant-numeric:tabular-nums;font-size:22px;font-weight:700}
@media (prefers-reduced-motion:reduce){*{transition:none!important}}
/* grips sit just outside the outline so they never cover the words */
.handle.right{transform:translate(-8px,-50%);justify-content:flex-start;padding-left:5px}
.handle.left{transform:translate(calc(-100% + 8px),-50%);justify-content:flex-end;padding-right:5px}
.handle.top{height:22px;transform:translate(-50%,-100%);align-items:flex-end}
.handle.bottom{height:22px;transform:translate(-50%,0);align-items:flex-start}
.handle.right::before{margin-left:0}
.handle.move{transform:translate(-50%,-70%)}
.item.blank .handle{display:none!important}
/* side edges: a strip as tall as the text, just outside it, with the grip in the middle */
.handle.right,.handle.left{width:30px;min-height:30px;align-items:center}
.handle.right{transform:translate(-4px,0);padding-left:1px}
.handle.left{transform:translate(calc(-100% + 4px),0);padding-right:1px}
.item .outline path{fill:none;stroke:var(--accent);stroke-width:2}
/* the side grips exist only in Stretch mode */
#app:not(.stretching) .handle.edge{display:none!important}
#app.stretching .handle.move{display:none}
#app.stretching #viewport{cursor:ew-resize}
#app.stretching .item .body{-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
/* the browser must not scroll the canvas on its own */
#viewport{overflow:clip}
