:root {
  --bg: #15181c; --panel: #1f242a; --line: #30373f; --fg: #e8ebee; --muted: #8e98a3;
  --accent: #f2a93b; --accent-2: #4fb3ff; --ok: #4fd18b; --bad: #ff6b6b; --panel-w: 420px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; -webkit-text-size-adjust: 100%; }
body { display: grid; grid-template-rows: auto 1fr; height: 100vh; height: 100dvh; overflow: hidden; }

/* header: brand, step buttons, actions on one bar */
header { position: relative; display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-weight: 700; letter-spacing: .3px; }
nav#steps { display: flex; gap: 4px; flex: 1; }
nav#steps .step { flex: 1; min-height: 44px; background: transparent; color: var(--muted); border: 1px solid var(--line); border-radius: 8px; padding: 6px; cursor: pointer; font-size: 15px; }
nav#steps .step span { margin-left: 4px; }
nav#steps .step.active { color: var(--fg); border-color: var(--accent); background: #2a2419; }
nav#steps .step.done { color: var(--ok); }
nav#steps .step:disabled { opacity: .4; cursor: not-allowed; }
.header-right { display: flex; gap: 6px; }
#settings { position: absolute; right: 12px; top: 100%; z-index: 20; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; min-width: 260px; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
#settings label { margin: 6px 0; }
.muted { color: var(--muted); } .small { font-size: 13px; }

main { display: grid; grid-template-columns: 1fr var(--panel-w); min-height: 0; }
#viewer { position: relative; min-width: 0; background: #0f1114; overflow: hidden; }
#canvas { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
#status { position: absolute; left: 10px; bottom: 8px; font: 12px ui-monospace, Menlo, monospace; color: var(--muted); background: rgba(0,0,0,.5); padding: 2px 8px; border-radius: 4px; pointer-events: none; }
#viewer-hint { position: absolute; top: 8px; left: 10px; max-width: calc(100% - 80px); font-size: 13px; color: var(--fg); background: rgba(0,0,0,.55); padding: 4px 10px; border-radius: 4px; pointer-events: none; }
#viewer-hint:empty { display: none; }
#view-btns { position: absolute; right: 10px; top: 8px; display: flex; flex-direction: column; gap: 6px; z-index: 5; }
#view-btns button { width: 44px; height: 44px; padding: 0; font-size: 22px; background: rgba(31,36,42,.9); }

aside#panel { border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 10px 14px 16px; display: flex; flex-direction: column; }
.pane { display: flex; flex-direction: column; gap: 6px; min-height: 0; }
h2 { font-size: 17px; margin: 2px 0 4px; } h3 { font-size: 12px; margin: 10px 0 2px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
p { margin: 2px 0 4px; } p.tip { color: #cfd6dd; font-size: 13px; }
body.no-tips p.tip { display: none; }
label { display: block; margin: 2px 0; color: #cfd6dd; font-size: 14px; }
label input[type=number], label input[type=text], select { width: 100%; margin-top: 2px; background: #12151a; color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font: inherit; min-height: 40px; }
label input[type=range] { width: 100px; vertical-align: middle; }
.row { display: flex; gap: 8px; align-items: flex-end; } .row > * { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
button, a.button { background: #2b323a; color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; min-height: 40px; cursor: pointer; font: inherit; text-decoration: none; text-align: center; display: inline-flex; align-items: center; justify-content: center; }
button:hover, a.button:hover { border-color: #4a535e; }
button.primary, a.button.primary { background: var(--accent); color: #1a1205; border-color: var(--accent); font-weight: 600; }
button.big, a.button.big { min-height: 48px; font-size: 16px; }
button.ghost, a.button.ghost { background: transparent; }
button.icon { width: 44px; padding: 0; font-size: 20px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.tools .tool { min-height: 44px; } .tools .tool.active { border-color: var(--accent-2); color: var(--accent-2); background: #182431; }
.row.tools { flex-wrap: wrap; } .row.tools > * { flex: 1 1 auto; }
.result { font-size: 13px; color: #cfd6dd; white-space: pre-line; min-height: 1.2em; }
.result.err { color: var(--bad); } .result.ok { color: var(--ok); }
#dropzone { border: 2px dashed var(--line); border-radius: 10px; padding: 22px 12px; text-align: center; cursor: pointer; }
#dropzone.over { border-color: var(--accent); background: #2a2419; }
ul.list { list-style: none; padding: 0; margin: 0; } ul.list li { padding: 8px 6px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; min-height: 40px; }
ul.list li a { color: var(--accent-2); cursor: pointer; flex: 1; }
ul.list li .x { color: var(--bad); cursor: pointer; padding: 6px 10px; font-size: 18px; }
.scroll { overflow: auto; min-height: 0; max-height: 40vh; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 5px 4px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table input { width: 100%; background: #12151a; color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 6px; font: inherit; min-height: 38px; }
table input.manual { border-color: #5a4a1e; font-weight: 600; } table input.manual.missing { border-color: var(--bad); }
table select { background: #12151a; color: var(--fg); border: 1px solid var(--line); border-radius: 6px; font-size: 13px; padding: 6px 4px; min-height: 38px; }
table .x { color: var(--bad); cursor: pointer; font-size: 18px; padding: 4px 8px; }
table .scale-btn { padding: 2px 8px; min-height: 32px; font-size: 13px; }
tr.hl td { background: #2a2419; }
.w-lbl { width: 110px; } .w-num { width: 84px; } .w-off { width: 60px; }
#checklist tr.done td:first-child::before { content: "✓ "; color: var(--ok); }
#checklist tr.armed td { background: #2a2419; }
#checklist .hint { color: var(--muted); font-size: 12px; }
#checklist button { padding: 2px 10px; min-height: 36px; font-size: 13px; }
#value-entry { background: #2a2419; border: 1px solid var(--accent); border-radius: 10px; padding: 8px 10px; }
#value-entry input { font-size: 22px; min-height: 52px; }
#value-entry button { min-height: 52px; font-size: 18px; min-width: 80px; }
#scale-line { font-size: 13px; }
#export-preview { width: 100%; margin-top: 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
#export-preview[src=""] { display: none; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #2b323a; border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; z-index: 30; max-width: 90vw; }
#toast.err { border-color: var(--bad); }
details summary { cursor: pointer; color: var(--muted); margin-top: 6px; min-height: 32px; display: flex; align-items: center; }
label.inline { display: flex; align-items: center; gap: 6px; margin: 0; }
label.inline select { width: auto; margin: 0; }

/* portrait tablets and phones: viewer on top, panel below */
@media (max-width: 1000px) {
  main { grid-template-columns: 1fr; grid-template-rows: 46vh 1fr; }
  aside#panel { border-left: 0; border-top: 1px solid var(--line); padding: 8px 12px 40px; }
  .brand { display: none; }
  nav#steps .step span { display: none; }
  .header-right .ghost:not(.icon) { display: none; }
  #settings .muted { display: block; }
}
@media (pointer: coarse) { nav#steps .step { min-height: 48px; } }

.static-only { display: none; } body.static-app .static-only { display: block; } body.static-app .flask-only { display: none; }
