﻿/* ============================================================
   BASE RESET
============================================================ */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; }
input, button { font-family: var(--font-ui); }
img { display: block; max-width: 100%; }

/* ============================================================
   CSS VARIABLES — LIGHT MODE (default)
============================================================ */
:root {
  --font-ui:      'DM Mono', monospace;
  --font-display: 'Cormorant Garamond', serif;

  --bg:           #F7F5F2;
  --bg-panel:     #F2F0ED;
  --bg-card:      #EEECEA;
  --ink:          #1A1A18;
  --ink-2:        #6B6960;
  --ink-3:        #B0ADA6;
  --accent:       #C8B89A;
  --line:         rgba(26,26,24,0.08);
  --line-strong:  rgba(26,26,24,0.16);
}

/* ============================================================
   DARK MODE — system preference
============================================================ */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #0E0E0D;
    --bg-panel:     #141413;
    --bg-card:      #1C1C1A;
    --ink:          #E8E6E1;
    --ink-2:        #7A7870;
    --ink-3:        #3A3935;
    --accent:       #C8B89A;
    --line:         rgba(232,230,225,0.07);
    --line-strong:  rgba(232,230,225,0.14);
  }
}

/* DARK MODE — manual toggle */
body.dark {
  --bg:           #0E0E0D;
  --bg-panel:     #141413;
  --bg-card:      #1C1C1A;
  --ink:          #E8E6E1;
  --ink-2:        #7A7870;
  --ink-3:        #3A3935;
  --accent:       #C8B89A;
  --line:         rgba(232,230,225,0.07);
  --line-strong:  rgba(232,230,225,0.14);
}

/* ============================================================
   SCROLLBARS
============================================================ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 0;
}

/* ============================================================
   LAYOUT
============================================================ */
html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}

#app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  position: relative;
}

#sidebar {
  width: 240px;
  flex-shrink: 0;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  gap: 24px;
}

#canvas {
  flex: 1;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  position: relative;
  transition: opacity 0.2s ease;
}

/* Restrict scroll in board and 3D modes */
#canvas.view-board,
#canvas.view-3d {
  overflow: hidden;
}

#panel {
  width: 280px;
  flex-shrink: 0;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg-panel);
  border-left: 1px solid var(--line);
  padding: 24px 20px;
  transform: translateX(100%);
  transition: transform 0.4s ease;
}

#panel.open {
  transform: translateX(0);
}

/* ============================================================
   COMPONENT — LOGO
============================================================ */
.logo {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 300;
  font-style: italic;
  color: var(--ink);
  letter-spacing: 0.02em;
}

/* ============================================================
   COMPONENT — SEARCH INPUT
============================================================ */
.search-input {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 300;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line-strong);
  width: 100%;
  padding: 8px 0;
  outline: none;
  caret-color: var(--accent);
}

.search-input::placeholder { color: var(--ink-3); }
.search-input:focus { border-bottom-color: var(--accent); }

.search-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.search-row .search-input {
  flex: 1;
  min-width: 0;
}

.search-mode-toggle {
  font-family: var(--font-ui);
  font-size: 9px;
  font-weight: 300;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--line-strong);
  padding: 6px 10px;
  line-height: 1;
  white-space: nowrap;
  transition: border-color 0.3s ease, color 0.3s ease, opacity 0.3s ease;
}

.search-mode-toggle:hover { opacity: 0.6; }

.search-mode-toggle.exact {
  border-color: rgba(95, 172, 110, 0.65);
  color: #5fac6e;
}

/* ============================================================
   COMPONENT — TAG PILL
============================================================ */
.tag {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--line-strong);
  padding: 3px 8px;
  cursor: pointer;
  transition: opacity 0.3s ease;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.tag:hover { opacity: 0.5; }

.tag.active {
  color: var(--ink);
  border-color: var(--accent);
  font-weight: 400;
}

.tag.ai {
  border-style: dashed;
  color: var(--accent);
}

/* Keyword pills container */
#keyword-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 0;
}

#cache-indicator {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 0 2px 0;
}

#cache-indicator #cache-age-text {
  font-family: var(--font-ui);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: lowercase;
  color: var(--ink-3);
  flex: 1;
}

#cache-indicator #btn-refresh-cache {
  width: auto;
  padding: 3px 8px;
  font-size: 12px;
  line-height: 1;
  flex-shrink: 0;
}

#more-container {
  display: none;
  justify-content: center;
  padding: 24px 0;
  grid-column: 1 / -1;
}

#btn-load-more {
  width: auto;
  padding: 8px 32px;
  text-align: center;
}

/* ============================================================
   COMPONENT — UI BUTTON
============================================================ */
.btn {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 0.1em;
  text-transform: lowercase;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--line);
  padding: 6px 12px;
  cursor: pointer;
  transition: opacity 0.3s ease;
  width: 100%;
  text-align: left;
}

.btn:hover { opacity: 0.5; }

.btn.active {
  color: var(--ink);
  border-color: var(--line-strong);
  font-weight: 400;
}

/* View toggle button group */
.btn-group {
  display: flex;
  gap: 4px;
}

.btn-group .btn {
  flex: 1;
  text-align: center;
}

/* ============================================================
   COMPONENT — SECTION LABEL
============================================================ */
.section-label {
  font-family: var(--font-ui);
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 8px;
}

/* ============================================================
   COMPONENT — SLIDER
============================================================ */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1px;
  background: var(--line-strong);
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  background: var(--ink);
  cursor: pointer;
  border-radius: 0;
}

.slider::-moz-range-thumb {
  width: 10px;
  height: 10px;
  background: var(--ink);
  cursor: pointer;
  border-radius: 0;
  border: none;
}

/* ============================================================
   COMPONENT — DIVIDER
============================================================ */
.divider {
  width: 100%;
  height: 1px;
  background: var(--line);
  flex-shrink: 0;
}

/* ============================================================
   COMPONENT — COLOR DOT (palette extraction)
============================================================ */
.color-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s ease;
  border: 1px solid var(--line);
}
.color-dot:hover {
  transform: scale(1.25);
  z-index: 10;
}
.color-dot.copied {
  animation: dotCopied 0.4s ease;
}
@keyframes dotCopied {
  0%   { transform: scale(1.25); }
  50%  { transform: scale(1.5); }
  100% { transform: scale(1.25); }
}
.color-dot-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 10px;
  font-family: var(--font-ui);
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.15s ease;
  text-align: center;
  line-height: 1.4;
}
.color-dot:hover .color-dot-tooltip {
  opacity: 1;
}
.dot-name {
  display: block;
  color: var(--ink-2);
}
.dot-hex {
  display: block;
  color: var(--ink-3);
  letter-spacing: 0.05em;
}
.dot-copied-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 14px;
  color: #fff;
  text-shadow: 0 0 4px rgba(0,0,0,0.5);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.color-dot.copied .dot-copied-badge {
  opacity: 1;
}

.swatches-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Legacy .swatch compatibility */
.swatch {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

/* ============================================================
   IMAGE CARD
============================================================ */
.image-card {
  position: relative;
  overflow: hidden;
  background: var(--bg-card);
  cursor: pointer;
  aspect-ratio: 1;
  content-visibility: auto;
  contain-intrinsic-size: auto 202px;
}

.image-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.image-card img.loaded { opacity: 1; }

.image-card.selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.image-card .source-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  font-family: var(--font-ui);
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: lowercase;
  color: var(--bg);
  background: rgba(26,26,24,0.6);
  padding: 2px 6px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.image-card:hover .source-badge { opacity: 1; }

.source-badge .badge-refresh {
  display: none;
  margin-left: 3px;
  cursor: pointer;
  opacity: 0.7;
}

.source-badge:hover .badge-refresh {
  display: inline;
}

.source-badge .badge-refresh:hover { opacity: 1; }

/* Deep Zoom button on image cards */
.image-card .zoom-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--bg);
  background: rgba(26,26,24,0.6);
  border: none;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.3s ease;
  padding: 0;
  line-height: 1;
}
.image-card:hover .zoom-btn { opacity: 1; }
.image-card .zoom-btn:hover { background: rgba(26,26,24,0.85); }

/* OpenSeadragon deep-zoom modal */
#osd-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0,0,0,0.92);
  align-items: center;
  justify-content: center;
}
#osd-modal.open { display: flex; }
#osd-container {
  width: 90vw;
  height: 85dvh;
  background: #111;
}
#osd-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  z-index: 10001;
  font-family: var(--font-ui);
  opacity: 0.7;
  transition: opacity 0.2s;
}
#osd-close:hover { opacity: 1; }

/* Sketch mode — Sobel canvas overlay; CSS filter fallback for tainted images */
.sketch-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
}

/* ============================================================
   IMAGE GRID
============================================================ */
#image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 2px;
  padding: 2px;
  min-height: 100dvh;
}

/* ============================================================
   EMPTY STATE
============================================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--ink-3);
}

.empty-state p {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 300;
  font-style: italic;
}

.empty-state span {
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.1em;
}

/* ============================================================
   LOADING STATE
============================================================ */
.loading-indicator {
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  animation: pulse 1.5s ease infinite;
  min-height: 14px;
}

.sources-active-counter {
  font-family: var(--font-ui);
  font-size: 9px;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  min-height: 12px;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; }
  50%       { opacity: 1; }
}

/* ============================================================
   TOAST NOTIFICATION
============================================================ */
.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--ink-2);
  background: var(--bg-panel);
  border: 1px solid var(--line-strong);
  padding: 8px 16px;
  z-index: 300;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
}
.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ============================================================
   SKIP TO CONTENT (accessibility)
============================================================ */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--accent);
  color: var(--bg);
  padding: 8px 16px;
  z-index: 999;
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.06em;
}
.skip-link:focus {
  top: 0;
}

/* ============================================================
   PANEL — RELATED SEARCH LINK
============================================================ */
.related-link {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 300;
  color: var(--ink-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
  transition: opacity 0.3s ease;
}

.related-link:hover { opacity: 0.5; }
.related-link::before { content: '→'; color: var(--accent); }

/* ============================================================
   DARK MODE TOGGLE
============================================================ */
.theme-toggle {
  font-family: var(--font-ui);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: lowercase;
  color: var(--ink-3);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: opacity 0.3s ease;
}

.theme-toggle:hover { opacity: 0.5; }

/* ============================================================
   SIDEBAR LAYOUT HELPERS
============================================================ */
.sidebar-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-spacer {
  flex: 1;
}

.slider-label {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 300;
  color: var(--ink-3);
  letter-spacing: 0.08em;
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ============================================================
   PANEL LAYOUT HELPERS
============================================================ */
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.panel-close {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--ink-3);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: opacity 0.3s ease;
  line-height: 1;
}

.panel-close:hover { opacity: 0.5; }

.panel-section {
  margin-bottom: 24px;
}

.panel-empty-hint {
  display: none;
  margin: 8px 0 18px;
  color: var(--ink-3);
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.06em;
  line-height: 1.6;
}

/* Source info */
.source-info {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 300;
  color: var(--ink-2);
  line-height: 1.6;
}

.source-info a {
  color: var(--accent);
  border-bottom: 1px solid var(--line-strong);
}

.source-identity {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.source-identity .source-icon-wrap {
  width: 14px;
  height: 14px;
  position: relative;
  flex-shrink: 0;
}

.source-identity .source-icon {
  width: 14px;
  height: 14px;
  object-fit: cover;
  display: block;
}

.source-identity .source-mono {
  width: 14px;
  height: 14px;
  display: none;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  color: var(--ink-3);
  font-family: var(--font-ui);
  font-size: 7px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1;
}

.source-identity .source-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#source-info .source-identity {
  margin-bottom: 6px;
}

#source-info .source-identity .source-icon-wrap,
#source-info .source-identity .source-icon,
#source-info .source-identity .source-mono {
  width: 16px;
  height: 16px;
}

#source-info .source-identity .source-mono {
  font-size: 8px;
}

/* AI label inline badge */
.ai-label {
  font-family: var(--font-ui);
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-transform: lowercase;
}

/* No-key note */
.no-key-note {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 300;
  color: var(--ink-3);
  letter-spacing: 0.05em;
  padding-top: 8px;
}

/* ============================================================
   KEYS OVERLAY PANEL (slides in from left over sidebar)
============================================================ */
#keys-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 240px;
  height: 100dvh;
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  gap: 0;
  transform: translateX(-100%);
  transition: transform 0.4s ease;
  overflow-y: auto;
  overscroll-behavior: contain;
}

#keys-panel.open {
  transform: translateX(0);
}

/* ============================================================
   SETTINGS OVERLAY PANEL (slides in from left over sidebar)
============================================================ */
#settings-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 240px;
  height: 100dvh;
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  gap: 0;
  transform: translateX(-100%);
  transition: transform 0.4s ease;
  overflow-y: auto;
  overscroll-behavior: contain;
}

#settings-panel.open {
  transform: translateX(0);
}

.settings-gear-btn {
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--ink-3);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: opacity 0.3s ease;
  line-height: 1;
}

.settings-gear-btn:hover { opacity: 0.5; }

.settings-toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.settings-row-label {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 300;
  color: var(--ink-2);
  letter-spacing: 0.06em;
}

.settings-toggle-row .btn-group {
  flex-shrink: 0;
}

.settings-toggle-row .btn {
  width: auto;
  flex: none;
  padding: 4px 10px;
  text-align: center;
}

.settings-value-text {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 300;
  color: var(--ink-3);
  letter-spacing: 0.04em;
  padding: 4px 0;
}

.settings-danger-btn {
  color: #B04040;
  border-color: rgba(176,64,64,0.3);
}

.no-badges .source-badge { opacity: 0 !important; pointer-events: none; }

.keys-panel-subheader {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 300;
  color: var(--ink-3);
  letter-spacing: 0.06em;
  margin-top: 4px;
}

.keys-panel-footer {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 300;
  color: var(--ink-3);
  letter-spacing: 0.04em;
  line-height: 1.5;
  margin-top: auto;
  padding-top: 16px;
}

.keys-panel-actions {
  display: flex;
  gap: 4px;
  margin-top: 12px;
}

.keys-panel-actions .btn {
  flex: 1;
  text-align: center;
}

.source-toggle {
  font-family: var(--font-ui);
  font-size: 8px;
  color: var(--ink-3);
  background: none;
  border: none;
  padding: 0 4px 0 0;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
}

.source-toggle.enabled { color: var(--ink); }

.key-source-row.source-disabled { opacity: 0.4; }

.preset-btn {
  font-size: 9px;
  padding: 2px 6px;
  flex-shrink: 0;
}

.preset-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

/* --- Key source row --- */
.key-source-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.key-source-row:last-child {
  border-bottom: none;
}

.key-source-top {
  display: flex;
  align-items: center;
  gap: 6px;
}

.key-source-name {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 400;
  color: var(--ink);
  letter-spacing: 0.04em;
  flex: 1;
  min-width: 0;
  overflow: hidden; /* clips source-identity to flex width */
}

.key-status-badge {
  font-family: var(--font-ui);
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.08em;
  padding: 2px 6px;
  white-space: nowrap;
  cursor: default;
  flex-shrink: 0;
}

.key-status-badge.badge-active {
  background: rgba(60,140,60,0.12);
  color: #3c8c3c;
}

.key-status-badge.badge-inactive {
  background: var(--line);
  color: var(--ink-3);
}

.key-status-badge.badge-cors {
  background: rgba(60,120,60,0.08);
  color: #5a8c5a;
}

.key-get-link {
  font-family: var(--font-ui);
  font-size: 9px;
  font-weight: 300;
  color: var(--ink-3);
  letter-spacing: 0.06em;
  text-decoration: none;
  flex-shrink: 0;
  transition: opacity 0.2s ease;
}

.key-get-link:hover { opacity: 0.5; }

.key-source-desc {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 300;
  color: var(--ink-3);
  letter-spacing: 0.04em;
}

.key-source-input-row {
  display: none;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.key-source-input-row.visible {
  display: flex;
}

.key-source-input {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 300;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line-strong);
  flex: 1;
  padding: 6px 0;
  outline: none;
  caret-color: var(--accent);
  min-width: 0;
}

.key-source-input::placeholder { color: var(--ink-3); }
.key-source-input:focus { border-bottom-color: var(--accent); }

/* --- api keys button in sidebar --- */
.btn-keys {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-keys-dot {
  width: 5px;
  height: 5px;
  background: var(--accent);
  flex-shrink: 0;
}

/* Source badge tints */
.source-badge       { background: rgba(26,26,24,0.55); }
.badge-wiki         { background: rgba(26,26,24,0.55); }
.badge-met          { background: rgba(184,92,56,0.7); }
.badge-archive      { background: rgba(56,100,184,0.7); }
.badge-nasa         { background: rgba(20,60,120,0.75); }
.badge-rijks        { background: rgba(140,40,40,0.7); }
.badge-euro         { background: rgba(0,90,120,0.7); }
.badge-harvard      { background: rgba(180,30,30,0.7); }
.badge-smithsonian  { background: rgba(20,80,160,0.7); }
.badge-pexels       { background: rgba(5,160,100,0.7); }
.badge-inaturalist  { background: rgba(40,140,80,0.75); }
.badge-loc          { background: rgba(140,20,20,0.75); }
.badge-openlibrary  { background: rgba(100,60,160,0.75); }
.badge-chicago      { background: rgba(180,30,50,0.75); }
.badge-cleveland    { background: rgba(20,80,140,0.75); }
.badge-va           { background: rgba(160,20,100,0.75); }
.badge-flickr       { background: rgba(255,0,132,0.6); }
.badge-pixabay      { background: rgba(32,173,73,0.75); }
.badge-wikiart      { background: rgba(80,40,120,0.75); }
.badge-nordic       { background: rgba(0,100,160,0.75); }
.badge-getty        { background: rgba(180,140,20,0.75); }
.badge-nga          { background: rgba(20,60,120,0.75); }
.badge-gbif         { background: rgba(20,140,60,0.75); }
.badge-eol          { background: rgba(0,120,80,0.75); }
.badge-apod         { background: rgba(10,20,80,0.8); }
.badge-gallica      { background: rgba(0,80,160,0.75); }
.badge-chronicling  { background: rgba(120,20,20,0.75); }
.badge-openverse    { background: rgba(200,80,0,0.75); }
.badge-trove        { background: rgba(0,100,60,0.75); }
.badge-digitalnz    { background: rgba(0,60,140,0.75); }
.badge-bhl          { background: rgba(60,120,20,0.75); }
.badge-carnegie     { background: rgba(160,40,40,0.75); }
.badge-prado        { background: rgba(140,0,20,0.8); }
.badge-parismusees  { background: rgba(0,60,120,0.8); }
.badge-yale         { background: rgba(0,40,100,0.8); }
.badge-picsum       { background: rgba(80,80,80,0.6); }
.badge-usgs         { background: rgba(80,60,20,0.75); }
.badge-cooperhewitt { background: rgba(200,60,0,0.75); }
.badge-tate         { background: rgba(0,0,0,0.75); }
.badge-finna        { background: rgba(0,80,160,0.75); }
.badge-soch         { background: rgba(180,0,0,0.75); }
.badge-joconde      { background: rgba(0,60,120,0.8); }
.badge-mnw          { background: rgba(180,0,40,0.75); }
.badge-tepapa       { background: rgba(0,120,80,0.75); }
.badge-dpla         { background: rgba(40,100,180,0.75); }
.badge-artsy        { background: rgba(0,0,0,0.8); }
.badge-pas          { background: rgba(100,80,20,0.75); }
.badge-smg          { background: rgba(20,60,120,0.75); }
.badge-auckland     { background: rgba(0,100,100,0.75); }
.badge-photogrammar { background: rgba(80,60,20,0.8); }
.badge-wellcome     { background: rgba(180,0,80,0.75); }
.badge-maas         { background: rgba(200,80,0,0.75); }
.badge-smk          { background: rgba(180,40,0,0.75); }
.badge-thyssen      { background: rgba(0,80,40,0.75); }
.badge-wdl          { background: rgba(100,0,60,0.75); }
.badge-walters      { background: rgba(120,60,0,0.75); }
.badge-princeton    { background: rgba(255,140,0,0.75); }
.badge-wikidata     { background: rgba(0,90,160,0.75); }
.badge-noaa         { background: rgba(0,60,120,0.8); }
.badge-hubble       { background: rgba(10,0,60,0.85); }
.badge-cornell      { background: rgba(180,30,30,0.75); }
.badge-folger       { background: rgba(80,40,0,0.8); }
.badge-onb          { background: rgba(180,0,60,0.75); }
.badge-nypl         { background: rgba(0,60,120,0.8); }
.badge-mak          { background: rgba(0,80,80,0.75); }
.badge-mna              { background: rgba(180,80,0,0.8); }
.badge-louvre           { background: rgba(100,80,20,0.8); }
/* Batch 7 badge tints */
.badge-mia              { background: rgba(180,0,40,0.8); }
.badge-lacma            { background: rgba(0,60,120,0.8); }
.badge-munch            { background: rgba(180,80,0,0.8); }
.badge-mauritshuis      { background: rgba(0,80,40,0.8); }
.badge-nationalmuseumse { background: rgba(0,60,80,0.8); }
.badge-naturalis        { background: rgba(0,100,40,0.8); }
.badge-nmaahc           { background: rgba(40,20,0,0.85); }
.badge-nasm             { background: rgba(0,40,100,0.85); }
.badge-whitney          { background: rgba(0,0,60,0.85); }
.badge-nationalzoo      { background: rgba(0,100,20,0.8); }
.badge-gbiflit          { background: rgba(40,100,0,0.8); }
.badge-freersackler     { background: rgba(120,60,0,0.8); }
.badge-ago              { background: rgba(180,60,0,0.8); }
.badge-pem              { background: rgba(0,80,100,0.8); }
.badge-npg              { background: rgba(40,0,80,0.8); }
.badge-louvread         { background: rgba(180,120,0,0.85); }
.badge-idigbio          { background: rgba(20,120,60,0.8); }
.badge-ala              { background: rgba(0,140,70,0.8); }
.badge-nasa_images      { background: rgba(11,61,145,0.9); }
.badge-loc              { background: rgba(140,20,20,0.9); }

/* ============================================================
   BOARD VIEW
============================================================ */
#board-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

.board-card {
  position: absolute;
  cursor: move;
  user-select: none;
}

.board-card img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.board-card .resize-handle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  cursor: se-resize;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.board-card:hover .resize-handle { opacity: 1; }

/* Board card title overlay (visible on hover) */
.board-card .board-title {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  font-family: var(--font-ui);
  font-size: 9px;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: #E8E6E1;
  background: rgba(20,20,18,0.72);
  padding: 3px 7px;
  opacity: 0;
  transition: opacity 0.3s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
.board-card:hover .board-title { opacity: 1; }

/* ============================================================
   BOARD OVERLAY (floating panel — coexists with all views)
============================================================ */
#board-overlay {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 480px;
  height: 520px;
  min-width: 280px;
  min-height: 200px;
  z-index: 200;
  background: var(--bg-panel);
  border: 1px solid var(--line-strong);
  box-shadow: 0 8px 32px rgba(0,0,0,0.2), 0 2px 8px rgba(0,0,0,0.1);
  display: none;
  flex-direction: column;
  resize: both;
  overflow: hidden;
}

#board-overlay.open { display: flex; }

#board-overlay-header {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  cursor: move;
  user-select: none;
  gap: 6px;
  flex-shrink: 0;
  background: var(--bg-panel);
}

#board-overlay-content {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.board-delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  background: rgba(20,20,18,0.72);
  color: #E8E6E1;
  border: none;
  cursor: pointer;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  padding: 0;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 10;
}

.board-card:hover .board-delete-btn { opacity: 1; }

/* ============================================================
   3D VIEW CONTAINER
============================================================ */
#three-canvas {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

#three-canvas.active {
  display: block;
}

/* ============================================================
   FLOATING ACTION BAR (cross-reference)
============================================================ */
#floating-bar {
  position: sticky;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  transition: transform 0.3s ease;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-panel);
  border: 1px solid var(--line-strong);
  padding: 10px 16px;
  width: fit-content;
  max-width: 600px;
  z-index: 50;
  font-family: var(--font-ui);
}

#floating-bar.visible {
  transform: translateX(-50%) translateY(0);
}
#floating-bar.bar-hidden {
  display: none !important;
}

.bar-thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  cursor: pointer;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.bar-thumb:hover { opacity: 0.6; }

#interpret-btn.disabled {
  opacity: 0.35;
  cursor: default;
}

#interpret-btn {
  position: relative;
}

#interpret-btn.disabled:hover::after {
  content: 'add an ai key to unlock';
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  padding: 4px 8px;
  font-size: 9px;
  white-space: nowrap;
  color: var(--ink-2);
  pointer-events: none;
}

#canvas.bar-active { padding-bottom: 80px; }

/* ============================================================
   ONBOARDING OVERLAY
============================================================ */
#onboarding {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(10, 10, 10, 0.88);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.4s ease;
}
#onboarding.visible { opacity: 1; }
#onboarding.hidden { pointer-events: none; }

.ob-inner {
  width: 100%;
  max-width: 600px;
  padding: 40px 32px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  overflow: hidden;
  max-height: 100dvh;
  background: var(--bg-panel);
  border: 1px solid var(--line-strong);
  box-shadow: 0 22px 56px rgba(0, 0, 0, 0.35);
}

.ob-viewport {
  width: 100%;
  overflow: hidden;
  position: relative;
}

.ob-track {
  display: flex;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}

.ob-step {
  min-width: 100%;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0 8px;
}

.ob-logo {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 300;
  font-size: 42px;
  color: var(--ink);
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}

.ob-tagline {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: var(--ink-2);
  margin-bottom: 28px;
}

.ob-big-num {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 48px;
  color: var(--ink);
  line-height: 1;
  margin-bottom: 6px;
}

.ob-big-label {
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--ink-3);
  text-transform: uppercase;
  margin-bottom: 24px;
}

/* Hero statement slide */
.ob-step-hero {
  justify-content: center;
  padding-top: 0;
}
.ob-step-hero .ob-logo {
  font-size: 36px;
  margin-bottom: 32px;
}
.ob-hero-statement {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 36px;
  line-height: 1.25;
  color: var(--ink);
  margin-bottom: 28px;
  letter-spacing: -0.01em;
}
.ob-hero-sub {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 300;
  line-height: 1.6;
  color: var(--ink-2);
  letter-spacing: 0.04em;
  max-width: 380px;
}

/* Persistent source info bar (top of canvas) */
#source-info-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
  font-family: var(--font-ui);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  gap: 6px;
  flex-shrink: 0;
  position: relative;
}

/* API badge button */
#sib-api-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: transparent;
  font-family: var(--font-ui);
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #c47a20;
  border-color: rgba(196,122,32,0.33);
}
#sib-api-badge:hover { opacity: 0.7; }
#sib-api-badge.all-connected {
  color: #4a9;
  border-color: rgba(68,170,153,0.33);
}
#sib-api-count {
  font-size: 7px;
  opacity: 0.7;
}

/* API dropdown panel */
#sib-api-dropdown {
  position: absolute;
  top: 100%;
  right: 16px;
  width: 340px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 900;
  padding: 10px 0;
  font-family: var(--font-ui);
}
#sib-api-dropdown.hidden { display: none; }

.sib-dd-header {
  padding: 0 12px 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}
.sib-dd-title {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--ink);
}
.sib-dd-hint {
  display: block;
  font-size: 9px;
  font-weight: 300;
  color: var(--ink-3);
  margin-top: 3px;
  line-height: 1.5;
}
.sib-dd-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  transition: background 0.15s ease;
}
.sib-dd-row:hover { background: var(--bg-hover); }
.sib-dd-row.connected { opacity: 0.45; }
.sib-dd-name {
  font-size: 10px;
  font-weight: 400;
  color: var(--ink);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sib-dd-status {
  font-size: 8px;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}
.sib-dd-status.active { color: #4a9; }
.sib-dd-status.missing { color: #c47a20; }
.sib-dd-link {
  font-size: 8px;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--ink-2);
  text-decoration: none;
  flex-shrink: 0;
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 3px;
  transition: all 0.15s ease;
}
.sib-dd-link:hover {
  color: var(--ink);
  border-color: var(--ink-3);
}
.sib-dd-footer {
  padding: 8px 12px 2px;
  border-top: 1px solid var(--line);
  margin-top: 6px;
  font-size: 8px;
  font-weight: 300;
  color: var(--ink-3);
  line-height: 1.5;
}

.ob-heading {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 28px;
  color: var(--ink);
  margin-bottom: 16px;
}

.ob-text {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 300;
  line-height: 1.7;
  color: var(--ink-2);
  letter-spacing: 0.04em;
  max-width: 440px;
  margin-bottom: 20px;
}

.ob-features {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 24px;
  width: 100%;
  max-width: 520px;
  margin-bottom: 20px;
}

.ob-feat {
  border-left: 1px solid var(--ink-3);
  padding: 10px 0 10px 16px;
  text-align: left;
  transition: border-color 0.35s ease;
}

.ob-feat:hover { border-color: var(--ink); }

.ob-feat-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 300;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: 5px;
}

.ob-feat-desc {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 300;
  color: var(--ink-3);
  letter-spacing: 0.03em;
  line-height: 1.6;
}

/* DB summary step */
.ob-stats-row {
  display: flex;
  gap: 24px;
  justify-content: center;
  margin-bottom: 20px;
}

.ob-stat {
  text-align: center;
}

.ob-stat-num {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 32px;
  color: var(--ink);
  line-height: 1.1;
}

.ob-stat-label {
  font-family: var(--font-ui);
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  text-transform: uppercase;
}

.ob-cat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  max-width: 440px;
  margin-bottom: 16px;
}

.ob-cat {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 300;
  color: var(--ink-2);
  letter-spacing: 0.06em;
}

.ob-cat-count {
  margin-left: auto;
  color: var(--ink-3);
  font-size: 9px;
}

.ob-source-list {
  width: 100%;
  max-width: 440px;
  max-height: 140px;
  overflow-y: auto;
  border: 1px solid var(--line);
  padding: 8px 12px;
  margin-bottom: 16px;
}

.ob-source-list::-webkit-scrollbar { width: 3px; }
.ob-source-list::-webkit-scrollbar-thumb { background: var(--line-strong); }

.ob-src-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  font-family: var(--font-ui);
  font-size: 9px;
  font-weight: 300;
  color: var(--ink-2);
  letter-spacing: 0.04em;
}

.ob-src-count {
  color: var(--ink-3);
}

.ob-src-key {
  color: var(--accent);
  font-size: 8px;
  margin-left: 4px;
}

/* Navigation */
.ob-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 20px;
}

.ob-dots {
  display: flex;
  gap: 8px;
}

.ob-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line-strong);
  border: none;
  padding: 0;
  cursor: pointer;
  transition: background 0.3s ease, transform 0.3s ease;
}

.ob-dot.active {
  background: var(--accent);
  transform: scale(1.3);
}

.ob-btn {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 0.1em;
  text-transform: lowercase;
  background: none;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  padding: 8px 20px;
  cursor: pointer;
  transition: border-color 0.3s ease, opacity 0.3s ease;
}

.ob-btn:hover { border-color: var(--accent); }

.ob-btn-primary {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.ob-btn-primary:hover { opacity: 0.8; border-color: var(--ink); }

.ob-skip {
  font-family: var(--font-ui);
  font-size: 9px;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  background: none;
  border: none;
  cursor: pointer;
  position: absolute;
  top: 16px;
  right: 16px;
  transition: opacity 0.3s ease;
}

.ob-skip:hover { opacity: 0.5; }

.ob-note {
  font-family: var(--font-ui);
  font-size: 9px;
  font-weight: 300;
  color: var(--ink-3);
  letter-spacing: 0.04em;
  margin-top: 12px;
}

.quiet-tip {
  position: fixed;
  z-index: 12000;
  max-width: 220px;
  font-family: var(--font-ui);
  font-size: 9px;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: var(--bg-panel);
  border: 1px solid var(--line-strong);
  padding: 8px 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

.quiet-tip.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Source view filters (Phase 2) ── */
#source-view-filters {
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.filter-group {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 5px;
  flex-wrap: wrap;
}
.filter-group-label {
  font-size: 10px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  min-width: 38px;
  flex-shrink: 0;
}
.filter-pill {
  background: none;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--ink-3);
  font-family: var(--font-ui);
  font-size: 10px;
  padding: 2px 6px;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.filter-pill:hover { border-color: var(--line); color: var(--ink-2); }
.filter-pill.active {
  border-color: var(--line);
  color: var(--ink-1);
  background: #1a1a1a;
}
#filter-source-count {
  font-size: 10px;
  color: var(--ink-3);
  margin-top: 3px;
  display: block;
}

/* Help button in sidebar */
.btn-help {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  background: none;
  border: 1px solid var(--line);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 50%;
  transition: border-color 0.3s ease, color 0.3s ease;
  margin-bottom: 8px;
}

.btn-help:hover {
  border-color: var(--accent);
  color: var(--ink);
}

@media (max-width: 640px) {
  .ob-features { grid-template-columns: 1fr; }
  .ob-cat-grid { grid-template-columns: 1fr; }
  .ob-big-num { font-size: 36px; }
  .ob-logo { font-size: 32px; }
  .ob-inner { padding: 24px 16px 20px; }
  .ob-stats-row { gap: 16px; }
  .ob-stat-num { font-size: 24px; }
}

/* ============================================================
   MOBILE LAYOUT (≤ 480px)
   At 375px the fixed-width sidebar (240px) + panel (280px)
   overflow the viewport and crush #canvas to 0. Fix: sidebar
   becomes a fixed overlay; canvas takes full width.
============================================================ */
#mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 110;
  background: var(--bg-panel);
  border: 1px solid var(--line-strong);
  color: var(--ink-2);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1;
  padding: 6px 9px;
  cursor: pointer;
  transition: opacity 0.2s;
}
#mobile-menu-btn:hover { opacity: 0.6; }

#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 99;
}
#sidebar-backdrop.visible { display: block; }

@media (max-width: 480px) {
  #mobile-menu-btn { display: block; }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 85vw;
    max-width: 320px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    padding-top: calc(24px + env(safe-area-inset-top));
    padding-bottom: env(safe-area-inset-bottom);
  }
  #sidebar.mobile-open { transform: translateX(0); }

  /* Panel becomes full-width when open */
  #panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    z-index: 90;
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Keys & settings panels full-width */
  #keys-panel,
  #settings-panel {
    width: 85vw;
    max-width: 320px;
  }

  /* Image grid works at small widths */
  #image-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  /* Floating bar fits on narrow screens */
  #floating-bar {
    max-width: calc(100vw - 24px);
    flex-wrap: wrap;
    gap: 6px;
  }

  /* AI chat panel full-width */
  #ai-chat-panel {
    width: 100vw;
  }

  /* Board overlay full-screen on mobile */
  #board-overlay {
    width: 100vw !important;
    height: 100dvh !important;
    right: 0;
    bottom: 0;
    top: 0;
    left: 0;
    border: none;
  }

  /* ── Hover-gated elements → always visible ── */
  .image-card .source-badge { opacity: 1; }
  .image-card .zoom-btn { opacity: 1; font-size: 16px; padding: 6px 8px; }
  .board-card .resize-handle { opacity: 0.7; width: 20px; height: 20px; }
  .board-card .board-title { opacity: 1; }
  .board-card .board-delete-btn { opacity: 1; width: 28px; height: 28px; font-size: 16px; line-height: 28px; }

  /* Color dot tooltips — tap-accessible via :active */
  .color-dot-tooltip { pointer-events: auto; }
  .color-dot:active .color-dot-tooltip { opacity: 1; }

  /* ── Minimum font sizes ── */
  .source-badge,
  .board-title,
  .chat-pill,
  .chat-provider-badge,
  .chat-msg-label,
  .chat-empty-label,
  #btn-chat-snapshot { font-size: 11px; }

  /* ── Tap targets minimum 44px ── */
  .chat-pill { min-height: 36px; padding: 6px 10px; }
  .chat-starter { min-height: 44px; padding: 10px 12px; font-size: 13px; }
  .ob-dot { width: 28px; height: 28px; }
  #ob-prev, #ob-next { font-size: 28px; min-width: 44px; min-height: 44px; }

  /* ── OSD fullscreen on mobile ── */
  #osd-container { width: 100vw; height: 100dvh; }
  #osd-close { top: calc(8px + env(safe-area-inset-top)); right: 12px; font-size: 32px; padding: 8px; }

  /* ── Concept pills scrollable ── */
  #concept-pills {
    overflow-x: auto;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Mobile menu button safe area ── */
  #mobile-menu-btn {
    top: calc(12px + env(safe-area-inset-top));
    left: calc(12px + env(safe-area-inset-left));
  }

  /* ── Source info bar compact ── */
  #source-info-bar {
    font-size: 9px;
    padding: 3px 10px 3px calc(10px + env(safe-area-inset-left));
  }
}

/* ============================================================
   AI CHAT PANEL
============================================================ */
#ai-chat-panel {
  position: fixed;
  right: 0;
  bottom: 0;
  top: auto;
  width: 280px;
  height: 40dvh;
  background: var(--bg-panel);
  border-left: 1px solid var(--line);
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
#ai-chat-panel.open { transform: translateX(0); }
/* Give the concepts panel scroll room so content stays visible behind the chat */
body:has(#ai-chat-panel.open) #panel.open { padding-bottom: 40dvh; }
.chat-panel-header {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  gap: 6px;
  flex-shrink: 0;
}
.chat-panel-title {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.12em;
  color: var(--ink);
  flex: 1;
}
.chat-provider-badge {
  font-family: var(--font-ui);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 1px 5px;
  text-transform: lowercase;
}
#btn-chat-snapshot {
  font-size: 9px;
  padding: 2px 7px;
  letter-spacing: 0.05em;
  color: var(--ink-3);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-msg {
  font-family: var(--font-ui);
  font-size: 11px;
  line-height: 1.55;
  color: var(--ink);
}
.chat-msg.user { color: var(--ink-2); text-align: right; padding-left: 20%; }
.chat-msg.assistant { padding-right: 8%; }
.chat-msg .chat-msg-label {
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  margin-bottom: 3px;
}
.chat-pills { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chat-pill {
  font-family: var(--font-ui);
  font-size: 9px;
  letter-spacing: 0.06em;
  background: none;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  padding: 2px 7px;
  cursor: pointer;
  transition: border-color 0.2s;
}
.chat-pill:hover { border-color: var(--accent); color: var(--accent); }
.chat-empty {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 16px 4px;
}
.chat-empty-label {
  font-family: var(--font-ui);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  margin-bottom: 6px;
}
.chat-starter {
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.03em;
  color: var(--ink-3);
  cursor: pointer;
  padding: 6px 8px;
  border: 1px solid var(--line);
  text-align: left;
  background: none;
  transition: color 0.2s, border-color 0.2s;
  width: 100%;
}
.chat-starter:hover { color: var(--ink); border-color: var(--line-strong); }
.chat-input-row { display: flex; border-top: 1px solid var(--line); flex-shrink: 0; }
#chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--ink);
  padding: 10px 12px;
  resize: none;
  height: 68px;
  line-height: 1.4;
}
#chat-input::placeholder { color: var(--ink-3); }
#btn-chat-send {
  padding: 0 14px;
  font-size: 13px;
  border-left: 1px solid var(--line);
  background: none;
  color: var(--accent);
  cursor: pointer;
  font-family: var(--font-ui);
}
#btn-chat-send:hover { color: var(--ink); }
.chat-thinking {
  font-family: var(--font-ui);
  font-size: 10px;
  color: var(--ink-3);
  font-style: italic;
}
.ai-provider-pill.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
