/* ── Reset & base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: rgb(15, 15, 25);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: rgba(255, 255, 255, 0.82);
}

/* ── Top bar ───────────────────────────────────────────────────────────── */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 44px;
  background: rgba(12, 12, 22, 0.97);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  z-index: 2000;
  user-select: none;
}

.topbar-left { display: flex; align-items: center; }
.topbar-center { display: flex; gap: 4px; }
.topbar-right { display: flex; align-items: center; gap: 6px; }

#site-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.80);
}

.mode-btn {
  font-size: 12px;
  padding: 4px 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 4px;
  color: rgba(255, 255, 255, 0.50);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.mode-btn:hover  { background: rgba(255,255,255,0.11); color: rgba(255,255,255,0.80); }
.mode-btn.active { background: rgba(78,121,167,0.30); border-color: rgba(78,121,167,0.55);
                   color: rgba(255,255,255,0.90); }

.topbar-btn {
  font-size: 11px;
  padding: 3px 10px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 4px;
  color: rgba(255,255,255,0.45);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.topbar-btn:hover { background: rgba(255,255,255,0.10); color: rgba(255,255,255,0.78); }

/* ── Canvas ────────────────────────────────────────────────────────────── */
#three-canvas {
  position: fixed;
  top: 44px;
  left: 0;
  display: block;
  outline: none;
}

/* ── Left panel ────────────────────────────────────────────────────────── */
#left-panel {
  position: fixed;
  top: 56px; left: 12px; bottom: 12px;
  width: 290px;
  height: 400px;
  background: rgba(15, 15, 28, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 8px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.40);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow: hidden;
}

/* Story panel */
#story-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#story-content {
  flex: 1;
  padding: 20px 16px 12px;
  overflow-y: auto;
}

#story-title {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
  color: rgba(255,255,255,0.90);
  margin-bottom: 10px;
}

#story-subtitle {
  font-size: 13px;
  line-height: 1.65;
  color: rgba(255,255,255,0.60);
}

#story-nav {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,0.07);
}

#story-counter {
  font-size: 11px;
  color: rgba(255,255,255,0.32);
}

.nav-btn {
  font-size: 12px;
  padding: 5px 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 4px;
  color: rgba(255,255,255,0.60);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.nav-btn:hover    { background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.90); }
.nav-btn:disabled { opacity: 0.3; cursor: default; }

/* Explore panel */
#explore-panel {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  padding: 18px 16px;
}

#explore-default h2 {
  font-size: 15px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
  margin-bottom: 8px;
}

.explore-hint {
  font-size: 12px;
  line-height: 1.65;
  color: rgba(255,255,255,0.38);
}

#explore-recipe, #explore-cluster { display: none; }

#recipe-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
  color: rgba(255,255,255,0.90);
  margin-bottom: 8px;
}

#recipe-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 10px;
}

.recipe-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgba(78,121,167,0.25);
  color: rgba(255,255,255,0.70);
  border: 1px solid rgba(78,121,167,0.35);
}

#recipe-stats {
  font-size: 11px;
  color: rgba(255,255,255,0.42);
  margin-bottom: 10px;
  line-height: 1.7;
}

#recipe-ingredients {
  font-size: 11px;
  line-height: 1.7;
  color: rgba(255,255,255,0.55);
  margin-bottom: 10px;
}

#recipe-description {
  font-size: 11px;
  line-height: 1.65;
  color: rgba(255,255,255,0.42);
  font-style: italic;
}

#cluster-name {
  font-size: 14px;
  font-weight: 600;
  color: rgba(255,255,255,0.88);
  margin-bottom: 4px;
}

#cluster-count {
  font-size: 11px;
  color: rgba(255,255,255,0.38);
  margin-bottom: 14px;
}

#cluster-placeholder {
  font-size: 11px;
  color: rgba(255,255,255,0.25);
  padding: 12px;
  border: 1px dashed rgba(255,255,255,0.10);
  border-radius: 5px;
  text-align: center;
}

/* ── Right panel ───────────────────────────────────────────────────────── */
#right-panel {
  /* flex: 1; */
  height: 400px;
  min-height: 0;
  background: rgba(15, 15, 28, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 8px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.40);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#category-tabs {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  padding: 8px 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.cat-tab {
  font-size: 10px;
  padding: 4px 8px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  color: rgba(255,255,255,0.42);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  margin-bottom: -1px;
  white-space: nowrap;
}
.cat-tab:hover  { background: rgba(255,255,255,0.09); color: rgba(255,255,255,0.75); }
.cat-tab.active { background: rgba(15,15,28,0.88); border-color: rgba(255,255,255,0.10);
                  color: rgba(255,255,255,0.88); border-bottom-color: rgba(15,15,28,0.88); }

#category-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0 8px;
}
#category-list::-webkit-scrollbar { width: 4px; }
#category-list::-webkit-scrollbar-track { background: transparent; }
#category-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); border-radius: 2px; }

.cat-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  cursor: pointer;
  user-select: none;
  transition: background 0.10s;
}
.cat-row:hover     { background: rgba(255,255,255,0.04); }
.cat-row.active    { background: rgba(78,121,167,0.15); }

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

.cat-label {
  flex: 1;
  font-size: 12px;
  color: rgba(255,255,255,0.68);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cat-label.dimmed { color: rgba(255,255,255,0.28); }

.cat-count {
  flex-shrink: 0;
  font-size: 10px;
  color: rgba(255,255,255,0.24);
}

/* ── Right column ──────────────────────────────────────────────────────── */
#right-column {
  position: fixed;
  top: 56px; right: 12px; bottom: 12px;
  width: 290px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 1000;
  user-select: none;
}

/* ── Share popup ───────────────────────────────────────────────────────── */
#share-popup {
  position: fixed;
  top: 52px;
  right: 12px;
  width: 300px;
  background: rgba(22, 22, 36, 0.98);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.60);
  display: none;
  flex-direction: column;
  gap: 12px;
  z-index: 3000;
  backdrop-filter: blur(8px);
}
#share-popup.open { display: flex; }

#share-title {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
}

#share-close {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 13px;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 50%;
  color: rgba(255,255,255,0.55);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
#share-close:hover { background: rgba(255,255,255,0.14); color: rgba(255,255,255,0.90); }

#share-url-row {
  position: relative;
  margin-top: 6px;
}

#share-url {
  width: 100%;
  font-size: 11px;
  padding: 8px 58px 8px 10px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 5px;
  color: rgba(255,255,255,0.60);
  outline: none;
  cursor: text;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#share-view-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: rgba(255,255,255,0.60);
  cursor: pointer;
  user-select: none;
}
#share-view-label input[type="checkbox"] { cursor: pointer; accent-color: #4e79a7; }

#share-copy {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  padding: 3px 10px;
  background: rgba(78,121,167,1.00);
  border: 1px solid rgba(78,121,167,1.00);
  border-radius: 4px;
  color: rgba(255,255,255,1.00);
  cursor: pointer;
  transition: background 0.12s;
}
#share-copy:hover { background: rgba(72,115,155,1.00); }

/* ── Display widget ────────────────────────────────────────────────────── */
#display-widget {
  position: fixed;
  bottom: 20px;
  right: 40px;
  width: 230px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 15, 28, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 5px 12px 5px 10px;
  backdrop-filter: blur(6px);
  z-index: 1000;
  user-select: none;
}

.sw-label { font-size: 10px; color: rgba(255,255,255,0.35); white-space: nowrap; }
.sw-val   { font-size: 10px; color: rgba(255,255,255,0.40); min-width: 22px; text-align: right; }

.sw-slider {
  -webkit-appearance: none; appearance: none;
  flex: 1; height: 3px;
  background: rgba(255,255,255,0.16); border-radius: 2px;
  outline: none; cursor: pointer;
}
.sw-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px; border-radius: 50%;
  background: rgba(255,255,255,0.68); cursor: pointer;
}
.sw-slider::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: rgba(255,255,255,0.68); cursor: pointer; border: none;
}

/* ── Hover tooltip ─────────────────────────────────────────────────────── */
#hover-tip {
  position: fixed;
  display: none;
  pointer-events: none;
  z-index: 490;
  max-width: 280px;
  min-width: 180px;
}

#hover-tip-arrow {
  position: absolute;
  top: 12px; width: 0; height: 0;
}
#hover-tip-arrow.arrow-left  { left: -7px; border-top: 7px solid transparent; border-bottom: 7px solid transparent; border-right: 7px solid rgba(18,18,32,0.98); }
#hover-tip-arrow.arrow-right { right: -7px; border-top: 7px solid transparent; border-bottom: 7px solid transparent; border-left: 7px solid rgba(18,18,32,0.98); }

#hover-tip-inner {
  background: rgba(18,18,32,0.98);
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 7px;
  padding: 10px 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.70);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ht-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  color: rgba(255,255,255,0.90);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ht-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.ht-tag {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 8px;
  border: 1px solid transparent;
  color: rgba(255,255,255,0.95);
  letter-spacing: 0.01em;
  /* background and border-color set via inline style from palette */
}
.ht-tag.active-family {
  /* box-shadow wraps right against the element unlike outline */
  box-shadow: 0 0 0 2px rgba(255,255,255,0.70);
}

@keyframes ht-pulse {
  0%, 100% { opacity: 0.35; }
  50%       { opacity: 0.80; }
}
.ht-loading {
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  animation: ht-pulse 1.2s ease-in-out infinite;
}

.ht-meta {
  font-size: 11px;
  color: rgba(255,255,255,0.38);
  line-height: 1.5;
}

.ht-desc {
  font-size: 11px;
  line-height: 1.55;
  color: rgba(255,255,255,0.50);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Progress ──────────────────────────────────────────────────────────── */
#progress-wrap {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 3px; background: rgba(255,255,255,0.06); z-index: 9999;
}
#progress-bar {
  height: 100%; width: 0%;
  background: #4e79a7; transition: width 0.15s ease;
}
#progress-label {
  position: fixed; bottom: 7px; left: 12px;
  font-size: 11px; color: rgba(255,255,255,0.32);
  z-index: 9999; pointer-events: none;
}

/* ── Chart panel ───────────────────────────────────────────────────────── */
#chart-panel {
  position: fixed;
  bottom: 12px; left: 12px;
  width: 290px;
  background: rgba(15, 15, 28, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 8px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.40);
  display: none;
  flex-direction: column;
  z-index: 1000;
  overflow: hidden;
}
#chart-panel.open { display: flex; }

#chart-panel-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 7px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

#chart-panel-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.50);
}

#chart-panel-body {
  flex: 1;
  padding: 10px 12px;
  overflow: hidden;
}

/* ── Story content blocks ──────────────────────────────────────────────── */
.story-heading {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
  color: rgba(255,255,255,0.90);
  margin-bottom: 10px;
}

.story-body {
  font-size: 13px;
  line-height: 1.65;
  color: rgba(255,255,255,0.60);
  margin-bottom: 8px;
}

.story-caption {
  font-size: 11px;
  line-height: 1.6;
  color: rgba(255,255,255,0.38);
  margin-bottom: 8px;
}

.story-description {
  font-size: 12px;
  line-height: 1.6;
  color: rgba(255,255,255,0.48);
  font-style: italic;
  padding: 8px 10px;
  border-left: 2px solid rgba(78,121,167,0.45);
  margin-bottom: 8px;
}

.story-chart-inline {
  margin: 10px 0 6px;
}

/* ── About modal ───────────────────────────────────────────────────────── */
#about-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 5000;
  align-items: center;
  justify-content: center;
}
#about-overlay.open { display: flex; }

#about-modal {
  position: relative;
  background: rgb(22,22,36);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 28px 32px;
  max-width: 420px;
  width: 90%;
}

#about-modal h2 {
  font-size: 16px; font-weight: 600;
  color: rgba(255,255,255,0.90);
  margin-bottom: 12px;
}

#about-modal p {
  font-size: 13px; line-height: 1.65;
  color: rgba(255,255,255,0.60);
  margin-bottom: 10px;
}

#about-modal a { color: #4e79a7; text-decoration: none; }
#about-modal a:hover { text-decoration: underline; }

#about-close {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 13px;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 50%;
  color: rgba(255,255,255,0.55);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
#about-close:hover { background: rgba(255,255,255,0.14); color: rgba(255,255,255,0.90); }
