/* Layout: three working columns like a darkroom bench - sources left, picture centre, graphs and output right.
   One dark, neutral theme on purpose: colour is judged against grey, and the only hues on screen are the RGB channels. */
:root {
  color-scheme: dark;
  --bg: #17181a;
  --panel: #212225;
  --panel-2: #2a2c30;
  --line: #36383d;
  --fg: #ebe9e4;
  --muted: #a3a19b;
  --dim: #74736f;
  --paper: #f3f0e8;
  --paper-ink: #1b1b1c;
  --r: #ff5b52;
  --g: #3fcf63;
  --b: #4a8cff;
  --warn: #efb02e;
  --err: #ff7163;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 13px/1.45 var(--ui); display: flex; flex-direction: column; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

header { display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 46px; flex: none;
  border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font: 600 15px/1 "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; letter-spacing: .01em; display: flex; align-items: center; gap: 9px;
  white-space: nowrap; color: var(--fg); text-decoration: none; }
.mark { width: 18px; height: 18px; position: relative; flex: none; }
.mark::before, .mark::after { content: ""; position: absolute; width: 11px; height: 14px; border-radius: 2px; }
.mark::before { left: 0; top: 4px; background: #c8442a; }
.mark::after { left: 6px; top: 0; background: var(--paper); }
.apps { display: flex; gap: 2px; background: var(--panel-2); padding: 3px; border-radius: 999px; flex: none; }
.apps a { color: var(--muted); text-decoration: none; font-weight: 500; padding: 3px 12px; border-radius: 999px; white-space: nowrap; }
.apps a:hover { color: var(--fg); }
.apps a[aria-current="page"] { background: var(--bg); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.4); }
.apps a:focus-visible, .brand:focus-visible { outline: 2px solid var(--paper); outline-offset: 1px; }
#status { color: var(--muted); font-size: 12px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#status .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); margin-right: 7px; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { #status .dot, .spin { animation: none !important; } }

main { flex: 1; min-height: 0; display: grid; grid-template-columns: 296px minmax(0, 1fr) 336px; }
.col { min-height: 0; overflow-y: auto; background: var(--panel); }
.col.left { border-right: 1px solid var(--line); }
.col.right { border-left: 1px solid var(--line); }
section { padding: 14px 14px 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
h2 { margin: 0; font-size: 11px; font-weight: 650; letter-spacing: .09em; text-transform: uppercase; color: var(--muted);
  display: flex; align-items: center; gap: 8px; }
h2 .n { font: 600 11px/18px var(--mono); width: 18px; height: 18px; text-align: center; border-radius: 50%;
  background: var(--panel-2); color: var(--fg); letter-spacing: 0; }
h2 .count { margin-left: auto; font: 500 11px var(--mono); letter-spacing: 0; text-transform: none; color: var(--dim); }
.hint { color: var(--dim); font-size: 12px; margin: 0; }
.note { color: var(--muted); font-size: 12px; margin: 0; }
.note.warn { color: var(--warn); }

.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--dim); }
.btn:focus-visible, .seg button:focus-visible, .thumb:focus-visible, input:focus-visible, select:focus-visible, .x:focus-visible { outline: 2px solid var(--paper); outline-offset: 1px; }
.btn.primary { background: var(--paper); color: var(--paper-ink); border-color: var(--paper); font-weight: 650; padding: 9px 12px; width: 100%; }
.btn.primary:disabled { opacity: .35; cursor: default; }
.btn.quiet { background: none; border-color: transparent; color: var(--muted); padding: 5px 6px; }
.btn.quiet:hover { color: var(--fg); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.drop { border: 1px dashed var(--line); border-radius: 8px; padding: 14px 12px; text-align: center; color: var(--muted);
  display: flex; flex-direction: column; gap: 8px; align-items: center; }
.drop.over, .over > .drop { border-color: var(--paper); color: var(--fg); background: rgba(243,240,232,.05); }
.drop b { color: var(--fg); font-weight: 600; }

.ref { display: grid; grid-template-columns: 84px minmax(0,1fr) auto; gap: 10px; align-items: start;
  padding: 8px; border-radius: 8px; background: var(--panel-2); cursor: pointer; border: 1px solid transparent; }
.ref.sel { border-color: var(--paper); }
.ref img, .ref .ph { width: 84px; height: 60px; object-fit: cover; border-radius: 4px; background: #111; display: block; }
.ref .name { font-weight: 600; overflow-wrap: anywhere; }
.ref .meta { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.ref label { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; margin-top: 4px; cursor: pointer; }
.x { background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 4px; border-radius: 4px; }
.x:hover { color: var(--fg); }
.chip { display: inline-block; font: 500 11px var(--mono); padding: 1px 6px; border-radius: 4px; background: #1a1b1d; color: var(--muted); }
.chip.on { color: var(--fg); }
.chip.err { color: var(--err); }

#grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.thumb { position: relative; border: 1px solid transparent; border-radius: 6px; background: var(--panel-2); padding: 0; cursor: pointer; text-align: left; overflow: hidden; }
.thumb.sel { border-color: var(--paper); }
.thumb .pic { aspect-ratio: 3 / 2; background: #111; display: flex; align-items: center; justify-content: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .cap { padding: 4px 6px 5px; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb.sel .cap { color: var(--fg); }
.thumb .rm { position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,.6); border-radius: 4px; opacity: 0; }
.thumb:hover .rm, .thumb .rm:focus-visible { opacity: 1; }
.thumb .bad { color: var(--err); font-size: 11px; padding: 6px; text-align: center; }
.spin { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--muted); border-radius: 50%; animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.tabs { display: flex; align-items: center; gap: 10px; padding: 8px 14px; flex: none; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 2px; }
.seg button { background: none; border: 0; padding: 4px 11px; border-radius: 5px; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--panel-2); color: var(--fg); }
.tabs .file { color: var(--muted); font: 12px var(--mono); margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; padding: 6px 14px 10px; overflow: hidden; }
#cmp { position: absolute; inset: 6px 14px 10px; touch-action: none; user-select: none; overflow: hidden; cursor: ew-resize; border-radius: 3px; }
#cmp.zoomed { cursor: grab; }
#cmp.zoomed.onbar { cursor: ew-resize; }
#cmp.panning { cursor: grabbing; }
#cmp .layer { position: absolute; inset: 0; overflow: hidden; }
#cmp .layer img { position: absolute; max-width: none; display: block; -webkit-user-drag: none; background: #0d0d0e; }
#nav { position: absolute; right: 10px; bottom: 10px; width: 156px; border: 1px solid var(--line); border-radius: 4px; overflow: hidden;
  background: #000; box-shadow: 0 4px 18px rgba(0,0,0,.55); cursor: crosshair; }
#nav img { display: block; width: 100%; height: auto; -webkit-user-drag: none; pointer-events: none; }
#navBox { position: absolute; border: 1.5px solid var(--paper); box-shadow: 0 0 0 999px rgba(0,0,0,.5); pointer-events: none; }
#detailChip { position: absolute; left: 10px; bottom: 10px; font-size: 11px; background: rgba(0,0,0,.6); padding: 3px 8px; border-radius: 4px; color: var(--muted); pointer-events: none; }
body.picking [data-pick], body.picking #folderPick { opacity: .45; pointer-events: none; }
#cmp.side { cursor: default; }
#cmp.side.zoomed { cursor: grab; }
#cmp.side #layBefore { right: calc(50% + 3px); clip-path: none !important; }
#cmp.side #layAfter { left: calc(50% + 3px); }
#cmp.side #bar { display: none; }
.thumb.tweaked::after { content: ""; position: absolute; left: 6px; top: 6px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--paper); box-shadow: 0 0 0 2px rgba(0,0,0,.55); }
h3.sub { font-size: 13px; font-weight: 650; margin: 6px 0 0; color: var(--fg); }
.adj { display: grid; grid-template-columns: 1fr auto; gap: 0 8px; align-items: baseline; padding: 3px 0 1px; }
.adj label { color: var(--muted); }
.adj output { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--muted); }
.adj.changed output, .adj.changed label { color: var(--fg); }
.adj input[type="range"] { grid-column: 1 / -1; -webkit-appearance: none; appearance: none; height: 20px; background: transparent; margin: 0; cursor: pointer; }
.adj input[type="range"]::-webkit-slider-runnable-track { height: 2px; border-radius: 1px; background: var(--trk, #5b5d62); }
.adj input[type="range"]::-moz-range-track { height: 2px; border-radius: 1px; background: var(--trk, #5b5d62); }
.adj input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%; margin-top: -6.5px;
  background: var(--panel); border: 2px solid #c9c7c2; }
.adj input[type="range"]::-moz-range-thumb { width: 11px; height: 11px; border-radius: 50%; background: var(--panel); border: 2px solid #c9c7c2; }
.adj input[type="range"]:disabled { opacity: .35; cursor: default; }
.adj.temp { --trk: linear-gradient(90deg, #4b7be0, #7d8088 42%, #d8c247); }
.adj.tint { --trk: linear-gradient(90deg, #45b060, #7d8088 50%, #c653d6); }
.zoomctl button { min-width: 30px; }
#zFit { min-width: 54px; font-family: var(--mono); font-size: 12px; }
#cmp .tag { position: absolute; top: 10px; font: 600 10px var(--ui); letter-spacing: .1em; text-transform: uppercase;
  background: rgba(0,0,0,.55); padding: 3px 7px; border-radius: 4px; pointer-events: none; }
#cmp .tag.l { left: 10px; } #cmp .tag.r { right: 10px; }
#bar { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--paper); pointer-events: none; }
#bar::after { content: ""; position: absolute; top: 50%; left: 50%; width: 26px; height: 26px; margin: -13px; border-radius: 50%;
  background: var(--paper); box-shadow: 0 1px 6px rgba(0,0,0,.5); }
#refview { display: flex; gap: 12px; width: 100%; height: 100%; align-items: center; justify-content: center; }
#refview figure { margin: 0; flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; }
#refview img { max-width: 100%; max-height: calc(100% - 26px); object-fit: contain; background: #0d0d0e; }
#refview figcaption { color: var(--muted); font: 12px var(--mono); }
#foot { flex: none; padding: 0 14px 12px; color: var(--dim); font-size: 12px; min-height: 30px; }
#welcome { max-width: 460px; color: var(--muted); }
#welcome h3 { color: var(--fg); font-size: 20px; font-weight: 650; margin: 0 0 6px; letter-spacing: -.01em; text-wrap: balance; }
#welcome ol { margin: 16px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 12px; counter-reset: s; }
#welcome li { counter-increment: s; display: grid; grid-template-columns: 26px 1fr; gap: 10px; }
#welcome li::before { content: counter(s); font: 600 12px/24px var(--mono); width: 24px; height: 24px; text-align: center; border-radius: 50%; background: var(--panel-2); color: var(--fg); }
#welcome li b { color: var(--fg); display: block; font-weight: 600; }

/* the graphs stay in view while the rest of the right column scrolls under them */
#histSec { position: sticky; top: 0; z-index: 5; background: var(--panel); box-shadow: 0 6px 12px -8px rgba(0,0,0,.7); }
.hist { display: grid; grid-template-columns: 74px minmax(0,1fr); gap: 8px; align-items: center; }
.hist .lab { font-size: 11px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
canvas.h { width: 100%; height: 78px; display: block; background: #121314; border-radius: 4px; }
#curve { width: 132px; height: 132px; background: #121314; border-radius: 4px; flex: none; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; align-content: start; min-width: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.field { display: grid; grid-template-columns: 96px minmax(0,1fr); gap: 8px; align-items: center; }
.field > span:first-child, .field > label:first-child { color: var(--muted); }
input[type="range"] { width: 100%; accent-color: var(--paper); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--paper); }
input[type="text"], input[type="number"], select { background: #151617; border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; width: 100%; min-width: 0; }
.check { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.check input { margin-top: 3px; }
.check small { display: block; color: var(--dim); }
progress { width: 100%; height: 6px; accent-color: var(--paper); }
#result { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
#result b { color: var(--fg); font-weight: 600; }
#result .p { font-family: var(--mono); overflow-wrap: anywhere; color: var(--fg); }
#result ul { margin: 0; padding-left: 16px; color: var(--err); }

#toasts { position: fixed; left: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 20; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--paper); color: var(--paper-ink); border-radius: 8px; padding: 9px 12px; font-weight: 500; box-shadow: 0 6px 24px rgba(0,0,0,.45); }

@media (max-width: 1080px) {
  #histSec { position: static; box-shadow: none; }
  body { display: block; }
  main { display: block; }
  .col { overflow: visible; border: 0 !important; }
  .center { height: 62vh; min-height: 320px; }
  #grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}

/* web additions */
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
label.btn { display: inline-block; }
label.btn:focus-within { outline: 2px solid var(--paper); outline-offset: 1px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.path { overflow-wrap: anywhere; color: var(--muted); user-select: all; }
kbd { font: 11px var(--mono); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; color: var(--fg); }
details summary { cursor: pointer; }
.pathbox { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px;
  background: #151617; border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; }
.ver { color: var(--dim); font-size: 11px; margin: 18px 0 0; letter-spacing: .02em; }
#progRow progress { flex: 1; }
.drop .btn { cursor: pointer; }
#unsupported { position: fixed; inset: 46px 0 0; background: var(--bg); display: grid; place-items: center; padding: 24px; z-index: 30; }
#unsupported div { max-width: 460px; color: var(--muted); }
#unsupported h3 { color: var(--fg); font-size: 18px; margin: 0 0 8px; }
@media (max-width: 720px) {
  header { height: auto; flex-wrap: wrap; padding: 8px 16px; gap: 8px 12px; }
  #status { flex-basis: 100%; }
}
