:root {
  --bg: #0b0c0e;
  --panel: #111215;
  --line: #1f2125;
  --line2: #2a2d33;
  --text: #e4e5e8;
  --muted: #868a93;
  --faint: #5b5f67;
  --btn: #17181c;
  --btn-on: #2a2d34;
  --accent: #9fb8ff;
  --ax: #5b9eff;
  --cor: #4dc28a;
  --sag: #f0a33a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  display: flex;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }

/* ---------- sidebar ---------- */
#side {
  width: 276px;
  flex: none;
  height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 16px 16px;
  scrollbar-width: thin;
}
.brand h1 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.brand .sub { margin: 3px 0 0; color: var(--muted); font-size: 12px; }

section { margin-top: 20px; }
h2 {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 0 0 8px;
  font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
}
.note { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.fine { margin: 8px 0 0; color: var(--faint); font-size: 11.5px; }

.seg { display: flex; border: 1px solid var(--line2); border-radius: 7px; overflow: hidden; }
.seg button {
  flex: 1; padding: 6px 4px; border: 0; background: var(--btn); cursor: pointer;
  color: var(--muted); font-size: 12.5px; white-space: nowrap;
}
.seg button + button { border-left: 1px solid var(--line2); }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--btn-on); color: var(--text); }
.seg + .seg, .note + .seg { margin-top: 8px; }

.views { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
#presets { margin: 0 0 8px; }
.views button {
  padding: 4px 9px; border: 1px solid var(--line2); border-radius: 999px; background: transparent;
  color: var(--muted); font-size: 12px; cursor: pointer;
}
.views button:hover:not(:disabled) { color: var(--text); border-color: #3a3e46; }
.views button:disabled { opacity: 0.35; cursor: default; }

.link { border: 0; background: none; color: var(--faint); font-size: 11px; text-transform: none; letter-spacing: 0; cursor: pointer; padding: 0; }
.link:hover { color: var(--text); }

/* layers */
.layer { display: grid; grid-template-columns: 16px 10px 1fr 78px; align-items: center; gap: 8px; padding: 4px 0; }
.layer input[type=checkbox] { margin: 0; }
.layer .sw { width: 10px; height: 10px; border-radius: 3px; }
.layer label { cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer.off label { color: var(--muted); }
.layer.off input[type=range] { opacity: 0.35; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--muted); cursor: pointer; }
.check:hover { color: var(--text); }
.check input { margin: 0; }

/* sliders */
input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; margin: 0;
}
input[type=range]::-webkit-slider-runnable-track { height: 3px; background: var(--line2); border-radius: 2px; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%; background: #d7d9de; margin-top: -4.5px; border: 0;
}
input[type=range]::-moz-range-track { height: 3px; background: var(--line2); border-radius: 2px; }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #d7d9de; border: 0; }

.slider-row { display: grid; grid-template-columns: 70px 1fr 44px; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); }
.slider-row output { text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; }

/* dual range (cut-away) */
.crop-row { margin-bottom: 8px; }
.crop-row .lab { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.dual { position: relative; height: 20px; }
.dual .track { position: absolute; left: 0; right: 0; top: 8.5px; height: 3px; background: var(--line2); border-radius: 2px; }
.dual .fill { position: absolute; top: 8.5px; height: 3px; background: #8d93a0; border-radius: 2px; }
.dual input { position: absolute; inset: 0; pointer-events: none; }
.dual input::-webkit-slider-runnable-track { background: transparent; }
.dual input::-moz-range-track { background: transparent; }
.dual input::-webkit-slider-thumb { pointer-events: auto; cursor: ew-resize; }
.dual input::-moz-range-thumb { pointer-events: auto; cursor: ew-resize; }

/* comparison: the fade control sits on the 3D view so the picture stays in sight while dragging, phones included */
#cmpBar {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); width: min(440px, calc(100% - 230px));
  padding: 8px 12px 9px; border: 1px solid var(--line2); border-radius: 10px; background: rgba(17, 18, 21, 0.86);
  cursor: default; touch-action: manipulation;
}
.cmp-ends { display: flex; justify-content: space-between; color: var(--text); font-size: 12px; }
.cmp-row { display: grid; grid-template-columns: 30px 1fr; align-items: center; gap: 10px; margin-top: 6px; }
.note.first { margin: 0 0 4px; }
#cmpPlay {
  width: 30px; height: 26px; border: 1px solid var(--line2); border-radius: 7px; background: var(--btn);
  color: var(--text); font-size: 10px; cursor: pointer; padding: 0;
}
#cmpPlay:hover { background: var(--btn-on); }
.legend { list-style: none; margin: 8px 0 0; padding: 0; color: var(--muted); font-size: 12px; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend.off { opacity: 0.35; }
[hidden] { display: none !important; }

footer { margin-top: 22px; padding-top: 12px; border-top: 1px solid var(--line); }
details summary { cursor: pointer; color: var(--muted); font-size: 12px; }
details summary:hover { color: var(--text); }
dl { margin: 8px 0 0; font-size: 12px; }
dt { color: var(--text); margin-top: 6px; }
dd { margin: 2px 0 0; color: var(--muted); }

/* ---------- stage & panes ---------- */
#stage { position: relative; flex: 1; min-width: 0; height: 100%; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#panes { position: absolute; inset: 0; display: grid; gap: 1px; background: var(--line); }
#panes.quad { grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr); grid-template-rows: repeat(3, minmax(0, 1fr)); }
#panes.quad #p3d { grid-row: 1 / 4; }
#panes.max { grid-template-columns: 1fr; grid-template-rows: 1fr; }
#panes.max .pane:not(.big) { display: none; }

.pane { position: relative; overflow: hidden; outline: none; touch-action: none; background: transparent; }
/* the panes are transparent windows onto the canvas; the 1px grid gap shows through as a divider */
#panes { background: transparent; }
#panes .pane { box-shadow: 0 0 0 1px var(--line); }

.phead {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; font-size: 12px; color: var(--muted); pointer-events: none;
}
.phead .ptitle { color: var(--text); font-weight: 500; }
.phead .pinfo { font-variant-numeric: tabular-nums; }
.phead .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
#pax .dot { background: var(--ax); }
#pcor .dot { background: var(--cor); }
#psag .dot { background: var(--sag); }
.pmax {
  margin-left: auto; pointer-events: auto; border: 0; background: transparent; color: var(--faint);
  cursor: pointer; font-size: 14px; line-height: 1; padding: 2px 4px; border-radius: 4px;
}
.pmax:hover { color: var(--text); background: rgba(255,255,255,0.06); }

.ori { position: absolute; font-size: 11px; color: #9a9ea6; pointer-events: none; letter-spacing: 0.02em; background: rgba(0,0,0,0.72); padding: 0 4px; border-radius: 3px; }
.ori.t { top: 30px; left: 50%; transform: translateX(-50%); }
.ori.b { bottom: 8px; left: 50%; transform: translateX(-50%); }
.ori.l { left: 10px; top: 50%; transform: translateY(-50%); }
.ori.r { right: 10px; top: 50%; transform: translateY(-50%); }

.readout {
  position: absolute; left: 10px; bottom: 8px; font: 11.5px/1.3 ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--muted); pointer-events: none; white-space: nowrap;
}
.readout b { color: var(--text); font-weight: 500; }
.scalebar { position: absolute; right: 12px; bottom: 9px; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; pointer-events: none; }
.scalebar i { display: block; height: 4px; border: 1px solid var(--faint); border-top: 0; }
.scalebar span { font-size: 10.5px; color: var(--faint); }

.gizmo { position: absolute; right: 8px; bottom: 8px; width: 96px; height: 96px; pointer-events: none; }

#p3d { cursor: grab; }
#p3d.dragging { cursor: grabbing; }
.slice { cursor: crosshair; }
.slice.panning { cursor: move; }

#loading { position: absolute; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 5; }
#loading.gone { display: none; }
.lbox { width: 260px; }
.lbox p { margin: 0 0 10px; color: var(--muted); font-size: 12.5px; }
.bar { height: 2px; background: var(--line2); border-radius: 1px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--text); transition: width 0.15s; }

.toast {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 4;
  background: #1b1d21; border: 1px solid var(--line2); padding: 6px 12px; border-radius: 7px;
  color: var(--muted); font-size: 12px; pointer-events: none; transition: opacity 0.3s;
}

.touch-only { display: none; }
@media (pointer: coarse) { .touch-only { display: block; } .mouse-only { display: none; } }

@media (max-width: 760px) {
  html, body { height: auto; }
  body { flex-direction: column; overflow-x: hidden; overflow-y: auto; }
  #stage { order: -1; flex: none; height: 74vh; height: 74svh; }
  #side { width: 100%; height: auto; overflow: visible; border-right: 0; border-top: 1px solid var(--line); padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  #panes.quad { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: minmax(0, 1.75fr) minmax(0, 1fr); }
  #panes.quad #p3d { grid-row: 1; grid-column: 1 / 4; }
  #panes.quad .slice .pinfo, #panes.quad .slice .scalebar, #panes.quad .slice .ori { display: none; }
  .phead { padding: 6px 8px; gap: 6px; }
  .slice .ptitle { font-size: 11.5px; }
  .pmax { font-size: 18px; padding: 6px 9px; margin: -6px -8px 0 auto; }
  .readout { font-size: 10.5px; left: 8px; bottom: 6px; }
  .gizmo { width: 76px; height: 76px; right: 4px; bottom: 4px; }
  #cmpBar { left: 8px; bottom: 8px; transform: none; width: calc(100% - 96px); padding: 6px 10px 7px; }
  #cmpPlay { height: 30px; }
  .seg button { padding: 9px 4px; }
  .views button { padding: 7px 11px; }
  .layer { grid-template-columns: 18px 10px 1fr 110px; padding: 7px 0; }
  .toast { top: 8px; max-width: 90%; text-align: center; }
}


#layerSection.dim .layer, #layerSection.dim .check { opacity: 0.4; }
.legend li { align-items: flex-start; }
.legend i { margin-top: 4px; }
