:root {
  --bg: #1c1d20;
  --panel: #232428;
  --panel2: #2c2e33;
  --hover: #34363c;
  --line: #34363b;
  --text: #d8dade;
  --muted: #8d9199;
  --acc: #f0a03c;
  --acc2: #ffbe6b;
  --stage: #141518;
  --side: 296px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

button, select, input { font: inherit; color: inherit; }

button {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { border-color: #4a4d54; background: var(--hover); }
button:disabled { opacity: .35; cursor: default; }
button.primary { background: var(--acc); border-color: var(--acc); color: #1b1206; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--acc2); border-color: var(--acc2); }
button.ic { padding: 4px 6px; line-height: 0; background: none; border-color: transparent; }
button.ic:hover:not(:disabled) { background: var(--hover); border-color: transparent; }
button.sm { padding: 2px 6px; font-size: 12px; }
button.lb { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button.lb svg { width: 16px; height: 16px; }
button.sm svg { width: 15px; height: 15px; }

select { background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 3px 6px; }
input[type=range] { accent-color: var(--acc); width: 110px; }
input[type=checkbox] { accent-color: var(--acc); }
input[type=color] { width: 30px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; cursor: pointer; }

.grow { flex: 1; }

.menubar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; padding: 0 6px 0 2px; }
.menus { display: flex; align-items: center; gap: 2px; min-width: 0; }
.menu { position: relative; }
.menu > button { background: none; border-color: transparent; padding: 4px 9px; }
.menu > button:hover, .menu.open > button { background: var(--hover); }
.menu .pop {
  display: none;
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  z-index: 40;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px;
  min-width: 230px;
  max-height: calc(100vh - 60px);
  max-height: calc(100dvh - 60px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.menu.open .pop { display: flex; flex-direction: column; }
.pop > * { flex: none; }
.pop button { position: relative; display: flex; justify-content: space-between; gap: 24px; background: none; border: 0; text-align: left; padding: 6px 10px 6px 26px; }
.pop button.on::before { content: "✓"; position: absolute; left: 9px; color: var(--acc2); }
.pop button:hover:not(:disabled) { background: var(--hover); }
.pop button kbd { color: var(--muted); font: inherit; font-size: 12px; }
.pop button:disabled { opacity: .38; cursor: default; }
.tools button:disabled { opacity: .3; }
.pop hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; width: auto; }
.doc { flex: 1; text-align: center; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: 0 8px; }
.qa { display: flex; align-items: center; gap: 2px; }

.optbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 18px;
  min-height: 40px;
  padding: 5px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.grp { display: flex; align-items: center; gap: 8px; }
.grp output { min-width: 2ch; color: var(--muted); font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: 12px; }
.sw { display: flex; gap: 4px; }
.sw button { width: 19px; height: 19px; padding: 0; border-radius: 50%; border: 2px solid var(--line); }
.sw button.on { border-color: var(--text); }
input.hex { width: 76px; background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 3px 6px; font: 12px ui-monospace, Consolas, monospace; }
.sl.fname { grid-template-columns: 104px 1fr 0; }

.main { flex: 1; display: flex; min-height: 0; }

.tools {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  width: 46px;
  padding: 6px 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.tools button { padding: 5px; line-height: 0; background: none; border-color: transparent; border-radius: 6px; }
.tools button:hover { background: var(--hover); }
.tools button.on { background: #3a3326; border-color: #6b5226; color: var(--acc2); }
.tsep { width: 24px; height: 1px; background: var(--line); margin: 3px 0; flex: none; }
.optbar.noimg > * { visibility: hidden; }
.colors { position: relative; width: 38px; height: 38px; margin: 2px 0 4px; flex: none; }
.cchip { position: absolute; width: 22px; height: 22px; padding: 0; border-radius: 5px; border: 2px solid #e6e8eb; box-shadow: 0 0 0 1px #000; cursor: pointer; }
.cchip.fgc { left: 0; top: 0; z-index: 2; }
.cchip.bgc { right: 0; bottom: 0; z-index: 1; }
.cchip:hover { border-color: var(--acc2); }
.cswap { position: absolute; right: -3px; top: -4px; padding: 1px; background: none; border: 0; color: var(--muted); line-height: 0; }
.cswap svg { width: 12px; height: 12px; }
.cswap:hover { color: var(--text); background: none !important; }
.cpick { position: fixed; z-index: 70; width: 384px; max-width: calc(100vw - 16px); padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 16px 40px rgba(0, 0, 0, .6); display: flex; flex-direction: column; gap: 8px; }
.cpick[hidden] { display: none !important; }
.cp-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
.cp-x { background: none; border: 0; font-size: 16px; line-height: 1; padding: 0 4px; color: var(--muted); }
.cpick canvas { width: 100%; display: block; border-radius: 5px; touch-action: none; cursor: crosshair; }
.cp-sv { aspect-ratio: 240 / 160; }
.cp-wheel { width: 230px !important; height: 230px; align-self: center; cursor: crosshair; }
.cp-modes { display: flex; gap: 2px; margin-left: auto; margin-right: 6px; }
.cp-m { padding: 3px; line-height: 0; background: none; border-color: transparent; }
.cp-m svg { width: 14px; height: 14px; }
.cp-m.on { border-color: var(--acc); color: var(--acc2); }
.cpick canvas[hidden] { display: none; }
.cp-hue, .cp-alpha { height: 14px; }
.cp-row { display: flex; align-items: center; gap: 6px; }
.cp-prev { width: 30px; height: 30px; flex: none; border-radius: 5px; border: 1px solid var(--line); }
.cp-hex { flex: 1; min-width: 0; background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 5px 7px; font: 12.5px ui-monospace, Consolas, monospace; color: var(--text); }
.cp-a { display: flex; align-items: center; gap: 2px; color: var(--muted); font-size: 12px; }
.cp-anum { width: 58px; background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 5px 4px; font-size: 12.5px; }
.cp-eye { padding: 5px; line-height: 0; }
.cp-num { display: flex; gap: 6px; align-items: center; }
.cp-nm { flex: none; padding: 4px 2px; font-size: 12px; }
.cp-fields { flex: 1; display: grid; gap: 6px; min-width: 0; }
.cp-fields label { display: flex; align-items: center; gap: 3px; color: var(--muted); font-size: 11.5px; min-width: 0; }
.cp-fields input { padding: 5px 2px 5px 5px; min-width: 0; width: 100%; }
.cp-c { width: 100%; min-width: 0; background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 5px 4px; font: 12.5px ui-monospace, Consolas, monospace; color: var(--text); }
.cp-std { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 3px; }
.cp-std .cp-rl { grid-column: 1 / -1; }
.cp-std button { aspect-ratio: 1; width: 100%; padding: 0; border-radius: 3px; border: 1px solid rgba(255, 255, 255, .12); }
.cp-std button:hover { border-color: var(--text); transform: scale(1.12); }
.cp-recent { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.cp-rl { width: 100%; font-size: 11px; color: var(--muted); }
.cp-recent button { width: 18px; height: 18px; padding: 0; border-radius: 4px; border: 1px solid var(--line); }
.tools { overflow-y: auto; scrollbar-width: none; }
.tools::-webkit-scrollbar { display: none; }
.tools button { flex: none; }
.fg input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.fg span { position: absolute; inset: 3px; border-radius: 6px; border: 2px solid #e6e8eb; box-shadow: 0 0 0 1px #000; pointer-events: none; }

.work { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tabbar { height: 30px; display: flex; align-items: flex-end; padding: 0 8px; background: var(--bg); border-bottom: 1px solid var(--line); }
.tab { display: inline-flex; align-items: center; gap: 8px; background: var(--stage); border: 1px solid var(--line); border-bottom: 0; border-radius: 6px 6px 0 0; padding: 4px 6px 4px 14px; color: var(--text); font-size: 12px; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; position: relative; top: 1px; }

.tab #tabName { overflow: hidden; text-overflow: ellipsis; }
.tabx { background: none; border: 0; padding: 0 5px; font-size: 15px; line-height: 1; color: var(--muted); border-radius: 4px; }
.tabx:hover { color: var(--text); background: var(--hover) !important; }
.stage { position: relative; flex: 1; min-height: 0; background: var(--stage); overflow: hidden; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.stage.drop::after { content: ""; position: absolute; inset: 10px; border: 3px dashed var(--acc); border-radius: 12px; pointer-events: none; }

#ted {
  position: absolute;
  z-index: 5;
  margin: 0;
  padding: 0;
  border: 1px dashed var(--acc);
  background: rgba(0, 0, 0, .25);
  outline: none;
  resize: none;
  overflow: hidden;
  white-space: pre;
  font-weight: 600;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.25;
}

.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; padding: 16px; color: var(--muted); }
.empty .big { font-size: 16px; color: var(--text); margin: 18px 0 6px; }
.empty .priv { margin-top: 18px; font-size: 12.5px; }
.restore { margin-top: 18px; padding: 10px 14px; border: 1px solid #6b5226; background: #2a241a; border-radius: 8px; color: var(--text); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }
input.txt { width: 100%; background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; }
.empty button { font-size: 14px; padding: 6px 14px; }
.empty .samples-lbl { margin: 14px 0 6px; font-size: 13px; color: var(--muted); }
.empty .samples { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.empty .samples button { padding: 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: none; line-height: 0; transition: border-color .15s, transform .15s; }
.empty .samples button:hover, .empty .samples button:focus-visible { border-color: var(--acc2); transform: translateY(-1px); }
.empty .samples img { display: block; width: 96px; height: 60px; object-fit: cover; }
.empty button.link { background: none; border: 0; color: var(--acc2); text-decoration: underline; padding: 2px 4px; font-size: 13px; }

.side { width: var(--side); display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); min-height: 0; }
.panel { display: flex; flex-direction: column; border-bottom: 1px solid var(--line); min-height: 0; }
.panel.grow { flex: 1; }
.ph { display: flex; gap: 2px; padding: 0 6px; height: 32px; align-items: flex-end; border-bottom: 1px solid var(--line); background: var(--bg); }
.pt { background: none; border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0; padding: 5px 12px; color: var(--muted); font-size: 12px; position: relative; top: 1px; }
.pt.on { background: var(--panel); border-color: var(--line); color: var(--text); }
button.pt:hover:not(.on) { background: none; color: var(--text); border-color: transparent; }
.pb { padding: 10px; overflow-y: auto; }
.pf { display: flex; align-items: center; gap: 2px; padding: 4px 6px; border-top: 1px solid var(--line); }

.adjgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.adjgrid button { display: flex; align-items: center; gap: 7px; text-align: left; padding: 6px 8px; font-size: 12px; min-width: 0; }
.adjgrid button span { overflow: hidden; text-overflow: ellipsis; }
.adjgrid svg { width: 16px; height: 16px; color: var(--acc); }
.fxpane { max-height: 62vh; }
.fxpane h3 { margin: 0 0 8px; font-size: 13px; }

.list { flex: 1; padding: 4px; min-height: 80px; }
.lr { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 5px; cursor: pointer; user-select: none; }
.lr:hover { background: var(--panel2); }
.lr.on { background: #3a3326; }
.lr.off .ln { color: var(--muted); text-decoration: line-through; }
.lr .eye { padding: 2px; line-height: 0; background: none; border: 0; color: var(--muted); }
.lr .eye.hid { opacity: .35; }
.lr .li { width: 26px; height: 26px; display: grid; place-items: center; background: var(--stage); border: 1px solid var(--line); border-radius: 4px; color: var(--muted); }
.lr .li svg { width: 15px; height: 15px; }
.lr .ln { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.lr .lk { color: var(--muted); font-size: 11px; }
.hr { padding: 5px 10px; border-radius: 5px; cursor: pointer; display: flex; gap: 8px; }
.hr:hover { background: var(--panel2); }
.hr.on { background: #3a3326; color: var(--acc2); }
.hr.fut { color: var(--muted); font-style: italic; }
.ocrcats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 8px; margin: 8px 0; font-size: 12px; }
.ocrlist { display: flex; flex-direction: column; gap: 3px; margin: 8px 0; max-height: 34vh; overflow-y: auto; font-size: 12px; }
.ocrlist label { display: grid; grid-template-columns: auto 74px 1fr; align-items: center; gap: 6px; }
.ocrlist .oc { color: var(--muted); font-size: 11px; }
.ocrlist .ot { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-family: ui-monospace, Consolas, monospace; }
.info { flex: 1; }
.info canvas { width: 100%; height: auto; display: block; background: var(--stage); border: 1px solid var(--line); border-radius: 5px; margin-bottom: 8px; }
.info table { width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.chip { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--line); vertical-align: -2px; }
.hr .hn { color: var(--muted); min-width: 2ch; text-align: right; font-variant-numeric: tabular-nums; }

.status {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 26px;
  padding: 0 10px;
  background: var(--bg);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
}
.cmp { background: none; border: 1px solid var(--line); border-radius: 4px; padding: 0 7px; font-size: 11.5px; color: var(--muted); user-select: none; touch-action: none; }
.cmp.on { color: var(--acc2); border-color: var(--acc); }
.looks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-bottom: 6px; }
.looks button { display: flex; flex-direction: column; gap: 4px; padding: 4px; align-items: stretch; font-size: 11.5px; }
.looks button canvas { width: 100%; height: auto; border-radius: 3px; display: block; }
.looks button.on { border-color: var(--acc); color: var(--acc2); }
.zoomv { background: none; border: 0; padding: 0 4px; color: var(--text); font-size: 12px; min-width: 46px; text-align: left; }

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px;
  min-width: 320px;
  max-width: calc(100vw - 24px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .6);
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h3 { margin: 0 0 12px; font-size: 15px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 14px; }
.row.quick button { padding: 3px 9px; font-size: 12px; }
label { display: inline-flex; align-items: center; gap: 8px; }
dialog input[type=number] { width: 96px; background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; }
.sl { display: grid; grid-template-columns: 104px 1fr 40px; gap: 8px; margin: 8px 0; }
.sl input, .sl input[type=range] { width: 100%; }
.sl output { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.fxc { display: block; width: 100%; max-width: 300px; margin: 6px auto 10px; border: 1px solid var(--line); border-radius: 5px; background: var(--stage); touch-action: none; }
.fxc.hist { aspect-ratio: 256 / 90; }
.fxc.curve { aspect-ratio: 1; cursor: crosshair; }
.tabs { display: flex; gap: 3px; align-items: center; flex-wrap: wrap; }
.tabs button { padding: 2px 9px; font-size: 12px; }
.tabs button.on { border-color: var(--acc); color: var(--acc2); }
table { border-collapse: collapse; font-size: 13px; margin: 4px 0 8px; }
td { padding: 3px 14px 3px 0; vertical-align: top; }
td:first-child { color: var(--muted); white-space: nowrap; }
kbd { font: 12px ui-monospace, Consolas, monospace; background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }
#dKeys { width: 560px; }
#dCollage { width: 620px; }
#dStamp { width: 420px; }
.stamps { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 8px 0 12px; }
.stamps .stamp { border: 2px solid; background: transparent; font-weight: 800; letter-spacing: .06em; padding: 8px 6px; border-radius: 6px; }
.stamps .stamp:hover { background: rgba(255, 255, 255, .06); }
#fPresets { flex-wrap: wrap; }
#fPresets button.on { outline: 2px solid var(--accent); outline-offset: 1px; }
.cl-items { display: flex; gap: 8px; flex-wrap: wrap; min-height: 70px; padding: 8px; background: var(--stage); border: 1px solid var(--line); border-radius: 6px; }
.cl-it { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.cl-it canvas { border: 1px solid var(--line); border-radius: 3px; }
.cl-bar { display: flex; gap: 2px; }
.cl-bar button { padding: 0 6px; font-size: 12px; }
.cl-opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 16px; align-items: center; margin: 8px 0; }
.cl-opts .row { grid-column: 1 / -1; margin: 2px 0; }
.cl-opts input[type=number] { width: 60px; }
.cl-prev { display: block; width: 100%; height: auto; background: var(--stage); border: 1px solid var(--line); border-radius: 6px; }
@media (max-width: 760px) { .cl-opts { grid-template-columns: 1fr; } }
#keysBody { columns: 2; column-gap: 24px; }
#keysBody div { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; break-inside: avoid; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 35;
  max-height: 55vh;
  overflow-y: auto;
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, .5);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet .fxc.curve { max-width: 230px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  z-index: 60;
  max-width: calc(100vw - 32px);
}

body.nopanels .side { display: none; }
body.busy, body.busy * { cursor: progress !important; }
body.busy #sMsg { color: var(--acc2); }

@media (max-width: 1100px) {
  .side { display: none; }
  body.panels .side { display: flex; position: fixed; right: 0; top: 78px; bottom: 26px; z-index: 30; box-shadow: -10px 0 30px rgba(0, 0, 0, .5); }
}

@media (max-width: 760px) {
  .menubar { gap: 2px; padding: 0 4px; }
  .menus { overflow-x: auto; scrollbar-width: none; flex: 1; }
  .menus::-webkit-scrollbar { display: none; }
  .menu > button { padding: 4px 7px; }
  .menu .pop { position: fixed; top: 40px; left: 8px; right: 8px; min-width: 0; max-height: calc(100dvh - 48px); touch-action: pan-y; }
  .pop button { padding: 10px 12px 10px 30px; font-size: 14px; flex: none; }
  .pop button.on::before { left: 11px; }
  .doc { display: none; }
  .qa button.lb span { display: none; }
  .qa button.lb { padding: 4px 8px; }
  .main { flex-direction: column-reverse; }
  .tools { flex-direction: row; width: auto; height: 48px; padding: 0 6px; overflow-x: auto; border-right: 0; border-top: 1px solid var(--line); }
  .tsep { width: 1px; height: 24px; margin: 0 4px; }
  .tools .grow { flex: 0 0 8px; }
  .fg { margin: 0 4px; flex: none; }
  .tabbar { display: none; }
  .optbar { gap: 6px 12px; padding: 5px 8px; }
  .optbar.none { display: none; }
  input[type=range] { width: 84px; }
  .hint { display: none; }
  body.panels .side { top: auto; left: 0; bottom: 0; width: 100%; height: 55vh; border-radius: 14px 14px 0 0; }
  #sObjs, #sPos { display: none; }
  #keysBody { columns: 1; }
}
