/* ─── Tokens ───────────────────────────────────────────────────── */

:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-elev: #ffffff;
  --text: #18181b;
  --text-muted: #525252;
  --text-faint: #737373;
  --border: #e5e5e5;
  --border-strong: #d4d4d4;
  --accent: #18181b;
  --accent-fg: #ffffff;
  --danger: #b91c1c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --max-w: 1180px;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --font-serif: "Iowan Old Style", "Source Serif Pro", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --surface: #141414;
    --surface-elev: #1c1c1c;
    --text: #fafafa;
    --text-muted: #a3a3a3;
    --text-faint: #737373;
    --border: #262626;
    --border-strong: #404040;
    --accent: #fafafa;
    --accent-fg: #0a0a0a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
  transition: opacity 0.15s;
}
a:hover { opacity: 0.7; }

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  background: none;
  border: none;
  color: inherit;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--text);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 12%, transparent);
}

textarea { resize: vertical; line-height: 1.5; }

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 0.4em;
  line-height: 1.2;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.1rem; }

p { margin: 0 0 0.8em; }

.small { font-size: 0.875rem; color: var(--text-muted); }

/* ─── Layout ───────────────────────────────────────────────────── */

#header, main, #footer {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 24px;
}

main { padding-top: 32px; padding-bottom: 64px; }

/* ─── Header ──────────────────────────────────────────────────── */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.15rem;
  border-bottom: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: 6px;
  font-size: 16px;
}

.site-nav {
  display: flex;
  gap: 6px;
  align-items: center;
}

.site-nav a {
  padding: 6px 14px;
  border-radius: 999px;
  border-bottom: none;
  font-size: 0.95rem;
  color: var(--text-muted);
}
.site-nav a:hover { background: var(--border); opacity: 1; color: var(--text); }
.site-nav a.is-active { background: var(--accent); color: var(--accent-fg); }

@media (max-width: 640px) {
  .site-nav a { padding: 6px 10px; font-size: 0.85rem; }
  .brand-text { display: none; }
}

/* ─── Hero ────────────────────────────────────────────────────── */

.hero {
  padding: 48px 0 32px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}

.hero h1 {
  font-size: 2.5rem;
  max-width: 18ch;
  margin-bottom: 0.3em;
}

.hero .lede {
  font-size: 1.15rem;
  color: var(--text-muted);
  max-width: 60ch;
  margin-bottom: 1.2em;
}

.hero-cta { display: flex; gap: 12px; }

@media (max-width: 640px) {
  .hero h1 { font-size: 1.8rem; }
  .hero .lede { font-size: 1rem; }
}

/* ─── Buttons ─────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  text-decoration: none;
}

.btn:hover { background: var(--border); border-color: var(--text); opacity: 1; }
.btn:active { transform: translateY(1px); }

.btn.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.btn.primary:hover { opacity: 0.85; }

.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 8%, transparent); }

/* ─── Filters ─────────────────────────────────────────────────── */

.filters { margin-bottom: 28px; }

.filter-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.filter-row .search { flex: 1; }
.filter-row select { max-width: 200px; flex: 0 0 200px; }

@media (max-width: 640px) {
  .filter-row { flex-direction: column; }
  .filter-row select { max-width: none; flex: none; }
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 6px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.9rem;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.chip:hover { background: var(--border); color: var(--text); }
.chip.is-active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

/* ─── Grid & Card ─────────────────────────────────────────────── */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s, box-shadow 0.15s, border-color 0.15s;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--border-strong);
  opacity: 1;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-head h3 { margin: 0 0 2px; font-size: 1.1rem; font-family: var(--font-sans); }
.card-head .role { margin: 0; font-size: 0.85rem; color: var(--text-muted); }

.card .archetype {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.card .tagline {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1rem;
  color: var(--text);
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: auto;
  padding-top: 8px;
  font-size: 0.8rem;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
}

.empty {
  padding: 48px 0;
  text-align: center;
  color: var(--text-muted);
}

/* ─── Leader Detail ───────────────────────────────────────────── */

.leader-detail .back,
.builder .back,
.builder-intro .back,
.about .back,
.print-actions .back {
  display: inline-block;
  margin-bottom: 20px;
  font-size: 0.9rem;
  color: var(--text-muted);
  border-bottom: none;
}
.leader-detail .back:hover { color: var(--text); opacity: 1; }

.leader-head {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 16px;
}

.leader-head h1 { margin: 0 0 4px; font-size: 2.2rem; font-family: var(--font-sans); }
.leader-head .role { margin: 0 0 2px; color: var(--text-muted); }
.leader-head .meta { margin: 0 0 6px; color: var(--text-faint); font-size: 0.85rem; }
.leader-head .archetype {
  margin: 0 0 4px;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.leader-head .tagline {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.15rem;
}

.leader-detail .bio {
  font-size: 1.05rem;
  max-width: 70ch;
  color: var(--text-muted);
  margin: 16px 0 20px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0;
  margin: 0 0 32px;
  list-style: none;
}
.tags li {
  font-size: 0.78rem;
  padding: 3px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
}

.practices {
  display: grid;
  gap: 32px;
  margin-bottom: 40px;
}

.practice-group header { margin-bottom: 16px; }
.practice-group h2 { font-family: var(--font-sans); font-size: 1rem; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px; }
.cat-blurb { font-size: 0.9rem; color: var(--text-muted); margin: 0; }

.practice {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.practice h3 {
  font-family: var(--font-sans);
  font-size: 1.05rem;
  margin: 0 0 10px;
}

.practice .label {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-right: 6px;
  min-width: 36px;
}

.practice p { margin: 0 0 8px; }
.practice .why { color: var(--text); }
.practice .what { color: var(--text-muted); }
.practice .source { font-size: 0.8rem; color: var(--text-faint); margin: 8px 0 0; }
.practice .source a { color: var(--text-faint); border-bottom-color: var(--text-faint); }

.sources h3 { font-family: var(--font-sans); font-size: 1rem; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px; }
.sources ul { padding-left: 18px; margin: 0; color: var(--text-muted); }
.sources li { margin-bottom: 4px; font-size: 0.9rem; }

/* ─── Builder ─────────────────────────────────────────────────── */

.builder-intro h1 { font-size: 2rem; }
.builder-intro .lede { font-size: 1.05rem; color: var(--text-muted); max-width: 60ch; }

.templates {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.template-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.template-card h2 { font-family: var(--font-sans); font-size: 1.1rem; margin: 0 0 2px; }
.template-card .tagline { font-family: var(--font-serif); font-size: 1rem; color: var(--text); margin: 0; }
.template-card .inspired { font-size: 0.85rem; color: var(--text-muted); margin: 4px 0; }
.template-card .btn { margin-top: auto; align-self: flex-start; }

.import-box {
  margin-top: 28px;
  padding: 24px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.import-box h2 { font-family: var(--font-sans); font-size: 1.05rem; margin-bottom: 4px; }

.builder-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.builder-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.builder-identity {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.builder-identity label { display: flex; flex-direction: column; gap: 4px; }
.builder-identity span { font-size: 0.8rem; color: var(--text-muted); }

.autosave {
  text-align: right;
  font-size: 0.8rem;
  color: var(--text-faint);
  height: 1.2em;
  margin: 0 0 12px;
}

.builder-sections {
  display: grid;
  gap: 16px;
}

.builder-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.builder-section > header { margin-bottom: 16px; }
.builder-section > header h2 { font-family: var(--font-sans); font-size: 1.05rem; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 2px; }

.builder-items {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.builder-item {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  position: relative;
}

.builder-item label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.builder-item label span { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.builder-item label:last-child { margin-bottom: 0; }

.item-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
}

.icon-btn {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  font-size: 14px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); background: transparent; }

.section-actions {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.borrowed {
  font-size: 0.8rem;
  color: var(--text-faint);
  margin: 8px 0 0;
}

/* ─── Modal ───────────────────────────────────────────────────── */

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.modal {
  position: relative;
  width: min(640px, calc(100vw - 24px));
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  background: var(--surface-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-family: var(--font-sans); font-size: 1.05rem; margin: 0; }

.modal-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.borrow-item {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.borrow-item:hover { border-color: var(--text); background: var(--bg); }

.borrow-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.borrow-head strong { display: block; font-family: var(--font-sans); font-size: 0.95rem; }
.borrow-head .who { display: block; font-size: 0.8rem; color: var(--text-muted); }
.borrow-item .what { font-size: 0.85rem; color: var(--text-muted); margin: 0 0 4px; }
.borrow-item .why { font-size: 0.85rem; color: var(--text); margin: 0; }

/* ─── Print Sheet (also styled for screen preview) ────────────── */

.print-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.print-sheet {
  background: white;
  color: #18181b;
  padding: 40px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-family: var(--font-sans);
}

.print-head h1 {
  font-family: var(--font-serif);
  font-size: 1.8rem;
  margin: 0 0 4px;
}

.print-head .byline {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: #525252;
}

.print-head .tagline {
  margin: 0 0 24px;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.05rem;
}

.print-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px 32px;
}

.print-cat h2 {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid #e5e5e5;
}

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

.print-cat li {
  margin-bottom: 12px;
  font-size: 0.88rem;
  line-height: 1.4;
}

.print-cat li strong { display: block; font-size: 0.92rem; margin-bottom: 2px; }
.print-cat .what { color: #525252; margin: 2px 0; font-size: 0.85rem; }
.print-cat .why { color: #18181b; margin: 2px 0; font-size: 0.85rem; }

.print-foot {
  margin-top: 28px;
  padding-top: 12px;
  border-top: 1px solid #e5e5e5;
  font-size: 0.78rem;
  color: #737373;
  text-align: center;
}

/* ─── About ───────────────────────────────────────────────────── */

.about { max-width: 65ch; }
.about h2 { font-family: var(--font-sans); font-size: 1.05rem; text-transform: uppercase; letter-spacing: 0.08em; margin-top: 32px; }
.about dt { font-weight: 600; margin-top: 12px; }
.about dd { margin: 0 0 0 0; color: var(--text-muted); }
.about ul { color: var(--text-muted); }

/* ─── Footer ──────────────────────────────────────────────────── */

.site-footer {
  margin-top: 80px;
  padding: 24px 0;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
}
.site-footer p { margin: 0 0 4px; }

/* ben.gy attribution — subtle Chicago-font credit, same size as footer text. */
@font-face {
  font-family: 'Chicago';
  src: url('ChicagoFLF.woff2') format('woff2');
  font-weight: normal; font-style: normal; font-display: swap;
}
.chicago-font { font-family: 'Chicago', 'Geneva', sans-serif; letter-spacing: .5px; }
.site-footer .credit { display: inline-block; margin-top: 4px; }
.credit a { color: inherit; text-decoration: none; transition: color .15s; opacity: .9; }
.credit a:hover { color: var(--text); opacity: 1; }

/* ─── Small screens fine-tuning ───────────────────────────────── */

@media (max-width: 640px) {
  .leader-head { flex-direction: column; align-items: flex-start; text-align: left; }
  .builder-actions .btn { padding: 8px 12px; font-size: 0.85rem; }
  .print-grid { grid-template-columns: 1fr; }
  .print-sheet { padding: 24px; }
}
