:root {
  --bg-dark: #090d16;
  --bg-card: rgba(18, 25, 41, 0.75);
  --bg-card-hover: rgba(28, 38, 62, 0.85);
  --bg-panel: rgba(13, 19, 33, 0.85);
  --border-color: rgba(255, 255, 255, 0.1);
  --border-glow: rgba(56, 189, 248, 0.35);
  
  --primary: #06b6d4;
  --primary-glow: rgba(6, 182, 212, 0.5);
  --accent: #8b5cf6;
  --accent-glow: rgba(139, 92, 246, 0.45);
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.4);
  --warning: #f59e0b;
  --danger: #ef4444;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --radius-full: 9999px;
  
  --shadow-main: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px var(--primary-glow);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* Ambient Canvas Background */
.ambient-canvas, .fx-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 1;
}

.fx-canvas {
  z-index: 999;
}

/* App Container */
.app-container {
  position: relative;
  z-index: 10;
  max-width: 1540px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 740px;
  gap: 16px;
}

/* Header & HUD */
.game-header {
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-main);
  flex-wrap: wrap;
  gap: 16px;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-icon {
  font-size: 32px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.2), rgba(139, 92, 246, 0.3));
  border: 1px solid var(--border-glow);
  border-radius: var(--radius-md);
  box-shadow: 0 0 15px rgba(6, 182, 212, 0.3);
  animation: floatSlow 4s ease-in-out infinite alternate;
}

@keyframes floatSlow {
  0% { transform: translateY(0px) rotate(0deg); }
  100% { transform: translateY(-4px) rotate(3deg); }
}

.game-title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 1px;
  background: linear-gradient(120deg, #38bdf8, #818cf8, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.game-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
}

/* HUD Stats */
.hud-stats {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  padding: 8px 14px;
  border-radius: var(--radius-md);
}

.level-pill {
  border-color: rgba(139, 92, 246, 0.4);
  background: rgba(139, 92, 246, 0.1);
}

.money-pill {
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.1);
}

.stat-icon {
  font-size: 20px;
}

.stat-col {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.5px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.stat-value.small {
  font-size: 12px;
}

.progress-pill {
  min-width: 170px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.progress-bar-bg {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
  box-shadow: 0 0 8px var(--primary-glow);
}

.hud-controls {
  display: flex;
  gap: 6px;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--primary);
  transform: translateY(-2px);
}

/* Main Layout Grid */
.main-layout {
  display: grid;
  grid-template-columns: 310px 1fr 310px;
  gap: 16px;
  flex: 1;
  min-height: 0;
}

@media (max-width: 1200px) {
  .main-layout {
    grid-template-columns: 280px 1fr 280px;
  }
}

@media (max-width: 992px) {
  .app-container {
    height: auto;
    min-height: 100vh;
  }

  .main-layout {
    grid-template-columns: 1fr;
  }

  .elements-grid {
    max-height: 420px;
  }

  .codex-content {
    max-height: 360px;
  }
}

/* Sidebars */
.sidebar {
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-main);
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
}

.panel-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  flex-shrink: 0;
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: rgba(6, 182, 212, 0.15);
  color: var(--primary);
  border: 1px solid rgba(6, 182, 212, 0.3);
  font-weight: 600;
}

/* Elements Shop Grid */
.elements-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: max-content;
  align-content: start;
  gap: 10px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 6px 4px 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
}

.elements-grid::-webkit-scrollbar,
.codex-content::-webkit-scrollbar,
.recipes-grid::-webkit-scrollbar,
.help-content::-webkit-scrollbar {
  width: 6px;
}

.elements-grid::-webkit-scrollbar-track,
.codex-content::-webkit-scrollbar-track,
.recipes-grid::-webkit-scrollbar-track,
.help-content::-webkit-scrollbar-track {
  background: transparent;
}

.elements-grid::-webkit-scrollbar-thumb,
.codex-content::-webkit-scrollbar-thumb,
.recipes-grid::-webkit-scrollbar-thumb,
.help-content::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.3);
  border-radius: 10px;
}

.elements-grid::-webkit-scrollbar-thumb:hover,
.codex-content::-webkit-scrollbar-thumb:hover,
.recipes-grid::-webkit-scrollbar-thumb:hover,
.help-content::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.5);
}

.element-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: grab;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
  min-height: max-content;
}

.element-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: var(--elem-color, #38bdf8);
  box-shadow: 0 0 10px var(--elem-color, #38bdf8);
}

.element-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--elem-color, var(--primary));
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 6px 16px -4px rgba(0, 0, 0, 0.4), 0 0 15px rgba(56, 189, 248, 0.2);
}

.element-card.locked {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.8);
}

.element-atom-icon {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 800;
  font-family: var(--font-mono);
  color: #fff;
  background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.4), transparent 60%), var(--elem-color, #38bdf8);
  box-shadow: 0 4px 10px rgba(0,0,0,0.5), inset 0 0 8px rgba(0,0,0,0.4), 0 0 12px var(--elem-glow, rgba(56,189,248,0.4));
  margin-bottom: 6px;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.element-info {
  text-align: center;
  width: 100%;
  flex-shrink: 0;
}

.element-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.element-meta {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.element-cost {
  color: #fbbf24;
  font-weight: 700;
}

.element-valency {
  font-weight: 700;
  color: #a78bfa;
}

.inventory-footer {
  margin-top: auto;
  border-top: 1px solid var(--border-color);
  padding-top: 10px;
  flex-shrink: 0;
}

.current-level-banner {
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary);
}

/* Workbench Section */
.workbench-section {
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  padding: 16px;
  box-shadow: var(--shadow-main);
  position: relative;
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

/* Formula Input Bar */
.formula-bar-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.formula-form {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.formula-input-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  background: rgba(7, 10, 18, 0.85);
  border: 1.5px solid rgba(56, 189, 248, 0.35);
  border-radius: var(--radius-md);
  padding: 0 12px;
  gap: 10px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.formula-input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.2);
}

.formula-prefix-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.formula-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  padding: 12px 0;
  user-select: text;
  min-width: 0;
}

.formula-input::placeholder {
  font-family: var(--font-main);
  font-weight: 400;
  font-size: 13px;
  color: var(--text-dim);
}

.btn-clear-inline {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.btn-clear-inline:hover {
  background: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
}

.formula-submit-btn {
  padding: 0 22px;
  white-space: nowrap;
  flex-shrink: 0;
}

.formula-status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.formula-feedback {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.formula-status-text {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.formula-cost-pill {
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.formula-cost-pill strong {
  color: #fbbf24;
  font-family: var(--font-mono);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-weight: 700;
  flex-shrink: 0;
}

/* Interactive 3D Molecule Viewport */
.viewer-3d-stage {
  position: relative;
  flex: 1;
  min-height: 260px;
  background: radial-gradient(circle at 50% 48%, rgba(30, 41, 59, 0.5), rgba(15, 23, 42, 0.9)), #070a12;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: inset 0 0 36px rgba(0, 0, 0, 0.7);
}

.molecule-3d-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

.molecule-3d-canvas:active {
  cursor: grabbing;
}

.viewer-overlay-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-main);
  background: rgba(9, 13, 22, 0.78);
  backdrop-filter: blur(8px);
  padding: 5px 12px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(56, 189, 248, 0.3);
  pointer-events: none;
}

.viewer-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
}

.viewer-controls .btn-tool {
  padding: 5px 10px;
  font-size: 12px;
  background: rgba(9, 13, 22, 0.78);
  backdrop-filter: blur(8px);
}

.viewer-drag-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.45);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  pointer-events: none;
  white-space: nowrap;
}

/* Molecule Info & Facts Panel */
.molecule-facts-panel {
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  flex-shrink: 0;
  max-height: 255px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
}

.molecule-facts-panel::-webkit-scrollbar {
  width: 6px;
}

.molecule-facts-panel::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.3);
  border-radius: 10px;
}

.hidden {
  display: none !important;
}

.facts-empty-state {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.facts-empty-header h4 {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

.facts-empty-header p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.quick-try-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.quick-try-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
}

.quick-chip {
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.35);
  color: #7dd3fc;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
}

.quick-chip:hover {
  background: rgba(6, 182, 212, 0.25);
  transform: translateY(-1px);
  color: #fff;
}

.facts-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.facts-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.facts-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.facts-title-group h3 {
  font-size: 17px;
  font-weight: 800;
  color: var(--text-main);
}

.facts-formula-pill {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  background: rgba(6, 182, 212, 0.15);
  border: 1px solid rgba(6, 182, 212, 0.35);
  padding: 2px 10px;
  border-radius: var(--radius-full);
}

.facts-meta-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.meta-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.meta-pill.category {
  color: #c084fc;
  border-color: rgba(192, 132, 252, 0.35);
  background: rgba(139, 92, 246, 0.12);
}

.meta-pill.state {
  color: #34d399;
  border-color: rgba(52, 211, 153, 0.35);
  background: rgba(16, 185, 129, 0.12);
}

.meta-pill.geometry {
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.35);
  background: rgba(6, 182, 212, 0.12);
}

.meta-pill.mass {
  font-family: var(--font-mono);
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.3);
  background: rgba(245, 158, 11, 0.1);
}

.facts-description {
  font-size: 12.5px;
  color: var(--text-main);
  line-height: 1.5;
}

.facts-details-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 10px;
}

@media (max-width: 720px) {
  .facts-details-grid {
    grid-template-columns: 1fr;
  }
}

.facts-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.facts-box h5 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--primary);
  margin-bottom: 6px;
}

.facts-box ul {
  list-style: disc;
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.45;
}

.facts-box p {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

.codex-card {
  cursor: pointer;
}

.codex-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--primary);
  transform: translateX(2px);
}

.codex-card.active {
  border-color: var(--primary);
  background: rgba(6, 182, 212, 0.12);
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.25);
}

.recipes-filter-row {
  margin-bottom: 12px;
}

.recipes-search-input {
  width: 100%;
  background: rgba(7, 10, 18, 0.8);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 13px;
  outline: none;
  user-select: text;
}

.recipes-search-input:focus {
  border-color: var(--primary);
}

.recipe-item.discovered {
  border-color: rgba(16, 185, 129, 0.45);
  background: rgba(16, 185, 129, 0.07);
  cursor: pointer;
}

.recipe-item.discovered:hover {
  background: rgba(16, 185, 129, 0.14);
}

.recipe-item.locked-recipe {
  opacity: 0.48;
}

.quick-tips-card code {
  font-family: var(--font-mono);
  font-size: 10.5px;
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 4px;
  border-radius: 4px;
  color: #7dd3fc;
}

/* Reserved Minimally Invasive Sidebar Ad Slot */
.ad-slot-card {
  background: rgba(255, 255, 255, 0.025);
  border: 1px dashed rgba(148, 163, 184, 0.25);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ad-slot-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.ad-slot-body {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
}

.ad-slot-placeholder {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.4;
  padding: 0 8px;
}

.sidebar-legal-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
  padding-top: 2px;
}

.legal-link {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s ease;
}

.legal-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

.workbench-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mode-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: rgba(6, 182, 212, 0.1);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(6, 182, 212, 0.25);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary);
  animation: pulseDot 1.8s infinite;
}

@keyframes pulseDot {
  0% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.7; }
}

.workbench-status {
  font-size: 12px;
  color: var(--text-muted);
}

.toolbar-right {
  display: flex;
  gap: 8px;
}

.btn-tool {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-tool:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--primary);
}

.btn-tool.accent {
  background: rgba(139, 92, 246, 0.15);
  border-color: rgba(139, 92, 246, 0.4);
  color: #c084fc;
}

.btn-tool.accent:hover {
  background: rgba(139, 92, 246, 0.3);
  border-color: #a855f7;
  color: #f3e8ff;
  box-shadow: 0 0 12px rgba(168, 85, 247, 0.4);
}

.btn-tool.danger:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--danger);
  color: #fca5a5;
}

/* 2D Grid Viewport */
.grid-viewport {
  position: relative;
  flex: 1;
  min-height: 440px;
  background: radial-gradient(circle at 50% 50%, rgba(30, 41, 59, 0.4), rgba(15, 23, 42, 0.8)), #070a12;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.6);
}

/* SVG Bond Layer */
.bonds-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 25;
}

.bond-group {
  pointer-events: auto;
  cursor: pointer;
}

.bond-hitbox {
  stroke: transparent;
  stroke-width: 28px;
  fill: none;
  cursor: pointer;
}

.bond-line {
  stroke-linecap: round;
  transition: stroke 0.25s ease, stroke-width 0.25s ease, filter 0.25s ease;
  pointer-events: none;
}

.bond-group:hover .bond-line {
  stroke: #7dd3fc !important;
  filter: drop-shadow(0 0 10px rgba(56, 189, 248, 1)) !important;
}

.bond-badge-bg {
  fill: #090d16;
  stroke: rgba(56, 189, 248, 0.7);
  stroke-width: 1.5px;
  rx: 6px;
  pointer-events: none;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.8));
}

.bond-badge-text {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 800;
  fill: #38bdf8;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

/* Grid Board */
.grid-board {
  display: grid;
  grid-template-columns: repeat(6, 76px);
  grid-template-rows: repeat(5, 76px);
  gap: 8px;
  position: relative;
  z-index: 5;
  padding: 12px;
}

.grid-cell {
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  position: relative;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid-cell:hover {
  background: rgba(6, 182, 212, 0.06);
  border-color: rgba(6, 182, 212, 0.3);
}

.grid-cell.drag-over {
  background: rgba(6, 182, 212, 0.2);
  border-color: var(--primary);
  box-shadow: inset 0 0 15px rgba(6, 182, 212, 0.3);
}

/* Atoms placed on Grid */
.grid-atom {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 15;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease;
  background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.45), transparent 60%), var(--atom-color, #38bdf8);
  border: 2.5px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6), 0 0 16px var(--atom-glow, rgba(56, 189, 248, 0.4));
  color: #fff;
  font-family: var(--font-mono);
  animation: atomPopIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes atomPopIn {
  0% { transform: scale(0.2); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.grid-atom:hover {
  transform: scale(1.08);
  z-index: 20;
}

.grid-atom.selected {
  outline: 3px solid #facc15;
  outline-offset: 3px;
  box-shadow: 0 0 25px rgba(250, 204, 21, 0.8);
  animation: selectedPulse 1.5s infinite;
}

@keyframes selectedPulse {
  0%, 100% { transform: scale(1.06); }
  50% { transform: scale(1.12); }
}

.atom-symbol {
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 2px 4px rgba(0,0,0,0.6);
}

.atom-valency-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  font-size: 9px;
  font-weight: 800;
  background: #0f172a;
  border: 1.5px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-full);
  padding: 1px 5px;
  color: #e2e8f0;
}

.atom-valency-badge.satisfied {
  background: #059669;
  border-color: #34d399;
  color: #fff;
}

.atom-valency-badge.unsatisfied {
  background: #dc2626;
  border-color: #f87171;
  color: #fff;
}

.placement-hint {
  position: absolute;
  bottom: 16px;
  font-size: 12px;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.4);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.placement-hint.hidden {
  opacity: 0;
}

/* Bottom Action Bar */
.workbench-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  gap: 16px;
  flex-wrap: wrap;
}

.valency-meter-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.valency-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
}

.valency-rule-text {
  font-size: 11px;
  color: var(--text-muted);
}

.badge-neutral {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.badge-success {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-weight: 700;
}

.badge-warning {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.4);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-weight: 700;
}

.btn-primary {
  background: linear-gradient(135deg, #06b6d4, #3b82f6);
  border: none;
  color: #fff;
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 700;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 15px rgba(6, 182, 212, 0.4);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(6, 182, 212, 0.6);
  filter: brightness(1.1);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
  filter: grayscale(0.6);
}

/* Codex / Right Sidebar */
.codex-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
}

.empty-state {
  text-align: center;
  padding: 30px 10px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.empty-icon {
  font-size: 32px;
  opacity: 0.5;
}

.codex-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.codex-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 4px;
  background: var(--mol-color, #38bdf8);
}

.codex-preview-dot {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--mol-color, #38bdf8);
  box-shadow: 0 0 10px var(--mol-glow, rgba(56, 189, 248, 0.4));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.codex-info {
  flex: 1;
  min-width: 0;
}

.codex-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.codex-formula {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.codex-valency {
  font-size: 11px;
  color: #fbbf24;
  font-weight: 700;
  flex-shrink: 0;
  white-space: nowrap;
}

.quick-tips-card {
  background: rgba(139, 92, 246, 0.08);
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: var(--radius-md);
  padding: 12px;
  flex-shrink: 0;
}

.quick-tips-card h4 {
  font-size: 12px;
  color: #c084fc;
  margin-bottom: 6px;
}

.quick-tips-card ul {
  list-style: none;
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(3, 7, 18, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 20px;
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: all;
}

.modal-card {
  background: #0f172a;
  border: 1px solid var(--border-glow);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  padding: 28px;
  position: relative;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8), 0 0 35px var(--primary-glow);
  transform: scale(0.9) translateY(20px);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  overflow: hidden;
}

.modal-backdrop.active .modal-card {
  transform: scale(1) translateY(0);
}

.modal-glow-bg {
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  width: 250px;
  height: 250px;
  border-radius: 50%;
  background: var(--modal-accent-glow, rgba(6, 182, 212, 0.3));
  filter: blur(60px);
  pointer-events: none;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-pill {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--primary);
  background: rgba(6, 182, 212, 0.15);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  transition: color 0.2s;
}

.modal-close:hover {
  color: #fff;
}

.molecule-preview-stage {
  display: flex;
  justify-content: center;
  margin: 16px 0 24px;
}

.molecule-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.6), transparent 60%), var(--modal-mol-color, #06b6d4);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), 0 0 30px var(--modal-mol-glow, rgba(6, 182, 212, 0.6));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 38px;
  font-family: var(--font-mono);
  font-weight: 800;
  color: #fff;
  border: 3px solid rgba(255, 255, 255, 0.5);
  animation: floatAvatar 3s ease-in-out infinite alternate;
}

@keyframes floatAvatar {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-8px) scale(1.04); }
}

.molecule-name {
  font-size: 24px;
  font-weight: 800;
  text-align: center;
  margin-bottom: 4px;
}

.molecule-formula {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  text-align: center;
  margin-bottom: 12px;
}

.molecule-description {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 20px;
  line-height: 1.5;
}

.reward-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.reward-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.reward-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 700;
}

.reward-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
}

.reward-value.highlight {
  color: #fbbf24;
  font-size: 17px;
}

.modal-action-btn {
  width: 100%;
  justify-content: center;
  padding: 14px;
  font-size: 15px;
}

/* Level Up Modal Customization */
.levelup-card {
  max-width: 520px;
  text-align: center;
}

.levelup-trophy {
  font-size: 56px;
  margin-bottom: 10px;
  animation: bounceTrophy 1.5s infinite alternate ease-in-out;
}

@keyframes bounceTrophy {
  0% { transform: translateY(0) rotate(-5deg); }
  100% { transform: translateY(-10px) rotate(5deg); }
}

.levelup-title {
  font-size: 26px;
  font-weight: 800;
  background: linear-gradient(120deg, #f59e0b, #ec4899, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 6px;
}

.levelup-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.new-elements-showcase {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
}

.showcase-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.unlocked-chips {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.unlocked-chip {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 800;
  color: #fff;
  font-size: 16px;
  background: var(--chip-color, #38bdf8);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), 0 0 15px var(--chip-glow, rgba(56, 189, 248, 0.4));
  border: 2px solid rgba(255, 255, 255, 0.4);
}

.levelup-bonus {
  font-size: 14px;
  color: #fbbf24;
  margin-bottom: 24px;
}

/* Discovery Recipes Codex Modal */
.codex-modal-card, .help-modal-card {
  max-width: 650px;
}

.recipes-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: max-content;
  align-content: start;
  gap: 12px;
  max-height: min(450px, 65vh);
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
}

@media (max-width: 600px) {
  .recipes-grid {
    grid-template-columns: 1fr;
  }
}

.recipe-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.recipe-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.recipe-name {
  font-weight: 700;
  font-size: 14px;
}

.recipe-formula {
  font-family: var(--font-mono);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
}

.recipe-desc {
  font-size: 11px;
  color: var(--text-muted);
}

.recipe-atoms {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Help Steps */
.help-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 65vh;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
}

.help-step {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: rgba(255, 255, 255, 0.03);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #0f172a;
  font-weight: 800;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.step-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-main);
}
