
/* ==========================================================================
   SahajPatra Futuristic 3D Periodic Table — Complete Stylesheet
   Architecture: Futuristic Scientific Lab (Dark Default + Light + High Contrast)
   ========================================================================== */

:root {
  --bg-primary: #060913;
  --bg-secondary: #0c1222;
  --bg-panel: rgba(14, 21, 38, 0.92);
  --bg-panel-solid: #0f172a;
  --bg-elevated: #162038;
  --bg-glass: rgba(15, 23, 42, 0.78);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-subtle: rgba(148, 163, 184, 0.16);
  --border-focus: #38bdf8;
  --accent-primary: #0ea5e9;
  --accent-secondary: #6366f1;
  --accent-glow: rgba(14, 165, 233, 0.28);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.65);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Devanagari', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SFMono-Regular', Consolas, monospace;

  /* 11 Accessible Scientific Element Category Colors */
  --cat-alkali: #f43f5e;
  --cat-alkaline: #fb923c;
  --cat-transition: #38bdf8;
  --cat-post-transition: #34d399;
  --cat-metalloid: #a3e635;
  --cat-nonmetal: #22d3ee;
  --cat-halogen: #facc15;
  --cat-noble: #c084fc;
  --cat-lanthanoid: #f472b6;
  --cat-actinoid: #fb7185;
  --cat-unknown: #94a3b8;

  /* State indicator colors */
  --state-solid: #cbd5e1;
  --state-liquid: #38bdf8;
  --state-gas: #4ade80;
  --state-unknown: #f59e0b;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-panel: rgba(255, 255, 255, 0.95);
  --bg-panel-solid: #ffffff;
  --bg-elevated: #e2e8f0;
  --bg-glass: rgba(255, 255, 255, 0.88);
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --border-subtle: rgba(15, 23, 42, 0.14);
  --border-focus: #0284c7;
  --accent-primary: #0284c7;
  --accent-secondary: #4f46e5;
  --accent-glow: rgba(2, 132, 199, 0.18);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.12);

  --cat-alkali: #e11d48;
  --cat-alkaline: #ea580c;
  --cat-transition: #0284c7;
  --cat-post-transition: #059669;
  --cat-metalloid: #65a30d;
  --cat-nonmetal: #0891b2;
  --cat-halogen: #ca8a04;
  --cat-noble: #9333ea;
  --cat-lanthanoid: #db2777;
  --cat-actinoid: #be123c;
  --cat-unknown: #475569;
}

[data-theme="contrast"] {
  --bg-primary: #000000;
  --bg-secondary: #0a0a0a;
  --bg-panel: #000000;
  --bg-panel-solid: #000000;
  --bg-elevated: #171717;
  --bg-glass: #000000;
  --text-primary: #ffffff;
  --text-secondary: #fef08a;
  --text-muted: #e2e8f0;
  --border-subtle: #ffffff;
  --border-focus: #00ffff;
  --accent-primary: #00ffff;
  --accent-secondary: #ffff00;
}

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

html, body {
  width: 100%;
  min-height: 100vh;
  background-color: var(--bg-primary);
  background-image:
    radial-gradient(circle at 15% 15%, rgba(14, 165, 233, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(99, 102, 241, 0.08) 0%, transparent 40%),
    linear-gradient(rgba(148, 163, 184, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.03) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 36px 36px, 36px 36px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Reduced Motion Accessibility */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Top Command Header (Compact so Table is immediately visible) */
.sp-header {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem 1rem;
  padding: 0.55rem 1rem;
  background: var(--bg-panel);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
}

.sp-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.sp-logo-orb {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #38bdf8, #4f46e5 70%, #0f172a);
  box-shadow: 0 0 14px var(--accent-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  flex-shrink: 0;
}

.sp-title-wrap h1 {
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.sp-badge-brand {
  font-size: 0.68rem;
  padding: 0.1rem 0.42rem;
  border-radius: 999px;
  background: rgba(14, 165, 233, 0.16);
  color: var(--accent-primary);
  border: 1px solid rgba(14, 165, 233, 0.35);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sp-subtitle {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

/* Primary Mode Switcher */
.sp-mode-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--bg-secondary);
  padding: 0.22rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  overflow-x: auto;
  max-width: 100%;
}

.sp-mode-btn {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.38rem 0.72rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.16s ease;
}

.sp-mode-btn:hover {
  color: var(--text-primary);
  background: rgba(148, 163, 184, 0.1);
}

.sp-mode-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 2px 10px var(--accent-glow);
}

/* Search & Utility Controls */
.sp-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.sp-search-wrap {
  position: relative;
  width: 230px;
}

.sp-search-input {
  width: 100%;
  padding: 0.4rem 1.8rem 0.4rem 1.95rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.sp-search-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.sp-search-icon {
  position: absolute;
  left: 0.58rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.8rem;
  pointer-events: none;
}

.sp-search-clear {
  position: absolute;
  right: 0.4rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  display: none;
}

.sp-search-suggestions {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  background: var(--bg-panel-solid);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 310px;
  overflow-y: auto;
  z-index: 120;
  display: none;
}

.sp-search-suggestions.open {
  display: block;
}

.sp-suggest-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  font-size: 0.78rem;
}

.sp-suggest-item:hover, .sp-suggest-item.active {
  background: var(--bg-elevated);
}

.sp-icon-btn {
  appearance: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 0.38rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: all 0.15s ease;
}

.sp-icon-btn:hover {
  border-color: var(--border-focus);
  background: var(--bg-elevated);
}

.sp-icon-btn.active {
  border-color: var(--accent-primary);
  background: rgba(14, 165, 233, 0.18);
  color: var(--accent-primary);
}

/* Sub-Toolbar: Filters, Categories, Temperature Slider */
.sp-control-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.9rem;
  padding: 0.45rem 1rem;
  background: rgba(12, 18, 34, 0.75);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.75rem;
}

[data-theme="light"] .sp-control-strip {
  background: rgba(241, 245, 249, 0.9);
}

.sp-filter-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.sp-select {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.26rem 0.48rem;
  font-size: 0.74rem;
  font-family: inherit;
  cursor: pointer;
}

.sp-chip {
  appearance: none;
  border: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  padding: 0.22rem 0.52rem;
  border-radius: 999px;
  font-size: 0.71rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: all 0.14s ease;
}

.sp-chip:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.sp-chip.active {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
}

.sp-cat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* Temperature Control Strip */
.sp-temp-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-secondary);
  padding: 0.22rem 0.65rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.sp-temp-slider {
  width: 120px;
  accent-color: var(--accent-primary);
  cursor: pointer;
}

.sp-temp-readout {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.76rem;
  color: var(--accent-primary);
  min-width: 72px;
}

/* Category Legend Bar */
.sp-legend-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem 0.75rem;
  padding: 0.38rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-primary);
}

.sp-cat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.sp-cat-pill {
  appearance: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.69rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  transition: transform 0.12s ease, opacity 0.12s ease, border-color 0.12s ease;
}

.sp-cat-pill:hover {
  transform: translateY(-1px);
  border-color: var(--text-primary);
}

.sp-cat-pill.active {
  box-shadow: 0 0 0 2px var(--accent-primary);
  background: var(--bg-elevated);
}

.sp-state-counters {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.7rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.sp-state-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
}

/* ==========================================================================
   MAIN VIEWPORT & 2D PERIODIC TABLE GRID
   ========================================================================== */

.sp-main-stage {
  position: relative;
  width: 100%;
  padding: 0.65rem 1rem 2rem;
  max-width: 1820px;
  margin: 0 auto;
}

.sp-view-section {
  display: none;
}

.sp-view-section.active {
  display: block;
}

/* Scrollable & Zoomable Table Wrapper for Mobile + Desktop */
.sp-table-viewport {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  padding-bottom: 0.75rem;
  -webkit-overflow-scrolling: touch;
}

.sp-periodic-grid {
  display: grid;
  grid-template-columns: 26px repeat(18, minmax(56px, 1fr));
  grid-template-rows: 22px repeat(7, minmax(64px, auto)) 14px repeat(2, minmax(64px, auto));
  gap: 4px;
  min-width: 1080px;
  user-select: none;
  transform-origin: top left;
  transition: transform 0.2s ease;
}

.sp-grid-col-header {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.66rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-weight: 600;
}

.sp-grid-row-header {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-weight: 700;
}

/* Info Box in empty top-middle space (Cols 3-12, Rows 1-3) */
.sp-center-hud {
  grid-column: 4 / 14;
  grid-row: 2 / 5;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.95rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  backdrop-filter: blur(8px);
}

.sp-hud-preview {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex: 1;
}

.sp-hud-symbol-box {
  width: 68px;
  height: 74px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--accent-primary);
  background: rgba(14, 165, 233, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.sp-hud-symbol-box .hud-z {
  position: absolute;
  top: 3px;
  left: 5px;
  font-size: 0.66rem;
  font-family: var(--font-mono);
  font-weight: 700;
}

.sp-hud-symbol-box .hud-sym {
  font-size: 1.65rem;
  font-weight: 800;
  line-height: 1;
}

.sp-hud-symbol-box .hud-mass {
  font-size: 0.62rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  margin-top: 2px;
}

.sp-hud-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 1fr));
  gap: 0.28rem 0.75rem;
  font-size: 0.72rem;
  flex: 1;
}

.sp-hud-meta div span {
  color: var(--text-muted);
  display: block;
  font-size: 0.63rem;
  text-transform: uppercase;
}

.sp-hud-meta div strong {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.73rem;
}

/* Element Tile Card */
.sp-tile {
  position: relative;
  border-radius: var(--radius-sm);
  padding: 3px 5px 4px;
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-top: 3px solid var(--tile-color, var(--accent-primary));
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 64px;
  transition: transform 0.14s ease, box-shadow 0.14s ease, opacity 0.18s ease, background-color 0.18s ease;
  outline: none;
  overflow: hidden;
}

[data-theme="light"] .sp-tile {
  border-color: rgba(15, 23, 42, 0.12);
  border-top: 3px solid var(--tile-color, var(--accent-primary));
  background: #ffffff;
}

.sp-tile::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 0%, var(--tile-color, transparent), transparent 78%);
  opacity: 0.13;
  pointer-events: none;
}

.sp-tile:hover, .sp-tile:focus-visible {
  transform: translateY(-3px) scale(1.05);
  z-index: 25;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.55), 0 0 12px var(--tile-color, var(--accent-primary));
  border-color: var(--tile-color, var(--accent-primary));
}

.sp-tile.dimmed {
  opacity: 0.16;
  filter: grayscale(0.75);
  transform: scale(0.97);
}

.sp-tile.selected-compare {
  box-shadow: 0 0 0 2px #facc15, 0 0 14px rgba(250, 204, 21, 0.6);
}

.sp-tile-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  line-height: 1;
}

.sp-tile-z {
  font-weight: 700;
  color: var(--text-secondary);
}

.sp-tile-badges {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.sp-tile-state {
  font-size: 0.56rem;
  font-weight: 800;
  padding: 1px 3px;
  border-radius: 3px;
  line-height: 1;
}

.state-S { color: var(--state-solid); background: rgba(203, 213, 225, 0.14); }
.state-L { color: var(--state-liquid); background: rgba(56, 189, 248, 0.2); }
.state-G { color: var(--state-gas); background: rgba(74, 222, 128, 0.2); }
.state-U { color: var(--state-unknown); background: rgba(245, 158, 11, 0.2); }

.sp-tile-symbol {
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--text-primary);
  text-align: center;
  margin: 1px 0;
}

.sp-tile-name {
  font-size: 0.58rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sp-tile-mass {
  font-size: 0.54rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-align: center;
  line-height: 1;
}

.sp-tile-fav-indicator {
  position: absolute;
  bottom: 2px;
  right: 3px;
  font-size: 0.55rem;
  color: #facc15;
}

/* Bridge markers for 57-71 and 89-103 */
.sp-fblock-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  background: rgba(148, 163, 184, 0.06);
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 2px;
  text-align: center;
}

/* Trends Heatmap Overlay Bar */
.sp-trends-bar {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
  padding: 0.6rem 0.9rem;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.sp-trends-bar.active {
  display: flex;
}

.sp-gradient-scale {
  width: 220px;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #1e3a8a, #0ea5e9, #10b981, #facc15, #f43f5e);
  border: 1px solid rgba(255,255,255,0.2);
}

.sp-tile.unknown-trend {
  background: repeating-linear-gradient(
    45deg,
    rgba(100, 116, 139, 0.12),
    rgba(100, 116, 139, 0.12) 6px,
    rgba(30, 41, 59, 0.25) 6px,
    rgba(30, 41, 59, 0.25) 12px
  ) !important;
}

/* ==========================================================================
   3D PERIODIC TABLE & 3D LANDSCAPE VIEW
   ========================================================================== */

.sp-3d-stage {
  position: relative;
  width: 100%;
  height: calc(100vh - 190px);
  min-height: 540px;
  background: radial-gradient(ellipse at center, #0d182e 0%, #050811 100%);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

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

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

.sp-3d-hud-top {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  pointer-events: none;
}

.sp-3d-hud-panel {
  pointer-events: auto;
  background: rgba(10, 15, 29, 0.86);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.45rem 0.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.75rem;
  color: #f1f5f9;
}

.sp-3d-hud-bottom {
  position: absolute;
  bottom: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  pointer-events: none;
}

.sp-3d-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--accent-primary);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.65rem;
  color: #fff;
  font-size: 0.74rem;
  box-shadow: var(--shadow-lg);
  display: none;
  z-index: 30;
}

/* ==========================================================================
   COMPARE MODE (2 to 4 Elements)
   ========================================================================== */

.sp-compare-container {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.1rem;
}

.sp-compare-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.sp-compare-slots {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.1rem;
}

.sp-compare-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-top: 4px solid var(--accent-primary);
  border-radius: var(--radius-md);
  padding: 0.8rem;
  position: relative;
}

.sp-compare-table-wrap {
  overflow-x: auto;
}

.sp-compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.sp-compare-table th, .sp-compare-table td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
}

.sp-compare-table th {
  color: var(--text-secondary);
  font-weight: 600;
  width: 190px;
  background: rgba(148, 163, 184, 0.04);
}

.sp-bar-track {
  width: 100%;
  height: 6px;
  background: rgba(148, 163, 184, 0.15);
  border-radius: 999px;
  margin-top: 4px;
  overflow: hidden;
}

.sp-bar-fill {
  height: 100%;
  background: var(--accent-primary);
  border-radius: 999px;
}

/* ==========================================================================
   DISCOVERY TIMELINE MODE
   ========================================================================== */

.sp-timeline-container {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.1rem;
}

.sp-timeline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.65rem;
  margin-top: 1rem;
}

.sp-timeline-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--accent-primary);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.8rem;
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease;
}

.sp-timeline-item:hover {
  transform: translateY(-2px);
  border-color: var(--border-focus);
}

/* ==========================================================================
   QUIZ LAB MODE
   ========================================================================== */

.sp-quiz-container {
  max-width: 960px;
  margin: 0 auto;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}

.sp-quiz-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.65rem;
  margin-top: 1rem;
}

.sp-quiz-option-btn {
  appearance: none;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all 0.14s ease;
}

.sp-quiz-option-btn:hover:not(:disabled) {
  border-color: var(--accent-primary);
  background: var(--bg-elevated);
}

.sp-quiz-option-btn.correct {
  background: rgba(16, 185, 129, 0.22);
  border-color: #10b981;
  color: #34d399;
}

.sp-quiz-option-btn.wrong {
  background: rgba(244, 63, 94, 0.22);
  border-color: #f43f5e;
  color: #fb7185;
}

/* ==========================================================================
   FULL ELEMENT LAB DRAWER / MODAL
   ========================================================================== */

.sp-lab-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 14, 0.72);
  backdrop-filter: blur(5px);
  z-index: 90;
  display: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sp-lab-backdrop.open {
  display: block;
  opacity: 1;
}

.sp-element-lab {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(940px, 100vw);
  background: var(--bg-panel-solid);
  border-left: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(102%);
  transition: transform 0.26s cubic-bezier(0.16, 1, 0.3, 1);
}

.sp-element-lab.open {
  transform: translateX(0);
}

.sp-lab-header {
  padding: 0.85rem 1.2rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.sp-lab-hero-id {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.sp-lab-big-tile {
  width: 68px;
  height: 74px;
  border-radius: var(--radius-md);
  border: 2px solid var(--accent-primary);
  background: rgba(14, 165, 233, 0.12);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

.sp-lab-tabs {
  display: flex;
  gap: 0.3rem;
  padding: 0.45rem 1.2rem;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto;
}

.sp-lab-tab {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius-sm);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.sp-lab-tab.active {
  background: var(--bg-elevated);
  color: var(--accent-primary);
  border-color: var(--border-subtle);
}

.sp-lab-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.1rem 1.2rem 2.5rem;
}

/* 3D Visualizers Grid inside Element Lab */
.sp-lab-visualizers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.15rem;
}

.sp-viz-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
}

.sp-viz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.sp-viz-canvas-wrap {
  position: relative;
  width: 100%;
  height: 215px;
  background: radial-gradient(circle at center, #111c35 0%, #070b16 100%);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.08);
  overflow: hidden;
}

.sp-viz-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}

.sp-viz-note {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.38rem;
}

/* Orbital Boxes Display */
.sp-orbital-boxes-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.5rem;
}

.sp-subshell-group {
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
}

.sp-subshell-title {
  color: var(--accent-primary);
  font-weight: 700;
  margin-bottom: 2px;
  font-size: 0.64rem;
}

.sp-spin-boxes {
  display: flex;
  gap: 3px;
}

.sp-spin-box {
  width: 22px;
  height: 22px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.66rem;
  letter-spacing: -1px;
  color: var(--text-primary);
}

/* Data Sections inside Element Lab */
.sp-lab-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.9rem 1rem;
  margin-bottom: 0.9rem;
}

.sp-lab-section h3 {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--accent-primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.38rem;
}

.sp-kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
  gap: 0.55rem 0.85rem;
}

.sp-kv-item {
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.42rem 0.6rem;
}

.sp-kv-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  display: block;
}

.sp-kv-val {
  font-size: 0.79rem;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-mono);
  word-break: break-word;
}

/* Emission Spectrum Bar */
.sp-spectrum-bar {
  position: relative;
  width: 100%;
  height: 34px;
  background: #04060c;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  margin-top: 0.35rem;
}

.sp-spectrum-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2.5px;
  box-shadow: 0 0 6px currentColor;
}

/* Presentation Mode (Hides extra filters, maximizes table for classroom projection) */
body.presentation-mode .sp-control-strip,
body.presentation-mode .sp-subtitle {
  display: none !important;
}

body.presentation-mode .sp-periodic-grid {
  gap: 6px;
}

/* Print Styles (A4 Landscape / A3 / B&W support) */
@media print {
  @page {
    size: landscape;
    margin: 0.5cm;
  }
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .sp-header, .sp-control-strip, .sp-lab-backdrop, .sp-element-lab, .sp-trends-bar {
    display: none !important;
  }
  .sp-table-viewport {
    overflow: visible !important;
  }
  .sp-periodic-grid {
    min-width: 100% !important;
    gap: 2px !important;
  }
  .sp-tile {
    background: #ffffff !important;
    color: #000000 !important;
    border: 1px solid #000000 !important;
    box-shadow: none !important;
    min-height: 46px !important;
  }
  body.print-bw .sp-tile {
    border-top: 2px solid #000000 !important;
  }
}

/* Mobile Responsive Adjustments */
@media (max-width: 860px) {
  .sp-header {
    padding: 0.45rem 0.65rem;
  }
  .sp-search-wrap {
    width: 100%;
    order: 4;
  }
  .sp-center-hud {
    display: none;
  }
  .sp-element-lab {
    width: 100vw;
  }
  .sp-3d-stage {
    height: 460px;
  }
}


.sp-site-return{padding:.55rem 1rem;display:flex;gap:1.2rem;flex-wrap:wrap;font-size:.8rem;border-bottom:1px solid var(--border-subtle);align-items:center}.sp-site-return a,.sp-reference-directory a,.sp-reference-article a,.sp-reference-header a,.sp-reference-footer a{color:var(--accent-primary);text-decoration:none}.sp-site-return #sp-filter-results{margin-left:auto;color:var(--text-secondary)}
.sp-reference-directory{max-width:1150px;margin:2rem auto;padding:1.25rem;border:1px solid var(--border-subtle);border-radius:14px;background:var(--bg-panel-solid);line-height:1.8}.sp-reference-directory h2{font-size:1.2rem;margin:1.4rem 0 .65rem}.sp-reference-directory p{color:var(--text-secondary);margin:.75rem 0}.sp-reference-table-wrap{max-width:100%;overflow:auto}.sp-reference-table{width:100%;border-collapse:collapse;text-align:left;font-size:.88rem}.sp-reference-table th,.sp-reference-table td{padding:.6rem .8rem;border-bottom:1px solid var(--border-subtle);white-space:normal}.sp-reference-table thead{background:var(--bg-elevated)}.sp-reference-table th[scope=row]{font-weight:600}.sp-reference-note{font-size:.8rem;color:var(--text-secondary);line-height:1.75;margin:.7rem 0}.sp-reference-lead{line-height:1.9;font-size:1rem;margin-bottom:1rem}.sp-lab-section h2{font-size:1.05rem;margin-bottom:1rem;color:var(--accent-primary)}.sp-lab-section p{line-height:1.8;margin:.7rem 0}.sp-lab-section dd{margin:0}.sp-lab-section{scroll-margin-top:90px}.sp-extra{margin:.8rem 0;padding:.65rem .85rem;border:1px solid var(--border-subtle);border-radius:8px}.sp-extra summary{cursor:pointer;color:var(--accent-primary);font-size:.83rem}.sp-extra[open]>div{margin-top:.75rem;line-height:1.75;font-size:.83rem}.sp-source-list{display:flex;flex-wrap:wrap;gap:.5rem 1.4rem;padding-left:1.2rem;font-size:.82rem}.sp-source-list a{color:var(--accent-primary)}.sp-reference-header,.sp-reference-footer{max-width:1100px;margin:auto;padding:1rem;display:flex;justify-content:space-between;flex-wrap:wrap;gap:1rem}.sp-reference-header nav{display:flex;gap:1rem}.sp-reference-article{max-width:1100px;margin:auto;padding:1rem;line-height:1.8}.sp-reference-article .sp-lab-section{padding:1.4rem;margin:1.2rem 0;background:var(--bg-panel-solid);border:1px solid var(--border-subtle);border-radius:14px}.sp-element-page-title{display:flex;gap:1.4rem;align-items:center;flex-wrap:wrap;margin:1.5rem 0}.sp-element-page-title h1{font-size:clamp(1.5rem,4vw,2.2rem);line-height:1.5}.sp-element-page-title .sp-icon-btn{display:inline-block;margin-top:1rem}.sp-element-symbol{width:110px;min-height:140px;display:flex;flex-direction:column;justify-content:center;text-align:center;border:2px solid var(--accent-primary);border-radius:10px;background:var(--bg-panel-solid)}.sp-element-symbol strong{font-size:2.7rem}.sp-reference-jumps,.sp-element-neighbors{display:flex;gap:1rem;flex-wrap:wrap;margin:1.3rem 0}.sp-reference-jumps a,.sp-element-neighbors a{border:1px solid var(--border-subtle);border-radius:8px;padding:.4rem .7rem}.sp-reference-footer{border-top:1px solid var(--border-subtle);font-size:.85rem}.sp-dialog-open{overflow:hidden!important}.sp-element-lab:not(.open){visibility:hidden}.sp-element-lab.open{visibility:visible}.sp-skip-link{position:fixed;top:-100px;left:1rem;z-index:200;background:var(--bg-panel-solid);padding:1rem}.sp-skip-link:focus{top:1rem}:focus-visible{outline:2px solid var(--accent-primary);outline-offset:3px}.sp-3d-canvas,.sp-viz-canvas{touch-action:none}.sp-lab-header>.sp-icon-btn{align-self:flex-start}.sp-kv-val{overflow-wrap:anywhere}.sp-reference-table a:hover{text-decoration:underline}
@media(max-width:600px){.sp-reference-directory{margin:1rem .5rem;padding:.8rem}.sp-reference-article{padding:.65rem}.sp-reference-article .sp-lab-section{padding:1rem}.sp-kv-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.sp-lab-visualizers{grid-template-columns:1fr}.sp-header{position:relative}.sp-actions{width:100%;flex-wrap:wrap}.sp-search-wrap{width:100%}.sp-search-input{width:100%}.sp-3d-hud-top{position:relative;top:0;left:0;right:0}.sp-3d-hud-panel{max-width:100%;flex-wrap:wrap}.sp-3d-stage{height:600px}.sp-3d-hud-bottom{font-size:.65rem}.sp-reference-table th,.sp-reference-table td{padding:.45rem;font-size:.78rem}.sp-mode-nav{width:100%}}
@media print{.sp-site-return,.sp-reference-directory,.sp-reference-jumps,.sp-reference-header,.sp-reference-footer,.sp-element-neighbors{display:none!important}.sp-element-page .sp-reference-article{max-width:none}.sp-element-page .sp-lab-section{break-inside:avoid;color:#000!important;background:#fff!important}.sp-kv-val,.sp-kv-label,.sp-element-page h2{color:#000!important}body:not(.sp-element-page) .sp-view-section{display:none!important}body:not(.sp-element-page) #sp-section-table{display:block!important}.sp-table-viewport{overflow:visible!important}.sp-periodic-grid{transform:none!important;min-width:0!important;grid-template-columns:22px repeat(18,minmax(0,1fr))!important}.sp-tile{color:#000!important;min-height:42px!important;font-size:8px!important}.sp-tile *{color:#000!important}.sp-center-hud{display:none!important}body.print-bw .sp-tile{border-color:#000!important;border-top-color:#000!important}body:not(.print-bw) .sp-tile{border-top-color:var(--cat-color)!important}.sp-tile.is-filtered{opacity:1!important}}

