/* ── Vectors & Latent Space Demo ──────────────────────────────────────────── */
/* Follows the three-panel layout pattern from demo/, challenge/, etc.       */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg, #0f1117);
  color: var(--text, #e2e8f0);
  font-size: 14px;
  line-height: 1.5;
}
body {
  display: flex;
  flex-direction: column;
}

/* ── Theme toggle ──────────────────────────────────────────────────────────── */
.theme-toggle {
  position: fixed; top: 1rem; right: 1rem; z-index: 100;
  background: var(--surface, #1a1d27); border: 1px solid var(--border, #2d3148);
  color: var(--text, #e2e8f0); border-radius: 8px; width: 36px; height: 36px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; transition: background 0.2s;
}
.theme-toggle:hover { background: var(--surface-2, #22253a); }
html[data-theme="light"] .theme-icon-dark { display: none !important; }
html[data-theme="light"] .theme-icon-light { display: inline !important; }

/* ── Page header ───────────────────────────────────────────────────────────── */
.page-header {
  padding: 1.25rem 1.5rem 0.75rem;
  text-align: center;
}
.page-header h1 {
  font-size: 1.6rem; font-weight: 700; margin-bottom: 0.25rem;
}
.page-header p {
  color: var(--muted, #8892a4); font-size: 0.9rem; max-width: 700px; margin: 0 auto;
}
.accent { color: var(--accent, #5ba300); }
.accent-2 { color: var(--accent-2); }
.back-link {
  color: var(--muted, #8892a4); text-decoration: none; font-size: 0.8rem;
  display: inline-block; margin-bottom: 0.5rem;
}
.back-link:hover { color: var(--accent, #5ba300); }
.ai-disclaimer {
  font-size: 0.75rem; color: var(--muted, #8892a4); margin-top: 0.5rem;
  opacity: 0.7;
}

/* ── Mobile tab bar ────────────────────────────────────────────────────────── */
.mobile-tab-bar {
  display: none; /* shown at mobile breakpoint */
  justify-content: center; gap: 0.25rem;
  padding: 0.5rem 1rem; background: var(--surface, #1a1d27);
  border-bottom: 1px solid var(--border, #2d3148);
}
.mobile-tab {
  background: none; border: 1px solid var(--border, #2d3148); color: var(--muted, #8892a4);
  padding: 0.4rem 1rem; border-radius: 6px; cursor: pointer; font-size: 0.8rem;
}
.mobile-tab.active { background: var(--accent, #5ba300); color: #fff; border-color: var(--accent, #5ba300); }

/* ── Three-panel layout ────────────────────────────────────────────────────── */
.vectors-layout {
  display: grid;
  grid-template-columns: 260px 1fr 280px;
  gap: 0;
  flex: 1;
  min-height: 0;
  border-top: 1px solid var(--border, #2d3148);
}

.left-panel, .right-panel {
  background: var(--surface, #1a1d27);
  border-right: 1px solid var(--border, #2d3148);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.right-panel {
  border-right: none;
  border-left: 1px solid var(--border, #2d3148);
}

.panel-header {
  padding: 0.75rem 1rem;
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted, #8892a4);
  border-bottom: 1px solid var(--border, #2d3148);
  display: flex; justify-content: space-between; align-items: center;
  flex-shrink: 0;
}

.center-panel {
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* ── Tabs ──────────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex; border-bottom: 1px solid var(--border, #2d3148);
  background: var(--surface, #1a1d27); flex-shrink: 0;
}
.tab {
  padding: 0.6rem 1.25rem; font-size: 0.8rem; font-weight: 500;
  color: var(--muted, #8892a4); cursor: pointer; border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text, #e2e8f0); }
.tab.active { color: var(--accent, #5ba300); border-bottom-color: var(--accent, #5ba300); }

.tab-content { display: none; flex: 1; overflow: auto; position: relative; }
.tab-content.active { display: flex; flex-direction: column; }

/* ── Controls (left panel) ─────────────────────────────────────────────────── */
.controls-section {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border, #2d3148);
}
.control-label {
  display: block; font-size: 0.75rem; font-weight: 600;
  color: var(--muted, #8892a4); margin-bottom: 0.4rem; text-transform: uppercase;
  letter-spacing: 0.03em;
}
.input-row {
  display: flex; gap: 0.4rem;
}
.concept-input, .rag-input {
  flex: 1; background: var(--code-bg, #151820); border: 1px solid var(--border, #2d3148);
  color: var(--text, #e2e8f0); padding: 0.45rem 0.6rem; border-radius: 6px;
  font-size: 0.85rem; font-family: inherit;
}
.concept-input:focus, .rag-input:focus {
  outline: none; border-color: var(--accent, #5ba300);
}
.add-btn, .search-btn, .clear-btn, .preset-btn, .canvas-btn {
  background: var(--surface-2, #22253a); border: 1px solid var(--border, #2d3148);
  color: var(--text, #e2e8f0); border-radius: 6px; cursor: pointer;
  font-size: 0.8rem; font-family: inherit; transition: background 0.15s;
}
.add-btn:hover, .search-btn:hover, .clear-btn:hover, .preset-btn:hover,
.canvas-btn:hover {
  background: var(--accent, #5ba300); color: #fff; border-color: var(--accent, #5ba300);
}
.add-btn { padding: 0.45rem 0.7rem; font-size: 1rem; font-weight: 700; }
.search-btn { padding: 0.45rem 1rem; }
.clear-btn {
  width: 100%; padding: 0.5rem; font-size: 0.8rem;
  color: var(--danger); border-color: var(--danger);
  background: transparent;
}
.clear-btn:hover { background: var(--danger); color: #fff; }

.preset-row {
  display: flex; flex-wrap: wrap; gap: 0.3rem;
}
.preset-btn {
  padding: 0.3rem 0.6rem; font-size: 0.75rem;
}

/* ── Concept list ──────────────────────────────────────────────────────────── */
.concept-list {
  flex: 1; overflow-y: auto; padding: 0.5rem;
}
.concept-chip {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 0.6rem; margin-bottom: 0.3rem;
  background: var(--surface-2, #22253a); border-radius: 6px;
  font-size: 0.8rem; cursor: default;
  border: 1px solid transparent;
  transition: border-color 0.15s;
}
.concept-chip:hover { border-color: var(--accent, #5ba300); }
.concept-chip .chip-color {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.concept-chip .chip-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.concept-chip .chip-remove {
  background: none; border: none; color: var(--muted, #8892a4); cursor: pointer;
  font-size: 1rem; line-height: 1; padding: 0 0.2rem;
}
.concept-chip .chip-remove:hover { color: var(--danger); }

/* ── Embedding canvas ──────────────────────────────────────────────────────── */
#embedding-canvas {
  flex: 1; width: 100%; min-height: 0;
  background: var(--code-bg, #151820);
  cursor: grab;
}
#embedding-canvas:active { cursor: grabbing; }

.canvas-controls {
  position: absolute; top: 0.75rem; right: 0.75rem;
  display: flex; flex-direction: column; gap: 0.3rem;
}
.canvas-btn {
  width: 32px; height: 32px; font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.canvas-legend {
  position: absolute; bottom: 0.5rem; left: 0.75rem;
  font-size: 0.7rem; color: var(--muted, #8892a4); opacity: 0.7;
}

/* ── Similarity matrix ─────────────────────────────────────────────────────── */
.matrix-container {
  flex: 1; overflow: auto; padding: 1rem;
}
.matrix-empty, .rag-empty {
  color: var(--muted, #8892a4); text-align: center; padding: 3rem 1rem;
  font-size: 0.9rem;
}
.sim-matrix {
  border-collapse: collapse; font-size: 0.75rem; margin: 0 auto;
}
.sim-matrix th {
  padding: 0.4rem 0.6rem; font-weight: 600; color: var(--muted, #8892a4);
  text-align: center; max-width: 100px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
  border-bottom: 1px solid var(--border, #2d3148);
}
.sim-matrix th.row-header {
  text-align: right; border-right: 1px solid var(--border, #2d3148);
  border-bottom: none;
}
.sim-matrix td {
  padding: 0.4rem 0.6rem; text-align: center;
  border: 1px solid var(--border, #2d3148); min-width: 60px;
  font-variant-numeric: tabular-nums;
  transition: background 0.15s;
}
.sim-matrix td.sim-self {
  background: var(--surface-2, #22253a); color: var(--muted, #8892a4);
}

/* ── RAG search ────────────────────────────────────────────────────────────── */
.rag-container {
  flex: 1; padding: 1rem; overflow-y: auto;
}
.rag-explanation {
  background: var(--surface, #1a1d27); border: 1px solid var(--border, #2d3148);
  border-radius: 8px; padding: 1rem; margin-bottom: 1rem;
}
.rag-explanation h3 {
  font-size: 0.9rem; margin-bottom: 0.4rem; color: var(--accent-2);
}
.rag-explanation p {
  font-size: 0.85rem; color: var(--muted, #8892a4); line-height: 1.6;
}
.rag-search-row {
  display: flex; gap: 0.5rem; align-items: center; margin-bottom: 1rem;
}
.rag-k-label {
  font-size: 0.8rem; color: var(--muted, #8892a4); white-space: nowrap;
}
.rag-k-input {
  width: 50px; background: var(--code-bg, #151820); border: 1px solid var(--border, #2d3148);
  color: var(--text, #e2e8f0); padding: 0.4rem; border-radius: 6px; font-size: 0.85rem;
  text-align: center;
}
.rag-results {
  display: flex; flex-direction: column; gap: 0.5rem;
}
.rag-result {
  background: var(--surface, #1a1d27); border: 1px solid var(--border, #2d3148);
  border-radius: 8px; padding: 0.75rem 1rem;
  display: flex; align-items: center; gap: 1rem;
  transition: border-color 0.15s;
}
.rag-result.top-match { border-color: var(--accent, #5ba300); }
.rag-rank {
  font-size: 1.1rem; font-weight: 700; color: var(--muted, #8892a4);
  width: 28px; text-align: center; flex-shrink: 0;
}
.rag-result.top-match .rag-rank { color: var(--accent, #5ba300); }
.rag-result-body { flex: 1; }
.rag-result-label {
  font-weight: 600; font-size: 0.9rem; margin-bottom: 0.15rem;
}
.rag-result-score {
  font-size: 0.8rem; color: var(--muted, #8892a4); font-variant-numeric: tabular-nums;
}
.rag-result-bar {
  width: 80px; height: 6px; background: var(--surface-2, #22253a);
  border-radius: 3px; overflow: hidden; flex-shrink: 0;
}
.rag-result-bar-fill {
  height: 100%; background: var(--accent, #5ba300); border-radius: 3px;
  transition: width 0.3s;
}

/* ── Right panel info ──────────────────────────────────────────────────────── */
.info-section {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border, #2d3148);
}
.info-section h3 {
  font-size: 0.85rem; font-weight: 600; margin-bottom: 0.35rem;
  color: var(--accent-2);
}
.info-section p {
  font-size: 0.8rem; color: var(--muted, #8892a4); margin-bottom: 0.35rem;
  line-height: 1.5;
}
.info-section ol {
  font-size: 0.8rem; color: var(--muted, #8892a4); padding-left: 1.2rem;
  line-height: 1.6;
}
.info-example {
  background: var(--code-bg, #151820); border-radius: 6px; padding: 0.5rem 0.75rem;
  font-size: 0.8rem; margin: 0.4rem 0; overflow-x: auto;
}
.info-example code {
  color: var(--accent, #5ba300); font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.78rem;
}
.info-formula {
  background: var(--code-bg, #151820); border-radius: 6px; padding: 0.6rem 0.75rem;
  font-size: 0.85rem; text-align: center; margin: 0.4rem 0;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--accent-3);
}

.vector-display {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.75rem; color: var(--muted, #8892a4);
  background: var(--code-bg, #151820); border-radius: 6px;
  padding: 0.5rem 0.75rem; margin: 0.4rem 0;
  word-break: break-all;
}
.nearest-display {
  font-size: 0.8rem; color: var(--muted, #8892a4); margin-top: 0.4rem;
}
.nearest-display strong { color: var(--text, #e2e8f0); }

/* ── Embedding mode selector ───────────────────────────────────────────────── */
.mode-select {
  width: 100%; background: var(--code-bg, #151820); border: 1px solid var(--border, #2d3148);
  color: var(--text, #e2e8f0); padding: 0.45rem 0.6rem; border-radius: 6px;
  font-size: 0.8rem; font-family: inherit; cursor: pointer;
  margin-bottom: 0.4rem;
}
.mode-select:focus { outline: none; border-color: var(--accent, #5ba300); }
.mode-status {
  font-size: 0.75rem; color: var(--muted, #8892a4); min-height: 1.2em;
}
.mode-status.mode-ready { color: var(--accent, #5ba300); }
.mode-status.mode-error { color: var(--danger); }
.mode-status.mode-loading { color: var(--accent-4); }

.load-model-btn {
  width: 100%; padding: 0.5rem; margin-top: 0.4rem;
  background: var(--accent-2); border: 1px solid var(--accent-2);
  color: #fff; border-radius: 6px; cursor: pointer;
  font-size: 0.8rem; font-family: inherit; transition: opacity 0.15s;
}
.load-model-btn:hover { opacity: 0.85; }
.load-model-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.model-progress { margin-top: 0.4rem; }
.model-progress-bar {
  width: 100%; height: 6px; background: var(--surface-2, #22253a);
  border-radius: 3px; overflow: hidden;
}
.model-progress-fill {
  height: 100%; background: var(--accent-2); border-radius: 3px;
  width: 0%; transition: width 0.3s;
}
.model-progress-text {
  font-size: 0.7rem; color: var(--muted, #8892a4); display: block; margin-top: 0.2rem;
}

/* ── Vector Arithmetic ─────────────────────────────────────────────────────── */
.arithmetic-container {
  flex: 1; padding: 1rem; overflow-y: auto;
}
.arithmetic-explanation {
  background: var(--surface, #1a1d27); border: 1px solid var(--border, #2d3148);
  border-radius: 8px; padding: 1rem; margin-bottom: 1rem;
}
.arithmetic-explanation h3 {
  font-size: 0.9rem; margin-bottom: 0.4rem; color: var(--accent-3);
}
.arithmetic-explanation p {
  font-size: 0.85rem; color: var(--muted, #8892a4); line-height: 1.6;
}
.arithmetic-explanation code {
  background: var(--code-bg, #151820); padding: 0.15rem 0.4rem; border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.82rem;
  color: var(--accent-3);
}

.arithmetic-note {
  background: var(--surface, #1a1d27); border: 1px solid var(--accent-4);
  border-left: 3px solid var(--accent-4);
  border-radius: 6px; padding: 0.6rem 0.8rem; margin-bottom: 1rem;
  font-size: 0.8rem; color: var(--muted, #8892a4);
}

.arithmetic-preset-row { margin-bottom: 1rem; }
.arithmetic-preset-row .control-label { margin-bottom: 0.3rem; }

.arithmetic-inputs {
  display: flex; gap: 0.5rem; align-items: flex-end; margin-bottom: 1rem;
  flex-wrap: wrap;
}
.arith-group { flex: 1; min-width: 150px; }
.arith-input {
  width: 100%; background: var(--code-bg, #151820); border: 1px solid var(--border, #2d3148);
  color: var(--text, #e2e8f0); padding: 0.5rem 0.6rem; border-radius: 6px;
  font-size: 0.85rem; font-family: inherit;
}
.arith-input:focus { outline: none; border-color: var(--accent, #5ba300); }
.arith-positive .arith-input { border-left: 3px solid var(--accent, #5ba300); }
.arith-negative .arith-input { border-left: 3px solid var(--danger); }

.compute-btn {
  background: var(--accent-3); border: 1px solid var(--accent-3);
  color: #fff; padding: 0.5rem 1.5rem; border-radius: 6px;
  cursor: pointer; font-size: 0.85rem; font-weight: 600;
  font-family: inherit; transition: opacity 0.15s;
  white-space: nowrap; flex-shrink: 0;
}
.compute-btn:hover { opacity: 0.85; }
.compute-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.arith-result-card {
  background: var(--surface, #1a1d27); border: 1px solid var(--border, #2d3148);
  border-radius: 8px; padding: 0.75rem 1rem; margin-bottom: 0.5rem;
  display: flex; align-items: center; gap: 1rem;
}
.arith-result-card.top-match { border-color: var(--accent-3); }
.arith-rank {
  font-size: 1.1rem; font-weight: 700; color: var(--muted, #8892a4);
  width: 28px; text-align: center; flex-shrink: 0;
}
.arith-result-card.top-match .arith-rank { color: var(--accent-3); }
.arith-result-body { flex: 1; }
.arith-result-label { font-weight: 600; font-size: 0.95rem; }
.arith-result-score {
  font-size: 0.8rem; color: var(--muted, #8892a4); font-variant-numeric: tabular-nums;
}
.arith-equation {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.85rem; color: var(--muted, #8892a4); margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem; background: var(--code-bg, #151820); border-radius: 6px;
}
.arith-equation .arith-pos { color: var(--accent, #5ba300); }
.arith-equation .arith-neg { color: var(--danger); }
.arith-equation .arith-eq { color: var(--accent-3); font-weight: 700; }

/* ── Status bar ────────────────────────────────────────────────────────────── */
.status-bar {
  background: var(--surface, #1a1d27);
  border-top: 1px solid var(--border, #2d3148);
  padding: 0.4rem 1rem;
  font-size: 0.75rem;
  color: var(--muted, #8892a4);
  flex-shrink: 0;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .mobile-tab-bar { display: flex; }
  .vectors-layout {
    grid-template-columns: 1fr;
  }
  .left-panel, .right-panel { display: none; }
  .left-panel.mobile-active,
  .center-panel.mobile-active,
  .right-panel.mobile-active { display: flex; }
}
