:root {
  --bg: oklch(17% 0.015 260);
  --bg-raised: oklch(21% 0.018 260);
  --bg-node: oklch(24% 0.02 260);
  --bg-node-hover: oklch(28% 0.025 260);
  --line: oklch(32% 0.02 260);
  --line-soft: oklch(27% 0.015 260);

  --text: oklch(93% 0.008 260);
  --text-dim: oklch(70% 0.012 260);
  --text-faint: oklch(56% 0.012 260);

  --collect: oklch(72% 0.14 215);
  --event: oklch(78% 0.14 75);
  --shared: oklch(74% 0.13 300);
  --gap: oklch(68% 0.19 25);

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo",
    "Noto Sans KR", sans-serif;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── 헤더 ─────────────────────────────────────────── */

.masthead {
  border-bottom: 1px solid var(--line);
  padding: 28px 32px 20px;
  background: linear-gradient(
    180deg,
    oklch(20% 0.02 260) 0%,
    var(--bg) 100%
  );
}

.masthead h1 {
  margin: 0 0 6px;
  font-size: clamp(1.35rem, 1rem + 1.4vw, 2rem);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.masthead p {
  margin: 0;
  color: var(--text-dim);
  max-width: 62ch;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 18px;
  font-size: 12.5px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-dim);
}

.swatch {
  width: 22px;
  height: 3px;
  border-radius: 2px;
  background: var(--dot, var(--text-faint));
}

.swatch.dashed {
  background: repeating-linear-gradient(
    90deg,
    var(--gap) 0 5px,
    transparent 5px 9px
  );
}

/* ── 레이아웃 ─────────────────────────────────────── */

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

@media (max-width: 1080px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }
}

.canvas-wrap {
  position: relative;
  padding: 36px 28px 80px;
  overflow-x: auto;
}

.canvas {
  position: relative;
  display: grid;
  /* col0 = 되돌아가는 선 통로, col1~3 = 수집, col4 = 간격, col5 = 이벤트 */
  grid-template-columns: 78px repeat(3, minmax(196px, 1fr)) 44px minmax(210px, 250px);
  gap: 52px 20px;
  min-width: 1080px;
}

/* ── 레인 배경 ────────────────────────────────────── */

.lane-band {
  position: relative;
  z-index: 0;
  border-radius: var(--r-lg);
  border: 1px solid var(--line-soft);
  margin: -30px -14px -20px;
}

.lane-band[data-lane='collect'] {
  background: linear-gradient(
    180deg,
    oklch(24% 0.035 215 / 0.35),
    oklch(20% 0.02 260 / 0.15)
  );
}

.lane-band[data-lane='event'] {
  background: linear-gradient(
    180deg,
    oklch(24% 0.035 75 / 0.3),
    oklch(20% 0.02 260 / 0.12)
  );
}

.lane-band-label {
  position: absolute;
  top: -9px;
  left: 16px;
  padding: 0 8px;
  background: var(--bg);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  white-space: nowrap;
}

.lane-band[data-lane='collect'] .lane-band-label {
  color: oklch(from var(--collect) l c h / 0.75);
}

.lane-band[data-lane='event'] .lane-band-label {
  color: oklch(from var(--event) l c h / 0.75);
}

#wires {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

/* ── 노드 ─────────────────────────────────────────── */

.node {
  position: relative;
  z-index: 1;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: var(--bg-node);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent, var(--line));
  border-radius: var(--r-md);
  padding: 13px 15px 14px;
  transition:
    transform 220ms var(--ease),
    background 180ms var(--ease),
    border-color 180ms var(--ease),
    box-shadow 220ms var(--ease);
}

.node:hover {
  background: var(--bg-node-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 22px oklch(10% 0.02 260 / 0.5);
}

.node:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.node[data-lane='collect'] {
  --accent: var(--collect);
}
.node[data-lane='event'] {
  --accent: var(--event);
}
.node[data-lane='shared'] {
  --accent: var(--shared);
}
.node[data-kind='gap'] {
  --accent: var(--gap);
  border-style: dashed;
  border-left-style: solid;
  background: oklch(24% 0.03 25 / 0.4);
}

.node.is-active {
  background: var(--bg-node-hover);
  border-color: var(--accent);
  box-shadow:
    0 0 0 1px var(--accent),
    0 10px 26px oklch(10% 0.02 260 / 0.55);
}

.node.is-dimmed {
  opacity: 0.28;
  filter: saturate(0.4);
}

.node-kind {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 5px;
}

.node-title {
  display: block;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 3px;
}

.node-sub {
  display: block;
  color: var(--text-faint);
  font-size: 12.5px;
  line-height: 1.45;
}

.node-meta {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--line-soft);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  min-width: 0;
}

.node-meta span {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 그룹 노드(내부 단계가 여러 개)는 층이 쌓인 느낌을 준다 */
.node[data-kind='group']::after,
.node[data-kind='group']::before {
  content: '';
  position: absolute;
  left: 8px;
  right: 8px;
  height: 10px;
  border: 1px solid var(--line);
  border-top: none;
  border-radius: 0 0 var(--r-md) var(--r-md);
  background: var(--bg-node);
  z-index: -1;
}

.node[data-kind='group']::before {
  bottom: -5px;
}

.node[data-kind='group']::after {
  bottom: -9px;
  opacity: 0.6;
}

.node[data-kind='barrier'] {
  text-align: center;
  border-left-width: 1px;
  border-top: 2px solid var(--accent);
  background: linear-gradient(
    180deg,
    oklch(28% 0.04 215 / 0.6),
    var(--bg-node)
  );
}

/* ── 상세 패널 ────────────────────────────────────── */

.detail {
  position: sticky;
  top: 0;
  min-height: 100vh;
  max-height: 100vh;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--bg-raised);
  padding: 30px 28px 60px;
}

@media (max-width: 1080px) {
  .detail {
    position: static;
    max-height: none;
    border-left: none;
    border-top: 1px solid var(--line);
  }
}

.detail-empty {
  color: var(--text-faint);
  font-size: 13.5px;
}

.detail h2 {
  margin: 0 0 4px;
  font-size: 21px;
  letter-spacing: -0.02em;
}

.detail-sub {
  margin: 0 0 20px;
  color: var(--text-faint);
  font-size: 13px;
}

.detail-lane {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 100px;
  border: 1px solid currentColor;
  margin-bottom: 12px;
}

.spec {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 7px 14px;
  margin: 0 0 22px;
  padding: 15px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.spec dt {
  color: var(--text-faint);
  font-size: 12px;
}

.spec dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  word-break: break-word;
}

.prose {
  margin: 0 0 18px;
  color: var(--text-dim);
  font-size: 13.5px;
}

.note {
  margin: 0 0 22px;
  padding: 13px 15px;
  background: oklch(23% 0.02 260);
  border-left: 2px solid var(--accent, var(--text-faint));
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-size: 13px;
  color: var(--text-dim);
}

.note strong {
  display: block;
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.steps {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  counter-reset: step;
}

.steps li {
  counter-increment: step;
  position: relative;
  padding: 0 0 16px 30px;
  border-left: 1px solid var(--line);
  margin-left: 9px;
}

.steps li:last-child {
  border-left-color: transparent;
  padding-bottom: 0;
}

.steps li::before {
  content: counter(step);
  position: absolute;
  left: -10px;
  top: 0;
  width: 19px;
  height: 19px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--bg-node);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-faint);
}

.step-name {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text);
}

.step-queue {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent, var(--text-faint));
  margin-left: 7px;
}

.step-note {
  display: block;
  color: var(--text-faint);
  font-size: 12.5px;
  margin-top: 3px;
}

.code-ref {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-faint);
  word-break: break-all;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.code-ref span {
  display: block;
  color: var(--text-dim);
  margin-top: 3px;
}
