:root {
  --paper: #f6f3ec;
  --paper-2: #efe8dc;
  --ink: #1f1b16;
  --ink-soft: #4a433a;
  --ink-mute: #6f675c;
  --line: #ddd4c6;
  --card: #fffcf7;
  --sidebar: #2b2722;
  --sidebar-ink: #f3eee6;
  --sidebar-mute: #b7aea2;
  --accent: #1f6f64;
  --accent-2: #c45c26;
  --good: #1f6f64;
  --mid: #9a6b24;
  --low: #9b3d2a;
  --font-sans: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 12px;
}

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

body {
  font-family: var(--font-sans);
  background: var(--paper);
  color: var(--ink);
  height: 100vh;
  overflow: hidden;
  line-height: 1.55;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-ink);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}

.brand { display: flex; gap: 10px; align-items: baseline; }
.brand h2 { font-family: var(--font-serif); font-weight: 600; font-size: 1.35rem; }
.version-tag { font-size: 0.72rem; color: #d9b99a; font-family: var(--font-mono); }

.search-box input {
  width: 100%;
  background: #3a342d;
  border: 1px solid #524a41;
  color: var(--sidebar-ink);
  padding: 10px 12px;
  border-radius: 8px;
  font: inherit;
}
.search-box input::placeholder { color: var(--sidebar-mute); }

.filter-label {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sidebar-mute);
  margin-bottom: 8px;
}
.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: transparent;
  border: 1px solid #5a5248;
  color: var(--sidebar-mute);
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.75rem;
}
.chip.active {
  background: #efe8dc;
  color: var(--ink);
  border-color: #efe8dc;
}

.emotion-nav { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--sidebar-ink);
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.nav-item:hover { background: #3a342d; }
.nav-item.active { background: #efe8dc; color: var(--ink); }
.nav-badge { font-size: 0.7rem; font-family: var(--font-mono); color: inherit; opacity: 0.7; }

.content-viewport {
  overflow: auto;
  padding: 28px 36px 48px;
  background:
    linear-gradient(180deg, rgba(255,252,247,0.4), transparent 120px),
    var(--paper);
}

.emotion-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}
.title-row { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.title-row h1 { font-family: var(--font-serif); font-size: 2.15rem; font-weight: 600; }
#active-summary { max-width: 46rem; color: var(--ink-soft); margin-top: 8px; }

.badge {
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink-soft);
}

.metrics-cluster { display: flex; flex-wrap: wrap; gap: 10px; }
.metric-card {
  background: var(--card);
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: var(--radius);
  min-width: 108px;
}
.metric-title { display: block; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-mute); }
.metric-value { font-family: var(--font-mono); font-weight: 600; font-size: 1.1rem; }
.metric-sub { font-weight: 600; color: var(--accent); font-size: 0.92rem; }
.metric-scale { height: 3px; background: var(--paper-2); margin-top: 6px; border-radius: 2px; overflow: hidden; }
.metric-scale .bar { height: 100%; background: var(--accent); width: 0; }

.view-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--ink-mute);
  font: inherit;
  font-weight: 600;
  padding: 10px 14px;
  cursor: pointer;
}
.tab.active { color: var(--ink); border-bottom-color: var(--accent-2); }
.tab-panel { display: none; padding-top: 18px; }
.tab-panel.active { display: block; }
.panel-lead { color: var(--ink-soft); margin-bottom: 16px; max-width: 52rem; }

/* Split layouts with visuals */
.system-split-grid, .facs-split-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  align-items: start;
}
.system-list, .facs-list { min-width: 0; }
.system-visuals, .facs-visuals, .action-visuals {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  position: sticky;
  top: 12px;
}
.visual-placeholder {
  color: var(--ink-mute);
  font-size: 0.9rem;
  text-align: center;
  padding: 40px 20px;
  border: 2px dashed var(--line);
  border-radius: 8px;
}

/* System cards */
.system-grid, .system-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.system-card { padding: 18px 18px 16px; margin-bottom: 14px; }
.card-head { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.card-head h3, .action-card h3 { font-family: var(--font-serif); font-size: 1.15rem; font-weight: 600; }

.manifest-list { list-style: none; display: flex; flex-direction: column; gap: 12px; }
.claim-row { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; cursor: pointer; }
.claim-row:hover { background: var(--paper-2); border-radius: 6px; }
.claim-row.active { background: #e7f3f1; border-radius: 6px; }
.claim-row span:first-child { color: var(--ink); }
.rel-pill {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
}
.rel-T1 { border-color: #b7d7d1; background: #e7f3f1; color: var(--good); }
.rel-T2 { border-color: #e4d3b0; background: #f7efdf; color: var(--mid); }
.rel-T3, .rel-T4 { border-color: #e8c4b8; background: #f8ebe6; color: var(--low); }
.shared, .note { font-size: 0.8rem; color: var(--ink-mute); margin-top: 4px; }
.note { color: #7a4a28; }

/* Visual blocks */
.visual-block { display: flex; flex-direction: column; gap: 10px; }
.visual-block img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  display: block;
}
.visual-caption { font-size: 0.82rem; color: var(--ink-mute); }
.prompt-fallback {
  background: #2b2722;
  color: #f3eee6;
  border-radius: 8px;
  padding: 14px;
  display: none;
}
.prompt-fallback.show { display: block; }
.prompt-label {
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #d9b99a;
  margin-bottom: 8px;
}
.prompt-text {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.55;
  white-space: pre-wrap;
}
.btn-copy {
  margin-top: 10px;
  background: #efe8dc;
  color: var(--ink);
  border: 0;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.78rem;
}

/* FACS */
.facs-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.facs-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px 16px; cursor: pointer; }
.facs-card:hover { border-color: var(--accent-2); }
.facs-card.active { border-color: var(--accent); background: #e7f3f1; }
.facs-badge-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.facs-code {
  font-family: var(--font-mono);
  font-weight: 700;
  background: var(--paper-2);
  padding: 4px 9px;
  border-radius: 6px;
}
.role-tag { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-mute); }
.facs-muscles { font-size: 0.88rem; color: var(--ink-soft); }
.facs-desc { color: var(--ink-soft); font-size: 0.95rem; margin-top: 6px; }

/* Actions */
.action-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.large-list li { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 1rem; cursor: pointer; }
.large-list li:hover { background: var(--paper-2); border-radius: 6px; }
.large-list li.active { background: #e7f3f1; border-radius: 6px; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--ink);
  color: var(--paper);
  padding: 10px 14px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.toast.show { opacity: 1; }

@media (max-width: 1100px) {
  .system-split-grid, .facs-split-grid { grid-template-columns: 1fr; }
  .system-visuals, .facs-visuals, .action-visuals { position: static; margin-top: 14px; }
}
@media (max-width: 960px) {
  body { height: auto; overflow: auto; }
  .app-shell { grid-template-columns: 1fr; }
}