.tree-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: .65rem 1rem;
  margin: 0 0 .85rem;
  padding: .65rem .8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.tree-tools label { color: var(--muted); font-size: .8rem; }
.tree-tools select { display: block; max-width: 100%; margin: .18rem 0 0; }
.tree-tools button { padding: .38rem .65rem; font-size: .82rem; }
.tree-tools > .meta, .tree-key { align-self: center; }

.tree-key {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  color: var(--accent);
  font-size: .86rem;
  font-weight: 700;
}

.tree-key::before {
  width: 1.25rem;
  height: 3px;
  border-radius: 2px;
  background: #4d78c0;
  content: "";
}

.tree-context-note { margin: -.2rem 0 .7rem; }
.narrative-tree, .narrative-run ol { margin: 0; padding: 0; list-style: none; }
.narrative-tree { --tree-indent: 1rem; }
.narrative-tree .narrative-tree { margin-top: .4rem; }
.narrative-tree[data-deep="true"] { --tree-indent: .45rem; }

.narrative-junction {
  --tree-wire: #aebbd0;
  position: relative;
  padding: 0 0 .36rem var(--tree-indent);
}

.narrative-junction[data-path="true"] { --tree-wire: #4d78c0; }

.narrative-junction::before,
.narrative-junction::after {
  position: absolute;
  inset-inline-start: 0;
  pointer-events: none;
  content: "";
}

.narrative-junction::before { inset-block: 0; border-left: 2px solid var(--tree-wire); }
.narrative-junction:last-child::before { height: 1.2rem; }
.narrative-junction::after { inset-block-start: 1.2rem; width: var(--tree-indent); border-top: 2px solid var(--tree-wire); }
.narrative-junction[data-path="false"]::after { border-top-style: dashed; }

.narrative-node,
.narrative-run > summary {
  padding: .52rem .7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow-wrap: anywhere;
}

.narrative-node:focus { outline: 3px solid #548af1; outline-offset: 1px; }
.narrative-run > summary { min-height: 2.45rem; }
.narrative-run > summary:hover { background: #f0f4fb; }
.narrative-run > summary .meta { margin-inline-start: .4rem; }
.narrative-run[open] > summary { margin-bottom: .36rem; }
.narrative-run ol { display: grid; gap: .3rem; margin-inline-start: .45rem; padding-inline-start: .45rem; border-inline-start: 2px solid var(--tree-wire); }
.narrative-junction[data-path="true"] > .narrative-node,
.narrative-junction[data-path="true"] > .narrative-run > summary { border-color: #bfceeb; background: #f4f8ff; }
.narrative-junction[data-context="true"] > .narrative-node,
.narrative-junction[data-context="true"] > .narrative-run > summary { color: var(--muted); background: #f3f5f8; }

.tree-item-head { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .6rem; }
.tree-item-head > a { font-weight: 700; }
.tree-item-head .turn-badges { margin-inline-start: auto; }
.tree-fork { background: #eae6f8; color: #554177; }
.tree-gap { margin: .3rem 0 0; color: #77460b; }
.narrative-node .turn-excerpt { margin-top: .18rem; }

.cp-hero h1 { margin: 0; }
.cp-hero [hidden] { display: none; }
.cp-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cp-filters { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, .85fr) minmax(0, .9fr); }
.cp-filters button { justify-self: start; }
.cp-pending { background: #fff0d5; color: #73450a; }
.cp-group + .cp-group { margin-top: 1.2rem; }
.cp-group h3 { margin: .75rem 0 .6rem; color: var(--muted); font-size: .94rem; }

.cp-timeline {
  display: grid;
  gap: .55rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cp-timeline > li { display: grid; grid-template-columns: 3.4rem minmax(0, 1fr); align-items: start; gap: .65rem; position: relative; isolation: isolate; }
.cp-timeline > li::after {
  position: absolute;
  inset: 1.25rem auto -.55rem 1.65rem;
  z-index: -1;
  border-left: 2px solid #c0cde0;
  content: "";
}
.cp-timeline > li:last-child::after { display: none; }
.cp-code {
  justify-self: center;
  margin-top: .73rem;
  padding: .18rem .35rem;
  border: 1px solid #c0cde0;
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: .77rem;
  font-weight: 700;
}
.cp-code[data-tip="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.cp-card, .cp-episode {
  min-width: 0;
  padding: .7rem .85rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  overflow-wrap: anywhere;
}
.cp-card header { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .35rem .65rem; margin-bottom: .3rem; }
.cp-card header > a { color: var(--ink); font-weight: 700; }
.cp-card header > a:hover { color: var(--accent); }
.cp-period { display: grid; gap: .1rem; color: var(--ink); font-size: .85rem; line-height: 1.4; }
.cp-period .meta { font-weight: 700; }
.cp-card-meta { display: flex; flex-wrap: wrap; gap: .2rem .85rem; margin-top: .48rem; }
.cp-table th:first-child { min-width: 12rem; width: 29%; }
.cp-table tbody th { background: transparent; font-size: .89rem; letter-spacing: normal; text-transform: none; }
.cp-table td:nth-child(2) { min-width: 14rem; }
.cp-table tbody tr:hover { background: #f7faff; }
.cp-table .pill { white-space: nowrap; }
.cp-table-title { display: block; margin: .22rem 0; color: var(--ink); font-weight: 600; }
.cp-detail-head h1 { margin-top: .55rem; }
.cp-continuity h2 { margin-top: 0; }
.cp-detail-path { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .65rem; }
.cp-detail-path > div { display: grid; align-content: start; gap: .15rem; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px; overflow-wrap: anywhere; }
.cp-detail-path [data-current] { border-color: #c1d1ed; background: #eef4ff; }
.cp-detail-period { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .65rem; margin-top: .8rem; }
.cp-detail-period a, .cp-episode > a { font-size: .85rem; }
.cp-scene > div { line-height: 1.55; white-space: pre-wrap; }
.cp-detail-grid > section { min-width: 0; }
.cp-episode { display: grid; gap: .28rem; }

@media (max-width: 880px) {
  .cp-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
  .narrative-tree { --tree-indent: .64rem; }
  .narrative-tree[data-deep="true"] { --tree-indent: .3rem; }
  .tree-item-head .turn-badges { flex-basis: 100%; margin: 0; }
  .cp-detail-path { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 480px) {
  .cp-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cp-stats div:first-child { grid-column: auto; }
  .cp-stats div:nth-child(odd) { border-inline-end: 1px solid #ccdaee; }
  .cp-stats div:nth-child(even) { border-inline-end: 0; }
  .cp-stats div:nth-child(n+3) { border-bottom: 0; }
  .cp-timeline > li { grid-template-columns: 2.75rem minmax(0, 1fr); gap: .38rem; }
  .cp-timeline > li::after { inset-inline-start: 1.35rem; }
}
