/* ============================================================
   PiHKAL – Swedish Edition  |  6 Themes  |  Modern UI
   ============================================================ */

/* ─── Theme Definitions ─── */
:root {
  /* Default = Mörk (Dark) */
  --bg: #0a0a14;
  --bg-alt: #12121e;
  --surface: #1a1a2e;
  --surface-hover: #222240;
  --card-bg: #16162a;
  --card-border: #2a2a44;
  --text: #e8e8f0;
  --text-secondary: #b0b0c8;
  --text-muted: #6a6a88;
  --text-dim: #484860;
  --accent: #d4a840;
  --accent-hover: #f0c860;
  --accent-glow: rgba(212, 168, 64, 0.15);
  --red: #e74c3c;
  --green: #2ecc71;
  --purple: #a29bfe;
  --shadow: rgba(0, 0, 0, 0.5);
  --glow: 0 0 20px rgba(212, 168, 64, 0.06);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', Consolas, monospace;
  --font-book: Georgia, 'Times New Roman', Times, serif;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --header-blur: rgba(10, 10, 20, 0.85);
}

/* ─── Light Theme ─── */
/* Light theme: orange entry header like original Erowid */
body.theme-light .entry-header {
  background: linear-gradient(135deg, #f39c12, #e67e22) !important;
}
body.theme-light .entry-header .entry-number { color: rgba(255,255,255,0.8); }
body.theme-light .entry-header h2 { color: #fff; }
body.theme-light .entry-header .chemical-name { color: rgba(255,255,255,0.85); }

body.theme-light {
  --bg: #f8f5f0;
  --bg-alt: #f0ebe4;
  --surface: #ffffff;
  --surface-hover: #f5f0e9;
  --card-bg: #ffffff;
  --card-border: #e5ddd4;
  --text: #2d2d3d;
  --text-secondary: #5a5a6a;
  --text-muted: #8a8a9a;
  --text-dim: #b0b0ba;
  --accent: #c0392b;
  --accent-hover: #e74c3c;
  --accent-glow: rgba(192, 57, 43, 0.08);
  --shadow: rgba(0, 0, 0, 0.06);
  --glow: 0 2px 20px rgba(0, 0, 0, 0.04);
  --header-blur: rgba(248, 245, 240, 0.92);
}

/* ─── Matrix Theme ─── */
body.theme-matrix {
  --bg: #000000;
  --bg-alt: #050505;
  --surface: #0a0a0a;
  --surface-hover: #0f0f0f;
  --card-bg: #080808;
  --card-border: #1a3a1a;
  --text: #00ff41;
  --text-secondary: #00cc35;
  --text-muted: #007a20;
  --text-dim: #003d10;
  --accent: #00ff41;
  --accent-hover: #33ff66;
  --accent-glow: rgba(0, 255, 65, 0.12);
  --shadow: rgba(0, 255, 65, 0.05);
  --glow: 0 0 15px rgba(0, 255, 65, 0.08);
  --header-blur: rgba(0, 0, 0, 0.9);
  --font: 'Courier New', 'Fira Code', 'Source Code Pro', monospace;
  --font-mono: 'Courier New', 'Fira Code', monospace;
  --font-book: 'Courier New', monospace;
}

/* ─── Synthwave Theme ─── */
body.theme-synthwave {
  --bg: #1a0033;
  --bg-alt: #20003d;
  --surface: #2b004d;
  --surface-hover: #350060;
  --card-bg: #250040;
  --card-border: #4a0077;
  --text: #f8e0ff;
  --text-secondary: #d4a0ff;
  --text-muted: #8844bb;
  --text-dim: #552277;
  --accent: #ff2d95;
  --accent-hover: #ff6db8;
  --accent-glow: rgba(255, 45, 149, 0.15);
  --red: #ff2d95;
  --green: #00ffaa;
  --purple: #8844ff;
  --shadow: rgba(0, 0, 0, 0.6);
  --glow: 0 0 25px rgba(255, 45, 149, 0.1);
  --header-blur: rgba(26, 0, 51, 0.88);
}

/* ─── Dracula Theme ─── */
body.theme-dracula {
  --bg: #21222c;
  --bg-alt: #282a36;
  --surface: #2c2d3e;
  --surface-hover: #36384a;
  --card-bg: #282a36;
  --card-border: #3e4056;
  --text: #f8f8f2;
  --text-secondary: #c8c8b8;
  --text-muted: #7a7a8a;
  --text-dim: #4a4a5a;
  --accent: #ff79c6;
  --accent-hover: #ff9ad5;
  --accent-glow: rgba(255, 121, 198, 0.12);
  --red: #ff5555;
  --green: #50fa7b;
  --purple: #bd93f9;
  --shadow: rgba(0, 0, 0, 0.4);
  --glow: 0 0 20px rgba(255, 121, 198, 0.06);
  --header-blur: rgba(33, 34, 44, 0.9);
}

/* ─── Super Mario Theme ─── */
body.theme-supermario {
  --bg: #f0e8d8;
  --bg-alt: #e8dcc8;
  --surface: #ffffff;
  --surface-hover: #f5f0e8;
  --card-bg: #ffffff;
  --card-border: #d8c8b0;
  --text: #2c2c2c;
  --text-secondary: #5a4a3a;
  --text-muted: #8a7a6a;
  --text-dim: #b0a090;
  --accent: #e52521;
  --accent-hover: #ff3d35;
  --accent-glow: rgba(229, 37, 33, 0.08);
  --red: #e52521;
  --green: #4caf50;
  --purple: #8e44ad;
  --shadow: rgba(0, 0, 0, 0.08);
  --glow: 0 2px 16px rgba(0, 0, 0, 0.04);
  --header-blur: rgba(240, 232, 216, 0.92);
  /* Mario accents */
  --mario-red: #e52521;
  --mario-blue: #049cd8;
  --mario-yellow: #fbd000;
  --mario-green: #4caf50;
  --mario-brown: #8b6b4b;
}

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

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   HEADER
   ============================================================ */
.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  background: var(--header-blur);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--card-border);
  padding: 0 1.25rem;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background var(--transition), border-color var(--transition);
}

.site-header.scrolled {
  box-shadow: 0 2px 24px var(--shadow);
}

.site-header .logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  transition: color var(--transition);
  white-space: nowrap;
}

.site-header .logo span {
  color: var(--text-secondary);
  font-weight: 400;
  font-size: 0.8rem;
}

.site-header .logo-icon {
  width: 30px;
  height: 30px;
  background: var(--accent);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.75rem;
  color: var(--bg);
  flex-shrink: 0;
}

/* ─── Theme Picker ─── */
.theme-picker {
  position: relative;
  display: flex;
  align-items: center;
}

.theme-picker .theme-btn {
  background: var(--surface);
  border: 1px solid var(--card-border);
  color: var(--text-secondary);
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: var(--font);
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.theme-picker .theme-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--surface-hover);
}

.theme-picker .theme-btn .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.theme-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 32px var(--shadow);
  padding: 0.35rem;
  display: none;
  z-index: 200;
  min-width: 160px;
}

.theme-menu.open {
  display: block;
}

.theme-menu button {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.45rem 0.7rem;
  background: transparent;
  border: none;
  border-radius: var(--radius-xs);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: var(--font);
  transition: background var(--transition);
  text-align: left;
}

.theme-menu button:hover {
  background: var(--surface-hover);
}

.theme-menu button.active {
  background: var(--accent-glow);
  color: var(--accent);
}

.theme-menu button .swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid var(--card-border);
  flex-shrink: 0;
}

/* ─── Header Index / Slumpa Buttons ─── */
.header-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-nav button {
  background: var(--surface);
  border: 1px solid var(--card-border);
  color: var(--text-secondary);
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-size: 0.83rem;
  font-family: var(--font);
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.header-nav button:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================================================
   HERO / LANDING
   ============================================================ */
.hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 6rem 1.5rem 3rem;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 0%, var(--accent-glow) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 50%, var(--accent-glow) 0%, transparent 50%);
  pointer-events: none;
  transition: background var(--transition);
}

.hero-cover {
  width: 260px;
  max-width: 70vw;
  height: auto;
  border-radius: var(--radius);
  box-shadow:
    0 20px 60px var(--shadow),
    0 0 0 1px var(--card-border);
  margin-bottom: 1.75rem;
  transition: transform 0.4s ease, box-shadow var(--transition);
  position: relative;
  z-index: 1;
}

.hero-cover:hover {
  transform: scale(1.02) translateY(-4px);
  box-shadow:
    0 30px 80px var(--shadow),
    0 0 0 1px var(--accent);
}

.hero h1 {
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 0.4rem;
  position: relative;
  z-index: 1;
  letter-spacing: -0.02em;
  transition: color var(--transition);
}

.hero .subtitle {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
  position: relative;
  z-index: 1;
}

.hero .subtitle em {
  color: var(--accent);
  font-style: italic;
}

.hero .authors {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1.75rem;
  position: relative;
  z-index: 1;
}

.hero-buttons {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
  position: relative;
  z-index: 1;
}

.hero .btn-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 2rem;
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
  font-size: 0.95rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
  text-decoration: none;
}

.hero .btn-cta:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
  box-shadow: 0 8px 25px var(--accent-glow);
}

.hero .btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.7rem 1.4rem;
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 0.9rem;
  font-family: var(--font);
  text-decoration: none;
}

.hero .btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--surface-hover);
}

.hero-stats {
  display: flex;
  gap: 2rem;
  margin-top: 2rem;
  position: relative;
  z-index: 1;
}

.hero-stat {
  text-align: center;
}

.hero-stat .num {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  transition: color var(--transition);
}

.hero-stat .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ============================================================
   MAIN VIEW CONTAINER
   ============================================================ */
.view-container {
  max-width: 880px;
  margin: 0 auto;
  padding: 1.25rem;
}

/* ============================================================
   INDEX VIEW
   ============================================================ */
.index-header {
  padding: 4rem 0 1.25rem;
}

.index-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  color: var(--accent);
  transition: color var(--transition);
}

.index-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.search-box {
  position: relative;
  margin: 1rem 0;
}

.search-box input {
  width: 100%;
  padding: 0.75rem 1rem 0.75rem 2.6rem;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.92rem;
  font-family: var(--font);
  transition: all var(--transition);
  outline: none;
}

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

.search-box input::placeholder {
  color: var(--text-dim);
}

.search-box .search-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  font-size: 0.9rem;
  pointer-events: none;
}

.compound-count {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.compound-index {
  display: grid;
  gap: 0.4rem;
}

.compound-item {
  display: grid;
  grid-template-columns: 44px 1fr 20px;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  font-family: var(--font);
  color: var(--text);
}

.compound-item:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  transform: translateX(4px);
  box-shadow: var(--glow);
}

.compound-item .num {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  font-family: var(--font-mono);
}

.compound-item .code {
  font-weight: 600;
  color: var(--text);
  font-size: 0.92rem;
}

.compound-item .code .chem-name {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.78rem;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.compound-item .arrow {
  color: var(--text-dim);
  font-size: 0.8rem;
  opacity: 0;
  transition: opacity var(--transition);
}

.compound-item:hover .arrow {
  opacity: 1;
  color: var(--accent);
}

/* ============================================================
   ENTRY DETAIL VIEW
   ============================================================ */
.entry-view {
  padding-top: 4rem;
}

/* Breadcrumb */
.entry-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  margin-bottom: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  transition: background var(--transition), border-color var(--transition);
}

.entry-breadcrumb .bc-link {
  color: var(--accent);
  cursor: pointer;
  transition: opacity var(--transition);
  text-decoration: none;
}

.entry-breadcrumb .bc-link:hover {
  opacity: 0.7;
}

.entry-breadcrumb .bc-sep {
  color: var(--text-dim);
  font-size: 1.1rem;
}

.entry-breadcrumb .bc-current {
  color: var(--text-secondary);
  font-weight: 500;
}

.entry-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  overflow: hidden;
  box-shadow: var(--glow);
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.entry-header {
  padding: 2rem 1.5rem;
  text-align: center;
  border-bottom: 1px solid var(--card-border);
  background: linear-gradient(180deg, var(--surface) 0%, var(--card-bg) 100%);
  transition: background var(--transition);
}

.entry-header .entry-number {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-muted);
  font-weight: 600;
}

.entry-header h2 {
  font-size: 2rem;
  margin: 0.4rem 0;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.entry-header .chemical-name {
  font-size: 0.88rem;
  font-weight: 400;
  color: var(--text-muted);
  font-family: var(--font-mono);
  word-break: break-word;
  line-height: 1.5;
}

/* Info Grid */
.info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--card-border);
  transition: background var(--transition);
}

.info-item {
  text-align: center;
  padding: 0.65rem 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  transition: background var(--transition), border-color var(--transition);
}

.info-item .label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.info-item .value {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.info-item.dosage .value { color: var(--green); }
.info-item.duration .value { color: var(--purple); }

/* Structure placeholder */
.structure-placeholder {
  text-align: center;
  padding: 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--card-border);
  transition: background var(--transition);
}

.structure-placeholder .mol-icon {
  font-size: 2.5rem;
  margin-bottom: 0.3rem;
  opacity: 0.5;
}

.structure-placeholder .caption {
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* Entry Sections */
.entry-sections {
  padding: 1.75rem;
}

.section {
  margin-bottom: 1.75rem;
}

.section:last-child {
  margin-bottom: 0;
}

.section h3 {
  font-size: 1.05rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  padding-bottom: 0.5rem;
  margin-bottom: 1.1rem;
  transition: color var(--transition), border-color var(--transition);
}

.section p {
  margin-bottom: 1rem;
  line-height: 2.0;
  color: var(--text-secondary);
  font-size: 0.95rem;
  text-align: justify;
  hyphens: auto;
  word-spacing: 0.02em;
}

.section p:last-child {
  margin-bottom: 0;
}

/* Experience Reports */
.experience {
  background: var(--surface);
  padding: 1.1rem 1.25rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.85rem;
  border-left: 4px solid var(--accent);
  transition: background var(--transition);
}

.experience:last-child {
  margin-bottom: 0;
}

.experience .dose {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  transition: color var(--transition);
}

.experience p {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.9;
}

/* Commentary */
.commentary-box {
  background: var(--commentary-bg, var(--surface));
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--commentary-border, var(--card-border));
  transition: background var(--transition), border-color var(--transition);
}

.commentary-box h4 {
  color: var(--accent);
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
  font-weight: 700;
}

.commentary-box p {
  margin-bottom: 0.75rem;
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.9;
}

.commentary-box p:last-child {
  margin-bottom: 0;
}

/* Light theme: yellow commentary box like original Erowid */
body.theme-light .commentary-box {
  --commentary-bg: #fff9e6;
  --commentary-border: #f0c860;
}

body.theme-light .commentary-box h4 {
  color: #d4a017;
}

body.theme-light .commentary-box p {
  color: #5a4a3a;
}

/* Super Mario: warm commentary */
body.theme-supermario .commentary-box {
  --commentary-bg: #fef5e0;
  --commentary-border: var(--mario-yellow);
}

body.theme-supermario .commentary-box h4 {
  color: var(--mario-red);
}

/* Entry Navigation */
.entry-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border-top: 1px solid var(--card-border);
  gap: 0.5rem;
  transition: background var(--transition), border-color var(--transition);
}

.entry-nav a {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.9rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-xs);
  text-decoration: none;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.82rem;
  transition: all var(--transition);
  cursor: pointer;
  font-family: var(--font);
}

.entry-nav a:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.entry-nav a.disabled {
  opacity: 0.25;
  cursor: not-allowed;
  pointer-events: none;
}

.entry-nav .nav-index {
  color: var(--accent);
  border-color: var(--accent-glow);
}

/* ============================================================
   FOOTER
   ============================================================ */
.site-footer {
  text-align: center;
  padding: 1.75rem 1.5rem;
  color: var(--text-dim);
  font-size: 0.78rem;
  border-top: 1px solid var(--card-border);
  margin-top: 0.5rem;
  transition: color var(--transition), border-color var(--transition);
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
}

/* ============================================================
   LOADING & ANIMATIONS
   ============================================================ */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  min-height: 60vh;
}

.loading .spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--card-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: 0.85rem;
  transition: border-color var(--transition);
}

.loading p {
  color: var(--text-muted);
  font-size: 0.88rem;
}

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

.fade-in {
  animation: fadeIn 0.35s ease both;
}

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

.slide-up {
  animation: slideUp 0.4s ease both;
}

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

/* ============================================================
   NO RESULTS
   ============================================================ */
.no-results {
  text-align: center;
  padding: 2.5rem 1.5rem;
  color: var(--text-muted);
}

.no-results .icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  opacity: 0.4;
}

.no-results p {
  font-size: 0.9rem;
}

/* ============================================================
   BACK TO TOP
   ============================================================ */
.back-to-top {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  width: 38px;
  height: 38px;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: 50%;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  transition: all var(--transition);
  z-index: 50;
  font-size: 1rem;
  font-family: var(--font);
}

.back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
}

.back-to-top:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================================================
   SYNTHWAVE SUN BACKGROUND (decorative)
   ============================================================ */
body.theme-synthwave .hero::after {
  content: '';
  position: absolute;
  bottom: 30%;
  left: 50%;
  transform: translateX(-50%);
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, #ff2d95 0%, #ff2d9540 40%, transparent 70%);
  opacity: 0.15;
  pointer-events: none;
}

/* ============================================================
   SUPER MARIO DECORATIONS
   ============================================================ */
body.theme-supermario .entry-header {
  background: linear-gradient(135deg, var(--mario-red), #c0392b) !important;
}

body.theme-supermario .entry-header h2 {
  color: #fff;
  text-shadow: 2px 2px 0 #000;
}

body.theme-supermario .entry-header .chemical-name {
  color: #f5e0d0;
}

body.theme-supermario .entry-header .entry-number {
  color: var(--mario-yellow);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  html { font-size: 15px; }

  .site-header { padding: 0 0.75rem; }
  .site-header .logo span { display: none; }

  .header-nav button { font-size: 0.8rem; padding: 0.35rem 0.65rem; }
  .theme-picker .theme-btn { padding: 0.35rem 0.5rem; }

  .hero h1 { font-size: 1.9rem; }
  .hero .subtitle { font-size: 0.95rem; }
  .hero-cover { width: 200px; }

  .entry-header h2 { font-size: 1.5rem; }
  .entry-header .chemical-name { font-size: 0.8rem; }

  .info-grid { grid-template-columns: repeat(3, 1fr); gap: 0.5rem; padding: 1rem; }
  .info-item .value { font-size: 0.95rem; }

  .entry-breadcrumb { font-size: 0.8rem; padding: 0.5rem 0.75rem; }

  .entry-nav { flex-wrap: wrap; justify-content: center; }
  .entry-nav a { flex: 1; justify-content: center; font-size: 0.8rem; }

  .compound-item {
    grid-template-columns: 36px 1fr 16px;
    padding: 0.55rem 0.7rem;
  }

  .compound-item .num { font-size: 0.78rem; }
  .compound-item .code { font-size: 0.85rem; }

  .hero-stats { gap: 1.5rem; }
  .hero-stat .num { font-size: 1.3rem; }

  .view-container { padding: 0.85rem; }
  .entry-sections { padding: 1rem; }
  .entry-header { padding: 1.5rem 1rem; }
}

@media (max-width: 480px) {
  html { font-size: 14px; }

  .hero h1 { font-size: 1.5rem; }
  .hero-cover { width: 160px; }
  .hero .btn-cta { padding: 0.7rem 1.4rem; font-size: 0.88rem; }
  .hero .btn-secondary { padding: 0.55rem 1rem; font-size: 0.85rem; }

  .info-grid { grid-template-columns: 1fr; gap: 0.35rem; }
  .info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.45rem 0.65rem;
  }
  .info-item .label { margin-bottom: 0; font-size: 0.6rem; }
  .info-item .value { font-size: 0.9rem; }

  .compound-item { grid-template-columns: 32px 1fr 14px; gap: 0.4rem; }

  .entry-nav { flex-direction: column; }
  .entry-nav a { width: 100%; }

  .entry-header h2 { font-size: 1.3rem; }
  .section h3 { font-size: 0.9rem; }

  .hero-stats { gap: 0.75rem; flex-direction: column; }

  .theme-menu {
    right: -20px;
    min-width: 140px;
  }
}
