/* ============================================================
   DESIGN TOKENS
   Utilitarian + accessible first, light theme, one vivid accent.
   ============================================================ */
:root {
  /* Light palette: white viewport, dark ink, hairline borders. Separation
     comes from hairlines and a soft shadow rather than fill contrast. */
  /* 3D viewport clear colour. js/scene.js reads this at startup; the page
     background follows it so the canvas never flashes a different colour. */
  --scene-bg: #ffffff;
  --bg: var(--scene-bg);
  --bg-panel: #ffffff;
  --bg-panel-alt: #f7f8fa;
  --bg-elev: #f1f3f6;
  --bg-hover: rgba(0, 0, 0, 0.08);

  --border: rgba(0, 0, 0, 0.10);
  --border-interactive: rgba(0, 0, 0, 0.20);

  /* Darkened from #0576fe so the accent still carries white button text and
     reads as an accent against white, not as a wash. */
  --accent: #0b63ce;
  --accent-press: #0952ab;
  --danger: #d92d4b;

  --radius: 16px;
  --radius-sm: 10px;

  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.10);
  --shadow-glow: 0 0 22px rgba(11, 99, 206, 0.22);
  /* The cards are white on a white viewport, so fill contrast does nothing to
     separate them either: a soft, wide shadow lifts them off the page. */
  --shadow-black: 0 18px 48px rgba(0, 0, 0, 0.14), 0 2px 12px rgba(0, 0, 0, 0.08);

  /* Vertical space the bottom trails bar occupies, so the info card can sit
     just above it without hard-coding the bar's height in two places. */
  --trails-bar-h: 230px;

  /* Width of the right-hand caption sidebar. Shared with the icon cluster's
     offset so the two never overlap. */
  --info-w: 340px;

  --font: 'Inter', system-ui, -apple-system, sans-serif;
  /* Commands, embeddings and numeric formula fields: one stack everywhere, so
     the monospace surfaces read as one family. */
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;

  /* 1.250 Major Third scale */
  --fs-xl: 1.5625rem; /* 25px */
  --fs-lg: 1.25rem;   /* 20px */
  --fs-md: 1rem;      /* 16px */
  --fs-base: 0.875rem;/* 14px */
  --fs-sm: 0.75rem;   /* 12px */
  --fs-xs: 0.7rem;    /* 11.2px */

  /* Uppercase micro-labels (panel labels, search categories, dialog headers).
     One role, so one size and one tracking, rather than three near-misses. */
  --fs-label: var(--fs-xs);
  --tracking-label: 0.08em;

  /* Glyph-only controls, in two steps: the ✕/⌄ chips and the icon cluster.
     Same glyph, same size — a magnifier or a cross must not change size
     depending on which panel it landed in. */
  --fs-icon: 1rem;     /* 16px */
  --fs-icon-sm: 0.8rem;/* 12.8px */

  --lh-body: 1.55;
  --lh-heading: 1.2;

  /* Snappy, tactile motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --t-fast: 0.18s;
}

/* ============================================================
   BASE
   ============================================================ */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  overflow: hidden;
  background-color: var(--bg);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  /* Ink, not paper: these are the light-theme text tokens. */
  --text: #111827;
  --text-dim: #374151;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
}

/* The bar ships collapsed and only ~48px of it is left, so the panels that
   float above it can reclaim the rest. */
body.trails-collapsed {
  --trails-bar-h: 48px;
}

#canvas-container {
  width: 100vw;
  height: 100vh;
}

h1,
h2,
h3,
.panel-title,
.help-title {
  line-height: var(--lh-heading);
  letter-spacing: -0.01em;
}

h2 {
  margin: 0 0 8px 0;
  font-size: var(--fs-lg);
  font-weight: 800;
  color: var(--text);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================================
   SETTINGS CARD (pinned to the left edge, always visible)
   ============================================================ */
#ui-panel {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 268px;
  max-width: calc(100vw - 40px);
  /* Keep the card clear of the bottom trails bar: ~230px tall expanded, ~48px
     collapsed. */
  max-height: calc(100vh - 330px);
  overflow-y: auto;
  z-index: 30;
  padding: 14px 18px 16px;
  /* Pure black, same as the viewport: the shadow does the separating. */
  background: var(--scene-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-black);
}

/* The bar ships collapsed, so the card can reclaim the vertical space the
   expanded bar would have needed. */
body.trails-collapsed #ui-panel {
  max-height: calc(100vh - 150px);
}

#ui-panel::-webkit-scrollbar,
#info-panel::-webkit-scrollbar {
  width: 3px;
}
#ui-panel::-webkit-scrollbar-track,
#info-panel::-webkit-scrollbar-track {
  background: transparent;
}
#ui-panel::-webkit-scrollbar-thumb,
#info-panel::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 2px;
}

.btn-group {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  margin-top: 6px;
  margin-bottom: 10px;
}

#model-select {
  width: 100%;
  margin-top: 6px;
  margin-bottom: 2px;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border-interactive);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-family: inherit;
  font-weight: 700;
  font-size: var(--fs-xs);
  cursor: pointer;
  outline: none;
  transition: border-color var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease);
}

#model-select:hover,
#model-select:focus {
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
}

button {
  flex: 1;
  white-space: nowrap;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border-interactive);
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: var(--fs-xs);
  line-height: 1.3;
  transition: border-color var(--t-fast) var(--ease),
    background var(--t-fast) var(--ease), color var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}

button:hover:not(:disabled) {
  background: rgba(5, 118, 254, 0.18);
  border-color: var(--accent);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button.active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-glow);
  font-weight: 800;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.panel-label {
  margin: 10px 0 0 0;
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-dim);
  line-height: 1.4;
}

/* ============================================================
   SEARCH
   ============================================================ */
#spotlight-modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  /* Never block the scene: clicks fall through to the images behind. */
  pointer-events: none;
}

#spotlight-modal.hidden {
  display: none;
}

#spotlight-backdrop {
  position: absolute;
  inset: 0;
  /* No blur, no dimming: just a soft light behind the box so the images
     stay fully visible and interactive. */
  background: radial-gradient(ellipse at center,
    rgba(255, 255, 255, 0.7) 0%,
    rgba(255, 255, 255, 0.4) 40%,
    rgba(255, 255, 255, 0) 68%);
  pointer-events: none;
}

#spotlight-box {
  position: relative;
  width: 620px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.12);
  /* The box itself stays fully interactive. */
  pointer-events: auto;
}

#spotlight-drag-handle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  cursor: grab;
  user-select: none;
  touch-action: none;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  color: var(--text-dim);
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  flex-shrink: 0;
}

#spotlight-drag-handle.dragging {
  cursor: grabbing;
}

.spotlight-drag-grip {
  font-size: var(--fs-icon);
  letter-spacing: 0;
  opacity: 0.6;
}

#spotlight-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  margin: 14px 14px 0;
}

.spotlight-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--fs-icon);
  opacity: 0.7;
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 10px 44px 10px 38px;
  background: rgba(0, 0, 0, 0.08);
  border: 1px solid var(--border-interactive);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: var(--fs-md);
  font-family: inherit;
  outline: none;
  transition: border-color var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}

#search-input::placeholder {
  color: var(--text-muted);
}

#search-input:focus {
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
  background: rgba(0, 0, 0, 0.11);
}

#search-shortcut {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--fs-sm);
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.09);
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  pointer-events: none;
  font-weight: 600;
}

#search-loading {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
}

.spinner-small {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 30%, var(--accent));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 360px;
  overflow-y: auto;
  z-index: 30;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.14);
  scrollbar-width: thin;
  scrollbar-color: var(--accent) transparent;
  display: none;
}

#search-results::-webkit-scrollbar {
  width: 4px;
}
#search-results::-webkit-scrollbar-track {
  background: transparent;
}
#search-results::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 2px;
}

#search-results-list {
  padding: 4px 0;
}

.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background var(--t-fast) var(--ease);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.search-result-item:hover,
.search-result-item.selected {
  background: rgba(5, 118, 254, 0.12);
}

.search-result-item .result-info {
  flex: 1;
  overflow: hidden;
  min-width: 0;
}

.search-result-item .result-name {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-item .result-caption {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
  max-width: 65ch;
}

.search-result-item .result-caption .highlight {
  color: var(--accent);
  font-weight: 700;
}

.search-result-item .result-score {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-dim);
  padding: 2px 9px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 20px;
  flex-shrink: 0;
}

.search-suggestions {
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
}

.search-suggestion {
  padding: 5px 12px;
  background: rgba(5, 118, 254, 0.08);
  border: 1px solid rgba(5, 118, 254, 0.35);
  border-radius: 20px;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}

.search-suggestion:hover {
  background: rgba(5, 118, 254, 0.18);
  color: var(--accent);
  border-color: var(--accent);
}

.search-empty {
  padding: 22px;
  text-align: center;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  max-width: 65ch;
  margin: 0 auto;
}

.search-empty .icon {
  font-size: var(--fs-xl);
  margin-bottom: 8px;
  opacity: 0.5;
}

.search-category {
  padding: 6px 14px;
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-faint);
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
}

#search-stats {
  padding: 6px 14px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  border-top: 1px solid rgba(0, 0, 0, 0.07);
  text-align: center;
  display: none;
}

#spotlight-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: var(--fs-xs);
  color: var(--text-dim);
}

#spotlight-footer span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

#spotlight-footer kbd {
  font-family: inherit;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text);
  background: rgba(0, 0, 0, 0.09);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
}

/* ============================================================
   INFO SIDEBAR (right edge, follows the current selection)
   ============================================================ */
/* A right-hand column rather than a floating card under the image: the caption
   and the authored IPTC/XMP rows are long, and a fixed column reads them
   without covering the picture being looked at. Hidden until something is
   selected, so it never reserves space for nothing. */
/* Docked to the right edge and full height, the way a sidebar reads: no
   radius, no shadow, no floating card. Separation from the viewport is a single
   hairline and a slightly cooler fill. */
#info-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: var(--trails-bar-h);
  width: min(var(--info-w), calc(100vw - 40px));
  overflow-y: auto;
  z-index: 25;
  padding: 22px 24px 28px;
  display: none;
  text-align: left;
  background: var(--bg-panel-alt);
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 0;
  box-shadow: none;
}

/* The search/help glyphs own the top-right corner, so they move left while the
   sidebar is open instead of sitting inside it. */
body.info-open #image-count-help-panel {
  right: calc(var(--info-w) + 24px);
}

#info-panel .caption-text {
  /* This is the panel's primary content now, so it reads at body size rather
     than as a caption. Right padding clears the ✕. */
  padding-right: 34px;
  color: var(--text-dim);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
}

#info-meta {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* With no caption the tags are the first thing in the card, so drop the
   divider that would otherwise float above them. */
#info-caption:empty + #info-meta {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

#info-panel .meta-row {
  /* Stacked rather than label-left/value-right: in a 340px column the values
     ("Miglionico, Matera, Italia", keyword lists) wrap badly when pushed to
     the right edge. */
  display: block;
  padding: 7px 0;
  font-size: var(--fs-xs);
}

#info-panel .meta-row dt {
  color: var(--text-muted);
  margin-bottom: 2px;
}

#info-panel .meta-row dd {
  margin: 0;
  color: var(--text-dim);
  word-break: break-word;
}

/* Shared ✕ used by the info card (absolutely positioned over its top-right
   corner) and the debug panel header (inline in the header row). */
.close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  flex: none;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-dim);
  font-size: var(--fs-icon-sm);
  line-height: 1;
  cursor: pointer;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}

.close-btn:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.10);
}

#info-panel .close-btn {
  position: absolute;
  top: 10px;
  right: 12px;
}

/* ============================================================
   DEBUG PANEL (hidden by default — hosts the render controls)
   ============================================================ */
#debug-panel {
  position: absolute;
  top: 74px;
  /* Right, not left: the settings card owns the left edge now. */
  right: 32px;
  width: 268px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding: 12px 14px 14px;
  background: var(--bg-panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  z-index: 30;
}

#debug-panel.hidden {
  display: none;
}

#debug-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

#debug-panel-header .panel-title {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text);
}

/* The fps readout takes the auto margin, so it and the ✕ sit together on the
   right while the title stays left. */
#debug-fps {
  margin-left: auto;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-muted);
  /* Tabular figures: the number must not jitter as it changes. */
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

#debug-panel-header .close-btn {
  margin-left: 0;
  width: 22px;
  height: 22px;
  background: transparent;
}

#debug-panel-header .close-btn:hover {
  background: var(--bg-hover);
}

/* lil-gui ships its own fixed-position styling for the autoPlace case; hosted
   in a container it is a plain block, so it only needs to fill the panel and
   borrow the app's palette. */
#debug-panel-body .lil-gui {
  --width: 100%;
  --background-color: var(--bg-panel-alt);
  --widget-color: var(--bg-elev);
  --title-background-color: var(--bg-elev);
  --hover-color: var(--bg-hover);
  /* lil-gui paints `focus-color` behind focused widgets while the text stays
     `text-color`, so the accent itself would give dark-on-dark-blue. A tint of
     it keeps the focus affordance and the contrast. */
  --focus-color: rgba(11, 99, 206, 0.16);
  --number-color: #0b63ce;
  --string-color: #0b63ce;
  /* Both default to #ebebeb in lil-gui. Left alone they are near-white text on
     the light panel above. */
  --text-color: var(--text);
  --title-text-color: var(--text);
  /* lil-gui brings its own typefaces (system sans, Menlo mono). Point them at
     the app's so the debug panel is not a second type system. The sizes are
     left alone: lil-gui's 11px is within a rounding error of --fs-xs, and its
     touch stylesheet raises them on purpose. */
  --font-family: var(--font);
  --font-family-mono: var(--font-mono);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

/* ============================================================
   LOADING
   ============================================================ */
#loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--accent);
  font-size: var(--fs-md);
  font-weight: 800;
  line-height: var(--lh-heading);
  z-index: 5;
  text-align: center;
}

#loading .spinner {
  display: inline-block;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 25%, var(--accent));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  animation: spin 1s linear infinite;
  margin-bottom: 14px;
}

.error-title {
  color: var(--danger);
  font-weight: 800;
  line-height: var(--lh-heading);
}

.error-message {
  font-size: var(--fs-sm);
  margin-top: 8px;
  color: var(--text-dim);
  max-width: 65ch;
}

.error-hint {
  font-size: var(--fs-xs);
  margin-top: 12px;
  color: var(--text-muted);
  max-width: 65ch;
}

/* ============================================================
   TOP RIGHT (icon cluster)
   ============================================================ */
#image-count-help-panel {
  position: absolute;
  top: 26px;
  right: 32px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 29px;
  z-index: 20;
}

/* The reference draws these as bare glyphs with no button chrome, so the only
   affordance is the colour shift on hover. */
.icon-btn {
  flex: none;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #78808c;
  font-size: var(--fs-icon);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}

.icon-btn:hover,
.icon-btn[aria-expanded='true'] {
  color: var(--text);
  background: var(--bg-hover);
}

/* ============================================================
   HELP OVERLAY
   ============================================================ */
#help-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

#help-overlay.visible {
  display: flex;
}

#help-box {
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 30px;
  min-width: 340px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.12);
}

#help-box .help-title {
  font-size: var(--fs-lg);
  font-weight: 800;
  color: var(--text);
  margin-bottom: 16px;
}

#help-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.help-key {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: var(--fs-base);
  color: var(--text-dim);
}

.help-key .kbd {
  flex: 0 0 auto;
  min-width: 68px;
  text-align: center;
  background: var(--bg-elev);
  border: 1px solid var(--border-interactive);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text);
}

.help-note {
  margin-top: 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.10);
  padding-top: 12px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  max-width: 65ch;
}

/* ============================================================
   TOAST
   ============================================================ */
#toast {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border-interactive);
  border-radius: 10px;
  padding: 10px 20px;
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--text);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
  box-shadow: var(--shadow-glow);
}

#toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   TRAILS BOTTOM BAR
   ============================================================ */
#trails-panel {
  position: absolute;
  /* Full-bleed bar flush with the viewport edge, not a floating card: no side
     margins, no radius, no boxed border. Black on black matches the viewport
     background, so the top hairline is the only separator it needs. */
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 15;
  padding: 10px 20px 12px;
  background: var(--scene-bg);
  border-top: 1px solid var(--border);
}

/* Collapsing hides the cards but keeps the header, so the chevron stays
   clickable and the bar can always be reopened. */
#trails-panel.collapsed #trails-list,
#trails-panel.collapsed #trails-empty {
  display: none;
}

/* With the cards gone the header is the entire bar, so drop the gap that
   normally separates it from the list. */
#trails-panel.collapsed #trails-header {
  margin-bottom: 0;
}

#trails-empty {
  padding: 12px 2px 4px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

#trails-empty[hidden] {
  display: none;
}

#trails-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

/* Card header, same weight and tracking as the debug panel's and the parallax
   form's titles. */
#trails-header .trails-title {
  font-size: var(--fs-sm);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

#trails-collapse-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: var(--fs-icon-sm);
  line-height: 1;
  cursor: pointer;
  transition: color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}

#trails-collapse-btn:hover {
  color: var(--text);
}

#trails-panel.collapsed #trails-collapse-btn {
  transform: rotate(180deg);
}

#trails-count {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  background: var(--bg-hover);
  border-radius: 999px;
  padding: 1px 8px;
}

#new-trail-btn {
  flex: none;
  margin-left: auto;
  padding: 5px 12px;
  border-radius: 999px;
}

#trails-list {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
}

#trails-list::-webkit-scrollbar {
  height: 3px;
}
#trails-list::-webkit-scrollbar-track {
  background: transparent;
}
#trails-list::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 2px;
}

.trail-item {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 132px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}

.trail-item.active {
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
}

.trail-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  cursor: pointer;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--border-interactive);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
  background: var(--bg-panel-alt);
}

.trail-thumb:hover {
  border-color: var(--accent) !important;
  box-shadow: 0 0 10px rgba(5, 118, 254, 0.4);
}

.trail-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.trail-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.trail-name {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trail-count {
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

.trail-dot {
  position: absolute;
  bottom: 4px;
  left: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

.trail-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.06);
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: var(--fs-icon-sm);
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity var(--t-fast) var(--ease), color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
  flex: none;
}

.trail-thumb:hover .trail-delete {
  opacity: 1;
}

.trail-delete:hover {
  color: var(--danger);
  background: rgba(0, 0, 0, 0.10);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
/* Below this width a right-hand column would leave too little canvas, so the
   info sidebar turns back into a bottom sheet. */
@media (max-width: 900px) {
  #info-panel {
    top: auto;
    left: 12px;
    right: 12px;
    width: auto;
    bottom: calc(var(--trails-bar-h) + 12px);
    max-height: 40vh;
    /* Back to a floating sheet: at this width a docked column would eat the
       canvas, and the icons stay in their corner. */
    background: var(--scene-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-black);
  }
  body.info-open #image-count-help-panel {
    right: 12px;
  }
}

@media (max-width: 640px) {
  /* The settings card hugs the left edge at a reduced width instead of
     spanning the viewport. */
  #ui-panel,
  body.trails-collapsed #ui-panel {
    top: 64px;
    left: 10px;
    width: min(268px, calc(100vw - 20px));
    max-width: none;
    /* The trails bar is hidden at this width, so only the bottom icon cluster
       needs clearing. */
    max-height: calc(100vh - 120px);
  }
  /* The trails bar is hidden here, so clear the bottom-right icon cluster
     instead of the bar. */
  #info-panel {
    left: 10px;
    right: 10px;
    bottom: 56px;
    max-height: 38vh;
  }
  #debug-panel {
    top: 64px;
    left: 10px;
    right: 10px;
    width: auto;
    max-width: none;
  }
  button {
    font-size: var(--fs-sm);
    padding: 7px 8px;
  }
  #trails-panel {
    display: none;
  }
  #search-input {
    font-size: var(--fs-sm);
    padding: 8px 34px 8px 38px;
  }
  #search-shortcut {
    display: none;
  }
  /* The trails bar is hidden at this width, so nothing to clear. */
  #image-count-help-panel {
    top: auto;
    bottom: 10px;
    right: 10px;
  }
  #image-count {
    font-size: var(--fs-xs);
    padding: 5px 10px;
  }
  #help-box {
    min-width: 280px;
    padding: 22px 20px;
  }
}

/* ============================================================
   PARALLAX FORMULA (inline, under the model dropdown)
   ============================================================ */
#parallax-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#parallax-section.hidden {
  display: none;
}

.parallax-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.parallax-title {
  font-size: var(--fs-sm);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.parallax-badge {
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 12px;
  background: rgba(14, 116, 144, 0.10);
  color: #0e7490;
  border: 1px solid rgba(14, 116, 144, 0.30);
}

.parallax-presets {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-xs);
  color: var(--text-dim);
}

.parallax-presets select {
  flex: 1;
  min-width: 0; /* let a long preset name truncate instead of widening the card */
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: var(--fs-xs);
  outline: none;
  cursor: pointer;
}

.parallax-presets select:focus {
  border-color: #6d28d9;
}

.parallax-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.parallax-field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.10);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
}

.parallax-field:focus-within {
  border-color: #6d28d9;
  box-shadow: 0 0 0 2px rgba(167, 139, 250, 0.2);
}

.axis-tag {
  font-size: var(--fs-xs);
  font-weight: 800;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  flex-shrink: 0;
}

.axis-x { background: rgba(3, 105, 161, 0.12); color: #0369a1; }
.axis-y { background: rgba(21, 128, 61, 0.12); color: #15803d; }
.axis-z { background: rgba(109, 40, 217, 0.12); color: #6d28d9; }

.parallax-field input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  outline: none;
}

.parallax-field select {
  flex: 1;
  min-width: 0;
  background: transparent;
  color: var(--text);
  border: none;
  outline: none;
  font-family: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
  padding: 2px 0;
}

.parallax-field select:focus {
  color: var(--accent);
}

.parallax-field .polarity {
  flex-shrink: 0;
  font-size: var(--fs-xs);
  color: var(--text-dim);
}

.axis-field {
  gap: 6px;
}

.parallax-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.parallax-actions button {
  flex: 1;
  font-size: var(--fs-xs);
  padding: 6px 10px;
}

#btn-parallax-axes {
  flex: 0 0 auto;
  width: 34px;
  padding: 6px 0;
  background: rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.12);
  color: var(--text-dim);
}

#btn-parallax-axes.active {
  background: rgba(167, 139, 250, 0.15);
  border-color: #6d28d9;
  color: #6d28d9;
}

