:root {
  --bg: #fdfdfb;
  --bg-elev: #ffffff;
  --bg-muted: #f3f1ec;
  --border: #e5e1d8;
  --text: #1f1d18;
  --text-muted: #5b574e;
  --accent: #2d6a4f;
  --accent-soft: #d8f3dc;
  --link: #1b4332;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --radius: 10px;
  --radius-sm: 6px;
  --maxw: 1080px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --serif: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151a;
    --bg-elev: #1c1e25;
    --bg-muted: #232631;
    --border: #2d3140;
    --text: #ececec;
    --text-muted: #9a9aa6;
    --accent: #74c69d;
    --accent-soft: #1b3a2c;
    --link: #95d5b2;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
  }
}

[data-theme="light"] {
  --bg: #fdfdfb;
  --bg-elev: #ffffff;
  --bg-muted: #f3f1ec;
  --border: #e5e1d8;
  --text: #1f1d18;
  --text-muted: #5b574e;
  --accent: #2d6a4f;
  --accent-soft: #d8f3dc;
  --link: #1b4332;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] {
  --bg: #14151a;
  --bg-elev: #1c1e25;
  --bg-muted: #232631;
  --border: #2d3140;
  --text: #ececec;
  --text-muted: #9a9aa6;
  --accent: #74c69d;
  --accent-soft: #1b3a2c;
  --link: #95d5b2;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 1.25rem; }

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre {
  font-family: var(--mono);
  background: var(--bg-muted);
  border-radius: var(--radius-sm);
}
code { padding: 0.1em 0.35em; font-size: 0.9em; }
pre { padding: 1rem; overflow-x: auto; }
pre code { padding: 0; background: transparent; }

blockquote {
  margin: 1rem 0;
  padding: 0.5rem 1rem;
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
  background: var(--bg-muted);
  border-radius: var(--radius-sm);
}

hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }

table { border-collapse: collapse; width: 100%; margin: 1rem 0; }
th, td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); text-align: left; }
th { background: var(--bg-muted); }

.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: white;
  z-index: 1000;
}
.skip-link:focus { left: 1rem; top: 1rem; }

/* ── Header ───────────────────────────────────────────────────────────── */
.site-header {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(140%) blur(6px);
}
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: 56px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  font-weight: 600;
}
.brand:hover { text-decoration: none; color: var(--accent); }
.brand-mark { font-size: 1.4rem; }
.primary-nav { display: flex; gap: 1.25rem; }
.primary-nav a { color: var(--text-muted); font-size: 0.95rem; }
.primary-nav a:hover { color: var(--accent); text-decoration: none; }

.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  cursor: pointer;
  color: var(--text);
  font-size: 1rem;
}
.theme-toggle:hover { background: var(--bg-muted); }
.theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon-light { display: none; }
  :root:not([data-theme="light"]) .theme-icon-dark { display: inline; }
}

/* ── Hero ─────────────────────────────────────────────────────────────── */
.hero {
  padding: 3rem 0 2rem;
  text-align: center;
}
.hero h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  margin: 0 0 0.5rem;
  letter-spacing: -0.02em;
}
.hero .tagline {
  font-size: 1.15rem;
  color: var(--text-muted);
  max-width: 640px;
  margin: 0 auto 1.5rem;
}
.hero .stats {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1.5rem;
  font-size: 0.95rem;
  color: var(--text-muted);
}
.hero .cta-row {
  margin-top: 1.5rem;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.btn {
  display: inline-block;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  font-size: 0.95rem;
}
.btn:hover { text-decoration: none; background: var(--bg-muted); }
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover { background: var(--link); border-color: var(--link); color: white; }

/* ── Pillars (constitution strip) ─────────────────────────────────────── */
.pillars {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin: 2rem 0;
}
.pillar {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.pillar-name { font-weight: 600; color: var(--accent); }
.pillar-meaning { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.25rem; }

/* ── Filter bar ───────────────────────────────────────────────────────── */
.filter-bar {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1.5rem 0 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  box-shadow: var(--shadow);
}
.filter-bar label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  gap: 0.25rem;
}
.filter-bar select,
.filter-bar input[type="search"] {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}
.filter-bar input[type="search"] { width: 100%; }
.filter-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.filter-meta button.btn-clear {
  background: transparent;
  border: 0;
  color: var(--link);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
}
.filter-meta button.btn-clear:hover { text-decoration: underline; }

/* ── Skill cards ──────────────────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, border-color 0.08s ease;
}
.card:hover { transform: translateY(-1px); border-color: var(--accent); }
.card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}
.card-title a { color: var(--text); }
.card-title a:hover { color: var(--accent); text-decoration: none; }
.card-desc {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin: 0;
  flex: 1;
}
.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.25rem;
}
.tag {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--bg-muted);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-family: var(--mono);
  border: 1px solid transparent;
}
.tag:hover { border-color: var(--border); text-decoration: none; }
.tag-scope { background: var(--accent-soft); color: var(--accent); }
.tag-risk-safety-critical { background: #ffe1e1; color: #b00020; }
.tag-risk-irreversible { background: #fff2cc; color: #8a6d00; }
[data-theme="dark"] .tag-risk-safety-critical { background: #4a1a1a; color: #ff8a8a; }
[data-theme="dark"] .tag-risk-irreversible { background: #4a3d1a; color: #ffd56a; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tag-risk-safety-critical { background: #4a1a1a; color: #ff8a8a; }
  :root:not([data-theme="light"]) .tag-risk-irreversible { background: #4a3d1a; color: #ffd56a; }
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--mono);
}

.no-results {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--text-muted);
  background: var(--bg-elev);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ── Categories grid ──────────────────────────────────────────────────── */
.section-h {
  margin: 3rem 0 1rem;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}
.category-tile {
  display: block;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  color: var(--text);
}
.category-tile:hover { border-color: var(--accent); text-decoration: none; }
.category-num { color: var(--text-muted); font-family: var(--mono); font-size: 0.85rem; }
.category-name { font-weight: 600; margin-top: 0.1rem; }
.category-count { color: var(--text-muted); font-size: 0.85rem; }

/* ── Skill detail page ────────────────────────────────────────────────── */
.breadcrumb {
  margin: 1.25rem 0 0.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent); }

.skill-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 2rem;
  margin-top: 0.5rem;
}
@media (max-width: 800px) {
  .skill-layout { grid-template-columns: 1fr; }
}

.skill-content h1 {
  margin-top: 0.5rem;
  letter-spacing: -0.02em;
}
.skill-preview {
  border-top: 1px solid var(--border);
  margin-top: 2rem;
  padding-top: 1.5rem;
}
.cta-card {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1.5rem 0;
}
.cta-card p { margin: 0 0 0.75rem; color: var(--text); }

.skill-aside {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.aside-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.aside-card h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 0.6rem;
  font-weight: 600;
}
.aside-card .kv {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  padding: 0.2rem 0;
}
.aside-card .kv-key { color: var(--text-muted); }
.aside-card .kv-val { font-family: var(--mono); }
.aside-card ul { list-style: none; padding: 0; margin: 0; }
.aside-card li { padding: 0.2rem 0; font-size: 0.9rem; }
.aside-card .tag-list { display: flex; flex-wrap: wrap; gap: 0.3rem; }

/* ── Prose pages (concepts, tags, etc.) ───────────────────────────────── */
.prose {
  max-width: 760px;
  margin: 1.5rem auto 3rem;
}
.prose h1 { letter-spacing: -0.02em; }
.prose h2 { margin-top: 2rem; }
.prose h3 { margin-top: 1.5rem; }
.prose img { max-width: 100%; height: auto; }

/* ── Footer ───────────────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  margin-top: 4rem;
  padding: 1.5rem 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.footer-row p { margin: 0.2rem 0; }
.footer-row .muted { color: var(--text-muted); font-size: 0.85rem; }
