/* ============================================================
   The Power Engineer's Atlas of AI — stylesheet
   Aesthetic: engineering drawing meets field atlas.
   Warm paper surfaces, hairline rules, serif display, mono accents.
   Data colors: validated reference palette (see methodology).
   ============================================================ */

:root {
  --font-display: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --font-ui: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
}

html[data-theme="light"] {
  --page: #f7f4ee;
  --surface: #fdfcf9;
  --surface-2: #f1ede4;
  --ink: #1a1814;
  --ink-2: #55524b;
  --muted: #8a867c;
  --grid: #e6e2d8;
  --baseline: #c8c3b6;
  --border: rgba(26, 24, 20, 0.13);
  --accent: #8c4a0d;
  --accent-ink: #7a3f09;
  --accent-soft: rgba(140, 74, 13, 0.07);
  --shadow: 0 12px 40px rgba(26, 24, 20, 0.14);
  /* categorical slots (validated, light) */
  --cat-1: #2a78d6; --cat-2: #1baf7a; --cat-3: #eda100; --cat-4: #008300;
  --cat-5: #4a3aa7; --cat-6: #e34948; --cat-7: #e87ba4; --cat-8: #eb6834;
  --neutral-a: #6b675e; --neutral-b: #a09b8f;
  /* ordinal (horizon / maturity) ramp */
  --ord-1: #86b6ef; --ord-2: #2a78d6; --ord-3: #104281;
  /* sequential steps for heatmap */
  --seq-0: transparent; --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec;
  --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #184f95;
  --adjacent: #c65420; --bridge: #148a60;
  --nest-fill: rgba(42, 120, 214, 0.055);
  --paper-grid: rgba(26, 24, 20, 0.045);
}

html[data-theme="dark"] {
  --page: #141311;
  --surface: #1e1c19;
  --surface-2: #26231f;
  --ink: #f2efe7;
  --ink-2: #c6c1b4;
  --muted: #8a867c;
  --grid: #2e2b26;
  --baseline: #3f3b34;
  --border: rgba(242, 239, 231, 0.14);
  --accent: #d99a55;
  --accent-ink: #e2ab6e;
  --accent-soft: rgba(217, 154, 85, 0.10);
  --shadow: 0 12px 44px rgba(0, 0, 0, 0.5);
  --cat-1: #3987e5; --cat-2: #199e70; --cat-3: #c98500; --cat-4: #008300;
  --cat-5: #9085e9; --cat-6: #e66767; --cat-7: #d55181; --cat-8: #d95926;
  --neutral-a: #a5a094; --neutral-b: #6b675e;
  --ord-1: #9ec5f4; --ord-2: #3987e5; --ord-3: #184f95;
  --seq-0: transparent; --seq-1: #16324f; --seq-2: #1c4a79; --seq-3: #2264a5;
  --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #86b6ef;
  --adjacent: #e07038; --bridge: #1fb783;
  --nest-fill: rgba(57, 135, 229, 0.08);
  --paper-grid: rgba(242, 239, 231, 0.05);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-ink); text-decoration-color: color-mix(in srgb, var(--accent-ink) 45%, transparent); text-underline-offset: 2px; }
a:hover { text-decoration-color: var(--accent-ink); }

/* ---------- header ---------- */
.site-header {
  border-bottom: 1px solid var(--baseline);
  background:
    linear-gradient(to bottom, transparent, transparent 98%, var(--paper-grid) 100%),
    repeating-linear-gradient(to right, transparent 0 39px, var(--paper-grid) 39px 40px),
    repeating-linear-gradient(to bottom, transparent 0 39px, var(--paper-grid) 39px 40px);
  background-color: var(--page);
}
.masthead {
  max-width: 1180px; margin: 0 auto; padding: 40px 28px 8px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 20px;
}
.kicker {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 10px;
}
.masthead h1 {
  font-family: var(--font-display); font-weight: 500; font-size: clamp(30px, 4.6vw, 46px);
  line-height: 1.06; margin: 0 0 12px; letter-spacing: -0.01em;
}
.masthead h1 em { font-style: italic; color: var(--accent-ink); }
.standfirst { max-width: 640px; color: var(--ink-2); margin: 0 0 18px; font-size: 16px; }
.masthead-actions { display: flex; gap: 8px; padding-top: 34px; flex-shrink: 0; }

.ghost-btn {
  font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--border); border-radius: 7px;
  padding: 6px 11px; cursor: pointer; text-decoration: none; line-height: 1.4;
}
.ghost-btn:hover { color: var(--ink); border-color: var(--baseline); }

.tabs {
  max-width: 1180px; margin: 0 auto; padding: 0 28px;
  display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  appearance: none; background: none; border: none; cursor: pointer;
  font-family: var(--font-ui); font-size: 14px; color: var(--ink-2);
  padding: 11px 14px 13px; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab .tab-num { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); margin-right: 6px; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tab.active .tab-num { color: var(--accent-ink); }

/* ---------- layout ---------- */
.view { max-width: 1180px; margin: 0 auto; padding: 34px 28px 80px; min-height: 60vh; }
.view:focus { outline: none; }

.view-intro { max-width: 760px; margin: 0 0 26px; }
.view-intro h2 { font-family: var(--font-display); font-weight: 500; font-size: 27px; margin: 0 0 8px; }
.view-intro p { color: var(--ink-2); margin: 0; }
.view-intro .hint { font-size: 13px; color: var(--muted); margin-top: 8px; }

.section-rule {
  display: flex; align-items: center; gap: 12px; margin: 40px 0 18px;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.13em;
  text-transform: uppercase; color: var(--muted);
}
.section-rule::after { content: ""; flex: 1; height: 1px; background: var(--grid); }

.mono-kicker {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.13em;
  text-transform: uppercase; color: var(--muted);
}

/* ---------- cards ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 17px 15px; cursor: pointer; text-align: left; font: inherit; color: inherit;
  transition: border-color .15s, transform .15s; position: relative;
}
.card:hover { border-color: var(--baseline); transform: translateY(-1px); }
.card h3 { font-family: var(--font-display); font-weight: 600; font-size: 17.5px; margin: 6px 0 7px; line-height: 1.25; }
.card p { margin: 0; font-size: 13.5px; color: var(--ink-2); }
.card .card-meta { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.card.expanded { border-color: var(--accent); }

.detail-panel {
  grid-column: 1 / -1; background: var(--surface); border: 1px solid var(--accent);
  border-radius: 10px; padding: 22px 24px; margin: 2px 0 8px; animation: fadein .2s ease;
}
@keyframes fadein { from { opacity: 0; transform: translateY(-4px);} to { opacity: 1; transform: none; } }

/* chips & badges */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-2); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 20px; padding: 2.5px 10px;
  cursor: pointer; font-family: var(--font-ui); line-height: 1.5;
}
.chip:hover { color: var(--ink); border-color: var(--baseline); }
.chip.static { cursor: default; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.swatch { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.badge {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.05em;
  border: 1px solid var(--baseline); border-radius: 4px; padding: 1.5px 6px; color: var(--ink-2);
  white-space: nowrap;
}
.maturity-meter { display: inline-flex; gap: 2.5px; vertical-align: middle; }
.maturity-meter i {
  width: 11px; height: 7px; border-radius: 2px; background: var(--surface-2);
  border: 1px solid var(--grid);
}
.maturity-meter i.f1 { background: var(--ord-1); border-color: transparent; }
.maturity-meter i.f2 { background: var(--ord-2); border-color: transparent; }
.maturity-meter i.f3 { background: var(--ord-3); border-color: transparent; }

.filter-row {
  display: flex; flex-wrap: wrap; gap: 7px; align-items: center; margin: 0 0 18px;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.filter-row .flabel { font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-right: 3px; }
.filter-row .spacer { width: 10px; }
.search-input {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; min-width: 240px;
}
.search-input:focus { outline: none; border-color: var(--accent); }

/* ---------- concept map ---------- */
.concept-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 18px 8px; }
.concept-legend { display: flex; flex-wrap: wrap; gap: 14px; padding: 4px 6px 10px; font-size: 12.5px; color: var(--ink-2); }
.concept-legend .lg { display: inline-flex; align-items: center; gap: 7px; }
.concept-legend .lg i { width: 12px; height: 12px; border-radius: 3px; border: 1.5px solid; }
svg.concept { width: 100%; height: auto; display: block; }
svg.concept text { font-family: var(--font-ui); fill: var(--ink); }
svg.concept .node { cursor: pointer; }
svg.concept .node rect { transition: filter .12s; }
svg.concept .node:hover rect, svg.concept .node:focus rect { filter: brightness(0.96); }
html[data-theme="dark"] svg.concept .node:hover rect, html[data-theme="dark"] svg.concept .node:focus rect { filter: brightness(1.18); }
svg.concept .node:focus { outline: none; }
svg.concept .nlabel { font-weight: 600; font-size: 15px; }
svg.concept .nsub { font-size: 11px; fill: var(--muted); }
svg.concept .elabel { font-size: 10.5px; fill: var(--muted); font-family: var(--font-mono); }
svg.concept .edge { stroke: var(--muted); stroke-width: 1.3; fill: none; }

/* ---------- confusion accordion ---------- */
.confusions { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.confusion {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
}
.confusion > button {
  all: unset; display: block; width: 100%; padding: 13px 16px; cursor: pointer; box-sizing: border-box;
}
.confusion > button:hover { background: var(--accent-soft); }
.confusion h4 { font-family: var(--font-display); font-size: 15.5px; font-weight: 600; margin: 0 0 3px; }
.confusion .conf-line { font-size: 12.5px; color: var(--muted); margin: 0; }
.confusion .conf-body { padding: 2px 16px 15px; font-size: 13.5px; color: var(--ink-2); border-top: 1px dashed var(--grid); }
.confusion .conf-body p { margin: 10px 0 0; }
.confusion .conf-body .ps { border-left: 2px solid var(--accent); padding-left: 10px; }
.confusion .conf-body strong { color: var(--ink); }

/* ---------- matrix ---------- */
.matrix-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
table.matrix { border-collapse: separate; border-spacing: 2px; width: 100%; }
table.matrix th { font-weight: 500; font-size: 12px; color: var(--ink-2); padding: 4px 6px; }
table.matrix thead th { vertical-align: bottom; text-align: center; max-width: 84px; }
table.matrix thead th span { display: inline-block; line-height: 1.2; }
table.matrix tbody th { text-align: left; white-space: nowrap; padding-right: 10px; font-size: 12.5px; position: sticky; left: 0; background: var(--surface); }
table.matrix tbody th .swatch { display: inline-block; margin-right: 7px; vertical-align: baseline; }
td.cell {
  min-width: 42px; height: 34px; border-radius: 5px; text-align: center; cursor: pointer;
  font-family: var(--font-mono); font-size: 11.5px; border: 1px solid var(--grid);
  color: var(--ink-2);
}
td.cell.c0 { background: transparent; color: var(--muted); cursor: default; border-style: dashed; }
td.cell.sel { outline: 2px solid var(--accent); outline-offset: -1px; }
td.cell:not(.c0):hover { outline: 2px solid var(--baseline); outline-offset: -1px; }
.cell-ink-dark { color: #0b0b0b !important; }
.cell-ink-light { color: #f4f1ea !important; }
.matrix-note { font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.matrix-panel { margin-top: 14px; }

/* ---------- scatter plots ---------- */
.plot-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 14px 10px; }
svg.plot { width: 100%; height: auto; display: block; font-family: var(--font-ui); }
svg.plot .gridline { stroke: var(--grid); stroke-width: 1; }
svg.plot .axis-label { font-size: 12px; fill: var(--ink-2); }
svg.plot .axis-title { font-size: 12px; fill: var(--muted); font-family: var(--font-mono); letter-spacing: .08em; text-transform: uppercase; }
svg.plot .dot { stroke: var(--surface); stroke-width: 2; cursor: pointer; }
svg.plot .dot-hit { fill: transparent; cursor: pointer; }
svg.plot .dot-label { font-size: 10.5px; fill: var(--ink-2); pointer-events: none; }
svg.plot .rank-pip { font-family: var(--font-mono); font-size: 10px; font-weight: 700; fill: var(--ink); pointer-events: none; }
svg.plot g.mark:focus { outline: none; }
svg.plot g.mark:focus .dot { stroke: var(--accent); }
.plot-legend { display: flex; flex-wrap: wrap; gap: 16px; padding: 8px 8px 6px; font-size: 12.5px; color: var(--ink-2); align-items: center; }
.plot-legend .lg { display: inline-flex; align-items: center; gap: 7px; }
.plot-legend .lg i { width: 10px; height: 10px; border-radius: 50%; }

/* ---------- drawer ---------- */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(15, 13, 10, 0.4); z-index: 40;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100vw);
  background: var(--surface); border-left: 1px solid var(--baseline); z-index: 50;
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  animation: slidein .18s ease;
}
@keyframes slidein { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px 12px; border-bottom: 1px solid var(--grid);
}
.drawer-body { padding: 18px 22px 40px; overflow-y: auto; }
.drawer-body h2 { font-family: var(--font-display); font-weight: 600; font-size: 22px; margin: 0 0 6px; line-height: 1.2; }
.drawer-body h3 { font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 22px 0 8px; font-weight: 600; }
.drawer-body p { font-size: 14px; color: var(--ink-2); margin: 8px 0; }
.drawer-body p strong, .drawer-body li strong { color: var(--ink); }
.drawer-body ul { margin: 6px 0; padding-left: 18px; }
.drawer-body li { font-size: 13.5px; color: var(--ink-2); margin: 5px 0; }
.drawer-body .lede { font-size: 15px; color: var(--ink); }
.drawer-body .quote { border-left: 2px solid var(--accent); padding-left: 12px; font-style: italic; color: var(--ink-2); }
.drawer-body .chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.drawer-body table { width: 100%; border-collapse: collapse; font-size: 13px; }
.drawer-body table td { padding: 6px 8px 6px 0; vertical-align: top; border-top: 1px solid var(--grid); color: var(--ink-2); }
.drawer-body table td:first-child { font-weight: 600; color: var(--ink); width: 34%; }
.scorebar { display: grid; grid-template-columns: 110px 1fr 24px; gap: 8px; align-items: center; margin: 5px 0; font-size: 12.5px; color: var(--ink-2); }
.scorebar .track { height: 7px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.scorebar .fill { height: 100%; background: var(--ord-2); border-radius: 4px; }
.scorebar .num { font-family: var(--font-mono); text-align: right; }
.drawer-nav { display: flex; gap: 8px; margin-top: 22px; }

/* ---------- glossary ---------- */
.glossary-group h3 { font-family: var(--font-display); font-size: 19px; font-weight: 600; margin: 26px 0 10px; }
.gterm { padding: 9px 0; border-top: 1px solid var(--grid); font-size: 14px; color: var(--ink-2); }
.gterm b { color: var(--ink); }
.gterm .ps { color: var(--muted); font-style: italic; }
mark { background: var(--accent-soft); color: var(--accent-ink); border-radius: 2px; padding: 0 1px; }

/* ---------- misc lists ---------- */
.ranked { counter-reset: rank; list-style: none; padding: 0; margin: 0; }
.ranked li {
  counter-increment: rank; position: relative; padding: 12px 14px 12px 52px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px;
  font-size: 13.5px; color: var(--ink-2); cursor: pointer;
}
.ranked li:hover { border-color: var(--baseline); }
.ranked li::before {
  content: counter(rank); position: absolute; left: 14px; top: 12px;
  font-family: var(--font-mono); font-weight: 700; font-size: 15px; color: var(--accent-ink);
}
.ranked li b { color: var(--ink); display: block; margin-bottom: 2px; }

.tooltip {
  position: fixed; z-index: 80; pointer-events: none; max-width: 300px;
  background: var(--ink); color: var(--page); font-size: 12.5px; line-height: 1.45;
  border-radius: 7px; padding: 8px 11px; box-shadow: var(--shadow);
}
.tooltip b { display: block; margin-bottom: 2px; }
.tooltip .tt-sub { opacity: .75; }

.notai-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.notai-table th, .notai-table td { text-align: left; padding: 10px 14px; font-size: 13.5px; border-top: 1px solid var(--grid); color: var(--ink-2); }
.notai-table th { font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); border-top: none; }
.notai-table td:first-child { font-weight: 600; color: var(--ink); white-space: nowrap; }

/* ---------- footer ---------- */
.site-footer {
  border-top: 1px solid var(--baseline); padding: 22px 28px 34px; text-align: center;
  font-size: 12.5px; color: var(--muted);
}
.site-footer a { color: var(--ink-2); }
.footer-note { margin-top: 6px; }

@media (max-width: 720px) {
  .masthead { flex-direction: column; padding-top: 28px; }
  .masthead-actions { padding-top: 0; }
  .view { padding: 24px 16px 60px; }
  .drawer { width: 100vw; }
  table.matrix tbody th { position: static; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}
