/* ==========================================================================
   PERIODIC TABLE 118 — INTERACTIVE SCIENCE MUSEUM (SPATIAL UI)
   ========================================================================== */

:root {
  /* Core Category Colors (Mandatory + Harmonious) */
  --c-kim-loai: #3B82F6;
  --c-phi-kim: #EF4444;
  --c-kim-loai-chuyen-tiep: #EAB308;
  --c-khi-hiem: #22C55E;
  --c-kim-loai-kiem: #6366F1;
  --c-kim-loai-kiem-tho: #06B6D4;
  --c-a-kim: #F97316;
  --c-halogen: #EC4899;
  --c-lanthanide: #A855F7;
  --c-actinide: #D946EF;

  /* Dark Museum Theme (Default) */
  --bg-primary: #070B14;
  --bg-secondary: #0D1322;
  --bg-surface: rgba(17, 25, 44, 0.72);
  --bg-surface-hover: rgba(26, 38, 66, 0.9);
  --bg-glass: rgba(13, 19, 34, 0.78);
  --border-subtle: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.32);
  --text-primary: #F8FAFC;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --accent: #38BDF8;
  --shadow-card: 0 20px 50px rgba(0, 0, 0, 0.45);
  --cell-bg: rgba(15, 23, 42, 0.85);
}

[data-theme="light"] {
  --bg-primary: #F1F5F9;
  --bg-secondary: #E2E8F0;
  --bg-surface: rgba(255, 255, 255, 0.88);
  --bg-surface-hover: #FFFFFF;
  --bg-glass: rgba(255, 255, 255, 0.85);
  --border-subtle: rgba(15, 23, 42, 0.1);
  --border-strong: rgba(15, 23, 42, 0.22);
  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #64748B;
  --accent: #0284C7;
  --shadow-card: 0 14px 36px rgba(15, 23, 42, 0.08);
  --cell-bg: rgba(255, 255, 255, 0.92);
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Spatial Nebula Background */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 15% 15%, rgba(59, 130, 246, 0.14), transparent 40%),
    radial-gradient(circle at 85% 20%, rgba(168, 85, 247, 0.11), transparent 38%),
    radial-gradient(circle at 50% 85%, rgba(34, 197, 94, 0.08), transparent 45%);
  pointer-events: none;
}

[data-theme="light"] body::before {
  background:
    radial-gradient(circle at 15% 15%, rgba(59, 130, 246, 0.08), transparent 42%),
    radial-gradient(circle at 85% 20%, rgba(168, 85, 247, 0.06), transparent 40%);
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* Container */
.container {
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Top Museum Navigation */
.museum-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  background: var(--bg-glass);
  border-bottom: 1px solid var(--border-subtle);
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-orb {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3B82F6, #A855F7);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.9rem;
  color: #fff;
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.45);
}

.brand-text span {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  transition: all 0.2s ease;
}

.btn-pill:hover {
  border-color: var(--border-strong);
  background: var(--bg-surface-hover);
  transform: translateY(-1px);
}

/* Hero Section with Live Spatial Spotlight */
.hero-museum {
  padding: 28px 0 20px;
}

.hero-grid {
  display: grid;
  grid-template-columns: 1.35fr 0.95fr;
  gap: 24px;
  align-items: stretch;
}

.hero-intro {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 22px;
  padding: 28px 30px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.museum-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.28);
  padding: 5px 12px;
  border-radius: 999px;
  width: fit-content;
  margin-bottom: 14px;
}

.hero-intro h1 {
  font-size: clamp(1.75rem, 3vw, 2.55rem);
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 12px;
}

.hero-intro p {
  color: var(--text-secondary);
  font-size: 0.96rem;
  max-width: 62ch;
  margin-bottom: 20px;
}

.hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.stat-chip {
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border-subtle);
  font-size: 0.82rem;
}

.stat-chip strong {
  color: var(--text-primary);
  font-weight: 700;
}

/* Spatial Spotlight Card on Homepage */
.spotlight-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 22px;
  padding: 18px 22px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-card);
  display: grid;
  grid-template-columns: 165px 1fr;
  gap: 18px;
  align-items: center;
  position: relative;
  overflow: hidden;
}

.spotlight-canvas-wrap {
  width: 165px;
  height: 165px;
  border-radius: 18px;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.16), rgba(7, 11, 20, 0.45));
  border: 1px solid var(--border-subtle);
  position: relative;
}

#spotlight-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.spotlight-info .sp-meta {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.spotlight-info h2 {
  font-size: 1.45rem;
  font-weight: 800;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.spotlight-info .sp-symbol {
  font-size: 1.05rem;
  padding: 2px 9px;
  border-radius: 8px;
  background: rgba(148, 163, 184, 0.14);
}

.spotlight-info .sp-desc {
  font-size: 0.84rem;
  color: var(--text-secondary);
  margin: 8px 0 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sp-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--accent);
}

/* Search & Filter Toolbar */
.controls-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  backdrop-filter: blur(14px);
}

.controls-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 240px;
  max-width: 440px;
}

.search-box input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.mode-switch {
  display: inline-flex;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 3px;
}

.mode-btn {
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 9px;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.mode-btn.active {
  background: var(--accent);
  color: #fff;
}

.state-select {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.84rem;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--border-subtle);
  background: rgba(148, 163, 184, 0.06);
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.filter-pill .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--pill-color, var(--accent));
}

.filter-pill:hover {
  border-color: var(--pill-color, var(--border-strong));
  color: var(--text-primary);
}

.filter-pill.active {
  background: color-mix(in srgb, var(--pill-color, var(--accent)) 20%, transparent);
  border-color: var(--pill-color, var(--accent));
  color: var(--text-primary);
}

/* Periodic Table Grid */
.ptable-wrapper {
  overflow-x: auto;
  padding-bottom: 14px;
}

.ptable-grid {
  display: grid;
  grid-template-columns: 36px repeat(18, minmax(60px, 1fr));
  gap: 6px;
  min-width: 1180px;
}

.col-header {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding-bottom: 4px;
  line-height: 1.2;
}

.col-header strong {
  display: block;
  color: var(--text-secondary);
  font-size: 0.76rem;
}

.period-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
}

.el-cell {
  --el-color: var(--c-kim-loai);
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 6px 7px;
  min-height: 70px;
  border-radius: 10px;
  background: var(--cell-bg);
  border: 1px solid color-mix(in srgb, var(--el-color) 38%, var(--border-subtle));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, opacity 0.2s ease;
  overflow: hidden;
}

.el-cell::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--el-color);
}

.el-cell:hover {
  transform: translateY(-4px) scale(1.06);
  z-index: 10;
  border-color: var(--el-color);
  box-shadow: 0 10px 26px color-mix(in srgb, var(--el-color) 35%, transparent);
}

.el-cell.dimmed {
  opacity: 0.16;
  pointer-events: none;
  transform: none;
}

.el-num {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
}

.el-sym {
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.1;
}

.el-name {
  font-size: 0.62rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.f-block-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px dashed var(--border-strong);
  font-size: 0.68rem;
  color: var(--text-secondary);
  padding: 4px;
  text-align: center;
}

.ptable-spacer {
  grid-column: 1 / -1;
  height: 12px;
}

.f-row-label {
  grid-column: 1 / 4;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 10px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
}

/* Color mapping classes */
.cat-kim-loai { --el-color: var(--c-kim-loai); }
.cat-phi-kim { --el-color: var(--c-phi-kim); }
.cat-kim-loai-chuyen-tiep { --el-color: var(--c-kim-loai-chuyen-tiep); }
.cat-khi-hiem { --el-color: var(--c-khi-hiem); }
.cat-kim-loai-kiem { --el-color: var(--c-kim-loai-kiem); }
.cat-kim-loai-kiem-tho { --el-color: var(--c-kim-loai-kiem-tho); }
.cat-a-kim { --el-color: var(--c-a-kim); }
.cat-halogen { --el-color: var(--c-halogen); }
.cat-lanthanide { --el-color: var(--c-lanthanide); }
.cat-actinide { --el-color: var(--c-actinide); }

/* SGK Reference Section */
.sgk-section {
  margin: 36px 0 48px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 22px;
  padding: 26px 28px;
  backdrop-filter: blur(14px);
}

.sgk-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 20px;
}

.sgk-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
}

.sgk-header p {
  color: var(--text-secondary);
  font-size: 0.88rem;
}

.sgk-gallery {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 20px;
}

.sgk-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sgk-card img {
  width: 100%;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border-subtle);
}

.sgk-caption {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.sgk-subcards {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ==========================================================================
   ELEMENT DETAIL PAGE (/element/<slug>/)
   ========================================================================== */
.detail-main {
  padding: 24px 0 56px;
}

.detail-breadcrumb {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.crumb-links {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  color: var(--text-secondary);
}

.crumb-links a:hover {
  color: var(--accent);
}

.prev-next-nav {
  display: flex;
  gap: 10px;
}

.detail-hero {
  --el-color: var(--c-kim-loai);
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 24px;
  margin-bottom: 26px;
}

.spatial-stage {
  background: var(--bg-surface);
  border: 1px solid color-mix(in srgb, var(--el-color) 35%, var(--border-subtle));
  border-radius: 24px;
  padding: 20px;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 390px;
  box-shadow: 0 20px 60px color-mix(in srgb, var(--el-color) 16%, transparent);
}

.stage-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  z-index: 2;
}

.stage-label {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--el-color);
  background: color-mix(in srgb, var(--el-color) 15%, transparent);
  padding: 5px 11px;
  border-radius: 999px;
}

#element-spatial-canvas {
  width: 100%;
  flex: 1;
  min-height: 290px;
  cursor: grab;
  display: block;
}

#element-spatial-canvas:active {
  cursor: grabbing;
}

.stage-hint {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.identity-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 24px;
  padding: 26px 28px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
}

.id-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.id-symbol-box {
  width: 88px;
  height: 88px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--el-color) 18%, var(--bg-secondary));
  border: 2px solid var(--el-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 28px color-mix(in srgb, var(--el-color) 30%, transparent);
}

.id-symbol-box span {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.id-symbol-box strong {
  font-size: 2.1rem;
  font-weight: 800;
  line-height: 1;
}

.id-titles h1 {
  font-size: clamp(1.6rem, 2.8vw, 2.25rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.id-titles .en-sub {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.id-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.badge-tag {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(148, 163, 184, 0.08);
}

.specs-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.spec-item {
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
}

.spec-item .spec-k {
  font-size: 0.74rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.spec-item .spec-v {
  font-size: 1rem;
  font-weight: 700;
  margin-top: 3px;
  word-break: break-word;
}

.src-tag {
  font-size: 0.64rem;
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 700;
  text-transform: uppercase;
}

.src-sgk {
  background: rgba(34, 197, 94, 0.16);
  color: #4ADE80;
}

[data-theme="light"] .src-sgk {
  color: #15803D;
}

.src-sup {
  background: rgba(56, 189, 248, 0.15);
  color: #38BDF8;
}

[data-theme="light"] .src-sup {
  color: #0369A1;
}

/* Detail Knowledge & SGK Comparison Section */
.detail-body-grid {
  display: grid;
  grid-template-columns: 1.25fr 0.85fr;
  gap: 24px;
}

.knowledge-panel, .sgk-ref-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 22px;
  padding: 24px 26px;
}

.panel-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.highlights-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.highlights-list li {
  position: relative;
  padding: 13px 16px 13px 40px;
  border-radius: 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  font-size: 0.94rem;
}

.highlights-list li::before {
  content: attr(data-idx);
  position: absolute;
  left: 13px;
  top: 14px;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--el-color, var(--accent)) 22%, transparent);
  color: var(--el-color, var(--accent));
  font-size: 0.74rem;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.sgk-ref-box {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sgk-ref-box img {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
}

.sgk-note-box {
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(234, 179, 8, 0.1);
  border: 1px solid rgba(234, 179, 8, 0.28);
  font-size: 0.84rem;
  color: var(--text-primary);
}

.sgk-honest-note {
  font-size: 0.82rem;
  color: var(--text-secondary);
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-secondary);
  border: 1px dashed var(--border-strong);
}

/* Modal for Full SGK Chart */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(2, 6, 23, 0.82);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  max-width: 980px;
  width: 100%;
  padding: 20px;
  max-height: 92vh;
  overflow-y: auto;
}

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

.modal-content img {
  width: 100%;
  border-radius: 12px;
}

.museum-footer {
  border-top: 1px solid var(--border-subtle);
  padding: 24px 0;
  text-align: center;
  font-size: 0.84rem;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 1024px) {
  .hero-grid,
  .detail-hero,
  .detail-body-grid,
  .sgk-gallery {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .spotlight-card {
    grid-template-columns: 1fr;
    text-align: center;
  }
  .spotlight-canvas-wrap {
    margin: 0 auto;
  }
  .specs-grid {
    grid-template-columns: 1fr;
  }
  .nav-actions .btn-text {
    display: none;
  }
}
