:root {
  --bg: #17181A;
  --bg-card: #1E1F22;
  --bg-card-2: #26272B;
  --bg-input: #2A2B2F;
  --text: #FFFFFF;
  --text-muted: #9CA3AF;
  --text-dim: #6B7280;
  --accent: #ff7a00;
  --accent-hover: #e66e00;
  --border: #333538;
  --radius: 8px;
  --radius-lg: 12px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Archivo', system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  line-height: 1.5; -webkit-font-smoothing: antialiased;
}
.app { display: flex; flex-direction: column; min-height: 100vh; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  flex-wrap: wrap;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #1c1d20, #17181a);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.brand h1 { font-size: 1.05rem; font-weight: 700; letter-spacing: .04em; }
.brand h1 span { color: var(--text-muted); font-weight: 500; }

.controls { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-dim); }
select, .btn {
  font-family: inherit; font-size: .85rem; color: var(--text);
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 7px 10px; cursor: pointer; outline: none;
}
select:hover, .btn:hover { border-color: #4a4d52; }
.btn { background: var(--accent); border-color: var(--accent); color: #1b1200; font-weight: 600; }
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: var(--bg-input); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); background: var(--bg-card-2); }
.btn-ghost.on { background: var(--accent); border-color: var(--accent); color: #1b1200; }
#solve-out code { color: var(--accent); }
#rng-zoom { width: 140px; min-height: 34px; accent-color: var(--accent); cursor: pointer; }

/* crop pan/tilt joystick */
.joy { display: flex; align-items: center; gap: 14px; }
.joy-track { position: relative; width: 96px; height: 96px; flex: none; border-radius: 50%;
  background: var(--bg-input); border: 1px solid var(--border); cursor: pointer; touch-action: none; }
.joy-track::before, .joy-track::after { content: ""; position: absolute; background: var(--border); }
.joy-track::before { left: 8px; right: 8px; top: 50%; height: 1px; }
.joy-track::after { top: 8px; bottom: 8px; left: 50%; width: 1px; }
.joy-knob { position: absolute; width: 28px; height: 28px; margin: -14px 0 0 -14px; left: 48px; top: 48px;
  border-radius: 50%; background: var(--accent); border: 2px solid #1b1200; cursor: grab; }
.joy-knob.dragging { cursor: grabbing; }
.joy-info { font-size: .76rem; color: var(--text-muted); line-height: 1.7; }
.joy-info b { color: var(--text); font-variant-numeric: tabular-nums; }
.joy-reset { margin-top: 6px; background: var(--bg-input); border: 1px solid var(--border); color: var(--text-muted);
  border-radius: var(--radius); padding: 4px 8px; cursor: pointer; font-family: inherit; font-size: .74rem; }
.joy-reset:hover { border-color: var(--accent); color: var(--text); }
.lens-info { font-size: .75rem; color: var(--text-muted); align-self: flex-end;
  display: flex; align-items: center; min-height: 34px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px; white-space: nowrap; }
.lens-info b { color: var(--accent); }
.check { display: flex; align-items: center; gap: 6px; align-self: flex-end; min-height: 34px;
  font-size: .8rem; color: var(--text-muted); cursor: pointer; user-select: none; white-space: nowrap; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
.ctl input[type=text] { width: 100%; font-family: inherit; font-size: .85rem; color: var(--text);
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 8px; outline: none; }
.ctl select { width: 100%; }
.ctl input[type=color] { width: 100%; height: 30px; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; padding: 2px; }
.dimrow { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin: 12px 0; }
.dimcell { display: flex; flex-direction: column; gap: 4px; }
.dimcell span { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); white-space: nowrap; }
.dimcell input { width: 100%; font-family: inherit; font-size: .9rem; color: var(--text); text-align: center;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 4px; outline: none; }
.dimcell input:focus { border-color: var(--accent); }

/* Stage */
.stage { flex: 1; display: grid; grid-template-columns: 1fr 340px; gap: 16px; padding: 16px 20px; align-items: start; }
.views { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.view { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.view-head { display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; font-size: .78rem; font-weight: 600; border-bottom: 1px solid var(--border); background: var(--bg-card-2); }
.view-head .meta { color: var(--text-dim); font-weight: 400; }
.pov { width: 100%; max-width: calc(46vh * 16 / 9); aspect-ratio: 16 / 9; margin: 0 auto; background: #000; }
.pov canvas { display: block; width: 100% !important; height: 100% !important; }
.plan { width: 100%; height: 32vh; min-height: 240px; display: block; background: #202227; touch-action: none; cursor: grab; }

/* Editor */
.editor { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 78px; }
.panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px; }
.panel-title { font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; color: var(--text-dim); margin-bottom: 10px; }
.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chip { display: flex; align-items: center; gap: 8px; font-size: .82rem; font-weight: 500;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; cursor: pointer; color: var(--text); }
.chip:hover { border-color: var(--accent); }
.chip .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.chip .plus { margin-left: auto; color: var(--accent); font-weight: 700; }

.selbody.muted { color: var(--text-dim); font-size: .82rem; }
.sel-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.sel-name { font-weight: 600; font-size: .95rem; }
.sel-tag { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); }
.ctl { margin: 10px 0; }
.ctl label { display: flex; justify-content: space-between; font-size: .78rem; color: var(--text-muted); margin-bottom: 4px; }
.ctl label b { color: var(--text); font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.btn-del { width: 100%; margin-top: 6px; background: #3a2020; border: 1px solid #5a2b2b; color: #ffb4b4; font-weight: 600;
  border-radius: var(--radius); padding: 8px; cursor: pointer; font-family: inherit; font-size: .82rem; }
.btn-del:hover { background: #4a2626; }

/* pixels-on-target table */
.pxbox { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.pxbox .lbl { font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-dim); margin-bottom: 8px; }
.pxtable { display: grid; grid-template-columns: auto 1fr 1fr; gap: 6px 10px; font-size: .82rem; align-items: center; }
.pxtable .h { font-size: .66rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); }
.pxtable .res { color: var(--text-muted); }
.pxtable .val { font-variant-numeric: tabular-nums; font-weight: 600; }
.pxtable .val.uhd { color: var(--accent); }
.dist { font-size: .82rem; color: var(--text-muted); margin-bottom: 8px; }
.dist b { color: var(--text); font-variant-numeric: tabular-nums; }
.fw-row { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.fw-row:last-child { border-bottom: 0; }
.fw-row span { color: var(--text-muted); }
.fw-row b { color: var(--text); font-variant-numeric: tabular-nums; }
.dori { font-size: .74rem; color: var(--text-dim); margin-top: 8px; }
.dori b { color: var(--text-muted); }
.dori code { display: inline-block; margin-top: 4px; font-family: ui-monospace, Menlo, monospace; font-size: .72rem;
  color: var(--accent); background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; word-break: break-all; }

.hint p { font-size: .78rem; color: var(--text-muted); }
.hint b { color: var(--text); }

@media (max-width: 900px) {
  .stage { grid-template-columns: 1fr; }
  .editor { position: static; }
}
