:root {
  --bg: oklch(0.14 0.015 255);
  --bg-2: oklch(0.18 0.018 255);
  --panel: rgba(18, 24, 34, 0.9);
  --panel-2: rgba(255, 255, 255, 0.04);
  --panel-3: rgba(255, 255, 255, 0.06);
  --text: oklch(0.97 0.01 255);
  --muted: oklch(0.72 0.02 255);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --accent: oklch(0.72 0.12 257);
  --accent-soft: rgba(138, 164, 255, 0.12);
  --good: oklch(0.84 0.11 154);
  --good-soft: rgba(124, 224, 160, 0.12);
  --radius: 22px;
  --radius-sm: 16px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background:
    radial-gradient(circle at top, rgba(138, 164, 255, 0.08), transparent 28%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--text);
}

a {
  color: #c9d5ff;
  text-decoration: none;
}

a:hover { text-decoration: underline; }
button, input { font: inherit; }
h1, h2, h3, h4, p { margin-top: 0; }
p { margin-bottom: 0; }
video, img { display: block; max-width: 100%; }
summary { list-style: none; }
summary::-webkit-details-marker { display: none; }

.app-shell {
  width: min(1320px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.topbar,
.sidebar,
.viewer,
.panel-section,
.item-button,
.card-surface,
.search-wrap,
.filter-chip,
.mini-stat,
.info-card,
.section-card,
.source-item,
.media-card,
.empty-list {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.topbar {
  padding: 20px 22px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.topbar h1,
.sidebar h2,
.detail h2 { margin-bottom: 0; }

.topbar-copy {
  margin-top: 10px;
  max-width: 64ch;
  color: var(--muted);
  line-height: 1.55;
}

.eyebrow,
.section-kicker,
.search-label {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
  margin: 0 0 6px;
}

.ghost-link,
.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.layout {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.sidebar,
.viewer {
  min-height: calc(100vh - 120px);
}

.sidebar {
  padding: 16px;
  position: sticky;
  top: 16px;
}

.viewer {
  padding: 16px;
  overflow: auto;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin-bottom: 14px;
}

.count-pill,
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
}

.library-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.mini-stat {
  padding: 12px;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.03));
}

.mini-stat strong {
  display: block;
  font-size: 20px;
  line-height: 1;
  margin-bottom: 6px;
}

.mini-stat span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.search-wrap {
  display: block;
  padding: 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

.search-wrap input {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,0.03);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}

.search-wrap input:focus {
  border-color: rgba(138, 164, 255, 0.42);
  box-shadow: 0 0 0 3px rgba(138, 164, 255, 0.12);
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.filter-chip {
  border-radius: 999px;
  min-height: 36px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--muted);
  background: rgba(255,255,255,0.04);
}

.filter-chip strong { color: var(--text); font-size: 12px; }
.filter-chip.active {
  border-color: rgba(138, 164, 255, 0.32);
  background: linear-gradient(180deg, rgba(138, 164, 255, 0.14), rgba(255, 255, 255, 0.04));
  color: var(--text);
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-button {
  width: 100%;
  text-align: left;
  padding: 14px;
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.item-button:hover {
  transform: translateY(-1px);
  border-color: rgba(138, 164, 255, 0.32);
}

.item-button.active {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(138, 164, 255, 0.12), rgba(255, 255, 255, 0.03));
  box-shadow: 0 0 0 1px rgba(138, 164, 255, 0.24) inset, var(--shadow);
}

.card-topline,
.meta-row,
.card-footer,
.card-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.card-topline { margin-bottom: 10px; }
.item-button strong {
  display: block;
  font-size: 15px;
  line-height: 1.35;
  margin-bottom: 8px;
}
.item-button p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: 12px;
}
.card-metrics {
  color: var(--text);
  font-size: 12px;
  margin-bottom: 10px;
}
.card-footer {
  color: var(--muted);
  font-size: 12px;
}

.chip-default { background: rgba(255, 255, 255, 0.05); }
.chip-accent { background: var(--accent-soft); color: #d9e2ff; border-color: rgba(138, 164, 255, 0.2); }
.chip-good { background: var(--good-soft); color: #dff8e7; border-color: rgba(124, 224, 160, 0.2); }
.chip-soft { background: rgba(255, 255, 255, 0.03); }

.empty-state {
  min-height: 260px;
  display: grid;
  align-content: center;
  gap: 10px;
  color: var(--muted);
  padding: 8px;
}

.empty-list {
  padding: 18px;
  color: var(--muted);
  border-radius: var(--radius-sm);
}

.detail {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.detail-hero {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 18px;
}

.detail-hero-copy {
  min-width: 0;
}

.meta-row { margin-bottom: 10px; }
.excerpt {
  color: var(--muted);
  line-height: 1.65;
  margin-top: 12px;
  max-width: 72ch;
}

.overview-grid,
.section-grid,
.source-grid,
.media-grid {
  display: grid;
  gap: 10px;
}

.overview-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.info-card,
.section-card,
.source-item,
.media-card {
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.025));
}

.info-card,
.section-card,
.source-item,
.media-card {
  padding: 14px;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.metric-helper {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.panel-section {
  padding: 14px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-summary {
  cursor: pointer;
  margin: -2px -2px 0;
  padding: 2px;
}

.summary-hint {
  color: var(--muted);
  font-size: 12px;
}

.panel-head h3 {
  margin-bottom: 0;
  font-size: 16px;
}

.summary-text {
  color: var(--text);
  line-height: 1.65;
  font-size: 15px;
}

.section-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.analysis-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.analysis-card h4 {
  color: #dce5ff;
}

.section-card h4 {
  margin-bottom: 10px;
  font-size: 14px;
}

.source-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 12px;
}

.source-item dt {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.source-item dd {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.media-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.media-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.media-frame {
  overflow: hidden;
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
  aspect-ratio: 4 / 3;
}

.media-frame img,
.media-frame video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-caption {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.media-caption strong {
  font-size: 14px;
}

.media-caption span {
  color: var(--muted);
  font-size: 12px;
}

.rich-block {
  color: var(--text);
  line-height: 1.72;
}

.prose-block {
  font-size: 14px;
}

.rich-block h1,
.rich-block h2,
.rich-block h3 {
  margin: 1em 0 0.6em;
  font-size: 1rem;
}

.rich-block p + p,
.rich-block ul + p,
.rich-block p + ul,
.rich-block h2 + p,
.rich-block h3 + p {
  margin-top: 0.78rem;
}

.rich-block ul {
  margin: 0;
  padding-left: 18px;
}

.rich-block li + li {
  margin-top: 0.45rem;
}

.rich-block code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: rgba(255, 255, 255, 0.06);
  padding: 0.12rem 0.35rem;
  border-radius: 6px;
}

.empty-copy {
  color: var(--muted);
}

.hidden { display: none !important; }

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .viewer {
    min-height: auto;
  }

  .sidebar {
    position: static;
  }
}

@media (max-width: 760px) {
  .app-shell { padding: 12px; }

  .topbar,
  .sidebar,
  .viewer,
  .panel-section,
  .item-button,
  .card-surface,
  .search-wrap,
  .mini-stat,
  .filter-chip,
  .info-card,
  .section-card,
  .source-item,
  .media-card,
  .empty-list {
    border-radius: 18px;
  }

  .topbar,
  .detail-hero {
    flex-direction: column;
    align-items: stretch;
  }

  .overview-grid,
  .section-grid,
  .source-grid,
  .media-grid,
  .library-stats {
    grid-template-columns: 1fr;
  }

  .viewer,
  .sidebar,
  .panel-section,
  .info-card,
  .section-card,
  .source-item,
  .item-button,
  .search-wrap,
  .media-card,
  .detail-hero {
    padding-left: 12px;
    padding-right: 12px;
  }
}
