/* Layout: two-pane workbench. Left = live station stage (what you see is the GIF); right = slot inspector + item/tag picker. */
:root{
  --bg:#ECEFEA; --surface:#FFFFFF; --sunk:#F4F6F2; --fg:#1D2420; --muted:#5B6860; --line:#D2D9D1;
  --accent:#2E7D4B; --accent-fg:#FFFFFF; --accent-soft:#DCEFE2; --danger:#B3402F; --sel:#F2C94C; --tag:#7A4FB5;
  --f-display:"Pixelify Sans","Courier New",monospace;
  --f-body:"IBM Plex Sans",system-ui,-apple-system,"Segoe UI",sans-serif;
  --f-mono:"IBM Plex Mono",ui-monospace,Menlo,Consolas,monospace;
  --r:8px;
}
@media (prefers-color-scheme: dark){:root:not([data-theme="light"]){
  --bg:#141917; --surface:#1D2420; --sunk:#171D1A; --fg:#E4EAE5; --muted:#97A49B; --line:#323C36;
  --accent:#62BE84; --accent-fg:#0E1A12; --accent-soft:#1F3828; --danger:#E5826F; --sel:#F2C94C; --tag:#B794E6; color-scheme:dark}}
:root[data-theme="dark"]{
  --bg:#141917; --surface:#1D2420; --sunk:#171D1A; --fg:#E4EAE5; --muted:#97A49B; --line:#323C36;
  --accent:#62BE84; --accent-fg:#0E1A12; --accent-soft:#1F3828; --danger:#E5826F; --sel:#F2C94C; --tag:#B794E6; color-scheme:dark}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{margin:0}
img{max-width:100%}
[hidden]{display:none!important}
body{background:var(--bg);color:var(--fg);font:15px/1.5 var(--f-body);
  padding-left:max(16px,env(safe-area-inset-left,0px));padding-right:max(16px,env(safe-area-inset-right,0px));padding-block:20px 40px}
.wrap{max-width:1180px;margin:0 auto;display:flex;flex-direction:column;gap:18px}
header{display:flex;flex-wrap:wrap;align-items:baseline;gap:6px 16px}
h1{font:700 28px/1.1 var(--f-display);margin:0;letter-spacing:.5px}
header p{margin:0;color:var(--muted);max-width:62ch}
h2{font:500 13px/1.2 var(--f-body);text-transform:uppercase;letter-spacing:.08em;color:var(--muted);margin:0}
.bench{display:grid;grid-template-columns:minmax(0,1.05fr) minmax(0,1fr);gap:18px;align-items:start}
@media (max-width:880px){.bench{grid-template-columns:minmax(0,1fr)}}
.pane{background:var(--surface);border:1px solid var(--line);border-radius:var(--r);padding:16px;display:flex;flex-direction:column;gap:14px;min-width:0}
.stations{display:flex;gap:6px;flex-wrap:wrap}
.stations button{flex:1 1 120px;justify-content:center;padding:9px 12px}
.stations button[aria-pressed="true"]{background:var(--accent-soft);border-color:var(--accent);font-weight:600}
.stage{display:flex;justify-content:center;background:repeating-conic-gradient(var(--sunk) 0 25%, var(--bg) 0 50%) 0 0/16px 16px;border-radius:6px;padding:22px 10px}
.canvas-box{position:relative;width:100%;max-width:528px;line-height:0}
.canvas-box canvas{width:100%;height:auto;image-rendering:pixelated;display:block}
.hit{position:absolute;cursor:pointer;border-radius:1px;outline:none}
.hit:hover{background:rgba(255,255,255,.28)}
.hit.sel{box-shadow:0 0 0 3px var(--sel) inset}
.hit.primary{box-shadow:0 0 0 3px var(--sel) inset,0 0 0 1px #000 inset}
.hit.drop{background:rgba(242,201,76,.45)}
.hit.soft:hover{background:rgba(255,255,255,.12)}
.hit.soft.sel{box-shadow:0 0 0 2px var(--sel) inset}
.hit:focus-visible{box-shadow:0 0 0 3px var(--accent) inset}
.row{display:flex;flex-wrap:wrap;gap:10px;align-items:center}
.row.spread{justify-content:space-between}
.hint{color:var(--muted);font-size:13px;margin:0}
.hint kbd{font:500 11px var(--f-mono);border:1px solid var(--line);border-bottom-width:2px;border-radius:4px;padding:0 4px;background:var(--sunk)}
button,.btn{font:500 14px var(--f-body);border:1px solid var(--line);background:var(--surface);color:var(--fg);border-radius:6px;padding:7px 12px;cursor:pointer;display:inline-flex;align-items:center;gap:6px}
button:hover{border-color:var(--muted)}
button:focus-visible,input:focus-visible,select:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
button.primary{background:var(--accent);color:var(--accent-fg);border-color:var(--accent)}
button.primary:hover{filter:brightness(1.07)}
button.ghost{border-color:transparent;background:none;color:var(--muted);padding:5px 8px}
button.ghost:hover{color:var(--fg)}
button:disabled{opacity:.5;cursor:default}
.seg{display:inline-flex;border:1px solid var(--line);border-radius:6px;overflow:hidden;align-self:flex-start}
.seg button{border:0;border-radius:0;padding:6px 11px;background:var(--surface)}
.seg button+button{border-left:1px solid var(--line)}
.seg button[aria-pressed="true"]{background:var(--accent-soft);color:var(--fg);font-weight:600}
label.field,div.field{display:flex;flex-direction:column;gap:4px;font-size:12px;color:var(--muted)}
input[type=text],input[type=number],input[type=search],select{font:14px var(--f-body);color:var(--fg);background:var(--sunk);border:1px solid var(--line);border-radius:6px;padding:7px 10px;min-width:0}
input[type=number]{width:84px;font-family:var(--f-mono)}
.check{display:flex;align-items:center;gap:8px;font-size:14px;color:var(--fg);cursor:pointer;padding-block:6px}
.check input{width:16px;height:16px;accent-color:var(--accent)}
.frame-meter{font:500 13px var(--f-mono);color:var(--muted);font-variant-numeric:tabular-nums}
.controls{display:flex;flex-wrap:wrap;gap:12px 18px;align-items:flex-end}
.warn{color:var(--danger);font-size:13px;margin:0}
.result{border-top:1px solid var(--line);padding-top:14px;display:flex;flex-direction:column;gap:10px}
.result img{image-rendering:pixelated;max-width:100%;align-self:flex-start;border-radius:2px}
/* inspector */
.slot-head{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap}
.slot-title{font:700 18px/1.2 var(--f-display);margin:0}
.chips{display:flex;flex-wrap:wrap;gap:6px;min-height:52px;padding:8px;background:var(--sunk);border:1px dashed var(--line);border-radius:6px}
.chips .empty{color:var(--muted);font-size:13px;align-self:center;padding:0 4px}
.chip{position:relative;width:44px;height:44px;border:1px solid var(--line);background:var(--surface);border-radius:5px;padding:0;display:flex;align-items:center;justify-content:center;cursor:pointer}
.chip.tagchip{width:auto;padding:0 10px 0 5px;gap:6px;border-color:var(--tag);font:500 13px var(--f-mono);color:var(--tag)}
.chip:hover{border-color:var(--danger)}
.chip:hover::after{content:"×";position:absolute;top:-7px;right:-7px;width:16px;height:16px;border-radius:50%;background:var(--danger);color:#fff;font:600 12px/16px var(--f-body);text-align:center}
.chip .n{position:absolute;left:2px;bottom:0;font:500 9px var(--f-mono);color:var(--muted)}
.ico{display:block;margin:auto;background-repeat:no-repeat;flex:none}
.tagmark{position:absolute;right:1px;top:0;font:700 11px/1 var(--f-mono);color:var(--tag)}
.slot-note{font-size:13px;color:var(--muted);margin:0}
.tabs{display:flex;gap:4px;border-bottom:1px solid var(--line);overflow-x:auto}
.tabs button{border:0;border-bottom:2px solid transparent;border-radius:0;background:none;padding:8px 12px;color:var(--muted);white-space:nowrap}
.tabs button[aria-selected="true"]{color:var(--fg);border-bottom-color:var(--accent);font-weight:600}
.tabpanel{display:flex;flex-direction:column;gap:10px}
.picker{display:grid;grid-template-columns:repeat(auto-fill,minmax(46px,1fr));gap:4px;max-height:430px;overflow-y:auto;padding:2px;align-content:start}
.pick{aspect-ratio:1;border:1px solid transparent;background:var(--sunk);border-radius:5px;padding:0;display:flex;align-items:center;justify-content:center;cursor:pointer;position:relative}
.pick:hover{border-color:var(--accent);background:var(--accent-soft)}
.pick .del,.tagrow .del{position:absolute;top:-6px;right:-6px;width:18px;height:18px;border-radius:50%;border:0;background:var(--danger);color:#fff;font:600 12px/18px var(--f-body);padding:0;justify-content:center;display:none}
.pick:hover .del,.pick:focus-within .del,.tagrow:hover .del,.tagrow:focus-within .del{display:inline-flex}
.recent{display:flex;gap:4px;overflow-x:auto;padding-bottom:2px}
.recent .pick{width:40px;height:40px;flex:none}
.taglist{display:flex;flex-direction:column;gap:2px;max-height:430px;overflow-y:auto;padding:2px}
.tagrow{position:relative;display:grid;grid-template-columns:36px minmax(0,1fr) auto;align-items:center;gap:10px;text-align:left;padding:4px 10px 4px 4px;border:1px solid transparent;background:none;border-radius:6px;width:100%}
.tagrow:hover{background:var(--accent-soft);border-color:var(--accent)}
.tagrow .tn{font:500 13px var(--f-mono);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.tagrow .tc{font:12px var(--f-mono);color:var(--muted);font-variant-numeric:tabular-nums}
.tagrow .ico{border-radius:4px;background-color:var(--sunk)}
.tagrow.custom .tn{color:var(--tag)}
.newtag{display:flex;flex-wrap:wrap;gap:8px;align-items:center;padding:10px;border:1px dashed var(--line);border-radius:6px}
.newtag input{flex:1 1 160px}
.count-line{display:flex;align-items:center;gap:8px;font-size:13px;color:var(--muted)}
.custom-form{display:grid;grid-template-columns:minmax(0,1fr) 140px;gap:14px;align-items:start}
@media (max-width:480px){.custom-form{grid-template-columns:minmax(0,1fr)}}
.custom-form .fields{display:flex;flex-direction:column;gap:10px;min-width:0}
.prev{width:128px;height:128px;image-rendering:pixelated;background:#8B8B8B;border-radius:4px;border:1px solid var(--line)}
.drop-zone{border:1px dashed var(--line);border-radius:6px;padding:10px;font-size:13px;color:var(--muted);display:flex;flex-direction:column;gap:8px}
.drop-zone.over{border-color:var(--accent);background:var(--accent-soft)}
.file-row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.file-row span{font-size:12px;color:var(--muted);min-width:64px}
input[type=file]{font-size:12px;max-width:100%;color:var(--muted)}
.loading{color:var(--muted);font-size:13px;padding:20px;text-align:center}
@media (prefers-reduced-motion:reduce){*{transition:none!important}}
footer{border-top:1px solid var(--line);padding-top:14px;display:flex;flex-direction:column;gap:6px;color:var(--muted);font-size:13px}
footer p{margin:0;max-width:90ch}
footer a{color:var(--accent)}
a.btn{text-decoration:none}
a.btn.primary{background:var(--accent);color:var(--accent-fg);border-color:var(--accent)}
button.linkish{border:0;background:none;padding:0;font:inherit;color:var(--accent);text-decoration:underline;cursor:pointer;display:inline}
dialog#licenses{width:min(680px,calc(100vw - 32px));max-height:min(80vh,760px);padding:0;border:1px solid var(--line);border-radius:var(--r);background:var(--surface);color:var(--fg);box-shadow:0 18px 50px rgba(0,0,0,.3)}
dialog#licenses[open]{display:flex;flex-direction:column}
dialog#licenses::backdrop{background:rgba(10,14,12,.55)}
.dlg-head{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:14px 16px;border-bottom:1px solid var(--line)}
.dlg-title{font:700 18px/1.2 var(--f-display);text-transform:none;letter-spacing:0;color:var(--fg)}
.dlg-body{overflow-y:auto;padding:4px 16px 18px;display:flex;flex-direction:column}
.dlg-body section{padding-block:12px;border-bottom:1px solid var(--line)}
.dlg-body section:last-child{border-bottom:0}
.dlg-body h3{font:600 14px/1.3 var(--f-body);margin:0 0 4px}
.dlg-body p{margin:0;font-size:14px;color:var(--muted)}
.dlg-body a{color:var(--accent)}
.dlg-body pre{margin:8px 0 0;padding:10px;background:var(--sunk);border:1px solid var(--line);border-radius:6px;font:11.5px/1.5 var(--f-mono);white-space:pre-wrap;overflow-x:auto;color:var(--fg)}
a.btn[aria-disabled="true"]{opacity:.5;pointer-events:none}
.result img{min-height:40px}
.result.busy img{opacity:.55;transition:opacity .15s}
#seg-note{display:none}

/* potion maker */
.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.potion-maker{display:grid;grid-template-columns:minmax(0,1fr) 140px;gap:16px;align-items:start}
@media (max-width:480px){.potion-maker{grid-template-columns:minmax(0,1fr)}}
.pm-controls{display:flex;flex-direction:column;gap:12px;min-width:0}
.pm-preview{display:flex;flex-direction:column;gap:8px;align-items:flex-start}
.pm-forms{display:flex;gap:4px}
.pm-forms canvas{width:30px;height:30px;image-rendering:pixelated;background:#8B8B8B;border-radius:3px;cursor:pointer;border:1px solid var(--line)}
.pm-forms canvas.on{outline:2px solid var(--accent);outline-offset:1px}
.swatches{display:grid;grid-template-columns:repeat(auto-fill,minmax(26px,1fr));gap:5px}
.swatch{aspect-ratio:1;border-radius:50%;border:2px solid rgba(0,0,0,.18);padding:0;cursor:pointer;min-width:0}
.swatch:hover{transform:scale(1.12)}
.swatch[aria-pressed="true"]{box-shadow:0 0 0 2px var(--surface),0 0 0 4px var(--fg)}
.cpick{display:flex;flex-direction:column;gap:10px}
.sv{position:relative;height:150px;border-radius:6px;cursor:crosshair;touch-action:none;background:#f00;overflow:hidden}
.sv-white,.sv-black{position:absolute;inset:0;pointer-events:none}
.sv-white{background:linear-gradient(to right,#fff,rgba(255,255,255,0))}
.sv-black{background:linear-gradient(to top,#000,rgba(0,0,0,0))}
.knob{position:absolute;width:16px;height:16px;margin:-8px 0 0 -8px;border-radius:50%;border:2px solid #fff;box-shadow:0 0 0 1px rgba(0,0,0,.5),inset 0 0 0 1px rgba(0,0,0,.3);pointer-events:none}
.hue{position:relative;height:16px;border-radius:8px;cursor:pointer;touch-action:none;
  background:linear-gradient(to right,#f00 0%,#ff0 16.66%,#0f0 33.33%,#0ff 50%,#00f 66.66%,#f0f 83.33%,#f00 100%)}
.hue-knob{position:absolute;top:50%;width:18px;height:18px;margin:-9px 0 0 -9px;border-radius:50%;border:2px solid #fff;box-shadow:0 0 0 1px rgba(0,0,0,.5);pointer-events:none}
.sv:focus-visible,.hue:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.hexrow{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.cchip{width:30px;height:30px;border-radius:6px;border:1px solid var(--line);flex:none}
#hexIn{width:100px;font-family:var(--f-mono);text-transform:uppercase}
#hexIn[aria-invalid="true"]{border-color:var(--danger)}
