:root {
  --bg: #f5efe2;
  --paper: #fffaf0;
  --ink: #1f1a16;
  --muted: #6f655c;
  --line: #d7c7aa;
  --accent: #ab4e2f;
  --accent-strong: #7d3118;
  --accent-soft: #f2dfc7;
  --success: #2f6b4a;
  --pending: #8a6d24;
  --shadow: 0 18px 40px rgba(57, 34, 13, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(171, 78, 47, 0.12), transparent 30%),
    linear-gradient(180deg, #f2e8d8, #f8f4ea 28%, #f5efe2 100%);
}

a {
  color: inherit;
  text-decoration: none;
}

code,
pre,
input,
select,
textarea,
button {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.page-shell {
  max-width: 1480px;
  margin: 0 auto;
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 24px;
}

.brand {
  display: inline-block;
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.brand-copy {
  margin: 8px 0 0;
  max-width: 720px;
  color: var(--muted);
}

.source-link-block {
  display: grid;
  gap: 4px;
  margin-top: 10px;
}

.source-link-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.source-link {
  color: var(--accent-strong);
  word-break: break-all;
}

.topbar-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.ghost-link {
  color: var(--accent-strong);
}

.primary-button,
.secondary-button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  cursor: pointer;
  font-size: 0.95rem;
}

.primary-button {
  background: var(--accent);
  color: white;
}

.secondary-button {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.flash-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.flash {
  padding: 14px 16px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  background: var(--paper);
  border: 1px solid var(--line);
}

.flash-success {
  border-color: rgba(47, 107, 74, 0.35);
}

.flash-error {
  border-color: rgba(171, 78, 47, 0.35);
}

.panel,
.stat-card,
.story-row,
.source-chip,
.detail-hero {
  background: rgba(255, 250, 240, 0.94);
  border: 1px solid rgba(215, 199, 170, 0.85);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  padding: 20px;
}

.stat-label,
.eyebrow,
.subtle,
.item-id,
label span,
.chip-meta {
  color: var(--muted);
}

.stat-value {
  display: block;
  margin-top: 10px;
  font-size: 2rem;
}

.source-strip {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 18px 0;
}

.source-chip {
  display: block;
  padding: 14px 16px;
  min-width: 180px;
}

.source-chip-active {
  background: var(--accent-soft);
  border-color: rgba(171, 78, 47, 0.35);
}

.chip-name {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
}

.panel {
  padding: 20px;
  margin-bottom: 18px;
}

.catalog-shell {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.catalog-sidebar {
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 48px);
  overflow: auto;
}

.catalog-main {
  min-width: 0;
}

.tree-list {
  display: grid;
  gap: 8px;
}

.tree-group {
  border: 1px solid rgba(215, 199, 170, 0.7);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.65);
}

.tree-group-active {
  border-color: rgba(171, 78, 47, 0.28);
  background: rgba(242, 223, 199, 0.45);
}

.tree-group-link,
.tree-story-link {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  padding: 10px 12px;
}

.tree-group-link {
  font-weight: 700;
}

.tree-children {
  border-top: 1px solid rgba(215, 199, 170, 0.7);
  display: grid;
}

.tree-story-link {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  border-top: 1px solid rgba(215, 199, 170, 0.35);
}

.tree-children .tree-story-link:first-child {
  border-top: 0;
}

.tree-story-link small {
  color: var(--muted);
}

.tree-story-link-active {
  background: rgba(171, 78, 47, 0.12);
}

.tree-count {
  color: var(--muted);
  font-size: 0.9rem;
}

.filters {
  display: grid;
  grid-template-columns: 2fr 1fr auto;
  gap: 14px;
  align-items: end;
}

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

label {
  display: grid;
  gap: 8px;
}

input,
select,
textarea {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
  padding: 12px 14px;
  font-size: 0.95rem;
}

.table-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: baseline;
  margin-bottom: 18px;
}

.table-head h2,
.detail-copy h1 {
  margin: 0;
}

.story-list {
  display: grid;
  gap: 12px;
}

.story-row {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 18px;
}

.story-row h3 {
  margin: 6px 0 8px;
}

.story-badges {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge {
  border-radius: 999px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  font-size: 0.85rem;
  background: white;
}

.badge-ready {
  border-color: rgba(47, 107, 74, 0.35);
  color: var(--success);
}

.badge-approved {
  border-color: rgba(47, 107, 74, 0.35);
  background: rgba(47, 107, 74, 0.08);
  color: var(--success);
}

.pagination {
  margin-top: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.detail-hero {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 24px;
  margin-bottom: 18px;
}

.review-chip {
  min-width: 160px;
  border-radius: 18px;
  padding: 16px;
  border: 1px solid var(--line);
}

.review-chip.approved {
  background: rgba(47, 107, 74, 0.08);
}

.review-chip.pending {
  background: rgba(138, 109, 36, 0.08);
}

.review-chip strong {
  display: block;
  margin-top: 6px;
  font-size: 1.15rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 2.1fr) minmax(320px, 0.9fr);
  gap: 18px;
}

.version-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.version-tab {
  padding: 10px 14px;
  border-radius: 999px;
  background: white;
  border: 1px solid var(--line);
}

.version-tab.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: rgba(171, 78, 47, 0.35);
}

.reader-surface {
  background: linear-gradient(180deg, rgba(255,255,255,0.88), rgba(250,246,239,0.95));
  border-radius: 18px;
  padding: 20px;
  border: 1px solid rgba(215, 199, 170, 0.7);
}

.reader-surface p {
  margin: 0 0 18px;
  line-height: 1.7;
}

.reader-surface p:last-child {
  margin-bottom: 0;
}

.compare-head {
  margin-bottom: 12px;
}

.compare-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.toggle-chip {
  padding: 8px 12px;
  border-radius: 999px;
  background: white;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

.toggle-chip.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: rgba(171, 78, 47, 0.35);
}

.copy-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.copy-button {
  white-space: nowrap;
}

.copy-source {
  position: absolute;
  left: -99999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.compare-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.compare-column-label {
  font-weight: 700;
  color: var(--muted);
  padding: 0 4px;
}

.compare-list {
  display: grid;
  gap: 14px;
}

.compare-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.9), rgba(250,246,239,0.95));
  border-radius: 18px;
  padding: 16px;
  border: 1px solid rgba(215, 199, 170, 0.7);
}

.compare-row.compare-replace .compare-card,
.compare-row.compare-insert .compare-card,
.compare-row.compare-delete .compare-card {
  border-color: rgba(171, 78, 47, 0.25);
}

.compare-meta {
  margin-bottom: 10px;
}

.compare-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.82rem;
  border: 1px solid var(--line);
  background: white;
  color: var(--muted);
}

.compare-paragraph {
  margin: 0;
  line-height: 1.7;
  white-space: pre-wrap;
}

.diff-added {
  background: rgba(47, 107, 74, 0.16);
  color: #17402a;
  border-radius: 6px;
  padding: 0 2px;
}

.diff-removed {
  background: rgba(171, 78, 47, 0.16);
  color: #672715;
  border-radius: 6px;
  padding: 0 2px;
}

.json-block {
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: #211b17;
  color: #f4eadb;
  padding: 18px;
  border-radius: 16px;
}

.action-panel {
  display: grid;
  gap: 16px;
}

.stacked-form {
  display: grid;
  gap: 12px;
}

.approval-meta p {
  margin: 6px 0;
}

.empty-state {
  color: var(--muted);
  margin: 0;
}

@media (max-width: 980px) {
  .stats-grid,
  .filters,
  .catalog-shell,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .detail-hero,
  .story-row,
  .table-head,
  .pagination {
    flex-direction: column;
    align-items: stretch;
  }

  .story-badges {
    justify-content: flex-start;
  }

  .catalog-sidebar {
    position: static;
    max-height: none;
  }

  .compare-grid {
    grid-template-columns: 1fr;
  }
}
