:root {
  --bg: #0b0d10;
  --panel: #13161b;
  --panel2: #1a1e25;
  --line: #262b34;
  --text: #e8ecf1;
  --dim: #8a93a1;
  --accent: #b6f03c;
  --accent-ink: #11160a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.4 Inter, "Segoe UI", system-ui, sans-serif; }
.app { display: grid; grid-template-columns: 340px 1fr; height: 100vh; }

.panel { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 0 16px 32px; }
.brand { position: sticky; top: 0; z-index: 2; background: var(--panel); padding: 18px 0 14px; border-bottom: 1px solid var(--line); }
.logo { font-weight: 900; font-size: 22px; letter-spacing: -0.02em; }
.logo::after { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-left: 6px; vertical-align: 4px; }
.tag { color: var(--dim); font-size: 12px; }

section { padding: 16px 0 6px; border-bottom: 1px solid var(--line); }
section > * + * { margin-top: 10px; }
h3 { margin: 0 0 4px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); display: flex; align-items: center; gap: 8px; }
h3 span { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 6px; background: var(--panel2); color: var(--accent); font-size: 11px; }

.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: none; color: var(--dim); font: inherit; font-size: 13px; padding: 7px 6px; border-radius: 7px; cursor: pointer; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--panel2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.seg.small button { padding: 5px 10px; font-size: 12px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > select { flex: 1; min-width: 0; }
select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  font: inherit; padding: 7px 9px; width: 100%;
}
textarea { resize: vertical; font-weight: 700; font-size: 16px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 8px;
  padding: 8px 12px; font: inherit; font-weight: 600; font-size: 13px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--panel2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.btn:disabled { opacity: .5; cursor: default; }

.ctl { display: grid; grid-template-columns: 1fr auto; font-size: 13px; color: var(--text); row-gap: 2px; }
.ctl output { color: var(--dim); font-variant-numeric: tabular-nums; }
.ctl input { grid-column: 1 / -1; }
input[type=range] { width: 100%; accent-color: var(--accent); margin: 2px 0; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--accent); margin-top: 2px; }
.note { margin: 0; color: var(--dim); font-size: 12px; }
.meta { color: var(--dim); font-size: 12px; min-height: 1em; }
.meta.err { color: #ff8a7a; }

.viewport { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: #0d0f13; touch-action: none; cursor: grab; }
.viewport:active { cursor: grabbing; }
.viewport canvas { display: block; width: 100%; }
.vp-hint { position: absolute; left: 8px; bottom: 6px; font-size: 11px; color: #ffffff70; pointer-events: none; }
.thumb { display: block; max-width: 100%; max-height: 140px; border-radius: 8px; border: 1px solid var(--line); }
.thumb:not([src]), .thumb[src=""] { display: none; }
.tileprev { display: block; max-width: 100%; border-radius: 8px; border: 1px solid var(--line); image-rendering: auto; }

.progress { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .1s; }

.main { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; min-height: 0; }
.toolbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.grow { flex: 1; }
.status { color: var(--dim); font-size: 12px; font-variant-numeric: tabular-nums; }
.stage { overflow: auto; display: grid; place-items: center; padding: 16px; min-height: 0; }
.stage canvas { display: block; box-shadow: 0 10px 40px #0008; }
.stage.fit canvas { max-width: 100%; max-height: calc(100vh - 150px); width: auto; height: auto; object-fit: contain; }
.stage:not(.fit) { place-items: start; }
.howto { padding: 8px 16px 14px; color: var(--dim); font-size: 12px; text-align: center; }

[hidden] { display: none !important; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; height: auto; }
  .panel { border-right: 0; max-height: none; }
  .main { order: -1; }
  .stage.fit canvas { max-height: 70vh; }
}
