:root {
  --bg: #2a2622;
  --surface: #35302b;
  --surface-hover: #3f3933;
  --border: #4a433c;
  --text: #e9e3d8;
  --muted: #a39a8e;
  --accent: #b8a4e6;
  --accent-strong: #cfc0f2;
  --nolw: #5b8fd0;
  --lw: #c97a36;
  --radius: 10px;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.6;
}

.wrap {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding-inline: 1.5rem;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

h1,
h2 {
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 1.9rem;
  margin: 0 0 1rem;
}

h2 {
  font-size: 1.25rem;
  margin: 2.5rem 0 1rem;
}

small,
.muted {
  color: var(--muted);
}

/* nav */
header {
  border-bottom: 1px solid var(--border);
  background: rgba(42, 38, 34, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

header nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 3.75rem;
}

.brand {
  color: var(--text);
  font-weight: 600;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}

.brand span {
  color: var(--accent);
}

.brand:hover {
  color: var(--text);
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 1.5rem;
}

.nav-links a {
  color: var(--muted);
  font-size: 0.95rem;
}

.nav-links a:hover {
  color: var(--text);
  text-decoration: none;
}

main {
  flex: 1;
  padding-top: 2.5rem;
  padding-bottom: 5rem;
}

/* footer */
footer {
  border-top: 1px solid var(--border);
  padding: 2rem 0;
  font-size: 0.85rem;
  color: var(--muted);
}

footer p {
  margin: 0.25rem 0;
}

/* forms */
form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

input[type="search"] {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 1rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}

input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(184, 164, 230, 0.2);
}

button {
  padding: 0.7rem 1.25rem;
  font: inherit;
  font-weight: 500;
  color: #221d2e;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

/* lists (search results, notes) */
main ul {
  padding-left: 1.25rem;
}

main li {
  margin: 0.35rem 0;
}

/* tables */
table {
  border-collapse: collapse;
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.95rem;
}

th,
td {
  text-align: left;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
}

tr:last-child td,
tr:last-child th {
  border-bottom: none;
}

thead th {
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

tbody tr:hover {
  background: var(--surface-hover);
}

td {
  font-variant-numeric: tabular-nums;
}

.stats th {
  width: 16rem;
  font-weight: normal;
  color: var(--muted);
}

.stats td {
  font-family: var(--mono);
}

/* chart */
.chart {
  display: flex;
  height: 200px;
  gap: 1px;
  padding: 1rem 1rem 0;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: 1px solid var(--muted);
}

.slot {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: flex-end;
}

.slot:hover {
  background: var(--surface-hover);
}

.col {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-radius: 2px 2px 0 0;
  overflow: hidden;
}

.lw {
  background: var(--lw);
}

.nolw {
  background: var(--nolw);
}

.swatch {
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  border-radius: 2px;
  vertical-align: middle;
}

.axis,
.note {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
}

.axis {
  padding: 0.4rem 1rem 0;
}

details {
  margin-top: 1.5rem;
}

summary {
  cursor: pointer;
  color: var(--accent);
}

details table {
  margin-top: 0.75rem;
}

/* journey table of contents */
html {
  scroll-behavior: smooth;
}

section,
h3 {
  scroll-margin-top: 4.5rem;
}

.toc {
  scroll-margin-top: 4.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.toc-title {
  margin: 0 0 0.5rem;
  font-weight: 600;
}

.toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc li {
  margin: 0.2rem 0;
}

.toc details {
  margin: 0;
}

.toc summary {
  list-style: none;
}

.toc summary::-webkit-details-marker {
  display: none;
}

.toc summary::before,
.toc-plain::before {
  content: "▸";
  display: inline-block;
  width: 1.5em;
  color: var(--muted);
}

.toc details[open] > summary::before {
  content: "▾";
}

.toc-plain::before {
  visibility: hidden;
}

.toc details ul {
  padding-left: 1.5em;
  margin: 0.25rem 0 0.75rem;
}

.toc details li {
  font-size: 0.9rem;
}

.toc-back {
  margin-top: 1.5rem;
  font-size: 0.875rem;
}

/* methodology stats strip */
.stat-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.stat {
  flex: 1 1 9rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 1rem;
  background: var(--surface);
}

.stat-num {
  font-family: var(--mono);
  font-size: 1.35rem;
  font-weight: 500;
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.9rem;
  line-height: 1.3;
}

.stat-sub {
  font-size: 0.8rem;
  line-height: 1.3;
  color: var(--muted);
}

/* methodology pipeline */
.pipeline {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0 0 0 1.25rem;
}

.pipeline::before {
  content: "";
  position: absolute;
  left: 0.35rem;
  top: 1.4rem;
  bottom: 1.4rem;
  width: 2px;
  background: var(--border);
}

.stage {
  position: relative;
  display: grid;
  grid-template-columns: 9rem 15rem 1fr;
  gap: 1rem;
  margin: 0 0 0.5rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.stage::before {
  content: "";
  position: absolute;
  left: -1.15rem;
  top: 1.15rem;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--accent);
}

.stage-name {
  display: flex;
  flex-direction: column;
  font-size: 1rem;
  font-weight: 500;
}

.stage-tool {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--muted);
}

.stage-counts {
  color: var(--muted);
}

.count {
  font-family: var(--mono);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.case-bar {
  height: 4px;
  margin-top: 0.4rem;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.case-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
}

/* methodology diagrams (Mermaid) */
.diagram {
  padding: 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  overflow-x: auto;
}

.diagram pre {
  margin: 0;
}

.diagram svg {
  display: block;
  margin-inline: auto;
}

/* journey: one case as table rows */
.case-tables {
  display: grid;
  gap: 1.25rem;
  overflow-x: auto;
}

.case-tables caption {
  text-align: left;
  padding: 0.5rem 0 0.35rem 0.9rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
}

.case-tables td {
  font-family: var(--mono);
  font-size: 0.85rem;
}

.case-tables .key {
  color: var(--accent-strong);
}

.mermaid:not([data-processed]) {
  visibility: hidden;
}

code {
  font-family: var(--mono);
  font-size: 0.9em;
}

/* methodology cleaning trace */
.trace {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.trace-step {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.trace-step+.trace-step::before {
  content: "→";
  position: absolute;
  left: -1.2rem;
  top: 1rem;
  color: var(--accent);
}

.trace-label {
  font-weight: 500;
}

.trace-count {
  color: var(--muted);
}

.trace-note {
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--muted);
}

.chips {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.chips li {
  padding: 0.2rem 0.45rem;
  background: var(--bg);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.75rem;
  overflow-wrap: anywhere;
}

.arrow {
  color: var(--accent);
}

/* methodology mess log gallery */
.mess-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.mess-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.mess-title {
  font-weight: 500;
}

.mess-example {
  margin: 0;
  padding: 0.5rem 0.65rem;
  background: var(--bg);
  border-left: 2px solid var(--lw);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.75rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.mess-fix {
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--muted);
}

/* methodology 2x2 worked example */
.score {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 1rem;
  align-items: start;
}

.two-by-two td {
  font-family: var(--mono);
}

.two-by-two tbody th {
  font-weight: 500;
}

.two-by-two tbody tr:hover {
  background: none;
}

.cell-letter {
  display: inline-block;
  width: 1.2rem;
  margin-right: 0.4rem;
  color: var(--accent);
  font-weight: 500;
}

.calc {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.calc li {
  padding: 0.65rem 1rem;
  background: var(--surface);
  border-radius: var(--radius);
}

.calc-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.calc-math {
  font-family: var(--mono);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.calc-math b {
  color: var(--accent-strong);
  font-weight: 500;
}

.rank-compare th:nth-child(3),
.rank-compare th:nth-child(4) {
  width: 22%;
}

.rank-compare .num {
  text-align: right;
  font-family: var(--mono);
}

.rank-compare .case-bar span {
  min-width: 2px;
}

/* methodology lawyer burst */
.burst-flags {
  margin: 1rem 0;
}

@media (max-width: 640px) {
  .wrap {
    padding-inline: 1rem;
  }

  .brand {
    font-size: 1rem;
  }

  .nav-links {
    gap: 1rem;
  }

  .nav-links a {
    font-size: 0.875rem;
  }

  .hide-mobile {
    display: none;
  }

  .stage {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }

  .trace,
  .mess-grid,
  .score {
    grid-template-columns: 1fr;
  }

  .trace-step+.trace-step::before {
    content: "↓";
    left: 50%;
    top: -1.3rem;
  }

  h1 {
    font-size: 1.5rem;
  }

  main table {
    display: block;
    overflow-x: auto;
  }

  .stats th {
    width: auto;
  }
}
