/* Triple Bottom Line Index — design tokens and layout.
   Light palette on :root, dark redefined under both the media query and
   [data-theme], so the toggle wins in either direction. */

:root {
  --bg: #fbfaf8;
  --surface: #ffffff;
  --surface-2: #f4f2ee;
  --border: #e2ded6;
  --border-strong: #cdc7bb;
  --text: #1c1a17;
  --text-muted: #6b655c;
  --text-faint: #948d82;

  --people: #b4531f;
  --people-soft: #f6e7dc;
  --planet: #2f6b46;
  --planet-soft: #e0ede4;
  --profit: #3b5b8c;
  --profit-soft: #e2e8f3;

  --accent: #1c1a17;
  --shadow: 0 1px 2px rgba(28, 26, 23, .06), 0 8px 24px rgba(28, 26, 23, .05);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  --serif: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14130f;
    --surface: #1c1b17;
    --surface-2: #24221d;
    --border: #322f28;
    --border-strong: #45413a;
    --text: #f0ede7;
    --text-muted: #a49d91;
    --text-faint: #7b746a;

    --people: #e08b52;
    --people-soft: #33241a;
    --planet: #6cc08d;
    --planet-soft: #17281e;
    --profit: #85a8dd;
    --profit-soft: #1a2233;

    --accent: #f0ede7;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

:root[data-theme="dark"] {
  --bg: #14130f;
  --surface: #1c1b17;
  --surface-2: #24221d;
  --border: #322f28;
  --border-strong: #45413a;
  --text: #f0ede7;
  --text-muted: #a49d91;
  --text-faint: #7b746a;

  --people: #e08b52;
  --people-soft: #33241a;
  --planet: #6cc08d;
  --planet-soft: #17281e;
  --profit: #85a8dd;
  --profit-soft: #1a2233;

  --accent: #f0ede7;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px;
}

/* --- masthead --- */

.masthead {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.masthead-inner {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 0 20px;
  flex-wrap: wrap;
}

.wordmark {
  font-family: var(--serif);
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -.02em;
  margin: 0;
  text-decoration: none;
}

.wordmark span { color: var(--text-faint); font-weight: 400; }

.nav {
  display: flex;
  gap: 20px;
  align-items: center;
  font-size: 13.5px;
}

.nav a {
  color: var(--text-muted);
  text-decoration: none;
  padding-bottom: 2px;
  border-bottom: 1.5px solid transparent;
}

.nav a:hover, .nav a[aria-current="page"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  width: 30px; height: 30px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.theme-toggle:hover { border-color: var(--border-strong); color: var(--text); }

/* --- hero --- */

.hero { padding: 52px 0 34px; }

.hero h1 {
  font-family: var(--serif);
  font-size: clamp(30px, 5vw, 46px);
  line-height: 1.12;
  letter-spacing: -.025em;
  margin: 0 0 14px;
  max-width: 20ch;
}

.hero p {
  margin: 0;
  max-width: 62ch;
  color: var(--text-muted);
  font-size: 16.5px;
}

.hero p + p { margin-top: 12px; }

.stat-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin-top: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.stat {
  flex: 1 1 150px;
  padding: 14px 18px;
  border-right: 1px solid var(--border);
}
.stat:last-child { border-right: 0; }

.stat b {
  display: block;
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.02em;
}
.stat span {
  font-size: 12px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: .07em;
}

/* --- controls --- */

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin: 34px 0 14px;
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 12px 0;
  background: linear-gradient(var(--bg) 72%, transparent);
}

input[type="search"], select {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 11px;
}
input[type="search"] { flex: 1 1 240px; min-width: 180px; }
input[type="search"]:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.result-count {
  margin-left: auto;
  font-size: 13px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* --- table --- */

.table-shell {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow-x: auto;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  min-width: 720px;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  padding: 11px 14px;
  white-space: nowrap;
}

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th[aria-sort] { color: var(--text); }
th[aria-sort="descending"]::after { content: " ↓"; }
th[aria-sort="ascending"]::after { content: " ↑"; }

tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
tbody tr:last-child { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

td { padding: 11px 14px; vertical-align: middle; }

.c-rank { color: var(--text-faint); font-family: var(--mono); font-size: 13px; width: 52px; }
.c-name { font-weight: 550; }
.c-name small {
  display: block;
  font-weight: 400;
  font-size: 12px;
  color: var(--text-faint);
}
.c-num { text-align: right; }

.overall {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 15px;
}

.bar {
  --v: 0;
  --col: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}
.bar i {
  display: block;
  height: 5px;
  width: 54px;
  border-radius: 3px;
  background: var(--border);
  position: relative;
  overflow: hidden;
  flex: none;
}
.bar i::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--v) * 1%);
  background: var(--col);
  border-radius: 3px;
}
.bar b {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 13px;
  min-width: 34px;
  text-align: right;
}
.bar.people { --col: var(--people); }
.bar.planet { --col: var(--planet); }
.bar.profit { --col: var(--profit); }
.bar.none b { color: var(--text-faint); }

.unranked-note {
  margin: 40px 0 12px;
  padding-top: 26px;
  border-top: 1px solid var(--border);
}
.unranked-note h2 {
  font-family: var(--serif);
  font-size: 21px;
  margin: 0 0 6px;
  letter-spacing: -.02em;
}
.unranked-note p {
  margin: 0;
  color: var(--text-muted);
  max-width: 66ch;
  font-size: 14.5px;
}

/* --- detail drawer --- */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 9, 7, .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
  z-index: 40;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(560px, 100%);
  background: var(--bg);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform .22s cubic-bezier(.4, 0, .2, 1);
  z-index: 50;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.drawer.open { transform: none; }

.drawer-head {
  position: sticky;
  top: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 20px 26px 16px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}
.drawer-head h2 {
  font-family: var(--serif);
  font-size: 24px;
  letter-spacing: -.02em;
  margin: 0 0 3px;
}
.drawer-head .meta { color: var(--text-faint); font-size: 13px; }

.drawer-close {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  width: 30px; height: 30px;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.drawer-close:hover { color: var(--text); border-color: var(--border-strong); }

.drawer-body { padding: 8px 26px 60px; }

.pillar-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 18px;
  overflow: hidden;
  background: var(--surface);
}
.pillar-card > header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.pillar-card > header h3 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .09em;
}
.pillar-card > header .score {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 600;
}
.pillar-card.people > header { background: var(--people-soft); color: var(--people); }
.pillar-card.planet > header { background: var(--planet-soft); color: var(--planet); }
.pillar-card.profit > header { background: var(--profit-soft); color: var(--profit); }

.metric {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.metric:last-child { border-bottom: 0; }
.metric-top {
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.metric-top strong { font-weight: 550; font-size: 14px; }
.metric-top .val {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 14px;
  white-space: nowrap;
}
.metric-top .val em {
  font-style: normal;
  color: var(--text-faint);
  font-size: 12px;
  margin-left: 6px;
}
.metric p {
  margin: 5px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

.missing {
  padding: 14px 16px;
  font-size: 13.5px;
  color: var(--text-muted);
}

.source-note {
  padding: 10px 16px;
  background: var(--surface-2);
  font-size: 11.5px;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
}
.source-note a { color: var(--text-muted); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.chip {
  font-size: 11.5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  color: var(--text-muted);
  background: var(--surface);
}

/* --- prose pages --- */

.prose { max-width: 68ch; padding: 44px 0 80px; }
.prose h1 {
  font-family: var(--serif);
  font-size: clamp(28px, 4.5vw, 40px);
  letter-spacing: -.025em;
  margin: 0 0 18px;
}
.prose h2 {
  font-family: var(--serif);
  font-size: 23px;
  letter-spacing: -.02em;
  margin: 40px 0 10px;
}
.prose h3 { font-size: 15px; margin: 26px 0 6px; }
.prose p, .prose li { color: var(--text-muted); }
.prose strong { color: var(--text); font-weight: 600; }
.prose code {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
}
.prose table {
  min-width: 0;
  margin: 16px 0;
  font-size: 14px;
}
.prose thead th { position: static; }
.prose td { border-bottom: 1px solid var(--border); }
.prose .callout {
  border-left: 3px solid var(--border-strong);
  padding: 2px 0 2px 16px;
  margin: 20px 0;
}

/* --- footer --- */

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 60px;
  padding: 26px 0 44px;
  font-size: 13px;
  color: var(--text-faint);
}
.site-footer a { color: var(--text-muted); }
.site-footer p { margin: 0 0 6px; max-width: 70ch; }

@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  .hero { padding: 34px 0 24px; }
  .drawer-head, .drawer-body { padding-left: 18px; padding-right: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
