/* TCM Herbs — editorial NYT-Pudding-style explorer */

@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@300;400;500;700&family=Crimson+Pro:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=Inter:wght@400;500;600&display=swap');

:root {
  --bg: #fffef9;
  --paper: #fbf7ee;
  --ink: #111111;
  --ink-soft: #2a2520;
  --muted: #6b655c;
  --rule: #d8d2c4;
  --accent: #c44536;       /* cinnabar */
  --accent-soft: #e09a8e;
  --gold: #d4a017;
  --jade: #6b7c4a;
  --indigo: #2a3a52;
  --serif: 'Crimson Pro', 'Noto Serif SC', Georgia, serif;
  --sans: 'Inter', -apple-system, sans-serif;
  --cn: 'Noto Serif SC', 'Crimson Pro', serif;
}

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

html, body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

/* ─── Editorial intro ─── */
.intro {
  max-width: 760px;
  margin: 0 auto;
  padding: 96px 32px 64px;
  text-align: center;
}
.intro .kicker {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 28px;
}
.intro .kicker::before, .intro .kicker::after {
  content: '';
  display: inline-block;
  width: 28px;
  height: 1px;
  background: var(--rule);
  vertical-align: middle;
  margin: 0 14px;
}
.intro h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(44px, 6vw, 78px);
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin-bottom: 0;
  padding-bottom: 0;
}
.intro h1 .cn {
  display: block;
  font-family: var(--cn);
  font-weight: 400;
  font-size: 0.45em;
  color: var(--accent);
  letter-spacing: 0.18em;
  margin-bottom: 16px;
  opacity: 0.85;
}
.intro h1 em {
  font-style: italic;
  font-weight: 400;
  color: var(--accent);
}
.intro .deck {
  font-size: 22px;
  line-height: 1.45;
  color: var(--ink-soft);
  margin: 8px auto 28px;
  max-width: 620px;
  font-weight: 300;
  text-wrap: pretty;
}
.intro .byline {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.intro .byline strong { color: var(--ink); font-weight: 500; }

.intro-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 24px auto 0;
  color: var(--muted);
}
.intro-divider .line { flex: 1; max-width: 80px; height: 1px; background: var(--rule); }
.intro-divider .ornament { font-family: var(--cn); font-size: 14px; }

.intro-lede {
  max-width: 620px;
  margin: 12px auto 0;
  padding: 0 32px;
  font-size: 19px;
  line-height: 1.65;
  color: var(--ink-soft);
  text-wrap: pretty;
}
.intro-lede p + p { margin-top: 18px; text-indent: 1.5em; }
.intro-lede .dropcap::first-letter {
  font-family: var(--serif);
  font-size: 77px;
  font-weight: 500;
  float: left;
  line-height: 1;
  padding: 0 8px 0 0;
  margin-top: -9px;
  color: var(--accent);
}

/* ─── Controls ─── */
.controls-wrap {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 254, 249, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
  padding: 16px 24px;
  margin-top: 80px;
}
.controls {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}
.controls-label {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}
.classify-group {
  display: flex;
  gap: 2px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 3px;
  flex-wrap: wrap;
}
.classify-btn {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 7px 14px;
  border-radius: 2px;
  color: var(--muted);
  transition: color 160ms, background 160ms;
  white-space: nowrap;
}
.classify-btn:hover { color: var(--ink); }
.classify-btn.active {
  background: var(--ink);
  color: var(--bg);
}
.search {
  margin-left: auto;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--rule);
  padding: 4px 0;
  min-width: 180px;
}
.search input {
  font-family: var(--sans);
  font-size: 13px;
  border: none;
  outline: none;
  background: transparent;
  padding: 4px 8px;
  color: var(--ink);
  flex: 1;
}
.search input::placeholder { color: var(--muted); }
.search-icon { color: var(--muted); width: 14px; height: 14px; }

.story-btn, .compare-btn {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.06em;
  padding: 8px 14px;
  border: 1px solid var(--ink);
  color: var(--ink);
  border-radius: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 160ms, color 160ms;
}
.story-btn:hover, .compare-btn:hover, .story-btn.active, .compare-btn.active {
  background: var(--ink);
  color: var(--bg);
}

/* ─── Chart area ─── */
.chart-wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 40px 24px 20px;
  position: relative;
}

.chart-title {
  text-align: center;
  margin-bottom: 8px;
}
.chart-title h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 32px;
  letter-spacing: -0.01em;
}
.chart-title .cn {
  font-family: var(--cn);
  color: var(--accent);
  font-size: 18px;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
  display: block;
}
.chart-title .sub {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
  letter-spacing: 0.04em;
}

.chart {
  position: relative;
  min-height: 720px;
  margin-top: 32px;
}

.cluster {
  position: absolute;
  transition: opacity 320ms ease 200ms;
}
.cluster-label {
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 10px;
  white-space: nowrap;
}
.cluster-label-btn {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 0;
  cursor: pointer;
  border-bottom: 1px dashed transparent;
  transition: color 160ms, border-color 160ms;
}
.cluster-label-btn:hover { color: var(--ink); border-bottom-color: var(--ink); }
.cluster-label-btn:hover .cluster-arrow { transform: translateX(3px); color: var(--accent); }
.cluster-arrow { font-family: var(--serif); font-size: 12px; color: var(--muted); transition: transform 200ms, color 200ms; letter-spacing: 0; }
.cluster-label .cn {
  font-family: var(--cn);
  color: var(--accent);
  margin-right: 8px;
  letter-spacing: 0.1em;
  font-weight: 400;
}
.cluster-rule {
  height: 1px;
  background: var(--rule);
  margin-bottom: 12px;
}
.cluster-meta {
  font-family: var(--sans);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

/* ─── Herb tile ─── */
.herb {
  position: absolute;
  width: 56px;
  height: 76px;
  cursor: pointer;
  transition: transform 700ms cubic-bezier(0.7, 0, 0.2, 1),
              opacity 320ms ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  user-select: none;
  will-change: transform;
}
.herb.dimmed { opacity: 0.18; }
.herb.selected .herb-illus { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.herb-illus {
  width: 52px;
  height: 52px;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 200ms, border-color 200ms, background 200ms, color 200ms, box-shadow 200ms;
}
.herb:hover .herb-illus {
  transform: scale(1.15);
  border-color: var(--ink);
  box-shadow: 0 8px 24px -8px rgba(0,0,0,0.18);
  z-index: 5;
}
.herb-label {
  font-family: var(--cn);
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 5px;
  white-space: nowrap;
  letter-spacing: 0.02em;
  font-weight: 400;
}

/* rarity-aware sizing — rarer herbs render slightly larger */
.herb[data-rarity="3"] .herb-illus { border-color: #b8b0a0; }
.herb[data-rarity="4"] .herb-illus { border-color: var(--gold); border-width: 1.5px; }
.herb[data-rarity="5"] .herb-illus { border-color: var(--accent); border-width: 1.5px; box-shadow: inset 0 0 0 2px var(--bg); }

/* ─── Hover detail card ─── */
.detail-card {
  position: fixed;
  background: var(--bg);
  border: 1px solid var(--ink);
  width: 340px;
  padding: 24px;
  font-family: var(--serif);
  pointer-events: none;
  z-index: 100;
  box-shadow: 0 24px 60px -20px rgba(0,0,0,0.25), 0 4px 12px rgba(0,0,0,0.06);
  transition: opacity 160ms;
}
.detail-card .zh {
  font-family: var(--cn);
  font-size: 36px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
.detail-card .pinyin {
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  color: var(--accent);
  margin-bottom: 4px;
}
.detail-card .latin {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 2px;
}
.detail-card .en {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 16px;
}
.detail-card .uses {
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-soft);
  border-top: 1px solid var(--rule);
  padding-top: 14px;
  margin-bottom: 14px;
  text-wrap: pretty;
}
.detail-card .props {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-family: var(--sans);
  font-size: 11px;
  border-top: 1px solid var(--rule);
  padding-top: 12px;
  align-items: baseline;
}
.detail-card .props dt, .detail-card .props dd { margin: 0; line-height: 1.4; }
.detail-card .props dt {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 500;
}
.detail-card .props dd { color: var(--ink); }
.detail-card.pinned {
  box-shadow: 0 18px 60px rgba(20, 18, 14, 0.28);
  outline: 1.5px solid var(--accent);
  outline-offset: -1px;
}
.detail-close {
  position: absolute;
  top: 8px; right: 10px;
  width: 22px; height: 22px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.detail-close:hover { color: var(--accent); }

.rarity-pip {
  display: inline-flex;
  gap: 2px;
  vertical-align: middle;
}
.rarity-pip span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--rule);
}
.rarity-pip span.on { background: var(--accent); }

/* ─── Cluster detail panel ─── */
.cluster-panel-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 18, 14, 0.42);
  z-index: 90;
  display: flex; align-items: center; justify-content: center;
  padding: 32px;
  animation: fade-in 200ms ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.cluster-panel {
  background: var(--bg);
  width: min(880px, 100%);
  max-height: calc(100vh - 64px);
  overflow: hidden;
  border: 1px solid var(--ink);
  display: flex; flex-direction: column;
  position: relative;
  box-shadow: 0 32px 80px -20px rgba(0,0,0,0.4);
  animation: slide-up 280ms cubic-bezier(0.7,0,0.2,1);
}
@keyframes slide-up { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.cluster-panel-close {
  position: absolute; top: 14px; right: 14px;
  width: 32px; height: 32px;
  font-size: 22px; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  z-index: 2;
}
.cluster-panel-close:hover { color: var(--ink); }
.cluster-panel-head {
  padding: 28px 36px 20px;
  border-bottom: 1px solid var(--rule);
}
.cluster-panel-head .kicker {
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.cluster-panel-head h3 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 32px;
  letter-spacing: -0.01em;
  display: flex;
  align-items: baseline;
  gap: 14px;
}
.cluster-panel-head h3 .cn {
  font-family: var(--cn);
  font-size: 22px;
  color: var(--accent);
  letter-spacing: 0.08em;
}
.cluster-panel-meta {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}
.cluster-panel-list {
  overflow-y: auto;
  flex: 1;
  padding: 0 36px 28px;
}
.cluster-panel-row {
  display: grid;
  grid-template-columns: 56px 200px 1fr 200px;
  gap: 18px;
  padding: 18px 0;
  border-bottom: 1px solid var(--rule);
  align-items: center;
  cursor: pointer;
  transition: background 160ms;
}
.cluster-panel-row:hover { background: var(--paper); }
.cluster-panel-row:last-child { border-bottom: none; }
.cluster-panel-illus {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--rule);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-soft);
}
.cluster-panel-name .zh {
  font-family: var(--cn);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: 0.05em;
}
.cluster-panel-name .zh .py {
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  color: var(--accent);
  margin-left: 8px;
  letter-spacing: 0;
  font-weight: 400;
}
.cluster-panel-name .en {
  font-family: var(--sans);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.cluster-panel-name .en em { font-family: var(--serif); font-style: italic; }
.cluster-panel-uses {
  font-family: var(--serif);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-soft);
  text-wrap: pretty;
}
.cluster-panel-stats {
  font-family: var(--sans);
  font-size: 10px;
  display: grid;
  gap: 4px;
  color: var(--ink);
}
.cluster-panel-stats > div {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 8px;
  align-items: baseline;
}
.cluster-panel-stats span:first-child {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
@media (max-width: 720px) {
  .cluster-panel-row { grid-template-columns: 48px 1fr; grid-template-areas: 'illus name' 'uses uses' 'stats stats'; }
  .cluster-panel-illus { grid-area: illus; }
  .cluster-panel-name { grid-area: name; }
  .cluster-panel-uses { grid-area: uses; }
  .cluster-panel-stats { grid-area: stats; }
  .cluster-panel-head { padding: 20px 22px 16px; }
  .cluster-panel-list { padding: 0 22px 20px; }
}

/* ─── Map section ─── */
.map-section {
  max-width: 1100px;
  margin: 20px auto 20px;
  padding: 0 24px;
}
.map-section h3 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 32px;
  text-align: center;
  margin-bottom: 6px;
}
.map-section h3 .cn {
  display: block;
  font-family: var(--cn);
  color: var(--accent);
  font-size: 18px;
  letter-spacing: 0.1em;
  margin-bottom: 6px;
}
.map-section .sub {
  text-align: center;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 32px;
}
.map-svg {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  display: block;
}
.map-region {
  fill: var(--paper);
  stroke: var(--rule);
  stroke-width: 0.8;
  transition: fill 200ms;
  cursor: pointer;
}
.map-region:hover, .map-region.active { fill: var(--accent-soft); }
.map-region.has-herbs { fill: #f0e8d8; }
.map-region.has-herbs:hover, .map-region.has-herbs.active { fill: var(--accent-soft); }
.map-label {
  font-family: var(--sans);
  font-size: 8px;
  fill: var(--muted);
  pointer-events: none;
  letter-spacing: 0.04em;
}
.map-label-cn {
  font-family: var(--cn);
  font-size: 11px;
  fill: var(--ink-soft);
  pointer-events: none;
  letter-spacing: 0.06em;
  font-weight: 500;
}
.map-pip {
  fill: var(--accent);
  pointer-events: none;
}

/* ─── Comparison tray ─── */
.compare-tray {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg);
  border-top: 1px solid var(--ink);
  padding: 24px;
  z-index: 80;
  box-shadow: 0 -12px 40px -12px rgba(0,0,0,0.15);
  transform: translateY(100%);
  transition: transform 360ms cubic-bezier(0.7,0,0.2,1);
}
.compare-tray.open { transform: translateY(0); }
.compare-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 32px;
}
.compare-title {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  padding-top: 8px;
}
.compare-title strong { display: block; font-family: var(--serif); font-size: 18px; color: var(--ink); letter-spacing: 0; text-transform: none; margin-top: 2px; font-weight: 500; }
.compare-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}
.compare-card {
  border: 1px solid var(--rule);
  padding: 16px;
  position: relative;
  min-height: 140px;
}
.compare-card.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 12px;
  border-style: dashed;
}
.compare-card .x {
  position: absolute;
  top: 6px; right: 8px;
  font-size: 14px; color: var(--muted);
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
}
.compare-card .x:hover { color: var(--ink); }
.compare-card .zh { font-family: var(--cn); font-size: 22px; font-weight: 500; }
.compare-card .pinyin { font-family: var(--serif); font-style: italic; font-size: 13px; color: var(--accent); margin-bottom: 8px; }
.compare-card dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-family: var(--sans); font-size: 10px; }
.compare-card dt { color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.compare-card dd { color: var(--ink); }
.compare-close {
  align-self: flex-start;
  font-size: 18px;
  color: var(--muted);
  padding: 4px 10px;
}

/* ─── Story mode ─── */
.story-overlay {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 14px 22px;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 70;
  font-family: var(--sans);
  font-size: 12px;
  border-radius: 2px;
  box-shadow: 0 16px 40px -16px rgba(0,0,0,0.4);
}
.story-overlay .step {
  letter-spacing: 0.06em;
}
.story-overlay .step strong {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 14px;
  margin-right: 8px;
}
.story-overlay button {
  color: var(--bg);
  font-size: 16px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.story-overlay button:hover { background: rgba(255,255,255,0.12); }
.story-progress {
  width: 80px;
  height: 2px;
  background: rgba(255,255,255,0.2);
  position: relative;
  overflow: hidden;
}
.story-progress span {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--bg);
  transition: width 5000ms linear;
}

/* footer */
.footer {
  max-width: 760px;
  margin: 20px auto 0;
  padding: 20px 24px 40px;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-align: center;
}
.footer .cn { font-family: var(--cn); display: block; margin-bottom: 6px; color: var(--accent); letter-spacing: 0.2em; }

/* ─── Scroll reveal ─── */
.reveal {
  opacity: 0;
  transform: translateY(28px);
  transition: opacity 0.9s cubic-bezier(0.2, 0.7, 0.2, 1), transform 0.9s cubic-bezier(0.2, 0.7, 0.2, 1);
  will-change: opacity, transform;
}
.reveal.in {
  opacity: 1;
  transform: translateY(0);
}
@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; transition: none; }
}

/* responsive */
@media (max-width: 760px) {
  .intro { padding: 56px 20px 40px; }
  .controls { gap: 12px; }
  .search { margin-left: 0; width: 100%; }
  .compare-inner { grid-template-columns: 1fr; }
  .compare-cards { grid-template-columns: 1fr; }
}
