:root {
  --window: #232428; --base: #1a1b1e; --alt: #26272b; --text: #e6e6e6; --button: #2e3035;
  --accent: #3d7fd9; --hl-text: #ffffff; --mid: #8a8d93; --line: #3a3c42; --points: rgb(80, 220, 120);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --window: #f2f2f4; --base: #ffffff; --alt: #f5f5f7; --text: #1e1e1e; --button: #e6e6ea;
  --accent: #2f6fd0; --hl-text: #ffffff; --mid: #6d6f75; --line: #c9cad0; color-scheme: light;
}
:root[data-theme="night"] {
  --window: #120000; --base: #0b0000; --alt: #160000; --text: #d23a2a; --button: #1e0303;
  --accent: #8a1206; --hl-text: #ff6a50; --mid: #7a2a20; --line: #3a0a05; --points: rgb(255, 60, 40);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { display: flex; flex-direction: column; overflow: hidden; background: var(--window); color: var(--text);
  font: 13px "Segoe UI", system-ui, sans-serif; user-select: none; }
button, input, select { font: inherit; color: inherit; }
button, select { background: var(--button); border: 1px solid var(--line); border-radius: 4px; padding: 4px 10px; }
button:enabled:hover { border-color: var(--accent); }
button:disabled { color: var(--mid); }
button.primary { background: var(--accent); color: var(--hl-text); border-color: transparent; font-weight: 600; padding: 6px 14px; }
button.primary:disabled { background: var(--button); color: var(--mid); }
button.on { background: var(--accent); color: var(--hl-text); }
select { padding: 3px 6px; max-width: 100%; }
input[type="number"], input[type="text"] { background: var(--base); border: 1px solid var(--line); border-radius: 3px; padding: 3px 5px; }
input:disabled, select:disabled { color: var(--mid); }
input[type="checkbox"], input[type="range"] { accent-color: var(--accent); }
a { color: var(--accent); }

#menubar { display: flex; position: relative; background: var(--window); z-index: 20; }
#menubar > .head { padding: 4px 10px; cursor: default; }
#menubar > .head:hover { background: var(--button); }
.menu { position: absolute; background: var(--base); border: 1px solid var(--line); padding: 4px 0; min-width: 240px;
  box-shadow: 0 4px 14px #0006; white-space: nowrap; z-index: 30; }
.menu .item { display: flex; gap: 8px; padding: 4px 12px 4px 4px; position: relative; cursor: default; }
.menu .item:hover { background: var(--accent); color: var(--hl-text); }
.menu .item.disabled, .menu .item.disabled:hover { color: var(--mid); background: none; }
.menu .tick { width: 16px; text-align: center; }
.menu .text { flex: 1; }
.menu .key { color: var(--mid); }
.menu .item > .menu { display: none; left: 100%; top: -5px; color: var(--text); }
.menu .item:hover > .menu { display: block; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

#toolbar { display: flex; align-items: center; gap: 4px; padding: 4px 6px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#toolbar button:not(.primary):not(.on) { background: transparent; border-color: transparent; }
#toolbar button:enabled:not(.primary):hover { background: var(--button); }
#toolbar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 4px; }
#toolbar .stretch { flex: 1; }
#zoom { min-width: 52px; }

#main { flex: 1; display: flex; min-height: 0; }
#left { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#view { flex: 1; min-height: 0; }
.imageview { position: relative; overflow: hidden; background: #121214; cursor: grab; touch-action: none; }
.imageview.placing { cursor: crosshair; }
.imageview .stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.imageview .stage > canvas { display: block; }
.imageview .stage > .watermark { position: absolute; cursor: move; }
.imageview .stage > .detail { position: absolute; }
.imageview .stage > [hidden] { display: none; }
.imageview .marks { position: absolute; left: 0; top: 0; pointer-events: none; }
.bar { display: flex; align-items: center; gap: 8px; padding: 3px 6px; }
.bar[hidden], .bar [hidden] { display: none !important; }
.bar .stretch { flex: 1; }
.bar input[type="range"] { flex: 1; }
#frameinfo { min-width: 220px; }
#splitter { width: 5px; cursor: col-resize; background: var(--line); }

#panel { width: 430px; min-width: 340px; display: flex; flex-direction: column; }
#tabs { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
#tabs button { border: 0; border-radius: 0; background: transparent; padding: 6px 6px; border-bottom: 2px solid transparent; }
#tabs button.on { border-bottom-color: var(--accent); background: var(--alt); }
#pages { flex: 1; overflow-y: auto; padding: 8px; }
.page { display: flex; flex-direction: column; gap: 8px; }
.page[hidden] { display: none; }
.page > fieldset.off { opacity: 0.55; }
fieldset { border: 1px solid var(--line); border-radius: 5px; margin: 0; padding: 6px 8px 8px; min-width: 0; }
legend { font-weight: 600; padding: 0 3px; }
.form { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 5px 8px; align-items: center; }
.form .wide { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 4px; }
.field { display: flex; align-items: center; gap: 6px; min-width: 0; }
.field > select, .field > .spin:only-child, .field > .slider, .field > input[type="text"] { flex: 1; }
.spin { display: inline-flex; align-items: center; gap: 4px; }
.spin input { width: 72px; }
.unit { color: var(--mid); }
.slider { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.slider input[type="range"] { flex: 1; min-width: 60px; }
.check { display: flex; align-items: flex-start; gap: 6px; }
.hint { color: var(--mid); font-size: 12px; }
.text { white-space: pre-line; }
.stale { color: #e08a3c; font-weight: 600; }
.stale:empty, .text:empty { display: none; }
canvas.plot { width: 100%; background: var(--base); display: block; }
.layers { display: grid; grid-template-columns: 1fr auto auto auto; gap: 2px 8px; align-items: center; }
.layers .title { color: var(--mid); font-size: 12px; }
.layers .wide { grid-column: 1 / -1; display: flex; margin-bottom: 4px; }
.layers .spin input { width: 62px; }
.layers .factor { min-width: 44px; }

#statusbar { display: flex; align-items: center; gap: 8px; padding: 3px 8px; border-top: 1px solid var(--line); }
#status { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#statusbar progress { width: 260px; accent-color: var(--accent); }
#statusbar [hidden] { display: none; }

dialog { background: var(--window); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 14px;
  width: min(560px, 94vw); max-height: 94vh; }
dialog[open] { display: flex; flex-direction: column; gap: 10px; }
dialog.wide { width: min(980px, 96vw); height: min(720px, 94vh); }
dialog::backdrop { background: #0008; }
dialog h2 { margin: 0; font-size: 15px; }
dialog .buttons { display: flex; gap: 6px; flex-wrap: wrap; }
dialog .stretch { flex: 1; }
dialog form { display: flex; flex-direction: column; gap: 6px; }
.message { white-space: pre-line; overflow: auto; }
.mono { font: 12px Consolas, Menlo, monospace; white-space: pre-wrap; background: var(--base); padding: 8px;
  border: 1px solid var(--line); overflow: auto; user-select: text; margin: 0; }
.scroll { overflow: auto; flex: 1; min-height: 90px; background: var(--base); border: 1px solid var(--line); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 3px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.size { text-align: right; white-space: nowrap; }
.split { display: flex; gap: 6px; flex: 1; min-height: 160px; }
.split > * { flex: 1; min-width: 0; }
.split .imageview { border: 1px solid var(--line); }
.progressline { position: relative; }
.progressline progress { width: 100%; height: 18px; accent-color: var(--accent); }
.progressline span { position: absolute; inset: 0; text-align: center; line-height: 18px; text-shadow: 0 0 3px #000, 0 0 3px #000; color: #fff; }

@media (max-width: 800px) {
  #main { flex-direction: column; overflow: auto; }
  #left { min-height: 60vh; }
  #panel { width: 100% !important; min-width: 0; }
  #splitter { display: none; }
}
