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

:root {
  --bg: #050811;
  --glass-bg: rgba(12, 17, 30, 0.78);
  --glass-border: rgba(148, 163, 184, 0.18);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --gold: #fbbf24;
  --cyan: #38bdf8;
  --emerald: #34d399;
  --rose: #f87171;
  --purple: #a855f7;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

#canvas-wrap {
  position: fixed;
  inset: 0;
  z-index: 1;
  touch-action: none;
}

#cosmos-canvas {
  display: block;
  touch-action: none;
}

.zoom-controls {
  position: fixed;
  bottom: 16px;
  left: 260px;
  z-index: 16;
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
}

.zoom-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(15, 23, 42, 0.75);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}
.zoom-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--glass-border);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
}

.hidden {
  display: none !important;
}

/* Top Bar */
.top-bar {
  position: fixed;
  top: 14px;
  left: 16px;
  right: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  border-radius: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: 6px;
}

.brand-icon {
  font-size: 24px;
  color: var(--gold);
  text-shadow: 0 0 16px rgba(251, 191, 36, 0.7);
}

.brand h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  background: linear-gradient(90deg, #fef08a, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 11px;
  color: var(--muted);
}

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

.pill, .action-btn {
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(30, 41, 59, 0.55);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.pill:hover, .action-btn:hover {
  border-color: var(--cyan);
  background: rgba(56, 189, 248, 0.15);
}

.pill.active, .action-btn.active {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.28), rgba(251, 191, 36, 0.22));
  border-color: var(--gold);
  color: #fef08a;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 210px;
  max-width: 340px;
}

#search-input {
  width: 100%;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.75);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

#search-input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.25);
}

.search-results {
  position: absolute;
  top: 42px;
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  border-radius: 12px;
  padding: 6px;
}

.search-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.search-item:hover {
  background: rgba(56, 189, 248, 0.16);
}

.search-tag {
  font-size: 11px;
  color: var(--muted);
}

.mode-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

/* Tooltip */
.tooltip {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  background: rgba(9, 13, 24, 0.92);
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 12px;
  max-width: 250px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}

.tooltip strong {
  color: var(--gold);
  font-size: 13px;
}

/* Legend */
.legend {
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 15;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.dot.cold { background: #38bdf8; box-shadow: 0 0 8px #38bdf8; }
.dot.neutral { background: #34d399; box-shadow: 0 0 8px #34d399; }
.dot.hot { background: #f97316; box-shadow: 0 0 8px #f97316; }

.line {
  width: 14px;
  height: 2px;
  display: inline-block;
}
.line.add { background: var(--emerald); }
.line.sub { background: var(--rose); }
.line.morph { background: var(--gold); }
.line.combine { background: var(--cyan); }

.progress-row {
  color: var(--text);
  padding-top: 2px;
  border-top: 1px solid rgba(148, 163, 184, 0.14);
}
.progress-row strong {
  color: var(--gold);
}

/* Detail Drawer */
.drawer {
  position: fixed;
  top: 84px;
  right: 16px;
  bottom: 16px;
  width: 390px;
  max-width: calc(100vw - 32px);
  z-index: 20;
  border-radius: 16px;
  padding: 18px;
  overflow-y: auto;
}

.close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid var(--glass-border);
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
}
.close-btn:hover { color: var(--text); border-color: var(--gold); }

.drawer h2 {
  font-size: 20px;
  color: var(--gold);
  margin-bottom: 6px;
  padding-right: 28px;
}

.meta-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(56, 189, 248, 0.16);
  color: var(--cyan);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.section-title {
  font-size: 12px;
  color: var(--muted);
  margin: 12px 0 6px;
  letter-spacing: 0.5px;
}

.card-box {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.55;
}

.song-box {
  color: #fde68a;
  font-style: italic;
}

/* 2D Botanical Herb Grid in Drawer */
.herb-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.herb-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(15, 23, 42, 0.78);
  text-align: left;
  color: var(--text);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.herb-card:hover {
  transform: translateY(-2px);
  border-color: var(--gold);
}

.herb-card svg {
  flex-shrink: 0;
}

.herb-card-info strong {
  display: block;
  font-size: 13px;
}

.herb-card-info span {
  font-size: 11px;
  color: var(--muted);
}

.role-jun { border-left: 3px solid var(--gold); }
.role-chen { border-left: 3px solid var(--cyan); }
.role-zuo { border-left: 3px solid var(--purple); }

.herb-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
  padding: 10px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(251, 191, 36, 0.28);
}

.rel-link {
  display: inline-block;
  margin: 3px 4px 3px 0;
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 12px;
  background: rgba(52, 211, 153, 0.15);
  border: 1px solid rgba(52, 211, 153, 0.35);
  color: #a7f3d0;
  cursor: pointer;
}
.rel-link:hover { background: rgba(52, 211, 153, 0.28); }

.drawer-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

/* Floating Compare & Quiz HUD */
.floating-hud {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 390px;
  max-width: calc(100vw - 32px);
  z-index: 22;
  border-radius: 16px;
  padding: 16px;
}

.hud-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.hud-header h3 {
  font-size: 15px;
  color: var(--gold);
}

.compare-selectors {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.compare-selectors select {
  flex: 1;
  background: rgba(15, 23, 42, 0.9);
  color: var(--text);
  border: 1px solid var(--glass-border);
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 12px;
}

.vs {
  color: var(--gold);
  font-weight: 700;
  font-size: 12px;
}

.compare-summary {
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}

.quiz-stats {
  margin-left: auto;
  margin-right: 30px;
  font-size: 12px;
  color: var(--emerald);
}

.quiz-prompt {
  font-size: 13px;
  line-height: 1.55;
  background: rgba(15, 23, 42, 0.7);
  padding: 10px;
  border-radius: 10px;
  margin-bottom: 10px;
  border-left: 3px solid var(--cyan);
}

.quiz-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.quiz-slot {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  border: 1px dashed rgba(148, 163, 184, 0.4);
  color: var(--muted);
}

.quiz-slot.filled {
  border-style: solid;
  border-color: var(--emerald);
  background: rgba(52, 211, 153, 0.2);
  color: #ecfdf5;
}

.quiz-feedback {
  font-size: 12px;
  min-height: 18px;
  margin-bottom: 10px;
  color: var(--gold);
}

.quiz-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Multi-Herb Selection Bar */
.herbset-bar {
  position: fixed;
  top: 78px;
  left: 16px;
  z-index: 21;
  padding: 10px 14px;
  border-radius: 14px;
  max-width: calc(100vw - 425px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.herbset-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.herbset-label {
  font-size: 12px;
  color: var(--gold);
  font-weight: 600;
}

.herbset-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.selected-herb-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(251, 191, 36, 0.2);
  border: 1px solid var(--gold);
  color: #fef08a;
  cursor: pointer;
}

.selected-herb-chip:hover {
  background: rgba(248, 113, 113, 0.25);
  border-color: var(--rose);
}

.herbset-add-wrap {
  position: relative;
}

#herbset-input {
  width: 175px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(15, 23, 42, 0.85);
  color: var(--text);
  font-size: 12px;
  outline: none;
}

.herbset-presets {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.preset-btn {
  border: 1px solid rgba(56, 189, 248, 0.28);
  background: rgba(56, 189, 248, 0.1);
  color: #bae6fd;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  cursor: pointer;
}

.preset-btn:hover {
  border-color: var(--gold);
  color: #fef08a;
}

.herb-card-wrap {
  position: relative;
}

.herb-add-mini {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid rgba(251, 191, 36, 0.45);
  background: rgba(15, 23, 42, 0.9);
  color: var(--gold);
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
}
.herb-add-mini:hover {
  background: var(--gold);
  color: #000;
}

/* Mobile Responsive Layout (< 768px) */
@media (max-width: 768px) {
  .top-bar {
    top: 8px;
    left: 8px;
    right: 8px;
    padding: 8px 10px;
    gap: 8px;
    border-radius: 12px;
  }
  .brand { margin-right: 0; }
  .brand-icon { font-size: 18px; }
  .brand h1 { font-size: 14px; }
  .subtitle { display: none; }
  .mode-actions {
    gap: 4px;
  }
  .action-btn {
    padding: 5px 8px;
    font-size: 11px;
  }
  .search-wrap {
    order: 3;
    flex: 1 1 100%;
    max-width: none;
    min-width: 0;
  }
  #search-input {
    padding: 6px 12px;
    font-size: 13px;
  }
  .filter-pills {
    order: 4;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }
  .filter-pills .pill {
    flex-shrink: 0;
    padding: 4px 10px;
    font-size: 11px;
  }

  .legend {
    display: none;
  }

  .zoom-controls {
    left: 10px;
    bottom: 12px;
    flex-direction: column;
  }

  .herbset-bar {
    top: 128px;
    left: 8px;
    right: 8px;
    max-width: none;
    padding: 8px 10px;
  }
  .herbset-presets {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }
  .preset-btn { flex-shrink: 0; }

  .drawer {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-width: none;
    max-height: 46vh;
    padding: 14px;
    border-radius: 16px;
  }
  .herb-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .floating-hud {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-width: none;
    max-height: 44vh;
    overflow-y: auto;
    padding: 12px;
  }
}
