/* Wiper Mount Inference — hi-fi
   Warm dark · Rain-X blue + yellow accents · Inter Tight + JetBrains Mono */

@import url('https://fonts.googleapis.com/css2?family=Inter+Tight:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg-0: #0d1117;
  --bg-1: #131a23;
  --bg-2: #1a232f;
  --bg-3: #21303f;
  --bg-4: #2a3a4d;
  --line: #1e2937;
  --line-2: #2a3849;
  --line-3: #38485c;

  --t-0: #ede9d8;
  --t-1: #c2c4c0;
  --t-2: #868c8e;
  --t-3: #545c63;
  --t-4: #353c44;

  --acc:    #ffcb05;
  --acc-2:  #e6b400;
  --acc-3:  #8a6c00;
  --acc-glow: rgba(255, 203, 5, 0.18);
  --acc-bg: rgba(255, 203, 5, 0.08);

  --blu:    #3d6bd8;
  --blu-2:  #2a4ea3;
  --blu-3:  #1d3a8a;
  --blu-bg: rgba(61, 107, 216, 0.10);
  --blu-glow: rgba(61, 107, 216, 0.25);

  --vio: #6b9bff;
  --vio-bg: rgba(107, 155, 255, 0.10);

  --good:  #6fcf7e;
  --warn:  #ffcb05;
  --bad:   #e85d5d;
  --info:  #6b9bff;

  --det:        #6b9bff;
  --det-bg:     rgba(107, 155, 255, 0.10);
  --det-low:    #6b7480;
  --det-low-bg: rgba(107, 116, 128, 0.10);

  --sans: 'Inter Tight', -apple-system, system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;

  --r-1: 4px;
  --r-2: 6px;
  --r-3: 10px;
  --r-4: 14px;

  --sh-1: 0 1px 0 rgba(255,255,255,0.04) inset, 0 1px 2px rgba(0,0,0,0.5);
  --sh-2: 0 4px 12px rgba(0,0,0,0.5), 0 1px 0 rgba(255,255,255,0.04) inset;
  --sh-3: 0 12px 36px rgba(0,0,0,0.6), 0 1px 0 rgba(255,255,255,0.05) inset;
}

* { box-sizing: border-box; }
/* The HTML `hidden` attribute must beat .chip / .btn / etc. (same specificity → cascade order wins). */
[hidden] { display: none !important; }
html, body {
  margin: 0;
  background: var(--bg-0);
  color: var(--t-0);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}
button:disabled { cursor: not-allowed; opacity: 0.5; }
input, select { font: inherit; color: inherit; }

/* ── Type helpers ────────────────────────────────────────────────── */
.mono { font-family: var(--mono); }
.sans { font-family: var(--sans); }
.t-up { text-transform: uppercase; letter-spacing: 0.08em; }
.t-mut { color: var(--t-2); }
.t-dim { color: var(--t-3); }
.t-acc { color: var(--blu); }
.t-yel { color: var(--acc); }
.t-vio { color: var(--vio); }
.t-warn { color: var(--warn); }

/* ── Layout helpers ──────────────────────────────────────────────── */
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.between { justify-content: space-between; }
.center { align-items: center; justify-content: center; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

/* ── Dot indicator ───────────────────────────────────────────────── */
.dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--acc);
  vertical-align: middle;
  flex-shrink: 0;
}
.dot.warn { background: var(--warn); }
.dot.bad  { background: var(--bad); }
.dot.dim  { background: var(--t-3); }
.dot.blu  { background: var(--blu); }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.dot.live { animation: pulse 1.4s ease-in-out infinite; }

/* ── Chip ────────────────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-2);
  color: var(--t-1);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  flex-shrink: 0;
}
.chip > * { white-space: nowrap; flex-shrink: 0; }
.chip.acc { background: var(--acc-bg); border-color: var(--acc-3); color: var(--acc); }
.chip.blu { background: var(--blu-bg); border-color: var(--blu-3); color: var(--blu); }
.chip.vio { background: var(--vio-bg); border-color: rgba(107,155,255,0.3); color: var(--vio); }
.chip.solid {
  background: var(--blu); border-color: var(--blu); color: #f5f6f8;
  font-weight: 600;
}
.chip.solid-yel {
  background: var(--acc); border-color: var(--acc); color: #1a1200;
  font-weight: 600;
}
.chip.ghost { background: transparent; }
.chip-sm { height: 22px; padding: 0 8px; font-size: 10px; }
.chip.button { cursor: pointer; }
.chip.button:hover { background: var(--bg-3); }
.chip.button.acc:hover { background: rgba(255, 203, 5, 0.16); }
.chip.button.vio:hover { background: rgba(107, 155, 255, 0.18); }
.chip.button.blu:hover { background: rgba(61, 107, 216, 0.18); }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-2);
  color: var(--t-0);
  font-family: var(--sans);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn > * { white-space: nowrap; flex-shrink: 0; }
.btn:hover { background: var(--bg-3); }
.btn.primary {
  background: var(--acc);
  color: #1a1200;
  border-color: var(--acc-2);
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(255,255,255,0.2) inset, 0 2px 0 rgba(0,0,0,0.3);
}
.btn.primary:hover { background: var(--acc-2); }
.btn.primary:disabled { background: var(--bg-3); color: var(--t-3); border-color: var(--line-2); box-shadow: none; }
.btn.primary-blu {
  background: var(--blu);
  color: #f5f6f8;
  border-color: var(--blu-2);
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(255,255,255,0.15) inset, 0 2px 0 rgba(0,0,0,0.4);
}
.btn.ghost { background: transparent; }
.btn.lg { height: 44px; padding: 0 22px; font-size: 14px; }

/* ── Card ────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
}

/* ── Shutter ─────────────────────────────────────────────────────── */
.shutter {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--bg-1);
  border: 2px solid var(--t-1);
  position: relative;
  cursor: pointer;
  box-shadow: var(--sh-2);
  flex-shrink: 0;
  padding: 0;
}
.shutter::after {
  content: '';
  position: absolute; inset: 5px;
  border-radius: 50%;
  background: var(--acc);
  box-shadow: 0 1px 0 rgba(255,255,255,0.3) inset, 0 2px 4px rgba(0,0,0,0.4);
  transition: all 0.18s ease;
}
.shutter.frozen::after {
  inset: 12px;
  border-radius: 4px;
  background: var(--blu);
}
.shutter:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Tool button ─────────────────────────────────────────────────── */
.tool {
  width: 40px; height: 40px;
  border-radius: var(--r-2);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  display: flex; align-items: center; justify-content: center;
  color: var(--t-1);
  font-family: var(--mono);
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}
.tool svg { display: block; }
.tool:hover { background: var(--bg-3); color: var(--t-0); }
.tool.active {
  background: var(--blu-bg);
  border-color: var(--blu-3);
  color: var(--blu);
  box-shadow: 0 0 0 1px var(--blu-3) inset;
}
.tool:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Slider ──────────────────────────────────────────────────────── */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 110px;
  height: 4px;
  background: var(--bg-3);
  border-radius: 2px;
  border: 1px solid var(--line);
  outline: none;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--t-0);
  border: 2px solid var(--blu);
  box-shadow: 0 2px 4px rgba(0,0,0,0.5);
  cursor: pointer;
}
.slider::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--t-0);
  border: 2px solid var(--blu);
  box-shadow: 0 2px 4px rgba(0,0,0,0.5);
  cursor: pointer;
}

/* ── Segmented control ──────────────────────────────────────────── */
.seg {
  display: inline-flex;
  padding: 3px;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: var(--r-2);
  flex-shrink: 0;
}
.seg button {
  padding: 5px 12px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--t-2);
  cursor: pointer;
  white-space: nowrap;
}
.seg button.on {
  background: var(--bg-3);
  color: var(--t-0);
  box-shadow: var(--sh-1);
}

/* ── Sheet handle ────────────────────────────────────────────────── */
.sheet-handle {
  width: 36px; height: 4px;
  border-radius: 2px;
  background: var(--line-3);
  margin: 8px auto;
}

/* ── Divider ─────────────────────────────────────────────────────── */
.div-h { height: 1px; background: var(--line); }

/* ── Photo placeholder background (when no image yet) ───────────── */
.photo-bg {
  background: linear-gradient(135deg, #20262e 0%, #181f29 50%, #10141c 100%);
  position: relative;
}
.photo-bg::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    radial-gradient(ellipse at 30% 40%, rgba(255,255,255,0.05), transparent 60%),
    radial-gradient(ellipse at 70% 70%, rgba(61, 107, 216, 0.04), transparent 60%);
  pointer-events: none;
}

/* ─────────────────────────────────────────────────────────────────
   Application layout
   ───────────────────────────────────────────────────────────────── */

#app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr auto auto;
  grid-template-areas: "stage" "side" "bottomnav";
  background: var(--bg-0);
}

#stage {
  grid-area: stage;
  position: relative;
  background: var(--bg-0);
  overflow: hidden;
  min-height: 0;
}

/* Inner frame holds the photo/video + overlays. Centered, contained. */
#frame {
  position: absolute; inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#frame[hidden] { display: none; }

#photo, #video {
  display: block;
  max-width: 100%;
  max-height: 100%;
  background: #000;
  object-fit: contain;
}
#photo[hidden], #video[hidden] { display: none; }

/* The bbox + overlay layer. position-aligned to the displayed media
   (sized via JS to track the visible rect of #photo / #video). */
#bboxLayer {
  position: absolute;
  pointer-events: none;       /* default; specific tools enable it */
  z-index: 5;
  touch-action: none;         /* drag bboxes without page-scrolling */
}
#bboxLayer.draw,
#bboxLayer.edit { pointer-events: auto; cursor: crosshair; }
.bbox { touch-action: none; }

/* Hint text when no media loaded */
#hint {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px;
  color: var(--t-2);
  font-family: var(--mono);
  font-size: 12px;
  text-align: center;
  padding: 24px;
  pointer-events: none;
}
#hint .big {
  font-family: var(--sans);
  font-size: 16px;
  color: var(--t-1);
  font-weight: 500;
}
#hint[hidden] { display: none; }

/* ── Top bar (overlay on stage) ─────────────────────────────────── */
#topbar {
  position: absolute;
  top: 12px; left: 12px; right: 12px;
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 8px;
  z-index: 10;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }

#topbar .left,
#topbar .right {
  display: flex; flex-wrap: wrap; gap: 8px;
  align-items: center;
}

/* Mobile / portrait: hide the right-side controls in topbar — those
   live in the bottom dock. The left side keeps minimal indicators
   (FROZEN chip, frame tag). */
@media (max-width: 1023px) {
  #topbar .right { display: none; }
  #topbar { top: 8px; left: 8px; right: 8px; }
}

#liveReadout {
  position: absolute;
  top: 56px; left: 12px;
  display: flex; gap: 8px;
  z-index: 10;
}
#liveReadout .chip {
  background: rgba(10,13,16,0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
#liveReadout[hidden] { display: none; }

#vinFallback {
  position: absolute;
  top: 92px;
  left: 12px;
  right: 12px;
  z-index: 12;
  pointer-events: none;
  background: rgba(10, 13, 16, 0.86);
  border: 1px solid rgba(255, 203, 5, 0.45);
  border-radius: var(--r-3);
  box-shadow: var(--sh-2);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--t-1);
  line-height: 1.4;
}
#vinFallback .title {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
  color: var(--acc);
  margin-bottom: 2px;
}
#vinFallback[hidden] { display: none; }

/* ── Tool rail (overlay) ─────────────────────────────────────────── */
#tools {
  position: absolute;
  top: 56px; right: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}
#tools .tool { width: 38px; height: 38px; }
#tools[hidden] { display: none; }

/* ── Shutter dock (overlay, capture controls only) ──────────────── */
#shutterDock {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 14px 16px 18px;
  background: linear-gradient(180deg, transparent, rgba(10,13,16,0.92) 50%);
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  z-index: 10;
  gap: 12px;
}
#shutterDock[hidden] { display: none; }
#shutterDock .flip-btn { grid-column: 1; justify-self: start; }
#shutterDock .shutter-wrap { grid-column: 2; }
#shutterDock .dock-spacer { grid-column: 3; }
#shutterDock .shutter-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
#shutterDock .shutter-label {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--acc);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
#shutterDock .shutter.frozen + .shutter-label,
#shutterDock .shutter-wrap.is-frozen .shutter-label {
  color: var(--blu);
}

/* Dock children visibility, driven by phase + source classes on #app. */
#app:not(.live).source-camera #shutterDock .flip-btn,
#app:not(.source-camera) #shutterDock .flip-btn { visibility: hidden; }

/* ── Bottom nav (mobile-only footer: mode + settings) ───────────── */
#bottomNav {
  grid-area: bottomnav;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-1);
  border-top: 1px solid var(--line);
  z-index: 11;
}
#bottomNav[hidden] { display: none; }

/* ── Coord readout (canvas overlay, desktop) ─────────────────────── */
#coords {
  position: absolute;
  bottom: 10px; left: 10px;
  background: rgba(10,13,16,0.8);
  border: 1px solid var(--line-2);
  color: var(--t-1);
  font-family: var(--mono);
  font-size: 10px;
  padding: 4px 8px;
  border-radius: 3px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 10;
  pointer-events: none;
  display: none;        /* desktop / landscape unhide it via media query */
}

/* ── Status (corner) ────────────────────────────────────────────── */
#status {
  position: absolute;
  bottom: 10px; right: 10px;
  background: rgba(10,13,16,0.8);
  border: 1px solid var(--line-2);
  color: var(--t-2);
  font-family: var(--mono);
  font-size: 10px;
  padding: 4px 8px;
  border-radius: 3px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 9;
  max-width: 50%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#status.error { color: var(--bad); border-color: rgba(232,93,93,0.5); }
#status.ok    { color: var(--good); border-color: rgba(111,207,126,0.4); }
#status:empty { display: none; }

/* ── Side panel (mobile bottom sheet / desktop right inspector) ──── */
#side {
  grid-area: side;
  background: var(--bg-1);
  border-top: 1px solid var(--line);
  box-shadow: 0 -16px 40px rgba(0,0,0,0.6);
  border-radius: 14px 14px 0 0;
  display: flex;
  flex-direction: column;
  max-height: 55vh;
  overflow: hidden;
  position: relative;
}
#side[hidden] { display: none; }

#side .sheet-handle { flex-shrink: 0; }

#sheetHeader {
  padding: 0 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}
#sheetHeader .meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#sheetHeader .meta .lbl {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--t-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
#sheetHeader .meta .ttl {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}

#sheetBody {
  padding: 12px 16px 16px;
  display: flex; flex-direction: column; gap: 12px;
  overflow-y: auto;
  min-height: 0;
}

.section-label {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--t-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.section-label .num { color: var(--blu); }

/* ── Class picker ───────────────────────────────────────────────── */
.class-pick {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Detection / low-conf cards inside the sheet ────────────────── */
.det-card {
  padding: 12px;
  background: var(--blu-bg);
  border: 1px solid var(--blu-3);
  border-radius: var(--r-3);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.det-card.empty { background: var(--bg-2); border-color: var(--line-2); }
.det-card .head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 6px;
}
.det-card .id {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.det-card .scores {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--blu);
  white-space: nowrap;
}
.det-card.manual { background: var(--vio-bg); border-color: rgba(107,155,255,0.4); }
.det-card.manual .scores { color: var(--vio); }

.lowconf-card {
  padding: 8px 10px;
  background: var(--det-low-bg);
  border: 1px dashed var(--line-2);
  border-radius: var(--r-3);
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.lowconf-card .info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lowconf-card .info .lbl {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--t-1);
  white-space: nowrap;
}
.lowconf-card .info .sub {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--t-2);
  white-space: nowrap;
}

/* ── Bbox layer styling ─────────────────────────────────────────── */
.bbox {
  position: absolute;
  border: 2px solid var(--det);
  border-radius: 2px;
  background: var(--det-bg);
  pointer-events: auto;
  cursor: move;
}
.bbox.low { border-style: dashed; border-color: var(--det-low); background: transparent; pointer-events: none; }
.bbox.manual { border-color: var(--vio); background: var(--vio-bg); border-style: dashed; }
.bbox.too-small { border-color: var(--acc); background: var(--acc-bg); border-style: dashed; }
.bbox.too-small .label { background: var(--acc); color: var(--bg-0); }

/* Centered yellow guide that shows the current "min bbox size"
   threshold at the right scale relative to the displayed video.
   Visible while the settings popup is open. */
#minBboxGuide {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: 2px dashed var(--acc);
  background: var(--acc-bg);
  pointer-events: none;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
}
.bbox-guide-label {
  background: var(--acc);
  color: var(--bg-0);
  padding: 2px 6px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  border-radius: 2px;
  white-space: nowrap;
}
.bbox.selected { box-shadow: 0 0 0 1px var(--blu) inset, 0 0 12px rgba(61,107,216,0.5); }
.bbox .label {
  position: absolute; top: -22px; left: -2px;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 6px;
  background: var(--blu);
  color: #f5f6f8;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  border-radius: 2px;
  white-space: nowrap;
}
.bbox.low .label { background: rgba(107,116,128,0.85); }
.bbox.manual .label { background: var(--vio); color: var(--bg-0); }
.bbox .handle {
  position: absolute;
  width: 12px; height: 12px;
  background: var(--bg-0);
  border: 2px solid var(--blu);
  border-radius: 1px;
  z-index: 3;
  transform: translate(-50%, -50%);
}
.bbox.manual .handle { border-color: var(--vio); }
.bbox .handle.nw { left: 0;    top: 0; cursor: nwse-resize; }
.bbox .handle.ne { left: 100%; top: 0; cursor: nesw-resize; }
.bbox .handle.sw { left: 0;    top: 100%; cursor: nesw-resize; }
.bbox .handle.se { left: 100%; top: 100%; cursor: nwse-resize; }
.bbox .delete {
  position: absolute;
  top: -22px; right: -2px;
  width: 22px; height: 22px;
  border-radius: 2px;
  background: rgba(10,13,16,0.85);
  border: 1px solid var(--line-2);
  color: var(--bad);
  font-family: var(--mono);
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.bbox .delete:hover { background: rgba(232,93,93,0.2); }

/* drag-to-draw ghost */
#drawGhost {
  position: absolute;
  border: 2px dashed var(--vio);
  background: var(--vio-bg);
  border-radius: 2px;
  pointer-events: none;
  z-index: 6;
}
#drawGhost[hidden] { display: none; }

/* ── Settings sheet (popover) ────────────────────────────────────── */
#settingsSheet {
  position: absolute;
  top: 56px; right: 10px;
  width: 240px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-3);
  box-shadow: var(--sh-3);
  padding: 12px 14px;
  z-index: 20;
  display: flex; flex-direction: column; gap: 10px;
}
#settingsSheet[hidden] { display: none; }
#settingsSheet label {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--t-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
#settingsSheet .row { gap: 8px; }
#settingsSheet input[type="text"] {
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: var(--r-2);
  padding: 6px 8px;
  color: var(--t-0);
  width: 100%;
  font-size: 12px;
}

/* ── Shortcuts list (desktop only) ──────────────────────────────── */
#shortcuts { display: none; }

/* ─────────────────────────────────────────────────────────────────
   Mobile landscape — side rail
   ───────────────────────────────────────────────────────────────── */
@media (orientation: landscape) and (max-width: 1023px) {
  #coords { display: block; }
  #app {
    grid-template-columns: 1fr 250px;
    grid-template-rows: 1fr auto;
    grid-template-areas:
      "stage     side"
      "bottomnav bottomnav";
  }
  #side {
    max-height: none;
    height: 100%;
    border-radius: 0;
    border-top: none;
    border-left: 1px solid var(--line);
    box-shadow: -16px 0 40px rgba(0,0,0,0.4);
  }
  #side .sheet-handle { display: none; }
  #sheetHeader { padding: 12px 12px 8px; }
  #sheetHeader .meta .ttl { font-size: 13px; }
  #sheetBody { padding: 8px 12px 14px; }

  /* Tool rail moves to bottom-left of stage */
  #tools {
    flex-direction: row;
    top: auto; bottom: 80px; left: 10px; right: auto;
  }
  #tools .tool { width: 34px; height: 34px; font-size: 12px; }

  #shutterDock { padding: 8px 12px 12px; }
  #shutterDock .shutter { width: 56px; height: 56px; }
}

/* ─────────────────────────────────────────────────────────────────
   Desktop — top toolbar + left tool rail + right inspector
   ───────────────────────────────────────────────────────────────── */
@media (min-width: 1024px) {
  #coords { display: block; }
  #app {
    grid-template-columns: 56px 1fr 280px;
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "topbar topbar topbar"
      "tools  stage  side";
  }
  #bottomNav { display: none; }
  #topbar {
    grid-area: topbar;
    position: static;
    padding: 10px 14px;
    background: var(--bg-1);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
    pointer-events: auto;
  }
  #topbar > * { pointer-events: auto; }

  #liveReadout {
    position: static;
    margin: 0;
  }
  #liveReadout .chip {
    background: var(--bg-2);
    backdrop-filter: none;
  }

  #vinFallback {
    left: 24px;
    right: 24px;
    top: 16px;
    max-width: 640px;
  }

  #tools {
    grid-area: tools;
    position: static;
    flex-direction: column;
    align-items: center;
    padding: 12px 8px;
    gap: 8px;
    background: var(--bg-1);
    border-right: 1px solid var(--line);
  }
  #tools .tool { width: 40px; height: 40px; }

  #stage {
    grid-area: stage;
    padding: 16px;
  }
  #frame {
    inset: 16px;
  }
  #photo, #video {
    border-radius: var(--r-2);
  }

  #side {
    grid-area: side;
    max-height: none;
    height: 100%;
    border-radius: 0;
    border-top: none;
    border-left: 1px solid var(--line);
    box-shadow: none;
  }
  #side .sheet-handle { display: none; }
  #sheetHeader { padding: 14px 14px 10px; }
  #sheetBody { padding: 10px 14px 16px; }

  /* Shutter dock on desktop — bottom-center over the stage */
  #shutterDock {
    background: none;
    padding: 0;
    left: 0; right: 0; bottom: 16px;
    display: flex;
    justify-content: center;
  }
  #shutterDock .shutter { width: 56px; height: 56px; }
  #shutterDock .flip-btn,
  #shutterDock .settings-btn,
  #shutterDock #modeSegMobile { display: none; }

  #shortcuts {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--line);
  }
  #shortcuts .row {
    justify-content: space-between;
    font-family: var(--mono);
    font-size: 10px;
    color: var(--t-2);
  }
  #shortcuts .row .key {
    background: var(--bg-2);
    border: 1px solid var(--line-2);
    border-radius: 3px;
    padding: 1px 6px;
    color: var(--t-1);
  }
}

/* ── Model-input debug panel (?debug=1) ─────────────────────── */
#debugPanel {
  position: fixed;
  right: 12px;
  bottom: 12px;
  width: 280px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: var(--r-2);
  padding: 10px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.dbg-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dbg-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dbg-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--t-2);
}
.dbg-meta {
  font-size: 9px;
  color: var(--t-3);
}
#dbgDet {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  background: rgb(114, 114, 114);
  border: 1px solid var(--line-2);
  border-radius: var(--r-2);
  display: block;
  image-rendering: pixelated;
}
.dbg-cls-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.dbg-cls-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.dbg-cls-tile canvas {
  width: 64px;
  height: 64px;
  background: black;
  border: 1px solid var(--line-2);
  border-radius: var(--r-2);
  image-rendering: pixelated;
}
.dbg-cls-cap {
  font-size: 9px;
  color: var(--t-2);
}
