:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #2a2f3a;
  --fg: #e6e8ec; --mut: #8a93a3; --acc: #ff7a1a; --acc2: #ffb36b;
  font-family: "Segoe UI", system-ui, sans-serif; font-size: 13px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
button, select, input { font: inherit; color: var(--fg); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 9px; }
button { cursor: pointer; }
button:hover { border-color: var(--acc); }
button.active { background: var(--acc); border-color: var(--acc); color: #111; font-weight: 600; }
input[type=number] { width: 72px; }
input[type=color] { padding: 0; width: 32px; height: 28px; }

.topbar { height: 52px; display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-size: 15px; white-space: nowrap; }
.brand .logo { color: var(--acc); }
.tools { display: flex; gap: 6px; flex: 1; justify-content: center; align-items: center; }
.tools .sep { width: 1px; height: 22px; background: var(--line); margin: 0 6px; }
.actions { display: flex; gap: 6px; }

.layout { display: grid; grid-template-columns: 220px 1fr 310px; height: calc(100% - 52px); }
.panel { background: var(--panel); overflow-y: auto; padding: 4px 14px 20px; }
.left { border-right: 1px solid var(--line); }
.right { border-left: 1px solid var(--line); }
.panel h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--mut);
  margin: 16px 0 8px; }

.drop { display: block; border: 1.5px dashed var(--line); border-radius: 8px; padding: 16px;
  text-align: center; color: var(--mut); cursor: pointer; transition: .15s; }
.drop:hover, .drop.over { border-color: var(--acc); color: var(--fg); }
.files { list-style: none; padding: 0; margin: 12px 0 0; }
.files li { display: flex; gap: 8px; align-items: center; padding: 6px; border-radius: 6px;
  cursor: pointer; margin-bottom: 4px; }
.files li:hover { background: var(--panel2); }
.files li.sel { background: var(--panel2); outline: 1px solid var(--acc); }
.files canvas { width: 42px; height: 56px; border-radius: 3px; flex: none; }
.files .fn { font-size: 11px; word-break: break-all; }
.files .ft { font-size: 11px; color: var(--mut); }

.center { display: flex; flex-direction: column; min-width: 0; }
.viewer { flex: 1; position: relative; display: flex; align-items: center; justify-content: center;
  overflow: hidden; background: repeating-conic-gradient(#12141a 0 25%, #0f1115 0 50%) 0 0/24px 24px; }
#view { cursor: crosshair; box-shadow: 0 4px 30px #000a; }
.empty { position: absolute; color: var(--mut); font-size: 16px; }
.readout { position: absolute; pointer-events: none; background: #000c; padding: 3px 7px;
  border-radius: 4px; font-variant-numeric: tabular-nums; display: none; white-space: nowrap; }
.colorbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  background: var(--panel); border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.colorbar { padding: 10px 16px 22px; }
.cbin { display: flex; align-items: center; gap: 4px; }
.cbin input { width: 74px; text-align: right; }
.cbin .u { color: var(--mut); }
.cbwrap { position: relative; flex: 1; min-width: 0; height: 22px; cursor: ew-resize; user-select: none; }
#cbar { width: 100%; height: 22px; border-radius: 3px; display: block; }
.cbwrap .span { position: absolute; top: -3px; bottom: -3px; border: 1.5px solid #fff8; border-radius: 3px;
  cursor: grab; }
.cbwrap .handle { position: absolute; top: -6px; bottom: -6px; width: 10px; margin-left: -5px;
  background: var(--fg); border: 2px solid #111; border-radius: 3px; cursor: ew-resize; box-shadow: 0 0 4px #000; }
.cbwrap .handle:hover, .cbwrap .handle.drag { background: var(--acc); }
.zoomreset { position: absolute; right: 0; top: -24px; font-size: 10px; padding: 1px 7px; }
.zoomreset[hidden] { display: none; }

.palpick { position: relative; margin-bottom: 10px; }
.palbtn { width: 100%; display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto;
  gap: 5px 8px; padding: 7px 9px; text-align: left; align-items: center; }
.palbtn canvas { grid-column: 1 / 3; width: 100%; height: 18px; border-radius: 3px; display: block; }
.palbtn .pname { font-weight: 600; }
.palbtn .caret { color: var(--mut); }
.palmenu { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px; box-shadow: 0 10px 30px #000c;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.palmenu .opt .thumb { aspect-ratio: 3 / 4; height: auto; margin-bottom: 4px; image-rendering: auto; }
.palmenu .opt canvas.strip { height: 7px; }
.palmenu[hidden] { display: none; }
.palmenu .opt { border: 1px solid transparent; border-radius: 6px; padding: 5px; cursor: pointer; background: var(--panel2); }
.palmenu .opt:hover { border-color: var(--line); background: #252a34; }
.palmenu .opt.sel { border-color: var(--acc); }
.palmenu .opt canvas { width: 100%; height: 34px; border-radius: 3px; display: block; }
.palmenu .opt div { font-size: 11px; margin-top: 4px; display: flex; justify-content: space-between; }
.palmenu .opt.sel div::after { content: "✓"; color: var(--acc); }

.cbwrap .ticks { position: absolute; left: 0; right: 0; top: 26px; height: 12px; font-size: 10px; color: var(--mut); }
.cbwrap .ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.cbwrap .ticks span.edge { color: var(--fg); }

.row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.row > label:first-child { width: 64px; flex: none; color: var(--mut); }
.row > label.chk:first-child { width: auto; color: var(--fg); margin-right: 10px; }
.row select { flex: 1; min-width: 0; }
.row.two input { flex: 1; width: auto; min-width: 0; }
.panel.right { overflow-x: hidden; }
.chk { display: flex; gap: 5px; align-items: center; }

.stats { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stats td { padding: 3px 0; border-bottom: 1px solid var(--line); }
.stats td:first-child { color: var(--mut); }
.stats td:last-child { text-align: right; word-break: break-all; }
#hist, #profile, #measHist { width: 100%; background: var(--panel2); border-radius: 6px; display: block; }
#profile[hidden] { display: none; }
.mdetail { margin-top: 10px; }
.mdt { font-weight: 600; color: var(--acc2); margin-bottom: 4px; }
.mlab { font-size: 11px; color: var(--mut); margin: 8px 0 3px; }
.mlab[hidden] { display: none; }

@media (max-width: 980px) {
  html, body { height: auto; }
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .tools { justify-content: flex-start; flex-wrap: wrap; }
  .layout { grid-template-columns: 1fr; height: auto; }
  .center { height: 78vh; order: 1; }
  .left { order: 2; border: 0; border-top: 1px solid var(--line); }
  .right { order: 3; border: 0; border-top: 1px solid var(--line); }
  .files { display: flex; gap: 6px; overflow-x: auto; }
  .files li { flex: none; }
}

.meas .m { background: var(--panel2); border-radius: 6px; padding: 7px 9px; margin-bottom: 6px;
  border-left: 3px solid var(--acc); cursor: pointer; }
.meas .m.sel { outline: 1px solid var(--acc2); }
.meas .m .h { display: flex; justify-content: space-between; font-weight: 600; }
.meas .m .h button { padding: 0 6px; font-size: 11px; }
.meas .m .h .btns { display: flex; gap: 4px; }
.meas .m .h button.a { background: #2f7cf6; border-color: #2f7cf6; color: #fff; font-weight: 700; }
.meas .m .v { color: var(--mut); font-variant-numeric: tabular-nums; margin-top: 3px; }
.meas .hint { color: var(--mut); font-size: 12px; }
