/* ═══════════════════════════════════════════════════════════════════════
   ATLAS Observatory — Design System
   ═══════════════════════════════════════════════════════════════════════
   A dark, glass-morphism design language inspired by deep space
   observatories and cyberpunk control rooms.
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── CSS Custom Properties ─────────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg-deep:     #04050d;
  --bg-mid:      #0d1020;
  --bg-surface:  #141828;
  --bg-elevated: #1a2038;
  --bg-hover:    #1e2548;

  /* Brand Colors */
  --atlas-cyan:   #00d4ff;
  --atlas-cyan2:  #0099bb;
  --atlas-cyan-glow: rgba(0, 212, 255, 0.3);
  --palace-gold:  #d4a017;
  --palace-amber: #f0c040;
  --palace-gold-glow: rgba(212, 160, 23, 0.3);

  /* Semantic Colors */
  --success:  #34d399;
  --warning:  #fbbf24;
  --danger:   #f87171;
  --info:     #60a5fa;

  /* Text */
  --text:        #e2e8f0;
  --text-dim:    #94a3b8;
  --text-bright: #f8fafc;
  --text-muted:  #64748b;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  /* Borders */
  --border-subtle:  1px solid rgba(0, 212, 255, 0.08);
  --border-default: 1px solid rgba(0, 212, 255, 0.12);
  --border-bright:  1px solid rgba(0, 212, 255, 0.25);

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-pill: 999px;

  /* Shadows */
  --shadow-sm:   0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md:   0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg:   0 8px 32px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 20px rgba(0, 212, 255, 0.15);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;

  /* Layout */
  --navbar-height: 56px;
  --footer-height: 40px;
  --toolbar-height: 48px;
}

/* ─── Reset & Normalize ─────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-deep);
  color: var(--text);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

a {
  color: var(--atlas-cyan);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover {
  color: var(--atlas-cyan2);
  text-decoration: underline;
}

img, svg {
  display: block;
  max-width: 100%;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-bright);
}

code, pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

code {
  background: var(--bg-surface);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--atlas-cyan);
}

pre {
  background: var(--bg-surface);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  overflow-x: auto;
  border: var(--border-subtle);
}

::selection {
  background: rgba(0, 212, 255, 0.25);
  color: var(--text-bright);
}

/* ─── Scrollbar ─────────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-mid);
}
::-webkit-scrollbar-thumb {
  background: var(--atlas-cyan2);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--atlas-cyan);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--atlas-cyan2) var(--bg-mid);
}

/* ═══════════════════════════════════════════════════════════════════════
   LOADING SCREEN
   ═══════════════════════════════════════════════════════════════════════ */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.6s ease, visibility 0.6s ease;
}
.loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.4;
}

.loading-content {
  position: relative;
  z-index: 1;
  text-align: center;
}

.loading-logo {
  margin-bottom: var(--space-xl);
  animation: pulse 2s ease-in-out infinite;
}
.loading-logo-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto var(--space-md);
}
.loading-logo-icon svg {
  width: 100%;
  height: 100%;
}

.loading-title {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: 0.2em;
  background: linear-gradient(135deg, var(--atlas-cyan), var(--palace-gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.loading-subtitle {
  font-size: 1.1rem;
  color: var(--text-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-top: var(--space-xs);
}

.loading-progress {
  width: 240px;
  height: 3px;
  background: var(--bg-surface);
  border-radius: 2px;
  margin: var(--space-xl) auto var(--space-md);
  overflow: hidden;
}
.loading-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--atlas-cyan), var(--palace-gold));
  border-radius: 2px;
  transition: width 0.3s ease;
}

.loading-status {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ═══════════════════════════════════════════════════════════════════════
   APP CONTAINER
   ═══════════════════════════════════════════════════════════════════════ */
.app {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  transition: opacity 0.5s ease;
}

/* ═══════════════════════════════════════════════════════════════════════
   NAVIGATION BAR
   ═══════════════════════════════════════════════════════════════════════ */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--navbar-height);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-lg);
  background: rgba(13, 16, 32, 0.85);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  border-bottom: var(--border-subtle);
  box-shadow: var(--shadow-md);
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}
.navbar-logo {
  width: 28px;
  height: 28px;
}
.navbar-title {
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--text-bright);
}
.navbar-version {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: var(--bg-surface);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  margin-left: var(--space-xs);
}

.navbar-tabs {
  display: flex;
  gap: var(--space-xs);
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.tab-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.tab-btn.active {
  background: rgba(0, 212, 255, 0.12);
  color: var(--atlas-cyan);
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.15), inset 0 0 0 1px rgba(0, 212, 255, 0.2);
}
.tab-icon {
  font-size: 1rem;
}
.tab-label {
  display: inline;
}

.navbar-status {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition-base);
}
.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
}
.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 8px rgba(248, 113, 113, 0.5);
}
.status-text {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════════════
   TAB PANELS
   ═══════════════════════════════════════════════════════════════════════ */
.tab-panel {
  display: none;
  flex: 1;
  margin-top: var(--navbar-height);
  height: calc(100vh - var(--navbar-height) - var(--footer-height));
  overflow: hidden;
  animation: fadeIn 0.3s ease;
}
.tab-panel.active {
  display: flex;
  flex-direction: column;
}

/* ─── Glass Card (shared component) ─────────────────────────────────── */
.glass-card,
.panel-section,
.arena-card,
.library-card,
.forge-viz-panel {
  background: rgba(13, 16, 32, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(0, 212, 255, 0.1);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
}

.panel-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: var(--space-md);
}

/* ═══════════════════════════════════════════════════════════════════════
   TAB 1: PALACE — 3d-force-graph + Pheromone Particles
   ═══════════════════════════════════════════════════════════════════════ */

/* Main layout: toolbar-top + (viewport + side-panel) */
.palace-main {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

.palace-viewport {
  flex: 1;
  position: relative;
  min-width: 0;
  background: var(--bg-deep);
}

/* 3d-force-graph renders into this div */
.palace-graph-container {
  width: 100%;
  height: 100%;
}
.palace-graph-container canvas {
  display: block;
}

/* ─── Stats Overlay (top-right) ────────────────────────────────────── */
.palace-stats-overlay {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  background: rgba(4, 5, 13, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  pointer-events: none;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.7;
  z-index: 10;
}
.pso-line b {
  color: var(--atlas-cyan);
  font-weight: 600;
}

/* ─── Legend (bottom-left) ─────────────────────────────────────────── */
.palace-legend {
  position: absolute;
  bottom: var(--space-md);
  left: var(--space-md);
  display: flex;
  gap: var(--space-md);
  font-size: 0.7rem;
  color: var(--text-dim);
  pointer-events: none;
  z-index: 10;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.legend-line {
  width: 20px;
  height: 2px;
  display: inline-block;
  border-radius: 1px;
}
.legend-line.hot {
  background: linear-gradient(90deg, var(--palace-amber), var(--danger));
}
.legend-line.cold {
  background: linear-gradient(90deg, #3b82f6, #8b5cf6);
}
.legend-line.tunnel {
  background: var(--palace-gold);
  border-style: dashed;
  height: 1px;
  border-width: 1px 0 0 0;
  border-color: var(--palace-gold);
}

/* ─── FPS Counter (bottom-right) ───────────────────────────────────── */
.palace-fps {
  position: absolute;
  bottom: var(--space-md);
  right: var(--space-md);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 10;
}

/* ─── Search Results Dropdown ──────────────────────────────────────── */
.palace-search-results {
  position: absolute;
  top: 8px;
  left: var(--space-md);
  width: 320px;
  max-height: 300px;
  overflow-y: auto;
  background: rgba(13, 16, 32, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: var(--border-default);
  border-radius: var(--radius-md);
  z-index: 20;
  box-shadow: var(--shadow-lg);
}
.search-result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-sm) var(--space-md);
  cursor: pointer;
  transition: background var(--transition-fast);
  border-bottom: var(--border-subtle);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover {
  background: var(--bg-hover);
}
.sri-title {
  font-size: 0.8rem;
  color: var(--text);
  font-weight: 500;
}
.sri-score {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--palace-gold);
}

/* ─── Palace Toolbar (top controls bar) ────────────────────────────── */
.palace-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-lg);
  height: var(--toolbar-height);
  background: rgba(13, 16, 32, 0.9);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}
.palace-toolbar-top {
  border-bottom: var(--border-subtle);
}
.palace-search-box {
  min-width: 240px;
}
.palace-search-box .input {
  flex: 1;
}

/* Search box */
.search-box {
  display: flex;
  gap: var(--space-xs);
}
.search-box .input {
  flex: 1;
}

/* Active button state for toggles */
.btn.active {
  background: rgba(0, 212, 255, 0.15);
  color: var(--atlas-cyan);
  border-color: rgba(0, 212, 255, 0.3);
}

/* ─── Side Panel (slides in from right) ────────────────────────────── */
.palace-side-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 340px;
  height: 100%;
  background: rgba(10, 12, 24, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-left: var(--border-default);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.5);
  z-index: 30;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.palace-side-panel.open {
  transform: translateX(0);
}

.sp-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-bottom: var(--border-subtle);
  flex-shrink: 0;
}
.sp-icon {
  font-size: 1.4rem;
}
.sp-title {
  flex: 1;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sp-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--bg-surface);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.9rem;
}
.sp-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.sp-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md) var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}
.sp-section {
  /* layout section */
}
.sp-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
}

/* Type badges */
.sp-type-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}
.sp-type-wing {
  background: rgba(255, 107, 107, 0.15);
  color: #ff6b6b;
  border: 1px solid rgba(255, 107, 107, 0.3);
}
.sp-type-room {
  background: rgba(78, 205, 196, 0.15);
  color: #4ecdc4;
  border: 1px solid rgba(78, 205, 196, 0.3);
}
.sp-type-drawer {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

/* Content text */
.sp-content {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.6;
  background: var(--bg-surface);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  border: var(--border-subtle);
}

/* Pheromone bar */
.sp-pheromone-bar-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.sp-pheromone-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-surface);
  border-radius: 3px;
  overflow: hidden;
}
.sp-pheromone-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease, background 0.4s ease;
  background: var(--palace-amber);
}
.sp-pheromone-value {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--atlas-cyan);
  font-weight: 600;
  min-width: 36px;
  text-align: right;
}

/* Connected nodes list */
.sp-connections {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 200px;
  overflow-y: auto;
}
.sp-conn-item {
  font-size: 0.8rem;
  padding: 4px var(--space-sm);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-dim);
  transition: all var(--transition-fast);
}
.sp-conn-item:hover {
  background: var(--bg-hover);
  color: var(--atlas-cyan);
}

/* Actions */
.sp-actions {
  padding-top: var(--space-sm);
  border-top: var(--border-subtle);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.toolbar-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════════════════
   TAB 2: FORGE — AI Chat Interface with Live Visualization
   ═══════════════════════════════════════════════════════════════════════
   Layout: 60% chat (left) / 40% viz panel (right)
   Features: streaming chat, token stream, OODA ring, live stats
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── Forge Container: Main Split Layout ──────────────────────────────
   Flexbox row filling the entire tab panel height.
   Left side = chat, right side = visualization panels.
   ───────────────────────────────────────────────────────────────────── */
.forge-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;          /* anchor for loading overlay */
  min-height: 0;               /* flex child shrink fix */
}

/* ─── Chat Section (Left 60%) ─────────────────────────────────────── */
.forge-chat {
  flex: 0 0 60%;
  display: flex;
  flex-direction: column;
  border-right: var(--border-subtle);
  min-width: 0;                /* prevent flex blowout */
  overflow: hidden;
}

/* ─── Prompt Chips ─────────────────────────────────────────────────── */
.forge-prompt-chips {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  overflow-x: auto;
  flex-shrink: 0;
  border-bottom: var(--border-subtle);
  background: rgba(4, 5, 13, 0.35);
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 212, 255, 0.15) transparent;
}
.forge-prompt-chips::-webkit-scrollbar {
  height: 4px;
}
.forge-prompt-chips::-webkit-scrollbar-thumb {
  background: rgba(0, 212, 255, 0.15);
  border-radius: var(--radius-pill);
}

.prompt-chip {
  padding: 6px 14px;
  border: 1px solid rgba(0, 212, 255, 0.15);
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  color: var(--text-dim);
  font-size: 0.8rem;
  font-family: var(--font-sans);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
  user-select: none;
}
.prompt-chip:hover {
  border-color: rgba(0, 212, 255, 0.35);
  color: var(--atlas-cyan);
  background: rgba(0, 212, 255, 0.06);
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.08);
}
.prompt-chip:active {
  transform: scale(0.97);
}

/* ─── Message Area ─────────────────────────────────────────────────── */
.forge-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 212, 255, 0.12) transparent;
}
.forge-messages::-webkit-scrollbar {
  width: 6px;
}
.forge-messages::-webkit-scrollbar-track {
  background: transparent;
}
.forge-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 212, 255, 0.12);
  border-radius: var(--radius-pill);
}

/* ─── Welcome Message ──────────────────────────────────────────────── */
.forge-welcome {
  align-self: center;
  max-width: 520px;
  text-align: center;
  padding: var(--space-lg) var(--space-xl);
  background: rgba(212, 160, 23, 0.05);
  border: 1px solid rgba(212, 160, 23, 0.18);
  border-left: 3px solid var(--palace-gold);
  border-radius: var(--radius-lg);
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.7;
  animation: fadeInUp 0.5s ease;
}
.forge-welcome strong {
  color: var(--palace-amber);
}

/* ─── Chat Bubbles ─────────────────────────────────────────────────── */
.chat-bubble {
  max-width: 85%;
  animation: fadeInUp 0.3s ease;
}

/* User messages — right-aligned, cyan accent */
.chat-bubble.user {
  align-self: flex-end;
}
.chat-bubble.user .bubble-content {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
  background: rgba(0, 212, 255, 0.08);
  border: 1px solid rgba(0, 212, 255, 0.18);
  border-left: 3px solid var(--atlas-cyan);
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.65;
}

/* Assistant messages — left-aligned, glass card */
.chat-bubble.assistant {
  align-self: flex-start;
}
.chat-bubble.assistant .bubble-content {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
  background: rgba(13, 16, 32, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(0, 212, 255, 0.08);
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.65;
}

/* ─── Bubble Content Typography ────────────────────────────────────── */
.bubble-content p {
  margin: 0 0 var(--space-sm);
}
.bubble-content p:last-child {
  margin-bottom: 0;
}
.bubble-content h1,
.bubble-content h2,
.bubble-content h3 {
  color: var(--text-bright);
  margin: var(--space-md) 0 var(--space-sm);
  font-family: var(--font-sans);
  line-height: 1.3;
}
.bubble-content h1 { font-size: 1.25rem; }
.bubble-content h2 { font-size: 1.1rem; }
.bubble-content h3 { font-size: 1rem; color: var(--atlas-cyan); }

.bubble-content strong {
  color: var(--text-bright);
  font-weight: 600;
}
.bubble-content em {
  color: var(--text-dim);
  font-style: italic;
}
.bubble-content a {
  color: var(--atlas-cyan);
  text-decoration: underline;
  text-decoration-color: rgba(0, 212, 255, 0.3);
  text-underline-offset: 2px;
  transition: text-decoration-color var(--transition-fast);
}
.bubble-content a:hover {
  text-decoration-color: var(--atlas-cyan);
}

/* Lists */
.bubble-content ul,
.bubble-content ol {
  margin: var(--space-sm) 0;
  padding-left: var(--space-lg);
}
.bubble-content li {
  margin-bottom: var(--space-xs);
  line-height: 1.6;
}
.bubble-content ul li::marker {
  color: var(--atlas-cyan2);
}
.bubble-content ol li::marker {
  color: var(--atlas-cyan2);
  font-family: var(--font-mono);
  font-size: 0.85em;
}

/* Inline code */
.bubble-content code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 2px 6px;
  background: rgba(0, 212, 255, 0.06);
  border: 1px solid rgba(0, 212, 255, 0.12);
  border-radius: var(--radius-sm);
  color: var(--atlas-cyan);
}

/* Code blocks */
.bubble-content pre {
  margin: var(--space-sm) 0;
  padding: var(--space-md);
  background: var(--bg-deep);
  border: 1px solid rgba(0, 212, 255, 0.1);
  border-radius: var(--radius-md);
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 212, 255, 0.12) transparent;
}
.bubble-content pre code {
  padding: 0;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.82rem;
  line-height: 1.6;
}

/* ─── Think Blocks ─────────────────────────────────────────────────── */
.think-block {
  margin: var(--space-sm) 0;
  padding: var(--space-sm) var(--space-md);
  background: rgba(139, 92, 246, 0.06);
  border: 1px solid rgba(139, 92, 246, 0.15);
  border-radius: var(--radius-md);
  font-size: 0.85em;
}
.think-block summary {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 0.85em;
  user-select: none;
}
.think-block summary:hover {
  color: var(--text);
}
.think-content {
  margin-top: var(--space-sm);
  color: var(--text-dim);
  line-height: 1.5;
}
.think-content.dimmed {
  opacity: 0.6;
}
.think-label {
  color: rgba(139, 92, 246, 0.7);
  font-size: 0.8em;
  font-weight: 500;
}
.think-block.thinking {
  border-color: rgba(139, 92, 246, 0.25);
  animation: thinkPulse 1.5s ease-in-out infinite;
}
@keyframes thinkPulse {
  0%, 100% { border-color: rgba(139, 92, 246, 0.15); }
  50% { border-color: rgba(139, 92, 246, 0.35); }
}

/* ─── Bubble Meta (timestamp) ──────────────────────────────────────── */
.bubble-meta {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: var(--space-xs);
  padding: 0 var(--space-xs);
  font-family: var(--font-mono);
}
.chat-bubble.user .bubble-meta {
  text-align: right;
}

/* Demo mode — dimmed messages */
.chat-bubble.demo {
  opacity: 0.55;
  pointer-events: none;
}

/* Demo notice banner */
.forge-demo-notice {
  align-self: center;
  text-align: center;
  padding: var(--space-sm) var(--space-md);
  font-size: 0.8rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  justify-content: center;
}
.forge-demo-pulse {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--palace-gold);
  animation: oodaPulse 1.8s ease-in-out infinite;
}

/* ─── Streaming Indicator ──────────────────────────────────────────── */
.forge-cursor {
  display: inline-block;
  width: 7px;
  height: 16px;
  background: var(--atlas-cyan);
  border-radius: 1px;
  vertical-align: text-bottom;
  animation: streamingDot 0.8s ease-in-out infinite;
}
.chat-bubble.assistant.streaming .bubble-content::after {
  content: '';
  display: inline-block;
  width: 7px;
  height: 16px;
  margin-left: 2px;
  background: var(--atlas-cyan);
  border-radius: 1px;
  vertical-align: text-bottom;
  animation: streamingDot 0.8s ease-in-out infinite;
}

/* ─── Token Stream Placeholder ────────────────────────────────────── */
.forge-token-placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.75rem;
}

/* ─── Logprob Note ────────────────────────────────────────────────── */
.forge-logprob-note {
  font-size: 0.6rem;
  color: var(--text-muted);
  font-style: italic;
  margin-left: var(--space-sm);
}

/* ─── Input Area ───────────────────────────────────────────────────── */
.forge-input-area {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg) var(--space-md);
  border-top: var(--border-subtle);
  background: rgba(4, 5, 13, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  flex-shrink: 0;
}

#forge-input {
  width: 100%;
  background: var(--bg-surface);
  border: var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  line-height: 1.5;
  resize: none;
  min-height: 42px;
  max-height: 120px;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
#forge-input::placeholder {
  color: var(--text-muted);
}
#forge-input:focus {
  border-color: var(--atlas-cyan);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.08);
}

.forge-input-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
}

/* ─── Buttons ──────────────────────────────────────────────────────── */
.forge-btn {
  padding: 7px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all var(--transition-fast);
  user-select: none;
  white-space: nowrap;
}
.forge-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Send — primary cyan */
.forge-btn-send {
  background: linear-gradient(135deg, var(--atlas-cyan), var(--atlas-cyan2));
  color: var(--bg-deep);
  font-weight: 600;
  box-shadow: 0 0 16px rgba(0, 212, 255, 0.2);
}
.forge-btn-send:hover:not(:disabled) {
  box-shadow: 0 0 24px rgba(0, 212, 255, 0.35);
  transform: translateY(-1px);
}
.forge-btn-send:active:not(:disabled) {
  transform: scale(0.97);
}
/* Loading spinner inside send button */
.forge-btn-send.loading {
  pointer-events: none;
  position: relative;
  color: transparent;
}
.forge-btn-send.loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(4, 5, 13, 0.3);
  border-top-color: var(--bg-deep);
  border-radius: 50%;
  animation: spinnerRotate 0.7s linear infinite;
}

/* Stop — danger */
.forge-btn-stop {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.3);
  color: var(--danger);
  display: none;               /* hidden by default, shown during generation */
}
.forge-btn-stop.visible {
  display: inline-flex;
}
.forge-btn-stop:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.2);
  border-color: var(--danger);
  box-shadow: 0 0 12px rgba(248, 113, 113, 0.15);
}

/* Clear — ghost */
.forge-btn-clear {
  background: transparent;
  border-color: rgba(0, 212, 255, 0.1);
  color: var(--text-muted);
}
.forge-btn-clear:hover:not(:disabled) {
  border-color: rgba(0, 212, 255, 0.25);
  color: var(--text-dim);
  background: rgba(0, 212, 255, 0.04);
}


/* ═══════════════════════════════════════════════════════════════════════
   Visualization Panel (Right 40%)
   ═══════════════════════════════════════════════════════════════════════ */
.forge-viz {
  flex: 0 0 40%;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  padding: var(--space-md);
  overflow-y: auto;
  background: rgba(4, 5, 13, 0.25);
  min-width: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 212, 255, 0.1) transparent;
}

/* ─── Viz Panel (glass card base) ──────────────────────────────────── */
.forge-viz-panel {
  /* inherits from shared .forge-stats / .forge-stream / .forge-trace rule */
  background: rgba(13, 16, 32, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(0, 212, 255, 0.1);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  flex-shrink: 0;
}

.forge-viz-title {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
  font-family: var(--font-mono);
}

/* ─── Token Stream ─────────────────────────────────────────────────── */
.forge-token-stream {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 212, 255, 0.1) transparent;
}

.token-chip {
  display: inline-block;
  padding: 3px 7px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  animation: tokenAppear 0.25s ease;
  transition: background var(--transition-fast);
  cursor: default;
  white-space: pre-wrap;
  word-break: break-all;
}
.token-chip:hover {
  background: var(--bg-elevated);
}

/* Confidence color-coding on bottom border */
.token-chip.conf-high {
  border-bottom-color: var(--success);
}
.token-chip.conf-mid {
  border-bottom-color: var(--warning);
}
.token-chip.conf-low {
  border-bottom-color: var(--danger);
}
.token-chip.conf-unknown {
  border-bottom-color: var(--text-muted);
}

/* ─── OODA Cycle Visualization ─────────────────────────────────────── */
.forge-ooda {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-sm) 0;
  min-height: 180px;
  position: relative;
}
.forge-ooda svg {
  width: 100%;
  max-width: 200px;
  height: auto;
}

/* SVG arc segments */
.ooda-segment {
  fill: none;
  stroke-width: 12;
  stroke-linecap: round;
  stroke: rgba(0, 212, 255, 0.1);
  transition: stroke var(--transition-base), filter var(--transition-base);
}
.ooda-segment.active {
  stroke: var(--atlas-cyan);
  filter: drop-shadow(0 0 6px rgba(0, 212, 255, 0.5));
  animation: oodaPulse 1.8s ease-in-out infinite;
}
/* Phase-specific colors */
.ooda-segment[data-phase="observe"].active  { stroke: var(--info); filter: drop-shadow(0 0 6px rgba(96, 165, 250, 0.5)); }
.ooda-segment[data-phase="orient"].active   { stroke: var(--palace-amber); filter: drop-shadow(0 0 6px rgba(240, 192, 64, 0.5)); }
.ooda-segment[data-phase="decide"].active   { stroke: var(--success); filter: drop-shadow(0 0 6px rgba(52, 211, 153, 0.5)); }
.ooda-segment[data-phase="act"].active      { stroke: var(--atlas-cyan); filter: drop-shadow(0 0 6px rgba(0, 212, 255, 0.5)); }

/* Labels around the ring */
.ooda-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 500;
  fill: var(--text-muted);
  text-anchor: middle;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  transition: fill var(--transition-base);
}
.ooda-label.active {
  fill: var(--text-bright);
}

/* Center text */
.ooda-center-text {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  fill: var(--text-dim);
  text-anchor: middle;
  dominant-baseline: central;
}
.ooda-center-text.active {
  fill: var(--atlas-cyan);
}

/* ─── Stats Grid ───────────────────────────────────────────────────── */
.forge-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
}

.forge-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-sm);
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: var(--border-subtle);
  transition: border-color var(--transition-fast);
}
.forge-stat:hover {
  border-color: rgba(0, 212, 255, 0.2);
}

.forge-stat-label {
  font-size: 0.6rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 2px;
  font-family: var(--font-mono);
}

.forge-stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--atlas-cyan);
  font-family: var(--font-mono);
  line-height: 1.2;
}
/* Glow effect for pheromone deposits */
.forge-stat-value--glow {
  text-shadow: 0 0 8px rgba(0, 212, 255, 0.4);
}
/* Animated value change flash */
.forge-stat-value.flash {
  animation: statFlash 0.4s ease;
}


/* ═══════════════════════════════════════════════════════════════════════
   Loading Overlay — covers entire forge-container during model init
   ═══════════════════════════════════════════════════════════════════════ */
.forge-loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 5, 13, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: opacity var(--transition-slow), visibility var(--transition-slow);
}
.forge-loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.forge-loading-content {
  text-align: center;
  max-width: 380px;
  padding: var(--space-xl);
}
.forge-loading-content h3 {
  font-size: 1.15rem;
  color: var(--text-bright);
  margin: var(--space-md) 0 var(--space-sm);
  font-family: var(--font-sans);
}
.forge-loading-content p {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.6;
}

/* Spinning ring */
.forge-loading-spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto;
  border: 3px solid rgba(0, 212, 255, 0.12);
  border-top-color: var(--atlas-cyan);
  border-radius: 50%;
  animation: spinnerRotate 0.9s linear infinite;
}


/* ═══════════════════════════════════════════════════════════════════════
   Forge Keyframes
   ═══════════════════════════════════════════════════════════════════════ */

/* New message slides up and fades in */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Token chips scale in */
@keyframes tokenAppear {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Spinner rotation */
@keyframes spinnerRotate {
  to {
    transform: rotate(360deg);
  }
}

/* Active OODA segment glow pulse */
@keyframes oodaPulse {
  0%, 100% {
    filter: drop-shadow(0 0 4px rgba(0, 212, 255, 0.35));
    stroke-width: 12;
  }
  50% {
    filter: drop-shadow(0 0 10px rgba(0, 212, 255, 0.65));
    stroke-width: 14;
  }
}

/* Streaming cursor blink */
@keyframes streamingDot {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.15; }
}

/* Stat value flash on update */
@keyframes statFlash {
  0%   { color: var(--text-bright); }
  100% { color: var(--atlas-cyan); }
}


   TAB 3: ARENA — n-Morphic Evolution
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── Controls Bar ──────────────────────────────────────────────────── */
.arena-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-lg);
  background: rgba(13, 16, 32, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: var(--border-subtle);
  flex-shrink: 0;
}

/* k-Morphic selector radio-button group */
.arena-k-group { gap: var(--space-sm); }
.arena-k-selector {
  display: flex;
  gap: 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid rgba(0, 212, 255, 0.15);
}
.arena-k-btn {
  padding: 5px 14px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-surface);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.02em;
}
.arena-k-btn:not(:last-child) {
  border-right: 1px solid rgba(0, 212, 255, 0.1);
}
.arena-k-btn:hover {
  background: var(--bg-hover);
  color: var(--atlas-cyan);
}
.arena-k-btn.active {
  background: rgba(0, 212, 255, 0.15);
  color: var(--atlas-cyan);
  box-shadow: inset 0 0 12px rgba(0, 212, 255, 0.1);
}

/* Playback buttons */
.arena-playback { gap: var(--space-xs); }
.arena-ctrl-btn {
  font-size: 0.78rem;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.arena-ctrl-btn.playing {
  background: rgba(0, 212, 255, 0.2);
  border-color: var(--atlas-cyan);
}

/* Generation counter */
.arena-gen-group {
  margin-left: auto;
  gap: var(--space-sm);
}
.arena-gen-counter {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--atlas-cyan);
  white-space: nowrap;
}
.arena-progress {
  width: 100px;
  height: 4px;
  background: var(--bg-surface);
  border-radius: 2px;
  overflow: hidden;
}
.arena-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--atlas-cyan), var(--palace-gold));
  border-radius: 2px;
  transition: width 0.08s linear;
}

/* ─── 2×2 Visualization Grid ───────────────────────────────────────── */
#arena.tab-panel {
  overflow-y: auto;        /* allow vertical scroll on small viewports */
  overflow-x: hidden;
}
.arena-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: var(--space-md);
  padding: var(--space-md);
  flex: 1;
  min-height: 0;
}

.arena-card {
  display: flex;
  flex-direction: column;
  background: rgba(13, 16, 32, 0.6);
  border: 1px solid rgba(0, 212, 255, 0.08);
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
.arena-card:hover {
  border-color: rgba(0, 212, 255, 0.2);
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.06);
}

.arena-panel-label {
  display: block;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid rgba(0, 212, 255, 0.06);
  flex-shrink: 0;
}

.arena-card canvas {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: block;
  background: var(--bg-deep);
}

/* ─── Summary Stats Panel ──────────────────────────────────────────── */
.arena-summary {
  flex-shrink: 0;
  margin: 0 var(--space-md) var(--space-md);
  background: rgba(13, 16, 32, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(0, 212, 255, 0.1);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.arena-summary-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 8px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid rgba(0, 212, 255, 0.06);
}
.arena-summary-icon { font-size: 1rem; }

.arena-summary-content {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  padding: 10px 16px;
  align-items: center;
}

.arena-summary-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  background: var(--bg-surface);
  transition: background 0.2s ease;
}
.arena-summary-row.active {
  background: rgba(0, 212, 255, 0.1);
  border: 1px solid rgba(0, 212, 255, 0.15);
}
.arena-summary-k {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.82rem;
  min-width: 32px;
}
.arena-summary-fit {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.9rem;
}
.arena-summary-detail {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.arena-summary-advantage {
  margin-left: auto;
  padding: 6px 16px;
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.25);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: var(--success);
  font-weight: 600;
  animation: arenaAdvantageGlow 2s ease-in-out infinite alternate;
}
@keyframes arenaAdvantageGlow {
  from { box-shadow: 0 0 6px rgba(52, 211, 153, 0.1); }
  to   { box-shadow: 0 0 18px rgba(52, 211, 153, 0.25); }
}

/* Range inputs (kept for Workshop tab compatibility) */
.range-input {
  -webkit-appearance: none;
  appearance: none;
  width: 100px;
  height: 4px;
  background: var(--bg-surface);
  border-radius: 2px;
  outline: none;
}
.range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--atlas-cyan);
  cursor: pointer;
  box-shadow: 0 0 6px rgba(0, 212, 255, 0.4);
}
.range-input::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--atlas-cyan);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 6px rgba(0, 212, 255, 0.4);
}
.range-value {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--atlas-cyan);
  min-width: 32px;
  text-align: center;
}

/* ═══════════════════════════════════════════════════════════════════════
   TAB 4: LIBRARY
   ═══════════════════════════════════════════════════════════════════════ */
.library-layout {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-xl) var(--space-2xl);
}

.library-header {
  text-align: center;
  margin-bottom: var(--space-2xl);
}
.section-title {
  font-size: 2rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--atlas-cyan), var(--palace-gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-sm);
}
.section-subtitle {
  color: var(--text-dim);
  font-size: 1rem;
  max-width: 600px;
  margin: 0 auto;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: var(--space-lg);
  max-width: 1200px;
  margin: 0 auto;
}

.library-card {
  transition: transform var(--transition-base), box-shadow var(--transition-base);
}
.library-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}
.library-card-wide {
  grid-column: 1 / -1;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: var(--border-subtle);
}
.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-bright);
}
.card-badge {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--palace-gold);
  background: rgba(212, 160, 23, 0.1);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(212, 160, 23, 0.2);
}

.card-body {
  /* inherits from glass card */
}
.card-text {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.7;
  margin-bottom: var(--space-md);
}
.card-text:last-child {
  margin-bottom: 0;
}

.math-display {
  padding: var(--space-md);
  background: var(--bg-deep);
  border-radius: var(--radius-md);
  text-align: center;
  margin-bottom: var(--space-md);
  border: var(--border-subtle);
  overflow-x: auto;
}
.math-placeholder {
  font-size: 1.1rem;
  color: var(--text);
}

/* Sliders for Library */
.slider-group {
  margin-bottom: var(--space-sm);
}
.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: var(--space-xs);
}
.slider-label span {
  color: var(--atlas-cyan);
  font-family: var(--font-mono);
}

.iso-visualization {
  margin-top: var(--space-md);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-deep);
  border: var(--border-subtle);
}
.iso-visualization canvas {
  width: 100%;
  height: auto;
}

/* Architecture Diagram */
.arch-diagram {
  padding: var(--space-md);
}
.arch-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
}
.arch-layer {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
  justify-content: center;
}
.arch-box {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid;
  min-width: 140px;
}
.arch-box small {
  display: block;
  font-weight: 400;
  font-size: 0.7rem;
  margin-top: var(--space-xs);
  opacity: 0.7;
}
.arch-box-cyan {
  background: rgba(0, 212, 255, 0.08);
  border-color: rgba(0, 212, 255, 0.25);
  color: var(--atlas-cyan);
}
.arch-box-gold {
  background: rgba(212, 160, 23, 0.08);
  border-color: rgba(212, 160, 23, 0.25);
  color: var(--palace-gold);
}
.arch-box-green {
  background: rgba(52, 211, 153, 0.08);
  border-color: rgba(52, 211, 153, 0.25);
  color: var(--success);
}
.arch-box-purple {
  background: rgba(139, 92, 246, 0.08);
  border-color: rgba(139, 92, 246, 0.25);
  color: #a78bfa;
}
.arch-arrow {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-align: center;
}

/* Timeline */
.timeline {
  position: relative;
  padding-left: var(--space-lg);
}
.timeline::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--bg-surface);
}
.timeline-item {
  position: relative;
  margin-bottom: var(--space-lg);
}
.timeline-item:last-child {
  margin-bottom: 0;
}
.timeline-dot {
  position: absolute;
  left: calc(-1 * var(--space-lg) + 2px);
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 2px solid var(--text-muted);
}
.timeline-dot.active {
  background: var(--atlas-cyan);
  border-color: var(--atlas-cyan);
  box-shadow: 0 0 8px rgba(0, 212, 255, 0.4);
}
.timeline-content {
  padding-left: var(--space-xs);
}
.timeline-date {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--palace-gold);
  font-weight: 600;
}
.timeline-content p {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-top: var(--space-xs);
  line-height: 1.5;
}

/* ═══════════════════════════════════════════════════════════════════════
   TAB 5: WORKSHOP — Build Your Own Palace
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── API Banner ─────────────────────────────────────────────────────── */
.ws-api-banner {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 6px var(--space-lg);
  background: rgba(251, 191, 36, 0.08);
  border-bottom: 1px solid rgba(251, 191, 36, 0.2);
  color: var(--warning);
  font-size: 0.78rem;
  font-weight: 500;
}
.ws-banner-icon { font-size: 1rem; }

/* ─── Layout ─────────────────────────────────────────────────────────── */
.workshop-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Left: Tools Panel ──────────────────────────────────────────────── */
.workshop-tools {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: var(--border-subtle);
  background: rgba(4, 5, 13, 0.5);
}
.ws-tools-header {
  padding: var(--space-sm) var(--space-md);
  border-bottom: var(--border-subtle);
  flex-shrink: 0;
}
.ws-tools-header .panel-title { margin: 0; }
.ws-tools-scroll {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-sm);
}

/* Tool Cards (collapsible) */
.ws-tool-card {
  border: var(--border-subtle);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-xs);
  background: rgba(13, 16, 32, 0.6);
  transition: border-color var(--transition-fast);
}
.ws-tool-card:hover {
  border-color: rgba(0, 212, 255, 0.15);
}
.ws-tool-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  user-select: none;
  transition: color var(--transition-fast);
}
.ws-tool-header:hover { color: var(--atlas-cyan); }
.ws-tool-icon { font-size: 0.9rem; }
.ws-chevron {
  margin-left: auto;
  font-size: 0.9rem;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}
.ws-tool-card.open .ws-chevron { transform: rotate(90deg); }

.ws-tool-body {
  display: none;
  padding: 0 12px 12px;
  flex-direction: column;
  gap: 6px;
}
.ws-tool-card.open .ws-tool-body {
  display: flex;
}
.ws-tool-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}
.ws-full-btn { width: 100%; }
.ws-btn-row { display: flex; gap: 6px; }
.ws-btn-row .btn { flex: 1; }

/* Slider rows */
.ws-slider-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.ws-slider-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  min-width: 70px;
  flex-shrink: 0;
}
.ws-range {
  flex: 1;
  min-width: 60px;
  accent-color: var(--atlas-cyan);
}
.ws-range-val {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--atlas-cyan);
  min-width: 32px;
  text-align: right;
}

/* Inline results (inside tool card) */
.ws-inline-results {
  max-height: 200px;
  overflow-y: auto;
  margin-top: var(--space-xs);
}

/* Legacy classes kept for compatibility */
.tool-group { margin-bottom: var(--space-lg); }
.tool-group-title {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--palace-gold);
  margin-bottom: var(--space-sm); padding-bottom: var(--space-xs);
  border-bottom: 1px solid rgba(212, 160, 23, 0.15);
}
.tool-form { display: flex; flex-direction: column; gap: var(--space-xs); }


/* ─── Center: Palace Viewer ──────────────────────────────────────────── */
.workshop-viewport {
  flex: 1;
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Viewer toolbar */
.ws-viewer-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 6px var(--space-md);
  border-bottom: var(--border-subtle);
  background: rgba(4, 5, 13, 0.6);
  flex-shrink: 0;
}
.ws-view-toggle {
  display: flex;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: var(--border-subtle);
  overflow: hidden;
}
.ws-view-btn {
  padding: 4px 12px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-dim);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.ws-view-btn:hover { color: var(--text); background: var(--bg-hover); }
.ws-view-btn.active {
  color: var(--atlas-cyan);
  background: rgba(0, 212, 255, 0.1);
}
.ws-viewer-stats {
  display: flex;
  gap: var(--space-md);
  font-size: 0.72rem;
  color: var(--text-dim);
  flex: 1;
}
.ws-viewer-stats span {
  white-space: nowrap;
}
.ws-example-wrap {
  flex-shrink: 0;
}

/* Viewer content area */
.ws-viewer-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
  position: relative;
}

/* Empty state */
.ws-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 300px;
  text-align: center;
  color: var(--text-muted);
}
.ws-empty-icon { font-size: 3rem; margin-bottom: var(--space-md); opacity: 0.5; }
.ws-empty-state h3 { color: var(--text-dim); font-size: 1.1rem; margin-bottom: var(--space-sm); }
.ws-empty-state p { font-size: 0.85rem; max-width: 400px; line-height: 1.6; }

/* ─── Tree View ──────────────────────────────────────────────────────── */
.ws-tree { font-size: 0.82rem; }
.ws-tree-root {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 6px var(--space-sm);
  font-weight: 700;
  color: var(--text-bright);
  font-size: 0.9rem;
  margin-bottom: var(--space-sm);
}
.ws-tree-icon { font-size: 0.85rem; flex-shrink: 0; }
.ws-tree-label { font-weight: 600; color: var(--text); }
.ws-tree-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.ws-tree-desc {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: auto;
}
.ws-tree-branch {
  margin-left: var(--space-md);
  padding-left: var(--space-md);
  border-left: 2px solid rgba(0, 212, 255, 0.1);
  margin-bottom: var(--space-sm);
}
.ws-tree-wing {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 6px var(--space-sm);
  border-left: 3px solid;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: rgba(13, 16, 32, 0.5);
  margin-bottom: 4px;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.ws-tree-wing:hover { background: var(--bg-hover); }
.ws-tree-room-group {
  margin-left: var(--space-lg);
  padding-left: var(--space-sm);
  border-left: 1px solid rgba(0, 212, 255, 0.06);
}
.ws-tree-room {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 4px var(--space-sm);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.ws-tree-room:hover { background: var(--bg-hover); }
.ws-tree-ph {
  font-size: 0.6rem;
  margin-left: auto;
}
.ws-tree-drawer {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 3px var(--space-sm) 3px var(--space-xl);
  font-size: 0.78rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.ws-tree-drawer:hover { background: rgba(30, 37, 72, 0.5); }
.ws-tree-drawer .ws-tree-label { font-weight: 400; color: var(--text-dim); }
.ws-tree-tags { display: flex; gap: 3px; margin-left: auto; }
.ws-tag {
  font-size: 0.6rem;
  padding: 1px 5px;
  border-radius: var(--radius-pill);
  background: rgba(0, 212, 255, 0.08);
  color: var(--atlas-cyan2);
  border: 1px solid rgba(0, 212, 255, 0.12);
}

/* ─── 2D Graph Canvas ────────────────────────────────────────────────── */
.ws-graph-canvas {
  width: 100%;
  height: 100%;
  display: block;
  position: absolute;
  top: 0;
  left: 0;
}

/* ─── Search/Pheromone Results Overlay ────────────────────────────────── */
.ws-search-results {
  position: absolute;
  bottom: var(--space-md);
  left: var(--space-md);
  right: var(--space-md);
  max-height: 45%;
  overflow-y: auto;
  background: rgba(13, 16, 32, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  z-index: 10;
}
.ws-search-results:empty { display: none; }
.ws-results-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-bright);
  margin-bottom: var(--space-sm);
}
.ws-no-results {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: var(--space-sm);
  text-align: center;
}
.ws-search-result {
  padding: var(--space-sm);
  border-bottom: var(--border-subtle);
  transition: background var(--transition-fast);
}
.ws-search-result:last-child { border-bottom: none; }
.ws-search-result:hover { background: var(--bg-hover); }
.ws-sr-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}
.ws-sr-score {
  float: right;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--atlas-cyan);
  background: rgba(0, 212, 255, 0.08);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}
.ws-sr-preview {
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin-top: 2px;
}

/* KG Triple display */
.ws-kg-triple {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 4px var(--space-sm);
  font-size: 0.78rem;
  border-bottom: var(--border-subtle);
}
.ws-kg-triple:last-child { border-bottom: none; }
.ws-kg-s { color: var(--atlas-cyan); font-weight: 600; }
.ws-kg-p {
  color: var(--text-muted);
  font-size: 0.72rem;
  font-style: italic;
  padding: 0 2px;
}
.ws-kg-p::before { content: '—['; }
.ws-kg-p::after { content: ']→'; }
.ws-kg-o { color: var(--palace-gold); font-weight: 600; }
.ws-kg-conf {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* Pheromone bar */
.ws-pheromone-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 4px var(--space-sm);
  font-size: 0.78rem;
}
.ws-ph-path { flex: 1; color: var(--text-dim); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-ph-bar {
  flex: 0 0 80px;
  height: 6px;
  background: var(--bg-deep);
  border-radius: 3px;
  overflow: hidden;
}
.ws-ph-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}
.ws-ph-val {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  min-width: 30px;
  text-align: right;
  color: var(--text-dim);
}


/* ─── Right: Operation Log ───────────────────────────────────────────── */
.workshop-log {
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-left: var(--border-subtle);
  background: rgba(4, 5, 13, 0.5);
}
.ws-log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  border-bottom: var(--border-subtle);
  flex-shrink: 0;
}
.ws-log-header .panel-title { margin: 0; }
.ws-log-actions { display: flex; gap: 4px; }
.ws-log-entries {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-xs);
}

/* Log entry */
.ws-log-entry {
  font-size: 0.68rem;
  font-family: var(--font-mono);
  padding: 6px var(--space-sm);
  border-bottom: var(--border-subtle);
  border-left: 2px solid transparent;
  transition: background var(--transition-fast);
}
.ws-log-entry:hover { background: rgba(13, 16, 32, 0.5); }
.ws-log-entry.log-success { border-left-color: var(--success); }
.ws-log-entry.log-error { border-left-color: var(--danger); }
.ws-log-head {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.ws-log-time {
  color: var(--text-muted);
  font-size: 0.65rem;
}
.ws-log-method {
  font-weight: 700;
  font-size: 0.65rem;
  padding: 1px 4px;
  border-radius: 2px;
  text-transform: uppercase;
}
.ws-method-get { color: var(--info); }
.ws-method-post { color: var(--success); }
.ws-method-load { color: var(--palace-gold); }
.ws-method-init { color: var(--atlas-cyan); }
.ws-log-ep {
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
}
.ws-log-status {
  color: var(--text-muted);
  font-size: 0.62rem;
}
.ws-log-ms {
  color: var(--text-muted);
  font-size: 0.62rem;
  margin-left: auto;
}
.ws-log-msg {
  color: var(--text-dim);
  font-size: 0.68rem;
  margin-top: 2px;
  line-height: 1.4;
  word-break: break-word;
}
.ws-log-entry.log-success .ws-log-msg { color: var(--text-dim); }
.ws-log-entry.log-error .ws-log-msg { color: var(--danger); }

/* Legacy log classes (backward compat) */
.log-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-sm) var(--space-md); border-bottom: var(--border-subtle);
}
.log-entries { flex: 1; overflow-y: auto; padding: var(--space-sm); }
.log-entry {
  font-size: 0.7rem; font-family: var(--font-mono);
  padding: var(--space-xs) var(--space-sm);
  border-bottom: var(--border-subtle); display: flex; gap: var(--space-sm);
}
.log-time { color: var(--text-muted); flex-shrink: 0; min-width: 42px; }
.log-msg { color: var(--text-dim); word-break: break-word; }
.log-entry.log-info .log-msg { color: var(--text-dim); }
.log-entry.log-success .log-msg { color: var(--success); }
.log-entry.log-error .log-msg { color: var(--danger); }
.log-entry.log-warning .log-msg { color: var(--warning); }

/* ═══════════════════════════════════════════════════════════════════════
   SHARED COMPONENTS
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  outline: none;
}
.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--atlas-cyan2), var(--atlas-cyan));
  color: var(--bg-deep);
  font-weight: 600;
}
.btn-primary:hover {
  box-shadow: 0 0 16px rgba(0, 212, 255, 0.35);
  filter: brightness(1.1);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text);
  border: var(--border-default);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: rgba(0, 212, 255, 0.25);
}

.btn-danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.25);
}
.btn-danger:hover {
  background: rgba(248, 113, 113, 0.25);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.78rem;
  border-radius: var(--radius-sm);
}
.btn-xs {
  padding: 3px 8px;
  font-size: 0.7rem;
  border-radius: var(--radius-sm);
}
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text);
  border: var(--border-default);
}
.btn-icon:hover {
  background: var(--bg-hover);
  border-color: var(--atlas-cyan);
  color: var(--atlas-cyan);
}

/* ─── Inputs ────────────────────────────────────────────────────────── */
.input, select, .select-sm {
  background: var(--bg-surface);
  border: var(--border-default);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.input:focus, select:focus, .select-sm:focus {
  border-color: var(--atlas-cyan);
  box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.1);
}
.input::placeholder {
  color: var(--text-muted);
}
.input-sm {
  padding: 5px 10px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

select, .select-sm {
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394a3b8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.select-sm {
  padding: 5px 28px 5px 10px;
  font-size: 0.78rem;
  border-radius: var(--radius-sm);
}

textarea.input {
  resize: vertical;
  min-height: 60px;
}

/* ─── Text utilities ────────────────────────────────────────────────── */
.text-dim { color: var(--text-dim); }
.text-bright { color: var(--text-bright); }
.text-cyan { color: var(--atlas-cyan); }
.text-gold { color: var(--palace-gold); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-mono { font-family: var(--font-mono); }

/* ─── Footer ────────────────────────────────────────────────────────── */
.app-footer {
  height: var(--footer-height);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  font-size: 0.7rem;
  color: var(--text-muted);
  background: rgba(4, 5, 13, 0.8);
  border-top: var(--border-subtle);
  flex-shrink: 0;
}
.app-footer a {
  color: var(--atlas-cyan2);
  font-family: var(--font-mono);
}
.app-footer strong {
  color: var(--text-dim);
}

/* ═══════════════════════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════════════════════ */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes glow {
  0%, 100% {
    box-shadow: 0 0 5px rgba(0, 212, 255, 0.2);
  }
  50% {
    box-shadow: 0 0 20px rgba(0, 212, 255, 0.4), 0 0 40px rgba(0, 212, 255, 0.1);
  }
}

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

@keyframes shimmer {
  0% { background-position: -200% center; }
  100% { background-position: 200% center; }
}

/* Loading skeleton */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-surface) 25%,
    var(--bg-elevated) 50%,
    var(--bg-surface) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

/* ═══════════════════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ═══════════════════════════════════════════════════════════════════════ */

/* Tablet: ≤ 1024px */
@media (max-width: 1024px) {
  .palace-side-panel {
    width: 280px;
  }
  .palace-stats-overlay {
    font-size: 0.65rem;
  }
  .palace-toolbar {
    flex-wrap: wrap;
    height: auto;
    padding: var(--space-xs) var(--space-md);
    gap: var(--space-sm);
  }
  .palace-search-box {
    min-width: 180px;
  }

  .forge-container {
    flex-direction: column;
  }
  .forge-chat {
    flex: none;
    height: 60vh;
    border-right: none;
    border-bottom: var(--border-subtle);
  }
  .forge-viz {
    flex: none;
    max-height: 35vh;
    flex-direction: row;
    overflow-x: auto;
    gap: var(--space-md);
    padding: var(--space-sm);
  }
  .forge-viz-panel {
    min-width: 260px;
    flex-shrink: 0;
  }
  .forge-ooda {
    min-height: 140px;
  }

  .arena-grid {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, 240px);
    flex: 0 0 auto;     /* don't shrink — let section scroll */
  }
  .arena-gen-group {
    margin-left: 0;
  }
  .arena-summary-content {
    flex-direction: column;
  }
  .arena-summary-advantage {
    margin-left: 0;
  }

  .workshop-layout {
    flex-direction: column;
  }
  .workshop-tools {
    width: 100%;
    max-height: 30vh;
    border-right: none;
    border-bottom: var(--border-subtle);
  }
  .ws-tools-scroll {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
  }
  .ws-tool-card {
    flex: 1;
    min-width: 200px;
  }
  .workshop-viewport {
    height: 40vh;
    flex: none;
  }
  .ws-viewer-toolbar {
    flex-wrap: wrap;
    gap: var(--space-xs);
  }
  .ws-viewer-stats { font-size: 0.65rem; gap: var(--space-sm); }
  .workshop-log {
    width: 100%;
    border-left: none;
    border-top: var(--border-subtle);
    max-height: 25vh;
    flex: none;
  }

  .library-layout {
    padding: var(--space-lg) var(--space-md);
  }
  .library-grid {
    grid-template-columns: 1fr;
  }
}

/* Mobile: ≤ 640px */
@media (max-width: 640px) {
  :root {
    --navbar-height: 48px;
    --space-lg: 16px;
    --space-xl: 24px;
  }

  .navbar {
    padding: 0 var(--space-sm);
  }
  .navbar-brand {
    gap: 4px;
  }
  .navbar-title {
    font-size: 1rem;
  }
  .navbar-version {
    display: none;
  }
  .tab-label {
    display: none;
  }
  .tab-btn {
    padding: 6px 10px;
  }
  .navbar-status {
    display: none;
  }

  .section-title {
    font-size: 1.4rem;
  }

  .palace-toolbar {
    flex-wrap: wrap;
    height: auto;
    padding: var(--space-xs) var(--space-sm);
    gap: var(--space-xs);
  }
  .palace-side-panel {
    width: 100%;
  }
  .palace-stats-overlay {
    display: none;
  }
  .palace-legend {
    display: none;
  }
  .palace-search-box {
    min-width: 140px;
  }

  .forge-container {
    flex-direction: column;
  }
  .forge-chat {
    flex: none;
    height: 55vh;
    border-right: none;
    border-bottom: var(--border-subtle);
  }
  .forge-viz {
    flex: 1;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: var(--space-sm);
    gap: var(--space-sm);
  }
  .forge-viz-panel {
    min-width: 240px;
    flex-shrink: 0;
  }
  .forge-prompt-chips {
    padding: var(--space-xs) var(--space-md);
  }
  .forge-messages {
    padding: var(--space-md);
  }
  .forge-input-area {
    padding: var(--space-xs) var(--space-md) var(--space-sm);
  }
  .chat-bubble {
    max-width: 92%;
  }
  .forge-ooda {
    min-height: 120px;
  }
  .forge-ooda svg {
    max-width: 150px;
  }
  .forge-stats-grid {
    gap: var(--space-xs);
  }
  .forge-stat-value {
    font-size: 1.1rem;
  }

  .arena-controls {
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
  }
  .arena-k-btn {
    padding: 4px 10px;
    font-size: 0.75rem;
  }
  .arena-ctrl-btn {
    padding: 4px 8px;
    font-size: 0.72rem;
  }
  .arena-progress {
    width: 60px;
  }
  .arena-summary-row {
    font-size: 0.72rem;
    padding: 3px 8px;
  }

  .loading-title {
    font-size: 2rem;
  }
}

/* ═══════════════════════════════════════════════════════════════════════
   KATEX OVERRIDES
   ═══════════════════════════════════════════════════════════════════════ */
.katex {
  font-size: 1.15em;
}
.katex-display {
  margin: var(--space-md) 0;
}

/* ═══════════════════════════════════════════════════════════════════════
   LIBRARY — ENHANCED MATHEMATICAL FOUNDATIONS
   ═══════════════════════════════════════════════════════════════════════ */

.lib-nav {
  display: flex; flex-wrap: wrap; gap: var(--space-sm); justify-content: center;
  margin-bottom: var(--space-xl); position: sticky; top: 0; z-index: 10;
  padding: var(--space-sm) var(--space-md);
  background: rgba(4,5,13,0.85); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius-lg); border: var(--border-subtle);
}
.lib-nav-link {
  display: flex; align-items: center; gap: 5px; padding: 5px 14px;
  border-radius: var(--radius-pill); font-size: 0.78rem; font-weight: 500;
  color: var(--text-dim); cursor: pointer; transition: all var(--transition-fast);
  text-decoration: none !important;
}
.lib-nav-link:hover { background: var(--bg-hover); color: var(--atlas-cyan); }
.lib-nav-icon { font-size: 0.9rem; }

.library-sections {
  display: flex; flex-direction: column; gap: var(--space-xl);
  max-width: 1100px; margin: 0 auto;
}
.library-section {
  background: rgba(13,16,32,0.75); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(0,212,255,0.1); border-radius: var(--radius-xl);
  padding: var(--space-lg) var(--space-xl);
  transition: transform var(--transition-base), box-shadow var(--transition-base);
  scroll-margin-top: 60px;
}
.library-section:hover { transform: translateY(-2px); box-shadow: var(--shadow-glow); }
.lib-section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-lg); padding-bottom: var(--space-sm); border-bottom: var(--border-subtle);
}
.lib-section-header h3 { font-size: 1.15rem; font-weight: 700; color: var(--text-bright); }
.lib-desc { font-size: 0.85rem; color: var(--text-dim); line-height: 1.7; margin-top: var(--space-md); }

/* Triple Isomorphism */
.triple-sliders { display: flex; flex-direction: column; gap: var(--space-md); margin-bottom: var(--space-lg); }
.triple-slider-row { display: flex; align-items: center; gap: var(--space-md); }
.triple-label { min-width: 220px; font-size: 0.85rem; color: var(--text); display: flex; align-items: center; gap: 6px; }
.triple-label-icon { font-size: 1rem; }
.triple-sub { color: var(--text-muted); font-size: 0.75rem; }
.triple-val { min-width: 50px; font-family: var(--font-mono); font-size: 0.85rem; font-weight: 600; color: var(--atlas-cyan); text-align: right; }
.lib-range { flex: 1; min-width: 120px; }
.lib-range.cyan::-webkit-slider-thumb { background: var(--atlas-cyan); }
.lib-range.gold::-webkit-slider-thumb { background: var(--palace-gold); }
.lib-range.green::-webkit-slider-thumb { background: var(--success); }
.lib-range.cyan::-moz-range-thumb { background: var(--atlas-cyan); }
.lib-range.gold::-moz-range-thumb { background: var(--palace-gold); }
.lib-range.green::-moz-range-thumb { background: var(--success); }

.triple-eq-row { display: flex; gap: var(--space-md); margin-bottom: var(--space-lg); flex-wrap: wrap; }
.triple-eq-card { flex: 1; min-width: 180px; background: var(--bg-deep); border: var(--border-subtle); border-radius: var(--radius-md); padding: var(--space-md); text-align: center; }
.triple-viz-row { display: flex; gap: var(--space-lg); align-items: stretch; }
.triple-bars-canvas { flex: 1; min-width: 200px; height: 180px; background: var(--bg-deep); border: var(--border-subtle); border-radius: var(--radius-md); }
.triple-computed { flex: 0 0 220px; display: flex; flex-direction: column; gap: var(--space-sm); padding: var(--space-md); background: var(--bg-deep); border: var(--border-subtle); border-radius: var(--radius-md); }
.tc-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: var(--border-subtle); }
.tc-item:last-child { border-bottom: none; }
.tc-label { font-size: 0.78rem; color: var(--text-dim); }
.tc-value { font-family: var(--font-mono); font-size: 0.82rem; font-weight: 600; color: var(--atlas-cyan); }

/* Lambda Decay */
.decay-slider-row { display: flex; align-items: center; gap: var(--space-md); margin-bottom: var(--space-lg); }
.decay-formulas { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); margin-bottom: var(--space-lg); }
.decay-formula-card { background: var(--bg-deep); border-radius: var(--radius-md); padding: var(--space-md); border: 1px solid; }
.decay-formula-card.danger { border-color: rgba(248,113,113,0.25); }
.decay-formula-card.success { border-color: rgba(52,211,153,0.25); }
.decay-formula-title { font-size: 0.85rem; font-weight: 600; margin-bottom: var(--space-sm); }
.decay-formula-card.danger .decay-formula-title { color: var(--danger); }
.decay-formula-card.success .decay-formula-title { color: var(--success); }
.decay-formula-eq { margin-bottom: var(--space-sm); text-align: center; }
.decay-formula-result { font-size: 0.82rem; color: var(--text-dim); }
.decay-formula-result code { font-weight: 600; }
.lib-badge { display: inline-block; padding: 2px 8px; border-radius: var(--radius-pill); font-size: 0.7rem; font-weight: 600; margin-left: var(--space-sm); }
.danger-badge { background: rgba(248,113,113,0.15); color: var(--danger); border: 1px solid rgba(248,113,113,0.3); }
.success-badge { background: rgba(52,211,153,0.15); color: var(--success); border: 1px solid rgba(52,211,153,0.3); }
.decay-charts { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); }
.decay-chart-wrap { background: var(--bg-deep); border: var(--border-subtle); border-radius: var(--radius-md); overflow: hidden; }
.decay-canvas { width: 100%; height: 240px; display: block; }

/* Mamba FV Diagram */
.mfv-diagram { display: flex; flex-direction: column; align-items: center; gap: 0; padding: var(--space-md) 0; }
.mfv-box { width: 100%; max-width: 520px; padding: var(--space-lg); border-radius: var(--radius-lg); text-align: center; border: 1px solid; position: relative; transition: transform var(--transition-fast), box-shadow var(--transition-fast); }
.mfv-box:hover { transform: scale(1.02); }
.mfv-cyan { background: rgba(0,212,255,0.06); border-color: rgba(0,212,255,0.25); }
.mfv-gold { background: rgba(212,160,23,0.06); border-color: rgba(212,160,23,0.25); }
.mfv-green { background: rgba(52,211,153,0.06); border-color: rgba(52,211,153,0.25); }
.mfv-cyan:hover { box-shadow: 0 0 20px rgba(0,212,255,0.15); }
.mfv-gold:hover { box-shadow: 0 0 20px rgba(212,160,23,0.15); }
.mfv-green:hover { box-shadow: 0 0 20px rgba(52,211,153,0.15); }
.mfv-label { font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: var(--space-sm); }
.mfv-cyan .mfv-label { color: var(--atlas-cyan); }
.mfv-gold .mfv-label { color: var(--palace-gold); }
.mfv-green .mfv-label { color: var(--success); }
.mfv-eq { margin: var(--space-sm) 0; }
.mfv-sub { font-size: 0.75rem; color: var(--text-muted); font-style: italic; }

.mfv-connector { display: flex; flex-direction: column; align-items: center; padding: var(--space-sm) 0; position: relative; cursor: help; }
.mfv-arrow-line { width: 2px; height: 36px; background: linear-gradient(180deg, rgba(0,212,255,0.4), rgba(212,160,23,0.4)); position: relative; overflow: hidden; border-radius: 1px; }
.mfv-arrow-pulse { position: absolute; top: -8px; left: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--atlas-cyan); box-shadow: 0 0 8px var(--atlas-cyan); animation: mfvPulseDown 2s ease-in-out infinite; }
@keyframes mfvPulseDown { 0% { top: -8px; opacity: 0; } 20% { opacity: 1; } 80% { opacity: 1; } 100% { top: 36px; opacity: 0; } }
.mfv-conn-label { font-size: 0.72rem; font-family: var(--font-mono); color: var(--text-muted); margin-top: 2px; transition: color var(--transition-fast); }
.mfv-connector:hover .mfv-conn-label { color: var(--atlas-cyan); }
.mfv-connector::after { content: attr(data-tooltip); position: absolute; left: 50%; top: -4px; transform: translate(-50%,-100%); background: rgba(4,5,13,0.95); border: var(--border-default); border-radius: var(--radius-md); padding: var(--space-sm) var(--space-md); font-size: 0.75rem; color: var(--text); line-height: 1.5; max-width: 340px; white-space: normal; opacity: 0; pointer-events: none; transition: opacity var(--transition-fast); z-index: 20; box-shadow: var(--shadow-lg); }
.mfv-connector:hover::after { opacity: 1; }
.mfv-insight { margin-top: var(--space-lg); padding: var(--space-md) var(--space-lg); background: rgba(0,212,255,0.04); border-left: 3px solid var(--atlas-cyan); border-radius: 0 var(--radius-md) var(--radius-md) 0; font-size: 0.85rem; color: var(--text-dim); line-height: 1.7; }
.mfv-insight strong { color: var(--atlas-cyan); }

/* Crate Tree */
.ct-stats { display: flex; align-items: center; justify-content: center; gap: var(--space-sm); margin-bottom: var(--space-md); font-size: 0.82rem; color: var(--text-dim); }
.ct-stats strong { color: var(--atlas-cyan); font-family: var(--font-mono); }
.ct-stat-sep { color: var(--text-muted); }
.ct-legend { display: flex; flex-wrap: wrap; gap: var(--space-sm) var(--space-md); justify-content: center; margin-bottom: var(--space-lg); }
.ct-legend-item { display: flex; align-items: center; gap: 5px; font-size: 0.72rem; color: var(--text-dim); }
.ct-legend-dot { width: 8px; height: 8px; border-radius: 50%; }
.ct-tree { padding-left: 0; }
.ct-node { position: relative; }
.ct-node.ct-root { padding-left: 0; }
.ct-children { padding-left: 28px; border-left: 2px solid rgba(0,212,255,0.1); margin-left: 14px; margin-top: 2px; }
.ct-children .ct-node { position: relative; padding-top: 3px; padding-bottom: 3px; }
.ct-children .ct-node::before { content: ''; position: absolute; left: -28px; top: 17px; width: 24px; height: 2px; background: rgba(0,212,255,0.1); }
.ct-card { display: inline-flex; align-items: center; gap: var(--space-sm); padding: 5px 14px; background: var(--bg-surface); border: var(--border-subtle); border-left: 3px solid; border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition-fast); margin-bottom: 2px; }
.ct-card:hover { background: var(--bg-hover); box-shadow: var(--shadow-sm); }
.ct-card:focus { outline: 2px solid rgba(0,212,255,0.3); outline-offset: 2px; }
.ct-name { font-family: var(--font-mono); font-size: 0.82rem; font-weight: 600; color: var(--text); }
.ct-tests { font-family: var(--font-mono); font-size: 0.7rem; font-weight: 700; padding: 1px 6px; border-radius: var(--radius-sm); background: rgba(0,0,0,0.3); }
.ct-desc { font-size: 0.78rem; color: var(--text-dim); padding: 4px 0 4px 18px; line-height: 1.5; transition: max-height 0.3s ease, opacity 0.3s ease; overflow: hidden; }
.ct-desc.ct-hidden { max-height: 0; opacity: 0; padding: 0 0 0 18px; }
.ct-desc:not(.ct-hidden) { max-height: 60px; opacity: 1; }

/* Timeline */
.htl-track { position: relative; overflow-x: auto; overflow-y: hidden; padding: var(--space-lg) var(--space-sm) var(--space-md); }
.htl-line { position: absolute; left: 0; right: 0; top: calc(50% + 46px); height: 2px; background: linear-gradient(90deg, transparent, rgba(0,212,255,0.2) 5%, rgba(0,212,255,0.2) 95%, transparent); }
.htl-items { display: flex; gap: var(--space-md); min-width: min-content; position: relative; }
.htl-item { display: flex; flex-direction: column; align-items: center; min-width: 110px; cursor: pointer; transition: transform var(--transition-fast); }
.htl-item:hover { transform: translateY(-3px); }
.htl-card { background: var(--bg-surface); border: var(--border-subtle); border-radius: var(--radius-md); padding: var(--space-sm) var(--space-md); text-align: center; margin-bottom: var(--space-sm); transition: border-color var(--transition-fast), box-shadow var(--transition-fast); min-width: 100px; }
.htl-item:hover .htl-card, .htl-current .htl-card { border-color: rgba(0,212,255,0.3); box-shadow: 0 0 12px rgba(0,212,255,0.1); }
.htl-ver { font-family: var(--font-mono); font-size: 0.82rem; font-weight: 700; color: var(--text-bright); }
.htl-tests-badge { font-family: var(--font-mono); font-size: 0.68rem; color: var(--atlas-cyan); margin: 2px 0; }
.htl-delta { color: var(--success); font-weight: 700; }
.htl-theme { font-size: 0.7rem; color: var(--text-dim); line-height: 1.3; }
.htl-desc { font-size: 0.72rem; color: var(--text-muted); line-height: 1.4; margin-top: var(--space-xs); transition: max-height 0.3s ease, opacity 0.3s ease; overflow: hidden; }
.htl-desc.htl-hidden { max-height: 0; opacity: 0; margin-top: 0; }
.htl-desc:not(.htl-hidden) { max-height: 80px; opacity: 1; }
.htl-stem { width: 2px; height: 12px; background: rgba(0,212,255,0.2); }
.htl-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--bg-surface); border: 2px solid var(--text-muted); transition: all var(--transition-fast); }
.htl-dot-active, .htl-item:hover .htl-dot { background: var(--atlas-cyan); border-color: var(--atlas-cyan); box-shadow: 0 0 10px rgba(0,212,255,0.5); }
.htl-date { font-size: 0.68rem; font-family: var(--font-mono); color: var(--text-muted); margin-top: 4px; }

/* References */
.ref-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--space-md); }
.ref-card { background: var(--bg-deep); border: var(--border-subtle); border-radius: var(--radius-md); padding: var(--space-md) var(--space-lg); transition: border-color var(--transition-fast), transform var(--transition-fast); }
.ref-card:hover { border-color: rgba(212,160,23,0.3); transform: translateY(-2px); }
.ref-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-sm); }
.ref-year { font-family: var(--font-mono); font-size: 0.78rem; font-weight: 700; color: var(--palace-gold); background: rgba(212,160,23,0.1); padding: 2px 8px; border-radius: var(--radius-sm); }
.ref-link { font-size: 0.72rem; font-weight: 600; color: var(--atlas-cyan); }
.ref-link-dim { color: var(--text-muted); }
.ref-title { font-size: 0.88rem; font-weight: 600; color: var(--text-bright); line-height: 1.4; margin-bottom: 4px; }
.ref-authors { font-size: 0.78rem; color: var(--text-dim); margin-bottom: 2px; }
.ref-venue { font-size: 0.72rem; font-style: italic; color: var(--text-muted); margin-bottom: var(--space-sm); }
.ref-summary { font-size: 0.78rem; color: var(--text-dim); line-height: 1.6; margin: 0; padding-top: var(--space-sm); border-top: var(--border-subtle); }

/* Responsive */
@media (max-width: 1024px) {
  .triple-slider-row { flex-wrap: wrap; }
  .triple-label { min-width: 180px; }
  .triple-viz-row { flex-direction: column; }
  .triple-computed { flex: none; }
  .decay-formulas, .decay-charts { grid-template-columns: 1fr; }
  .mfv-box { max-width: 100%; }
  .ref-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .lib-nav-label { display: none; }
  .lib-nav-link { padding: 5px 8px; }
  .triple-eq-row { flex-direction: column; }
  .library-section { padding: var(--space-md); }
}
