:root {
  /* Warm editorial palette — no tech-gradient, no indigo default */
  --paper: #F7F3EA;
  --paper-raised: #FFFFFF;
  --ink: #211D16;
  --ink-soft: #57503F;
  --muted: #8A8272;
  --border: #E3DBC7;
  --accent: #1F6F5C;       /* deep teal — "supports" */
  --accent-soft: #E4EEE9;
  --warn: #B5502E;         /* terracotta — "limit / risk" */
  --warn-soft: #F3E4DC;
  --gold: #C79A3E;         /* sparing highlight */
  --marker: #B5502E;
  --marker-active: #1F6F5C;

  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Public Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 100vh;
  transition: grid-template-columns 0.28s ease;
  position: relative;
}

.app.collapsed {
  grid-template-columns: 0px 1fr;
}

/* ---------- Left rail ---------- */

.rail {
  background: var(--paper-raised);
  border-right: 1px solid var(--border);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  overflow: hidden;
  white-space: nowrap;
  transition: padding 0.28s ease, opacity 0.2s ease;
}

.app.collapsed .rail {
  padding: 28px 0;
  opacity: 0;
  pointer-events: none;
}

.rail-toggle {
  position: fixed;
  top: 24px;
  left: 284px;
  z-index: 20;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--paper-raised);
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(33,29,22,0.08);
  transition: left 0.28s ease, transform 0.28s ease, color 0.15s;
}

.rail-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.app.collapsed .rail-toggle {
  left: 16px;
  transform: rotate(180deg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.1rem;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--paper-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }

.brand-name {
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
}

.brand-tag {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.organ-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.organ-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  background: none;
  text-align: left;
  font-family: var(--serif);
  font-size: 1.02rem;
  color: var(--ink-soft);
  transition: background 0.15s, color 0.15s;
}

.organ-item .category {
  font-family: var(--sans);
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.organ-item:hover {
  background: var(--accent-soft);
  color: var(--ink);
}

.organ-item.active {
  background: var(--accent);
  color: var(--paper-raised);
}

.organ-item.active .category {
  color: rgba(255,255,255,0.75);
}

.rail-tip {
  margin-top: 8px;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px dashed var(--border);
  border-radius: 10px;
  font-size: 0.8rem;
  color: var(--ink-soft);
  line-height: 1.5;
  white-space: normal;
}

.rail-tip strong {
  display: block;
  font-family: var(--serif);
  font-size: 0.88rem;
  color: var(--ink);
  margin-bottom: 4px;
}

.rail-footer {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: auto;
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.5;
  white-space: normal;
}

.rail-footer p { margin: 0 0 6px; }
.disclaimer-note { font-weight: 600; color: var(--ink-soft); }

.rail-footer .back-link {
  display: inline-block;
  margin-bottom: 8px;
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.rail-footer .back-link:hover {
  text-decoration: underline;
}

/* ---------- Stage ---------- */

.stage {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 0;
}

.figure-pane {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: radial-gradient(ellipse at 50% 35%, rgba(199,154,62,0.06), transparent 65%);
}

#body-svg {
  width: 100%;
  max-width: 320px;
  height: auto;
}

.silhouette {
  transition: fill 0.3s;
}

.leaders line {
  opacity: 0.55;
}

.organ-marker {
  fill: var(--marker);
  stroke: var(--paper-raised);
  stroke-width: 2;
  cursor: pointer;
  transition: fill 0.2s, r 0.2s;
}

.organ-marker:hover {
  r: 9;
}

.organ-marker.active {
  fill: var(--marker-active);
  r: 9;
}

.chip {
  cursor: pointer;
}

.chip text {
  fill: var(--ink-soft);
}

.chip:hover text,
.chip.active text {
  fill: var(--marker-active);
}

.figure-hint {
  margin-top: 14px;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

/* ---------- Detail pane ---------- */

.detail-pane {
  padding: 56px 64px;
  overflow-y: auto;
  height: 100vh;
}

.empty-state {
  font-family: var(--serif);
  font-size: 1.3rem;
  color: var(--muted);
  padding-top: 20vh;
  text-align: center;
}

.detail {
  max-width: 620px;
  animation: rise 0.3s ease;
}

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

.detail .eyebrow {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 6px;
  display: block;
}

.title-row {
  display: flex;
  align-items: baseline;
  gap: 18px;
  flex-wrap: wrap;
}

.detail h1 {
  font-family: var(--serif);
  font-size: 2.6rem;
  font-weight: 500;
  margin: 0 0 18px;
  line-height: 1.05;
}

.organ-figure-pinned {
  display: none;
  flex-direction: column;
  align-items: center;
  margin-top: 20px;
  padding: 16px;
  background: linear-gradient(180deg, #F1EADA, #EAE1CB);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 280px;
}

.organ-figure-pinned.visible {
  display: flex;
}

.organ-figure-pinned img {
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
}

.organ-figure-pinned img[src*="heart"] {
  filter: sepia(0.7) saturate(3) hue-rotate(-40deg) brightness(0.92) contrast(1.05);
}

.organ-figure-pinned-caption {
  margin-top: 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.organ-figure-pinned-caption .name {
  font-family: var(--serif);
  font-size: 0.95rem;
  font-weight: 600;
}

.organ-figure-pinned-caption .credit {
  font-size: 0.68rem;
  color: var(--muted);
}

.detail .lede {
  font-size: 1.05rem;
  line-height: 1.65;
  color: var(--ink-soft);
  margin: 0 0 40px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
}

.detail h2 {
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 16px;
}

.detail section { margin-bottom: 36px; }

/* ---------- Tabs ---------- */

.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
}

.tab-btn {
  font-family: var(--sans);
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  padding: 10px 4px;
  margin-right: 22px;
  cursor: pointer;
  position: relative;
  transition: color 0.15s;
}

.tab-btn::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: transparent;
  transition: background 0.15s;
}

.tab-btn:hover {
  color: var(--ink-soft);
}

.tab-btn.active {
  color: var(--accent);
}

.tab-btn.active::after {
  background: var(--accent);
}

.tab-panel {
  margin-bottom: 36px;
  min-height: 160px;
}

.tab-panel.rise {
  animation: rise 0.25s ease;
}

.sources-section h2 {
  font-size: 0.95rem;
}

@media (max-width: 980px) {
  .tab-bar { gap: 0; overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tab-btn { white-space: nowrap; margin-right: 18px; }
}

.food-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 24px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.food-grid li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.food-grid .name {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 2px;
}

.food-grid .why {
  display: block;
  font-size: 0.83rem;
  color: var(--muted);
  line-height: 1.4;
}

.food-grid.eat .name::before {
  content: "";
}

.food-grid.limit .name { color: var(--warn); }

.effects {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.effect-block {
  background: var(--warn-soft);
  border-radius: 10px;
  padding: 16px 18px;
}

.effect-block .term {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--warn);
  display: block;
  margin-bottom: 8px;
}

.effect-block p {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink);
}

.tips {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tips li {
  display: flex;
  gap: 12px;
  font-size: 0.92rem;
  line-height: 1.5;
  align-items: baseline;
}

.tips .num {
  font-family: var(--serif);
  color: var(--accent);
  font-weight: 600;
  flex-shrink: 0;
}

.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sources a {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-decoration: none;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.sources a:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- Meal Plan ---------- */

.meal-plan {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.meal-card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 8px 14px;
  align-items: start;
}

.meal-card .meal-icon {
  font-size: 1.3rem;
  grid-row: span 2;
}

.meal-card .meal-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}

.meal-card p {
  grid-column: 2;
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink);
}

.no-data {
  color: var(--muted);
  font-style: italic;
}

.detail-disclaimer {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
}

@media (max-width: 1180px) {
  .stage { grid-template-columns: 280px 1fr; }
  #body-svg { max-width: 230px; }
  .detail-pane { padding: 48px 36px; }
}

@media (max-width: 1024px) {
  .app { grid-template-columns: 1fr; }
  .app.collapsed { grid-template-columns: 1fr; }

  .rail {
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
    gap: 16px;
    padding: 12px 16px;
  }
  .app.collapsed .rail { display: flex; }
  .rail-toggle { display: none; }

  .brand { flex-shrink: 0; }
  .brand-mark { width: 32px; height: 32px; font-size: 0.9rem; }
  .brand-tag { display: none; }

  .organ-list {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    flex: 1;
    min-width: 0;
  }
  .organ-item {
    flex-shrink: 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    padding: 7px 12px;
    font-size: 0.85rem;
    border-radius: 16px;
    border: 1px solid var(--border);
  }
  .organ-item.active { border-color: var(--accent); }
  .organ-item .category { font-size: 0.6rem; }

  .rail-tip, .rail-footer { display: none; }

  .stage { grid-template-columns: 260px 1fr; }
  .figure-pane { height: calc(100vh - 62px); }
}

@media (max-width: 700px) {
  .stage { grid-template-columns: 1fr; }
  .figure-pane { position: relative; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .detail-pane { height: auto; padding: 32px 24px; }
  .detail h1 { font-size: 2rem; }
  .food-grid { grid-template-columns: 1fr; }
  .effects { grid-template-columns: 1fr; }
}
