:root {
  color-scheme: light;
  --paper: oklch(96.5% 0.028 83);
  --ink: oklch(20% 0.035 58);
  --muted: oklch(47% 0.035 66);
  --line: oklch(84% 0.035 72);
  --panel: oklch(98% 0.02 86);
  --panel-strong: oklch(93% 0.038 82);
  --blue: oklch(47% 0.16 245);
  --red: oklch(52% 0.17 27);
  --green: oklch(46% 0.13 152);
  --amber: oklch(60% 0.14 74);
  --violet: oklch(48% 0.14 305);
  --shadow: 0 18px 60px oklch(32% 0.04 70 / 0.12);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: ui-serif, "Iowan Old Style", "Songti SC", Georgia, serif;
  background:
    linear-gradient(90deg, oklch(35% 0.04 64 / 0.035) 1px, transparent 1px),
    linear-gradient(0deg, oklch(35% 0.04 64 / 0.035) 1px, transparent 1px),
    radial-gradient(circle at 16% 12%, oklch(90% 0.1 74 / 0.55), transparent 28rem),
    radial-gradient(circle at 86% 20%, oklch(84% 0.08 178 / 0.28), transparent 30rem),
    var(--paper);
  background-size: 26px 26px, 26px 26px, auto, auto, auto;
  color: var(--ink);
}

button, input, select {
  font: inherit;
}

button, select {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-height: 38px;
}

button {
  cursor: pointer;
  padding: 0 14px;
}

button:hover, select:hover {
  border-color: color-mix(in oklch, var(--ink), var(--line) 60%);
}

.app-shell {
  width: min(1760px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 44px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 8px 0 18px;
}

.eyebrow {
  margin: 0 0 6px;
  font-family: ui-sans-serif, "Avenir Next", "PingFang SC", sans-serif;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

h1, h2, h3 {
  margin: 0;
  line-height: 1.05;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(32px, 4.2vw, 72px);
  font-weight: 760;
}

h2 {
  font-size: clamp(22px, 2vw, 34px);
}

.top-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.search-box {
  display: grid;
  gap: 6px;
  font-family: ui-sans-serif, "Avenir Next", "PingFang SC", sans-serif;
  font-size: 12px;
  color: var(--muted);
}

.search-box input {
  width: min(38vw, 460px);
  height: 42px;
  border: 1px solid var(--line);
  background: oklch(99% 0.012 84 / 0.88);
  color: var(--ink);
  padding: 0 14px;
  outline: none;
}

.search-box input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px oklch(70% 0.1 245 / 0.22);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 470px);
  gap: 16px;
  align-items: stretch;
}

.atlas-panel, .detail-panel, .pattern-browser, .report-reader {
  border: 1px solid var(--line);
  background: color-mix(in oklch, var(--panel), transparent 5%);
  box-shadow: var(--shadow);
}

.atlas-panel {
  min-height: 720px;
  display: grid;
  grid-template-rows: auto 1fr;
}

.atlas-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.metric-strip {
  display: flex;
  gap: 22px;
  font-family: ui-sans-serif, "Avenir Next", "PingFang SC", sans-serif;
}

.metric-strip div {
  display: grid;
  gap: 2px;
}

.metric-strip strong {
  font-size: 24px;
  line-height: 1;
}

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

.segmented {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.segmented button {
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  min-height: 34px;
}

.segmented button:last-child { border-right: 0; }

.segmented .active {
  background: var(--ink);
  color: var(--paper);
}

.graph-frame {
  position: relative;
  min-height: 560px;
  height: min(68vh, 660px);
}

#graphCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.graph-hint {
  position: absolute;
  left: 14px;
  bottom: 14px;
  padding: 7px 10px;
  background: oklch(99% 0.01 84 / 0.84);
  border: 1px solid var(--line);
  font-family: ui-sans-serif, "Avenir Next", "PingFang SC", sans-serif;
  font-size: 12px;
  color: var(--muted);
}

.detail-panel {
  min-height: 720px;
  overflow: auto;
}

.empty-state, .detail-content {
  padding: 22px;
}

.empty-state h2 {
  margin-bottom: 12px;
}

.empty-state p:last-child {
  color: var(--muted);
  line-height: 1.7;
}

.hidden { display: none; }

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 14px 0 18px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  font-family: ui-sans-serif, "Avenir Next", "PingFang SC", sans-serif;
  font-size: 12px;
}

.node-type {
  color: var(--paper);
  background: var(--ink);
  border-color: var(--ink);
}

.detail-section {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  margin-top: 16px;
}

.detail-section h3 {
  font-family: ui-sans-serif, "Avenir Next", "PingFang SC", sans-serif;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
  text-transform: uppercase;
}

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

.link-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}

.link-item button {
  min-height: 30px;
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(420px, 1.08fr);
  gap: 16px;
  margin-top: 16px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.pattern-list {
  max-height: 720px;
  overflow: auto;
}

.pattern-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 13px 18px;
  border-bottom: 1px solid color-mix(in oklch, var(--line), transparent 35%);
  cursor: pointer;
}

.pattern-item:hover {
  background: oklch(94% 0.04 80 / 0.72);
}

.pattern-item h3 {
  font-size: 18px;
}

.pattern-item p {
  margin: 6px 0 0;
  color: var(--muted);
  font-family: ui-sans-serif, "Avenir Next", "PingFang SC", sans-serif;
  font-size: 12px;
}

.count-badge {
  min-width: 54px;
  text-align: center;
  padding: 8px 10px;
  border-left: 3px solid var(--amber);
  background: var(--panel-strong);
  font-family: ui-sans-serif, "Avenir Next", "PingFang SC", sans-serif;
}

.report-reader {
  min-height: 720px;
}

.report-body {
  max-height: 720px;
  overflow: auto;
  padding: 22px;
  line-height: 1.78;
  font-size: 16px;
}

.report-body h1, .report-body h2, .report-body h3 {
  margin: 1.35em 0 0.55em;
}

.report-body h1 { font-size: 30px; }
.report-body h2 { font-size: 24px; }
.report-body h3 { font-size: 18px; }

.report-body p { margin: 0 0 0.9em; }

.report-body ul, .report-body ol {
  padding-left: 1.25em;
}

.report-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.report-body th, .report-body td {
  border: 1px solid var(--line);
  padding: 7px 8px;
  vertical-align: top;
}

.report-body code {
  background: var(--panel-strong);
  padding: 2px 5px;
}

@media (max-width: 1100px) {
  .workspace, .lower-grid {
    grid-template-columns: 1fr;
  }

  .detail-panel, .atlas-panel, .report-reader {
    min-height: 560px;
  }

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

  .top-actions {
    align-items: stretch;
  }

  .search-box input {
    width: 100%;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: calc(100vw - 18px);
    padding-top: 12px;
  }

  .top-actions, .atlas-toolbar, .section-head {
    flex-direction: column;
    align-items: stretch;
  }

  .segmented {
    overflow-x: auto;
  }

  .atlas-panel, .detail-panel, .report-reader {
    min-height: 520px;
  }

  .graph-frame {
    min-height: 390px;
    height: 52vh;
  }
}
