@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

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

:root {
  --bg: #0c0f1a;
  --bg-sidebar: #0a0d16;
  --card: #151929;
  --card-border: #1e2640;
  --card-hover: #1a2035;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.08);
  --green-border: rgba(34, 197, 94, 0.2);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.08);
  --red-border: rgba(239, 68, 68, 0.2);
  --purple: #a78bfa;
  --purple-bg: rgba(167, 139, 250, 0.08);
  --purple-border: rgba(167, 139, 250, 0.2);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.08);
  --amber-border: rgba(245, 158, 11, 0.2);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.08);
  --blue-border: rgba(59, 130, 246, 0.2);

  /* dynamic accent — set by JS per nutrient */
  --accent: #f97316;
  --accent-soft: #fb923c;
  --accent-dark: #ea580c;
  --accent-bg: rgba(249, 115, 22, 0.08);
  --accent-border: rgba(249, 115, 22, 0.2);
}

html, body { height: 100%; }

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  display: flex;
}

/* ===================== SIDEBAR ===================== */
.sidebar {
  width: 280px;
  min-width: 280px;
  height: 100vh;
  position: sticky;
  top: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  overflow: visible;
}

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--card-border);
}

.sidebar-logo {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo span {
  font-size: 22px;
}

.sidebar-controls {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.lang-toggle { flex-shrink: 0; }

/* VIEW TOGGLE */
.view-toggle {
  display: flex;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 14px;
}

.view-btn {
  flex: 1;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text-dim);
  border: none;
  background: none;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.15s;
  text-align: center;
}

.view-btn.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.view-btn:hover:not(.active) {
  color: var(--text-muted);
}

.lang-toggle {
  display: flex;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 12px;
}

.lang-btn {
  padding: 5px 12px;
  cursor: pointer;
  color: var(--text-dim);
  border: none;
  background: none;
  font-family: inherit;
  font-weight: 600;
  transition: all 0.15s;
}

.lang-btn.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.search-box {
  flex: 1;
  padding: 6px 12px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.search-box::placeholder { color: var(--text-dim); }
.search-box:focus { border-color: rgba(255, 255, 255, 0.15); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 4px; }

.nav-category {
  padding: 0 12px;
  margin-bottom: 4px;
}

.nav-category-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  cursor: pointer;
  transition: all 0.15s;
}

.nav-category-btn:hover { color: var(--text-muted); }

.nav-category-btn .arrow {
  font-size: 10px;
  transition: transform 0.2s;
  margin-left: auto;
}

.nav-category.open .arrow { transform: rotate(90deg); }

.nav-items {
  display: none;
  padding: 2px 0 8px;
}

.nav-category.open .nav-items { display: block; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px 7px 20px;
  margin: 1px 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: all 0.15s;
  border: none;
  background: none;
  width: 100%;
  font-family: inherit;
  text-align: left;
}

.nav-item:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); }

.nav-item.active {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.nav-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.nav-item .coming-soon {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-dim);
  opacity: 0.5;
}

/* ===================== MAIN ===================== */
.main {
  flex: 1;
  overflow-y: auto;
  height: 100vh;
}

.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 32px;
}

/* WELCOME */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  padding: 40px;
}

.welcome-icon {
  font-size: 64px;
  margin-bottom: 24px;
  opacity: 0.15;
}

.welcome h2 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
}

.welcome p {
  color: var(--text-dim);
  font-size: 16px;
  max-width: 480px;
  line-height: 1.7;
}

/* CARD HEADER */
.nutrient-header {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-bottom: 12px;
}

.nutrient-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 900;
  color: white;
  flex-shrink: 0;
}

.nutrient-header h1 {
  font-size: 42px;
  font-weight: 900;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #fff, #e2e8f0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nutrient-header .subtitle {
  color: var(--accent-soft);
  font-size: 16px;
  margin-top: -2px;
}

.pills {
  display: flex;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}

.pill {
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--accent-border);
  color: var(--accent-soft);
  background: var(--accent-bg);
}

/* MODE FALLBACK BANNER — shown when simple/learn content not yet translated */
.mode-fallback-banner {
  margin: 0 0 20px;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
  color: #fdba74;
  background: rgba(249, 115, 22, 0.08);
  border: 1px solid rgba(249, 115, 22, 0.28);
  border-left: 3px solid #f97316;
}

/* PER-CARD MODE TAB BAR */
.card-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin: 0 0 24px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.card-tab {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 0;
  padding: 8px 18px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.2px;
  color: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}
.card-tab:hover {
  color: rgba(255, 255, 255, 0.85);
}
.card-tab.active {
  background: var(--accent-bg);
  color: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent-border);
}
.card-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* RDA BAR */
.rda-bar {
  display: flex;
  gap: 24px;
  padding: 14px 20px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.rda-item { display: flex; align-items: baseline; gap: 6px; }
.rda-item .label { color: var(--text-dim); font-size: 12px; }
.rda-item .value { color: var(--text); font-weight: 700; font-size: 14px; }
.rda-item .value.highlight { color: var(--accent); }

/* RANGES BAR (Blood Panel) */
.ranges-bar {
  display: flex;
  gap: 12px;
  padding: 14px 20px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.range-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
}

.range-item.normal {
  background: var(--green-bg);
  border: 1px solid var(--green-border);
}

.range-item.warning {
  background: var(--amber-bg);
  border: 1px solid var(--amber-border);
}

.range-item.danger {
  background: var(--red-bg);
  border: 1px solid var(--red-border);
}

.range-label {
  font-weight: 600;
}

.range-item.normal .range-label { color: var(--green); }
.range-item.warning .range-label { color: var(--amber); }
.range-item.danger .range-label { color: var(--red); }

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

/* SUMMARY */
.summary {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 24px 28px;
  margin-bottom: 24px;
  border-left: 4px solid var(--accent);
}

.summary h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--accent);
  margin-bottom: 10px;
  font-weight: 700;
}

.summary p {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.85;
}

/* GRID */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

/* CARDS */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  overflow: hidden;
  transition: border-color 0.2s;
}

.card:hover { border-color: rgba(255, 255, 255, 0.08); }

.card-header {
  padding: 14px 20px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  border-bottom: 1px solid var(--card-border);
}

.card-header.accent { color: var(--accent); background: var(--accent-bg); border-bottom-color: var(--accent-border); }
.card-header.green { color: var(--green); background: var(--green-bg); border-bottom-color: var(--green-border); }
.card-header.red { color: var(--red); background: var(--red-bg); border-bottom-color: var(--red-border); }
.card-header.purple { color: var(--purple); background: var(--purple-bg); border-bottom-color: var(--purple-border); }
.card-header.amber { color: var(--amber); background: var(--amber-bg); border-bottom-color: var(--amber-border); }
.card-header.blue { color: var(--blue); background: var(--blue-bg); border-bottom-color: var(--blue-border); }

.card-body { padding: 18px 20px; }

/* ITEMS */
.item { display: flex; gap: 10px; margin-bottom: 14px; align-items: flex-start; }
.item:last-child { margin-bottom: 0; }

.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; margin-top: 7px; }
.dot.accent { background: var(--accent); }
.dot.green { background: var(--green); }
.dot.red { background: var(--red); }
.dot.purple { background: var(--purple); }
.dot.amber { background: var(--amber); }
.dot.blue { background: var(--blue); }

.item-text { font-size: 13px; color: var(--text-muted); line-height: 1.5; }
.item-text strong { color: var(--text); font-weight: 600; }

/* PHASES */
.phase-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 6px;
}

.phase-badge.early { background: rgba(251, 191, 36, 0.15); color: #fbbf24; }
.phase-badge.mid { background: rgba(251, 146, 60, 0.15); color: #fb923c; }
.phase-badge.severe { background: rgba(239, 68, 68, 0.15); color: #ef4444; }

.phase-block { margin-bottom: 14px; padding-left: 4px; }
.phase-block:last-child { margin-bottom: 0; }
.phase-text { font-size: 13px; color: var(--text-muted); line-height: 1.5; margin-top: 3px; }

.recovery-note {
  margin-top: 14px;
  padding: 8px 12px;
  background: var(--green-bg);
  border: 1px solid var(--green-border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--green);
}

/* INTERACTIONS */
.interaction-group { margin-bottom: 16px; }
.interaction-group:last-child { margin-bottom: 0; }

.group-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--card-border);
}

.group-label.good { color: var(--green); }
.group-label.bad { color: var(--red); }

/* ABSORPTION */
.absorption-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 10px;
  padding: 10px;
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  border-radius: 8px;
}

.absorption-row { display: flex; justify-content: space-between; padding: 3px 6px; font-size: 12px; }
.absorption-row .dose { color: var(--text-muted); }
.absorption-row .rate { color: var(--accent); font-weight: 600; }

/* FOODS */
.food-bar {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 18px 24px;
  margin-bottom: 20px;
}

.food-bar h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 14px;
}

.foods { display: flex; gap: 10px; flex-wrap: wrap; }

.food-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  border-radius: 8px;
  font-size: 13px;
}

.food-item .name { color: var(--text); font-weight: 500; }
.food-item .mg { color: var(--accent); font-weight: 700; }

/* REFERENCES */
.references { margin-top: 4px; }
.references summary { cursor: pointer; color: var(--text-dim); font-size: 12px; padding: 10px 0; user-select: none; }
.references summary:hover { color: var(--text-muted); }
.ref-list { display: grid; gap: 6px; padding: 12px 0; }
.ref { font-size: 11px; color: var(--text-dim); line-height: 1.5; }
.ref a { color: var(--blue); text-decoration: none; }
.ref a:hover { text-decoration: underline; }
sup { font-size: 9px; color: var(--text-dim); }

/* MOBILE SIDEBAR */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

/* ===================== PERIODIC TABLE OVERVIEW ===================== */
.pt-header { text-align: center; margin-bottom: 24px; }
.pt-header h2 {
  font-size: 26px; font-weight: 900; letter-spacing: -1.5px;
  background: linear-gradient(135deg, #fff, #8090b0);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.pt-header p { color: var(--text-dim); font-size: 11px; margin-top: 2px; }

.pt-rows { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.pt-row { display: flex; gap: 10px; justify-content: center; align-items: flex-start; flex-wrap: wrap; }

/* Category group with colored border */
.pt-cat {
  position: relative;
  border: 1.5px solid color-mix(in srgb, var(--c) 40%, transparent);
  border-radius: 10px;
  padding: 18px 4px 4px;
  width: fit-content;
  background: color-mix(in srgb, var(--c) 2.5%, transparent);
  transition: all 0.3s;
}
.pt-cat:hover {
  border-color: color-mix(in srgb, var(--c) 60%, transparent);
  box-shadow: 0 0 20px color-mix(in srgb, var(--c) 8%, transparent);
}
.pt-cat-label {
  position: absolute; top: -7px; left: 10px;
  font-size: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  color: var(--c); background: var(--bg); padding: 0 6px;
  white-space: nowrap; display: flex; align-items: center; gap: 4px;
}
.pt-cat-label::before { content:''; width: 5px; height: 5px; border-radius: 50%; background: var(--c); }

.pt-grid { display: grid; gap: 3px; grid-template-columns: repeat(var(--cols, 1), 100px); }

/* Pan-zoom viewport wrapper (no-op on desktop) */
.pt-viewport { position: relative; }

/* Element box */
.pt-el {
  width: 100px; height: 100px;
  background: var(--card); border: 1px solid var(--card-border); border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 4px 2px 6px; cursor: pointer; transition: all 0.2s; position: relative; overflow: hidden;
  gap: 2px;
}
.pt-el::before { content:''; position: absolute; top: 0; left: 0; right: 0; height: 2.5px; background: var(--e); }
.pt-el:hover {
  border-color: var(--e); transform: translateY(-2px) scale(1.06);
  box-shadow: 0 6px 18px rgba(0,0,0,0.5), 0 0 0 1px var(--e), 0 0 12px color-mix(in srgb, var(--e) 12%, transparent);
  z-index: 10; background: #1a2035;
}
.pt-el-num { position: absolute; top: 3px; right: 4px; font-size: 7px; color: var(--text-dim); font-weight: 600; }
.pt-el-sym { font-size: 24px; font-weight: 900; color: var(--e); line-height: 1; }
.pt-el-name { font-size: 10px; color: var(--text-muted); text-align: center; line-height: 1.2; opacity: 0.75; max-width: 90px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: normal; }

/* Planned/unavailable elements */
.pt-el.planned { opacity: 0.26; }
.pt-el.planned:hover { transform: none; box-shadow: none; border-color: var(--card-border); cursor: default; background: var(--card); }

/* Legend */
.pt-legend {
  display: flex; flex-wrap: wrap; gap: 12px; justify-content: center;
  margin-top: 20px; padding: 9px 18px;
  background: rgba(255,255,255,0.015); border: 1px solid var(--card-border); border-radius: 8px;
}
.pt-legend span { display: flex; align-items: center; gap: 4px; font-size: 8.5px; color: var(--text-muted); font-weight: 500; }
.pt-legend i { width: 6px; height: 6px; border-radius: 2px; display: inline-block; font-style: normal; }
.pt-legend .dim { opacity: 0.3; }

/* Back button (from detail view to overview) */
.back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; margin-bottom: 20px;
  background: var(--card); border: 1px solid var(--card-border); border-radius: 8px;
  color: var(--text-muted); font-family: inherit; font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
}
.back-btn:hover { border-color: rgba(255,255,255,0.15); color: var(--text); }

@media (max-width: 1000px) {
  .grid { grid-template-columns: 1fr; }
  .nutrient-header { flex-direction: column; align-items: flex-start; }
  .pills { margin-left: 0; }
  .rda-bar { flex-direction: column; gap: 8px; }
  .ranges-bar { flex-direction: column; gap: 8px; }
  .pt-row { flex-wrap: wrap; justify-content: center; }
  .pt-grid { grid-template-columns: repeat(auto-fill, 84px) !important; justify-content: center; }
  .pt-cat { width: auto; }
  .pt-el { width: 84px; height: 84px; }
  .pt-el-sym { font-size: 20px; }
  .pt-el-name { font-size: 9px; max-width: 76px; }
}

/* Mobile top bar — visible only on mobile */
.mobile-topbar {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: 48px; padding: 0 12px;
  background: var(--bg-sidebar); border-bottom: 1px solid var(--card-border);
  align-items: center; gap: 8px;
}

.mobile-topbar .sidebar-toggle {
  position: static; display: flex;
  width: 36px; height: 36px; font-size: 16px;
  border-radius: 8px; flex-shrink: 0;
}

.mobile-view-toggle {
  display: flex; flex: 1;
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: 6px; overflow: hidden;
}

.mobile-view-toggle .view-btn {
  flex: 1; padding: 6px 8px;
  background: none; border: none;
  color: var(--text-dim); font-family: inherit;
  font-size: 11px; font-weight: 600; cursor: pointer;
  transition: all 0.15s; text-align: center;
}

.mobile-view-toggle .view-btn.active {
  background: rgba(255,255,255,0.08); color: var(--text);
}

.mobile-lang {
  display: flex; background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 6px; overflow: hidden; flex-shrink: 0;
}

.mobile-lang .lang-btn {
  padding: 6px 10px; background: none; border: none;
  color: var(--text-dim); font-family: inherit;
  font-size: 10px; font-weight: 600; cursor: pointer;
}

.mobile-lang .lang-btn.active {
  background: rgba(255,255,255,0.08); color: var(--text);
}

@media (max-width: 768px) {
  /* Hide desktop sidebar toggle, show mobile topbar */
  body > .sidebar-toggle { display: none !important; }
  .mobile-topbar { display: flex; }

  .sidebar {
    position: fixed;
    left: -280px;
    z-index: 99;
    transition: left 0.25s ease;
    top: 48px; height: calc(100vh - 48px);
  }

  .sidebar.open { left: 0; }

  .main { margin-top: 48px; height: calc(100vh - 48px); }
  .main-content { padding: 20px 12px 40px; }
  .nutrient-header h1 { font-size: 24px; }
  .nutrient-header { gap: 14px; }
  .nutrient-icon { width: 52px; height: 52px; font-size: 26px; }

  /* Periodic table mobile */
  .pt-header { margin-bottom: 16px; }
  .pt-header h2 { font-size: 20px; }
  .pt-rows { gap: 10px; width: 100%; }
  .pt-row { gap: 10px; flex-direction: column; align-items: stretch; width: 100%; }
  .pt-cat { padding: 16px 6px 6px; width: auto; margin: 0 4px; }
  .pt-cat-label { font-size: 7.5px; top: -6px; }
  .pt-grid { gap: 4px; grid-template-columns: repeat(auto-fill, 74px) !important; justify-content: center; }
  .pt-el { width: 74px; height: 74px; }
  .pt-el-sym { font-size: 17px; }
  .pt-el-name { font-size: 8px; max-width: 66px; }
  .pt-el-num { font-size: 5px; top: 2px; right: 3px; }

  /* Legend compact */
  .pt-legend { gap: 8px; padding: 6px 12px; margin-top: 14px; }
  .pt-legend span { font-size: 7.5px; }

  /* Back button */
  .back-btn { font-size: 11px; padding: 5px 10px; margin-bottom: 14px; }

  /* Summary + cards compact */
  .summary { padding: 16px 18px; margin-bottom: 16px; }
  .summary p { font-size: 13px; }
  .card-body { padding: 14px 16px; }
  .item-text { font-size: 12px; }

  /* Ranges bar */
  .range-item { padding: 5px 10px; font-size: 12px; }

  /* Pills wrap better */
  .pills { gap: 6px; }
  .pill { padding: 4px 10px; font-size: 11px; }
}

@media (max-width: 400px) {
  .pt-grid { grid-template-columns: repeat(auto-fill, 66px) !important; }
  .pt-el { width: 66px; height: 66px; }
  .pt-el-sym { font-size: 15px; }
  .pt-el-name { font-size: 7px; max-width: 58px; }
  .pt-cat { padding: 14px 4px 4px; }
  .pt-cat-label { font-size: 6px; letter-spacing: 0.5px; }
  .mobile-view-toggle .view-btn { font-size: 10px; padding: 5px 4px; }
  .nutrient-header h1 { font-size: 20px; }
}

/* ===================== MOBILE PINCH-ZOOM + PAN ===================== */
/* Activated by body.pt-pz when the periodic table is shown on mobile.   */
/* Restores desktop-size tiles inside .pt-viewport and lets JS drive a    */
/* transform on .pt-rows for map-style pan/zoom.                          */
@media (max-width: 768px) {
  body.pt-pz .main-content {
    display: flex;
    flex-direction: column;
    padding: 12px 0 0;
    height: calc(100vh - 48px);
    overflow: hidden;
  }
  body.pt-pz .pt-header {
    flex-shrink: 0;
    padding: 0 12px;
    margin-bottom: 8px !important;
  }
  body.pt-pz .pt-legend {
    flex-shrink: 0;
    margin: 8px 12px 12px !important;
  }
  body.pt-pz .pt-viewport {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    cursor: grab;
  }
  body.pt-pz .pt-viewport .pt-rows {
    position: absolute;
    top: 0;
    left: 0;
    width: max-content !important;
    transform-origin: 0 0;
    will-change: transform;
    gap: 12px !important;
    align-items: center !important;
  }
  /* Restore desktop-size layout inside the zoom viewport */
  body.pt-pz .pt-viewport .pt-row {
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: flex-start !important;
    width: auto !important;
    gap: 10px !important;
  }
  body.pt-pz .pt-viewport .pt-cat {
    width: fit-content !important;
    margin: 0 !important;
    padding: 18px 4px 4px !important;
  }
  body.pt-pz .pt-viewport .pt-cat-label {
    font-size: 8px !important;
    top: -7px !important;
    letter-spacing: 1px !important;
  }
  body.pt-pz .pt-viewport .pt-grid {
    grid-template-columns: repeat(var(--cols, 1), 100px) !important;
    gap: 3px !important;
  }
  body.pt-pz .pt-viewport .pt-el {
    width: 100px !important;
    height: 100px !important;
  }
  body.pt-pz .pt-viewport .pt-el-sym { font-size: 24px !important; }
  body.pt-pz .pt-viewport .pt-el-name {
    font-size: 10px !important;
    max-width: 90px !important;
  }
  body.pt-pz .pt-viewport .pt-el-num {
    font-size: 7px !important;
    top: 3px !important;
    right: 4px !important;
  }
  /* Disable the hover lift — it glitches out during transform */
  body.pt-pz .pt-viewport .pt-el:hover {
    transform: none !important;
  }
}

/* ==========================================================================
   MODE / LANG DROPDOWNS (Task 6)
   ========================================================================== */

.sidebar-controls,
.mobile-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.dropdown {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dropdown-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted, #9ca3af);
}

.dropdown-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  color: #e5e7eb;
  cursor: pointer;
  font-weight: 600;
}

.dropdown-trigger:hover {
  border-color: #4b5563;
}

.dropdown-trigger.compact {
  padding: 5px 8px;
  font-size: 11px;
}

.dropdown-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #3b82f6;
  flex-shrink: 0;
}

.dropdown-caret {
  font-size: 10px;
  color: #6b7280;
  margin-left: 2px;
}

.dropdown-popover {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  background: #0f172a;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 1000;
}

.dropdown.open .dropdown-popover {
  display: block;
}

.dropdown-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: #e5e7eb;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
}

.dropdown-option:hover {
  background: rgba(255, 255, 255, 0.04);
}

.dropdown-option.active {
  background: rgba(59, 130, 246, 0.12);
}

.dropdown-option-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.dropdown-option-title {
  font-size: 13px;
  font-weight: 600;
}

.dropdown-option-sub {
  font-size: 11px;
  color: #9ca3af;
}

/* Mobile: drop labels, keep compact triggers next to hamburger */
@media (max-width: 768px) {
  .dropdown-label {
    display: none;
  }
  .mobile-dropdown .dropdown-popover {
    left: auto;
    right: 0;
    min-width: 180px;
  }
}

/* ==========================================================================
   SIMPLE / LEARN NARRATIVE SECTIONS (Task 9)
   ========================================================================== */

.sl-hero {
  background: rgba(59, 130, 246, 0.08);
  border-left: 4px solid #3b82f6;
  padding: 16px 20px;
  margin-bottom: 24px;
  border-radius: 8px;
}

.sl-hero-label {
  font-size: 11px;
  text-transform: uppercase;
  color: #60a5fa;
  letter-spacing: 1px;
  margin-bottom: 6px;
  font-weight: 600;
}

.sl-hero-text {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.5;
  color: #e5e7eb;
}

.sl-section {
  margin-bottom: 12px;
  border: 1px solid #1f2937;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.015);
}

.sl-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 12px 16px;
  background: transparent;
  border: none;
  color: #e5e7eb;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.sl-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sl-section-caret {
  color: #6b7280;
  font-size: 12px;
  transition: transform 0.15s ease;
}

.sl-section[data-open="true"] .sl-section-caret {
  transform: rotate(90deg);
}

.sl-section-body {
  display: none;
  padding: 0 16px 14px;
  font-size: 14px;
  line-height: 1.6;
  color: #d1d5db;
}

.sl-section[data-open="true"] .sl-section-body {
  display: block;
}

.sl-section-body ul {
  margin: 6px 0 0 18px;
  padding: 0;
}
.sl-section-body ul li {
  margin-bottom: 6px;
}

.sl-section-warn {
  border-color: rgba(245, 158, 11, 0.3);
}
.sl-section-warn .sl-section-title {
  color: #fbbf24;
}

.sl-section-danger {
  border-color: rgba(220, 38, 38, 0.4);
  background: rgba(220, 38, 38, 0.06);
}
.sl-section-danger .sl-section-title {
  color: #fca5a5;
}

.sl-section-good {
  border-color: rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.04);
}
.sl-section-good .sl-section-title {
  color: #34d399;
}

.sl-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.sl-pair .sl-section {
  margin-bottom: 0;
}

@media (max-width: 768px) {
  .sl-pair {
    grid-template-columns: 1fr;
  }
}

/* Glossary box (learn mode only) */
.sl-glossary {
  margin-top: 20px;
  background: rgba(59, 130, 246, 0.06);
  border: 1px solid rgba(59, 130, 246, 0.25);
  padding: 14px 16px;
  border-radius: 8px;
}

.sl-glossary-label {
  font-size: 11px;
  text-transform: uppercase;
  color: #60a5fa;
  letter-spacing: 1px;
  margin-bottom: 10px;
  font-weight: 600;
}

.sl-glossary-item {
  font-size: 13px;
  color: #d1d5db;
  line-height: 1.7;
  margin-bottom: 6px;
}

/* FAQ details inside a section */
.sl-faq-item {
  margin-bottom: 8px;
}
.sl-faq-item summary {
  cursor: pointer;
  font-weight: 600;
  color: #e5e7eb;
  padding: 6px 0;
}
.sl-faq-item p {
  margin: 4px 0 10px 0;
  color: #9ca3af;
  font-size: 13px;
}

/* Desktop: all sections always open, no accordion */
@media (min-width: 769px) {
  .sl-section[data-open="false"] .sl-section-body {
    display: block;
  }
  .sl-section .sl-section-caret {
    display: none;
  }
  .sl-section .sl-section-header {
    cursor: default;
  }
}

/* Mobile: top-3 sections (always-open) stay expanded, rest accordion */
@media (max-width: 768px) {
  .sl-section-always-open[data-open="true"] .sl-section-body {
    display: block;
  }
}

/* ==========================================================================
   DEIN WERT — styled to match narrative sections
   ========================================================================== */

.your-value-box {
  margin-top: 28px;
  margin-bottom: 28px;
  padding: 20px 22px;
  background: rgba(168, 85, 247, 0.06);
  border: 1px solid rgba(168, 85, 247, 0.25);
  border-left: 4px solid #a855f7;
  border-radius: 8px;
}

.your-value-label {
  font-size: 11px;
  text-transform: uppercase;
  color: #c4b5fd;
  letter-spacing: 1px;
  margin-bottom: 12px;
  font-weight: 600;
}

.your-value-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.your-value-input {
  flex: 1;
  min-width: 140px;
  padding: 10px 14px;
  background: #0f172a;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #e5e7eb;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
}

.your-value-input:focus {
  outline: none;
  border-color: #a855f7;
}

.your-value-unit {
  padding: 10px 12px;
  background: #0f172a;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #e5e7eb;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}

.your-value-age-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #9ca3af;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.your-value-age {
  width: 60px;
  padding: 10px 8px;
  background: #0f172a;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #e5e7eb;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  text-align: center;
  -moz-appearance: textfield;
}

.your-value-age::-webkit-outer-spin-button,
.your-value-age::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.your-value-age:focus {
  outline: none;
  border-color: #a855f7;
}

.your-value-result {
  margin-top: 12px;
  font-size: 14px;
  font-weight: 600;
  min-height: 20px;
}

.your-value-result-normal {
  color: #4ade80;
}

.your-value-result-warning {
  color: #fbbf24;
}

.your-value-result-danger {
  color: #f87171;
}

.your-value-result-unknown {
  color: #9ca3af;
  font-weight: 500;
  font-style: italic;
}

/* ─── Value Range Indicator (Stage 1: Thermometer) ─────────────── */

.your-value-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.your-value-header .your-value-label {
  margin-bottom: 0;
}

.viz-toggle-bar {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.viz-toggle-btn {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 0;
  color: #9ca3af;
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}

.viz-toggle-btn:hover {
  color: #e5e7eb;
}

.viz-toggle-btn.active {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.value-viz-container {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
  min-height: 260px;
}

.value-viz-stack,
.value-viz-curve-wrap {
  /* Legacy Stage-3-Pilot layout classes, superseded by .value-viz-row. */
  display: contents;
}

.value-viz-curve {
  display: block;
  width: 100%;
  height: 260px; /* match thermo H=260 so x-axes line up at the same baseline */
}

/* Single shared box per row — thermo+curve live in ONE bordered container so
   it visually reads as a unit. For sex-split cards we render two such rows
   stacked; for unisex cards one row. The optional sex/note label sits at the
   top of the row, thermo+curve align at the bottom so x-axes line up. */
.value-viz-row {
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 10px 14px;
  gap: 6px;
  flex: 1 1 380px;
  min-width: 0;
  max-width: 520px;
}

.value-viz-row-label {
  font-size: 11px;
  color: #9ca3af;
  font-weight: 500;
  letter-spacing: 0.3px;
}

.value-viz-row-content {
  display: flex;
  align-items: flex-end; /* shared baseline for thermo and curve */
  gap: 14px;
}

.value-viz-thermo-col {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.value-viz-curve-col {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: stretch;
}

@media (max-width: 600px) {
  .value-viz-row-content { flex-direction: column; align-items: center; }
  .value-viz-curve-col { width: 100%; }
  /* Mobile uses preserveAspectRatio="meet" — let the SVG keep its natural
     360:260 aspect instead of being forced into 260px height (which would
     leave blank bars left/right). */
  .value-viz-curve { height: auto; }
}

.value-viz-container:empty {
  min-height: 0;
  margin-top: 0;
}

.value-viz-thermo {
  display: block;
  max-width: 100%;
  height: auto;
}

.value-viz-split {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
}

.value-viz-split-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 0 1 auto;
}

.value-viz-split-label {
  font-size: 11px;
  color: #9ca3af;
  font-weight: 500;
  letter-spacing: 0.3px;
}

@media (max-width: 520px) {
  .your-value-header { flex-direction: column; align-items: flex-start; }
  .viz-toggle-bar { align-self: flex-end; }
  .value-viz-split { gap: 8px; }
}
