/* SPDX-License-Identifier: MIT */

:root {
  --paper: #fbfaf6;
  --ink: #17201d;
  --muted: #65706b;
  --line: #d8ddd5;
  --panel: #ffffff;
  --warm: #f2c96d;
  --teal: #129b8e;
  --blue: #11769f;
  --green: #48a522;
  --gray: #777b7b;
  --shadow: 0 18px 55px rgba(22, 34, 30, 0.12);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(251, 250, 246, 0.96) 38rem),
    radial-gradient(circle at 15% 10%, rgba(242, 201, 109, 0.2), transparent 22rem),
    var(--paper);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header,
.app-layout,
.index-section,
.reference-section,
.app-footer {
  width: min(1500px, calc(100% - 32px));
  margin-inline: auto;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto;
  gap: 24px;
  align-items: end;
  padding: 28px 0 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: #8d6d19;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 4.7rem);
  line-height: 0.95;
  letter-spacing: 0;
  text-transform: uppercase;
}

h2 {
  font-size: 1.35rem;
  line-height: 1.15;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 10px;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 280px) auto 44px;
  gap: 10px;
  align-items: end;
}

.search-box {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.search-box input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: var(--panel);
  outline: none;
}

.search-box input:focus {
  border-color: #0e8178;
  box-shadow: 0 0 0 3px rgba(18, 155, 142, 0.16);
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
}

.segmented button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: 0 11px;
  color: var(--muted);
  background: transparent;
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.segmented button.is-active {
  color: var(--ink);
  background: var(--warm);
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  font-size: 1.25rem;
  line-height: 1;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: #958046;
  box-shadow: 0 0 0 3px rgba(242, 201, 109, 0.28);
  outline: none;
}

.app-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(330px, 420px);
  gap: 20px;
  align-items: start;
}

.chart-area,
.detail-panel,
.index-section,
.reference-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
}

.chart-area {
  min-width: 0;
  overflow: hidden;
}

.chart-heading,
.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px 0;
}

.chart-heading h2,
.section-heading h2 {
  margin-bottom: 0;
}

.match-count,
.section-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.chart-shell {
  width: 100%;
  overflow: auto;
  padding: 10px;
}

#codexChart {
  display: block;
  width: max(900px, 100%);
  min-height: 640px;
  aspect-ratio: 1;
}

.sector {
  fill: none;
  stroke-width: 58;
  opacity: 0.11;
}

.sector-ring {
  fill: none;
  stroke: rgba(23, 32, 29, 0.12);
  stroke-width: 1.1;
}

.branch {
  fill: none;
  stroke-width: 1.15;
  opacity: 0.58;
}

.group-node {
  opacity: 0.96;
}

.group-label {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
}

.bias-node {
  outline: none;
}

.bias-dot {
  stroke: #ffffff;
  stroke-width: 2.2;
}

.bias-label {
  fill: #25322e;
  font-size: 9.8px;
  font-weight: 700;
  pointer-events: none;
}

.bias-node:hover .bias-dot,
.bias-node:focus-visible .bias-dot,
.bias-node.is-selected .bias-dot {
  r: 5.6;
  stroke: var(--warm);
  stroke-width: 3.2;
}

.bias-node:hover .bias-label,
.bias-node:focus-visible .bias-label,
.bias-node.is-selected .bias-label {
  fill: var(--ink);
  font-weight: 900;
}

.bias-node.is-muted,
.branch.is-muted,
.group-node.is-muted,
.group-label.is-muted {
  opacity: 0.1;
}

.brain-backing {
  fill: #ffffff;
  stroke: rgba(23, 32, 29, 0.08);
  stroke-width: 1;
}

.brain-art {
  filter: drop-shadow(0 6px 12px rgba(23, 32, 29, 0.18));
  pointer-events: none;
}

.detail-panel {
  position: sticky;
  top: 16px;
  padding: 22px;
}

.detail-topline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.problem-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 8px;
  padding: 0 10px;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 900;
}

.group-name {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

#detailTitle {
  margin-bottom: 12px;
  font-size: clamp(1.65rem, 4vw, 2.65rem);
  line-height: 1;
}

.definition {
  margin-bottom: 22px;
  color: #293531;
  font-size: 1.03rem;
  line-height: 1.55;
}

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

#detailExamples {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 20px;
  color: #34413c;
  line-height: 1.45;
}

.related-list,
.bias-index {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.related-list button,
.bias-index button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: #26342f;
  background: #ffffff;
  font-size: 0.86rem;
  font-weight: 760;
}

.related-list button:hover,
.related-list button:focus-visible,
.bias-index button:hover,
.bias-index button:focus-visible,
.bias-index button.is-selected {
  border-color: currentColor;
  outline: none;
}

.index-section,
.reference-section {
  margin-top: 20px;
  padding-bottom: 20px;
}

.bias-index {
  padding: 18px 20px 2px;
}

.reference-section {
  overflow: hidden;
  padding: 0;
}

.reference-section summary {
  min-height: 52px;
  padding: 16px 20px;
  font-weight: 900;
  cursor: pointer;
}

.reference-section img {
  display: block;
  width: 100%;
  border-top: 1px solid var(--line);
}

.source-note {
  margin: 0;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.app-footer {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 0 36px;
  color: var(--muted);
  font-size: 0.86rem;
}

.app-footer a,
.source-note a {
  color: #0e6b86;
  font-weight: 800;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.footer-links {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 14px;
}

@media (max-width: 1180px) {
  .app-header {
    grid-template-columns: 1fr;
  }

  .toolbar {
    grid-template-columns: minmax(220px, 1fr) auto 44px;
  }

  .app-layout {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
  }
}

@media (max-width: 760px) {
  .app-header,
  .app-layout,
  .index-section,
  .reference-section,
  .app-footer {
    width: min(100% - 20px, 1500px);
  }

  .toolbar {
    grid-template-columns: 1fr 44px;
  }

  .search-box {
    grid-column: 1 / -1;
  }

  .segmented {
    grid-auto-flow: row;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .segmented button {
    white-space: normal;
  }

  .chart-heading,
  .section-heading,
  .app-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  #codexChart {
    width: 820px;
  }
}
