:root {
  --bg: #121315;
  --panel: #1b1d20;
  --line: #2a2d31;
  --text: #e6e6e3;
  --muted: #8c8f94;
  --accent: #e8b04a;
  --warn: #e0745a;
  --ok: #7fbf8a;
  --field: #24272b;
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Inter", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { display: flex; flex-direction: column; }

header {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .04em; }
.brand span { font-weight: 400; color: var(--muted); }
.brand .beta { margin-left: 6px; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 600;
  letter-spacing: .02em; background: var(--accent); color: #1d1d20; vertical-align: 1px; }
.open { display: flex; gap: 8px; }
.fw { flex: 1; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { flex: 1; display: flex; min-height: 0; }
.stage { flex: 1; display: flex; flex-direction: column; min-width: 0; }
aside {
  width: 340px; flex: none; overflow-y: auto;
  border-left: 1px solid var(--line); background: var(--panel);
}

.toolbar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.shot { color: var(--muted); font-size: 12px; margin-left: auto; text-align: right; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button {
  background: none; border: 0; color: var(--muted); padding: 5px 12px; cursor: pointer; font: inherit;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--field); color: var(--text); }
.seg button:disabled { opacity: .4; cursor: default; }

.canvas-wrap { position: relative; flex: 1; min-height: 0; background: #0b0b0c; }
#view { position: absolute; inset: 16px; width: calc(100% - 32px); height: calc(100% - 32px); object-fit: contain; }
.empty, .busy {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: var(--muted); text-align: center;
}
.empty .hint { font-size: 12px; }
.canvas-wrap.drag { outline: 2px dashed var(--accent); outline-offset: -8px; }
.busy { background: rgba(0,0,0,.55); color: var(--text); }
.split { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px solid rgba(255,255,255,.8); cursor: ew-resize; }
.split .grip {
  position: absolute; top: 50%; left: -9px; width: 18px; height: 36px; margin-top: -18px;
  border-radius: 9px; background: rgba(255,255,255,.85);
}
.split::before { content: ""; position: absolute; top: 0; bottom: 0; left: -10px; width: 20px; }
.labels { position: absolute; top: 24px; left: 24px; right: 24px; display: flex; justify-content: space-between; pointer-events: none; }
.labels span { background: rgba(0,0,0,.6); padding: 2px 8px; border-radius: 4px; font-size: 12px; }

.panel { padding: 14px 16px; border-bottom: 1px solid var(--line); }
h2 { margin: 0 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.addr { text-transform: none; letter-spacing: 0; font-weight: 400; font-family: ui-monospace, Menlo, monospace; }
.tag { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--accent); }

.matrix { display: grid; grid-template-columns: repeat(3, 1fr) 0; gap: 6px; }
.matrix input {
  width: 100%; background: var(--field); border: 1px solid var(--line); color: var(--text);
  border-radius: 4px; padding: 5px 6px; font: 12px ui-monospace, Menlo, monospace; text-align: right;
}
.matrix input:focus { outline: none; border-color: var(--accent); }
.matrix input.diff { color: var(--accent); }
.sums { margin: 6px 0 12px; font-size: 11px; color: var(--muted); font-family: ui-monospace, Menlo, monospace; }
.sums .bad { color: var(--warn); }

.slider { margin: 10px 0; }
.slider label { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.slider output { color: var(--text); font-family: ui-monospace, Menlo, monospace; }
input[type=range] { width: 100%; accent-color: var(--accent); }
/* sliders that show their effect as a colour gradient (white balance) */
input[type=range].grad { -webkit-appearance: none; appearance: none; height: 18px; background: transparent; }
input[type=range].grad::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--grad); }
input[type=range].grad::-moz-range-track { height: 6px; border-radius: 3px; background: var(--grad); }
input[type=range].grad::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 14px; height: 14px;
  margin-top: -4px; border-radius: 50%; background: #f4f1ea; border: 2px solid #1d1d20; box-shadow: 0 0 0 1px rgba(255,255,255,.25); }
input[type=range].grad::-moz-range-thumb { width: 10px; height: 10px; border-radius: 50%; background: #f4f1ea;
  border: 2px solid #1d1d20; box-shadow: 0 0 0 1px rgba(255,255,255,.25); }
input[type=range].grad:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }
/* colour temperature: the camera setting, so a low value renders blue and a high one warm;
   neutral sits near 5200 K (36 % of 2500..10000 K) */
#wb-k { --grad: linear-gradient(90deg, #3d6fd4 0%, #9db5e3 22%, #dcdad4 36%, #e8c487 62%, #e3902c 100%); }
#wb-ab { --grad: linear-gradient(90deg, #3d6fd4 0%, #dcdad4 50%, #e3902c 100%); }
#wb-gm { --grad: linear-gradient(90deg, #3fae4c 0%, #dcdad4 50%, #c24fb8 100%); }

.row { display: flex; gap: 8px; margin-top: 10px; }
.btn {
  display: inline-block; background: var(--field); color: var(--text); border: 1px solid var(--line);
  border-radius: 5px; padding: 6px 12px; cursor: pointer; font: inherit;
}
.btn:hover { border-color: #444; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1407; font-weight: 600; }
.btn:disabled { opacity: .4; cursor: default; }

.note { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.note.warn { color: var(--warn); }
.muted { color: var(--muted); }
code { font-size: 11px; }
.field { display: block; font-size: 12px; color: var(--muted); margin: 10px 0; }
.field input {
  display: block; width: 100%; margin-top: 4px; background: var(--field); border: 1px solid var(--line);
  color: var(--text); border-radius: 4px; padding: 6px; font: 12px ui-monospace, Menlo, monospace;
}
.changes { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.changes li { padding: 2px 0; }
.check { display: flex; gap: 8px; align-items: baseline; font-size: 12px; margin: 0 0 10px; }
h3 { margin: 14px 0 6px; font-size: 11px; color: var(--muted); font-weight: 600; }
.downloads { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.downloads .btn { text-decoration: none; }
.downloads .note { flex-basis: 100%; }
#chan-curve, #chan-effective { width: 100%; display: block; background: var(--field); border-radius: 4px; }
#chan-curve { aspect-ratio: 1; cursor: crosshair; touch-action: none; }
#chan-effective { aspect-ratio: 560 / 300; }
#chan-curve:focus { outline: none; }
#chan-curve:focus-visible { outline: 1px solid var(--accent); }
.seg.small { display: flex; margin-bottom: 8px; }
.seg.small button { flex: 1; padding: 4px 6px; font-size: 12px; }
.seg.rgb button { font-weight: 700; }
.copy { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; margin-top: 10px; }
.copy label { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.copy select {
  background: var(--field); color: var(--text); border: 1px solid var(--line);
  border-radius: 4px; padding: 5px; font: inherit; font-size: 12px;
}
.row + .row { margin-top: 6px; }
.wheels { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.wheel { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.wheel .title { font-size: 12px; color: var(--muted); align-self: stretch; display: flex; justify-content: space-between; }
.wheel .title output { color: var(--text); font-family: ui-monospace, Menlo, monospace; font-size: 11px; }
.wheel canvas { width: 100%; max-width: 140px; aspect-ratio: 1; cursor: crosshair; touch-action: none; }
.wheel input[type=range] { width: 100%; }
.wheel.on .title span { color: var(--accent); }

.calib { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 8px; align-items: center; font-size: 12px; }
.calib .prim { font-weight: 700; }
.calib .lbl { color: var(--muted); }
.calib output { font-family: ui-monospace, Menlo, monospace; min-width: 3ch; text-align: right; }
.calib input[type=range] { width: 100%; }
.calib .gap { grid-column: 1 / -1; height: 4px; }
#hsl-curve { width: 100%; border-radius: 4px; display: block; margin: 6px 0 2px; touch-action: none; cursor: crosshair; }
#hsl-channels { margin-top: 4px; }
.hsl-foot { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.hsl-foot .note { margin: 0; }
#hsl-readout { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--accent); white-space: nowrap; }

/* ---- streamlined layout ---------------------------------------------------- */
aside { width: 360px; display: flex; flex-direction: column; overflow: hidden; }
.btn.ghost { background: none; }
.btn.accent { border-color: var(--accent); color: var(--accent); }
.btn.accent:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.btn.wide { display: block; width: 100%; text-align: center; margin-top: 10px; }
.note.ok { color: var(--ok); }
select {
  width: 100%; background: var(--field); color: var(--text); border: 1px solid var(--line);
  border-radius: 5px; padding: 7px 8px; font: inherit;
}
select:focus { outline: none; border-color: var(--accent); }

details.adv { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 10px; }
details summary { cursor: pointer; color: var(--muted); font-size: 12px; user-select: none; }
details summary:hover { color: var(--text); }
details.adv[open] summary { margin-bottom: 8px; }

.drawer { border-top: 1px solid var(--line); padding: 8px 16px; flex: none; background: var(--panel); }
.drawer summary { font-size: 12px; color: var(--text); }
.drawer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0 18px; margin-top: 4px; }
.drawer-grid .check { align-self: center; margin: 10px 0 0; }
.drawer .note { margin: 4px 0 4px; }

.empty .big { font-size: 16px; color: var(--text); margin: 0 0 4px; }
.steps { text-align: left; color: var(--muted); font-size: 13px; line-height: 1.6; margin: 14px 0 0; padding-left: 20px; max-width: 460px; }
.steps b { color: var(--text); font-weight: 600; }
.howto { margin: 0; padding-left: 18px; font-size: 12.5px; line-height: 1.55; color: var(--muted); }
.howto li { margin: 2px 0; }
.changes li::before { content: "• "; color: var(--accent); }
.changes li.muted::before { content: ""; }
.downloads { display: block; margin-top: 0; }

dialog {
  max-width: 520px; background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 20px 24px;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { font-size: 13px; color: var(--text); }
dialog .steps { max-width: none; margin-bottom: 12px; }
dialog form { margin-top: 16px; text-align: right; }

/* ---- firmware screen (web version) ------------------------------------------ */
.gate {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(10, 11, 12, .92);
}
.gate[hidden] { display: none; }
.gate-box {
  width: min(520px, 100%); padding: 22px 24px; border: 1px dashed #4a4d52; border-radius: 10px;
  background: var(--panel); display: grid; gap: 10px;
}
.gate.drag .gate-box { border-color: var(--accent); background: rgba(232,176,74,.07); }
.gate.busy .gate-box { opacity: .75; cursor: progress; }
.gate h2 { margin: 0; font-size: 18px; }
.gate p { margin: 0; }
.gate a { color: var(--accent); }

/* ---- side panel: target and source pinned, one scrolling column, space pinned ---- */
.pick { flex: none; padding: 12px 16px 10px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.pick-row { display: grid; grid-template-columns: 78px 1fr; align-items: center; gap: 8px; }
.pick-row label { display: flex; align-items: center; gap: 6px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.pick .num {
  display: inline-grid; place-items: center; width: 16px; height: 16px; flex: none;
  border-radius: 50%; background: var(--accent); color: #1a1407; font-size: 10px; letter-spacing: 0;
}
#target { font-weight: 600; }
.pick select:disabled { opacity: .5; }
.pick .note { margin: 0; }

.sections { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 0 16px; }
.sections .none { padding: 12px 16px; margin: 0; }
details.sec { border-bottom: 1px solid var(--line); }
details.sec > summary {
  list-style: none; display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  font-size: 12.5px; font-weight: 600; color: var(--text);
}
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::before { content: "▸"; color: var(--muted); width: 10px; transition: transform .12s; }
details.sec[open] > summary::before { transform: rotate(90deg); }
details.sec > summary .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); visibility: hidden; }
details.sec.dirty > summary .dot { visibility: visible; }
details.sec > summary .reset {
  margin-left: auto; background: none; border: 1px solid transparent; border-radius: 4px; color: var(--muted);
  font: inherit; font-size: 11px; font-weight: 400; padding: 2px 6px; cursor: pointer;
}
details.sec > summary .reset:hover:not(:disabled) { border-color: var(--line); color: var(--text); }
details.sec > summary .reset:disabled { visibility: hidden; }
details.sec .body { padding: 0 16px 14px; }
details.sec .body > .note:first-child { margin-top: 0; }
details.sec h3 { margin-top: 12px; }

.space { flex: none; display: flex; align-items: center; gap: 10px; padding: 9px 16px;
  border-top: 1px solid var(--line); font-size: 11.5px; color: var(--muted); }
.space .bar { flex: 1; height: 6px; border-radius: 3px; background: var(--field); overflow: hidden; }
.space .bar i { display: block; height: 100%; width: 0; background: var(--accent); }
.space.full .bar i { background: var(--warn); }
.space.full { color: var(--warn); }

.notice { display: flex; align-items: center; gap: 8px; padding: 6px 16px; font-size: 12px;
  border-bottom: 1px solid var(--line); background: rgba(127,191,138,.08); color: var(--text); }
.notice.warn { background: rgba(224,116,90,.1); color: var(--warn); }
.notice span { flex: 1; }
.notice .btn { padding: 0 8px; border: 0; }

#export-dlg { width: min(520px, calc(100vw - 32px)); }
#export-dlg .changes li { padding: 4px 0; }
#export-dlg form { margin-top: 12px; }
dialog .howto { padding-left: 18px; }
dialog details.adv { margin-top: 14px; }

@media (max-width: 820px) {
  header { flex-wrap: wrap; }
  main { flex-direction: column; overflow-y: auto; }
  .stage { min-height: 60vh; }
  aside { width: auto; border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .sections { overflow: visible; }
}
.seg.rgb button:first-child { color: var(--text); }
.seg.lang button { padding: 5px 9px; font-size: 12px; font-weight: 600; }
dialog a { color: var(--accent); }
a.btn { text-decoration: none; }
header .btn { white-space: nowrap; }
@media (max-width: 1100px) { header { flex-wrap: wrap; row-gap: 8px; } header .fw { flex-basis: 120px; } }

/* fit to a LUT (lut.js) */
#lut-open { justify-self: start; }
#lut-dlg { width: min(520px, calc(100vw - 32px)); }
#lut-dlg > * + * { margin-top: 10px; }
#lut-dlg.busy { cursor: progress; }
#lut-dlg select { width: 100%; }
.lut-report { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.lut-report th, .lut-report td { padding: 3px 6px; text-align: right; border-bottom: 1px solid var(--line); }
.lut-report th:first-child { text-align: left; font-weight: normal; color: var(--muted); }
.lut-report thead th { color: var(--muted); font-weight: normal; }
.lut-report tr.final td, .lut-report tr.final th { color: var(--text); font-weight: 600; }
.pick .note a { color: var(--accent); }
.pick-row .num:empty { visibility: hidden; }
/* the film's fit for the camera's highlight correction (lut.js renderHcBox) */
.pick-sub { margin-left: 86px; }
.pick-sub[open] summary { margin-bottom: 6px; }
.pick-sub .seg.small { margin: 6px 0 2px; }
.pick-sub .note + .note { margin-top: 6px; }

/* credits (index.html #credits) */
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }
.howto.credits li { margin: 6px 0; }

/* filmstrip (filmstrip.js) */
.filmstrip { flex: none; border-top: 1px solid var(--line); background: var(--panel); }
.filmstrip .strip { display: flex; gap: 6px; overflow-x: auto; padding: 8px 16px; }
.thumb { position: relative; flex: none; margin: 0; padding: 2px; border: 2px solid var(--line);
  border-radius: 4px; background: var(--field); color: var(--text); cursor: pointer; }
.thumb:hover { border-color: var(--muted); }
.thumb.on { border-color: var(--accent); }
.thumb canvas { display: block; width: 84px; height: 56px; background: #0b0b0c; }
.thumb.loading canvas { animation: thumb-shimmer 1.2s ease-in-out infinite alternate; }
@keyframes thumb-shimmer { from { opacity: .35; } to { opacity: .75; } }
.thumb.err canvas { background: repeating-linear-gradient(45deg, #0b0b0c 0 8px, var(--field) 8px 16px); }
.thumb-name { position: absolute; left: 2px; right: 2px; bottom: 2px; padding: 1px 4px;
  font-size: 10px; background: rgba(0, 0, 0, .55); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }

/* the filmstrip's instant preview (filmstrip.js): the camera JPEG shown while
   the raw pipeline renders; sits above the busy overlay, below the split */
#preview-cover { position: absolute; inset: 16px; width: calc(100% - 32px); height: calc(100% - 32px);
  object-fit: contain; background: #0b0b0c; z-index: 1; }

.thumb.portrait canvas { width: 56px; height: 84px; }
