/* ============================================================
   keyplate — tokens
   Neutral "gray card" chrome on purpose: warm/cool UI colors
   would bias value & color judgment while a reference is on
   screen, the way a colored studio wall skews a still life.
   ============================================================ */
:root{
  --bg-canvas: #141413;      /* viewport surround, near-neutral */
  --bg-chrome: #211f1d;      /* header / dock / rail */
  --bg-chrome-raised: #2a2826;
  --line: #3c3936;
  --line-soft: #2e2c2a;
  --text: #eae6de;
  --text-dim: #9a958c;
  --accent: #c9903f;         /* brass — active / selected */
  --accent-dim: #7a5c2c;
  --measure: #6f9bb0;        /* steel blue — instrument / measurement */
  --danger: #a8543f;

  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, "Courier New", monospace;

  --bar-h: 48px;
  --rail-h: 84px;
}

*{ box-sizing:border-box; -webkit-tap-highlight-color:transparent; -webkit-touch-callout:none; }
html,body{
  height:100%; margin:0; overscroll-behavior:none;
  background:var(--bg-canvas); color:var(--text);
  font-family:var(--font-ui); font-size:14px;
  -webkit-user-select:none; user-select:none;
}
button, select, input{ font-family:inherit; font-size:inherit; color:inherit; }
button{ -webkit-appearance:none; appearance:none; background:none; border:none; cursor:pointer; }

/* ---------------- header ---------------- */
.bar{
  height:var(--bar-h); flex-shrink:0;
  display:flex; align-items:center; justify-content:space-between;
  padding:0 12px; background:var(--bg-chrome);
  border-bottom:1px solid var(--line);
  padding-top:env(safe-area-inset-top);
}
.bar-group{ display:flex; align-items:center; gap:6px; }
.wordmark{ font-size:14px; letter-spacing:.02em; color:var(--text-dim); }
.wordmark em{ font-style:normal; color:var(--accent); }

.btn{
  padding:7px 12px; border:1px solid var(--line); border-radius:3px;
  background:var(--bg-chrome-raised); color:var(--text);
  font-size:12px; letter-spacing:.02em; white-space:nowrap;
}
.btn:active{ background:var(--line); }
.btn-quiet{ background:transparent; color:var(--text-dim); border-color:var(--line-soft); }
.btn-danger{ color:var(--danger); }
.btn:disabled{ opacity:.35; pointer-events:none; }

/* ---------------- stage layout ---------------- */
.stage-row{
  display:flex; flex-direction:row;
  height:calc(100% - var(--bar-h));
  width:100%;
}
.panel{
  position:relative; flex:1 1 50%; min-width:0;
  box-shadow:inset -1px 0 0 var(--line);
}
#panelRight{ box-shadow:none; }

/* Both viewports are absolutely inset to fill their panel exactly —
   this is what guarantees the two images always render at the same
   size: dock/rail overlay on top rather than pushing layout height,
   so there's no independent box-sizing math to drift out of sync. */
.viewport{
  position:absolute; inset:0;
  overflow:hidden; background:var(--bg-canvas);
  touch-action:none;
}
.frame{
  position:absolute; top:50%; left:50%;
  transform-origin:center center;
  will-change:transform;
  display:flex; align-items:center; justify-content:center;
}
.frame canvas, .frame img{
  display:block; width:100%; height:100%;
  pointer-events:none;
  -webkit-user-drag:none;
}

.empty-state{
  position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
  color:var(--text-dim); font-family:var(--font-mono); font-size:12px;
  letter-spacing:.03em; pointer-events:none;
}
.has-image .empty-state{ display:none; }

/* ---------------- left dock (filter controls) ---------------- */
.dock{
  position:absolute; left:0; right:0; bottom:0; z-index:5;
  background:rgba(33,31,29,.94);
  -webkit-backdrop-filter:blur(6px); backdrop-filter:blur(6px);
  border-top:1px solid var(--line);
  padding-bottom:env(safe-area-inset-bottom);
  touch-action:auto;
  max-height:70%; overflow-y:auto;
}
.dock-toggle{
  width:100%; padding:8px 0; text-align:center; color:var(--text-dim); font-size:12px;
  border-bottom:1px solid var(--line-soft);
}
.dock-body{ padding:10px 12px 12px; display:flex; flex-direction:column; gap:10px; }
.dock.is-collapsed .dock-body{ display:none; }

.dock-row{ display:flex; flex-direction:column; gap:6px; }

.add-row{ flex-direction:row; align-items:center; flex-wrap:wrap; gap:6px; }
.add-label{ color:var(--text-dim); font-size:11px; margin-right:2px; }
.add-btn{
  padding:6px 10px; border:1px dashed var(--line); border-radius:3px;
  background:transparent; color:var(--text-dim); font-size:11.5px; letter-spacing:.02em;
}
.add-btn:active{ background:var(--bg-chrome-raised); }

.ctrl-label{
  display:flex; align-items:center; justify-content:space-between;
  font-size:11px; color:var(--text-dim); letter-spacing:.02em; text-transform:lowercase;
}
.readout{ font-family:var(--font-mono); color:var(--measure); font-size:11px; }

.select{
  padding:7px 8px; border:1px solid var(--line); border-radius:3px;
  background:var(--bg-chrome-raised); color:var(--text); width:100%;
}

input[type="range"]{
  -webkit-appearance:none; appearance:none; width:100%; height:28px; background:transparent;
}
input[type="range"]::-webkit-slider-runnable-track{
  height:2px; background:var(--line); border-radius:1px;
}
input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance:none; width:18px; height:18px; margin-top:-8px;
  border-radius:50%; background:var(--accent); border:2px solid var(--bg-canvas);
}

/* ---------------- modifier stack ---------------- */
.modifier-list{ display:flex; flex-direction:column; gap:8px; }
.mod-row{
  border:1px solid var(--line); border-radius:4px; background:var(--bg-chrome-raised);
  overflow:hidden;
}
.mod-row.is-disabled .mod-type{ color:var(--text-dim); text-decoration:line-through; text-decoration-color:var(--line); }
.mod-row.is-disabled{ opacity:.6; }

.mod-head{ display:flex; align-items:center; gap:2px; padding:4px 6px; }
.mod-move{
  width:26px; height:26px; flex-shrink:0; color:var(--text-dim); font-size:11px;
  border-radius:3px;
}
.mod-move:active{ background:var(--line-soft); }
.mod-move:disabled{ opacity:.25; }
.mod-enable{
  width:20px; height:20px; flex-shrink:0; border-radius:50%; border:1px solid var(--line);
  margin:0 4px;
}
.mod-enable[aria-pressed="true"]{ background:var(--accent); border-color:var(--accent); }
.mod-type{
  flex:1; font-size:12px; letter-spacing:.02em; color:var(--text); text-align:left;
  padding:6px 2px;
}
.mod-expand{ width:26px; height:26px; flex-shrink:0; color:var(--text-dim); font-size:10px; }
.mod-remove{ width:26px; height:26px; flex-shrink:0; color:var(--danger); font-size:14px; }

.mod-body{ padding:4px 10px 12px; border-top:1px solid var(--line-soft); display:flex; flex-direction:column; gap:10px; }

/* levels ramp — step-wedge style black→white bar with draggable points (scoped per modifier instance) */
.ramp-wrap{ position:relative; height:34px; touch-action:none; }
.ramp{
  position:absolute; left:0; right:0; top:50%; height:10px; transform:translateY(-50%);
  border-radius:2px; border:1px solid var(--line);
  background:linear-gradient(to right, #000, #fff);
}
.ramp-handle{
  position:absolute; top:50%; width:2px; height:26px; transform:translate(-50%,-50%);
  background:var(--measure); cursor:ew-resize;
}
.ramp-handle::after{
  content:""; position:absolute; left:50%; top:-4px; width:8px; height:8px;
  transform:translateX(-50%) rotate(45deg); background:var(--measure);
}
.ramp-handle-mid{ background:var(--accent); height:20px; }
.ramp-handle-mid::after{ background:var(--accent); width:6px; height:6px; top:-2px; }

/* gradient-map stop editor */
.gradient-preview{
  position:relative; height:30px; border-radius:3px; border:1px solid var(--line);
  touch-action:none;
}
.gradient-stop{
  position:absolute; top:50%; width:18px; height:18px; transform:translate(-50%,-50%);
  border-radius:50%; border:2px solid var(--text); box-shadow:0 0 0 1px rgba(0,0,0,.4);
}
.gradient-stop.is-selected{ border-color:var(--measure); box-shadow:0 0 0 2px var(--measure); }
.gradient-stop-controls{ display:flex; align-items:center; gap:8px; }
.gradient-stop-controls input[type="color"]{
  width:36px; height:28px; border:1px solid var(--line); border-radius:3px; background:none; padding:0;
}
.gradient-stop-controls .hint{ font-size:10.5px; color:var(--text-dim); flex:1; }
.gradient-preset-row{ display:flex; gap:6px; align-items:center; }
.gradient-preset-row .select{ flex:1; }
.gradient-save-row{ display:flex; gap:6px; }
.gradient-save-row input[type="text"]{
  flex:1; padding:7px 8px; border:1px solid var(--line); border-radius:3px;
  background:var(--bg-chrome); color:var(--text); font-size:12px;
}
.gradient-import-row{ display:flex; gap:6px; }
.gradient-import-row input[type="text"]{
  flex:1; padding:7px 8px; border:1px solid var(--line); border-radius:3px;
  background:var(--bg-chrome); color:var(--text); font-size:11px; font-family:var(--font-mono);
}

/* ---------------- right rail (thumbnail gallery) ---------------- */
.rail{
  position:absolute; left:0; right:0; bottom:0; z-index:5;
  height:var(--rail-h); background:rgba(33,31,29,.9);
  -webkit-backdrop-filter:blur(6px); backdrop-filter:blur(6px);
  border-top:1px solid var(--line);
  overflow-x:auto; overflow-y:hidden; -webkit-overflow-scrolling:touch;
  padding-bottom:env(safe-area-inset-bottom);
  touch-action:auto;
}
.rail-track{
  display:flex; gap:8px; height:100%; padding:10px 10px; align-items:center;
}
.thumb{
  position:relative; flex:0 0 auto; width:56px; height:56px;
  border-radius:3px; overflow:hidden; border:1px solid var(--line);
  background:var(--bg-chrome-raised);
}
.thumb img{ width:100%; height:100%; object-fit:cover; display:block; pointer-events:none; }
.thumb.is-active{ border-color:var(--accent); box-shadow:0 0 0 1px var(--accent); }
.thumb-del{
  position:absolute; top:1px; right:1px; width:20px; height:20px; line-height:19px;
  text-align:center; border-radius:50%; background:rgba(20,20,19,.88); color:var(--text);
  font-size:12px; display:none;
}
.thumb.is-active .thumb-del{ display:block; }

/* ---------------- zoom readout ---------------- */
.zoom-readout{
  position:fixed; left:50%; bottom:8px; transform:translateX(-50%);
  font-family:var(--font-mono); font-size:11px; color:var(--text-dim);
  background:rgba(33,31,29,.85); border:1px solid var(--line);
  padding:3px 8px; border-radius:10px; pointer-events:none;
  opacity:0; transition:opacity .15s ease;
  z-index:20;
}
.zoom-readout.is-visible{ opacity:1; }

/* ---------------- responsive: stack on portrait / narrow ---------------- */
@media (max-width:820px), (orientation:portrait){
  .stage-row{ flex-direction:column; }
  .panel{ box-shadow:inset 0 -1px 0 var(--line); flex-basis:50%; }
  #panelRight{ box-shadow:none; }
  .rail{ height:72px; }
  .thumb{ width:48px; height:48px; }
}

@media (prefers-reduced-motion: reduce){
  .zoom-readout{ transition:none; }
}
