/* Kaikim Labs. Modern, calm, easy on the eyes. No frameworks, no webfonts. */

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --fg: #1c1c1f;
  --fg-soft: #3f3f46;
  --muted: #71717a;
  --accent: #4f46e5;
  --accent-soft: #eef0fe;
  --border: #e6e6e2;
  --shadow: 0 1px 2px rgba(20, 20, 25, 0.04), 0 4px 16px rgba(20, 20, 25, 0.05);
  --radius: 14px;
  --max-width: 44rem;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* Dark mode: OS preference by default, manual override via data-theme. */
:root[data-theme="dark"] {
  --bg: #101012;
  --surface: #18181b;
  --fg: #ececee;
  --fg-soft: #c8c8cd;
  --muted: #8e8e96;
  --accent: #8b93f8;
  --accent-soft: #23244a;
  --border: #29292e;
  --shadow: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101012;
    --surface: #18181b;
    --fg: #ececee;
    --fg-soft: #c8c8cd;
    --muted: #8e8e96;
    --accent: #8b93f8;
    --accent-soft: #23244a;
    --border: #29292e;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 1.0313rem;
  line-height: 1.75;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

.site-header, main, .site-footer {
  max-width: var(--max-width);
  margin: 0 auto;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}

/* Header */

.site-header { padding-top: 1.4rem; }

.site-header nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--fg);
}

.brand::before {
  content: "";
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
}

.nav-links { display: flex; gap: 0.25rem; }

.nav-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  transition: color 0.15s, background 0.15s;
}

.nav-links a:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

#theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1;
  border-radius: 999px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  margin-left: 0.35rem;
  transition: color 0.15s, border-color 0.15s;
}

#theme-toggle:hover { color: var(--accent); border-color: var(--accent); }

main { padding-top: 2.25rem; padding-bottom: 3.5rem; }

/* Typography */

h1, h2, h3 {
  line-height: 1.25;
  letter-spacing: -0.022em;
  color: var(--fg);
}

h1 { font-size: 2rem; font-weight: 750; margin: 0.4rem 0 0.9rem; }
h2 { font-size: 1.28rem; font-weight: 650; margin-top: 2.4rem; }
h3 { font-size: 1.08rem; font-weight: 650; }

p, li { color: var(--fg-soft); }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }

.muted { color: var(--muted); font-size: 0.9em; }

/* Hero */

.hero { padding: 1.25rem 0 0.5rem; }

.hero .eyebrow {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0;
}

.hero h1 { font-size: 2.5rem; margin-top: 0.6rem; }

.hero .lede {
  font-size: 1.13rem;
  line-height: 1.7;
  color: var(--fg-soft);
  max-width: 38rem;
}

/* Document header */

.breadcrumb { font-size: 0.88rem; color: var(--muted); margin-bottom: 0.25rem; }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }

.doc-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.9rem;
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0.75rem 0 0.5rem;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 0.12rem 0.7rem;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--accent-soft);
  color: var(--accent);
}

.status-validated { background: #e5f5e9; color: #1e7d35; }
.status-falsified { background: #fdeaea; color: #b3372f; }
@media (prefers-color-scheme: dark) {
  .status-validated { background: #14301c; color: #6fce88; }
  .status-falsified { background: #3a1a18; color: #f0928b; }
}

.tags { margin: 0.35rem 0 0; }

.tag {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.65rem;
  margin: 0 0.35rem 0.35rem 0;
}

/* Collapsible summary and takeaways */

details.machine-summary, details.key-takeaways {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0;
  margin: 1.4rem 0;
  overflow: hidden;
}

details.machine-summary > summary, details.key-takeaways > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.8rem 1.2rem;
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  user-select: none;
  transition: color 0.15s;
}

details.machine-summary > summary:hover, details.key-takeaways > summary:hover {
  color: var(--accent);
}

details.machine-summary > summary::-webkit-details-marker,
details.key-takeaways > summary::-webkit-details-marker { display: none; }

details.machine-summary > summary::after, details.key-takeaways > summary::after {
  content: "+";
  margin-left: auto;
  font-size: 1rem;
  font-weight: 500;
  color: var(--muted);
  transition: transform 0.15s;
}

details[open].machine-summary > summary::after,
details[open].key-takeaways > summary::after {
  content: "−";
}

details.machine-summary .details-body, details.key-takeaways .details-body {
  padding: 0 1.2rem 1rem;
  border-top: 1px solid var(--border);
}

details.machine-summary p { margin: 0.9rem 0 0; }

details.key-takeaways ul { margin: 0.9rem 0 0; padding-left: 1.2rem; }
details.key-takeaways li { margin-bottom: 0.4rem; }

/* Document body */

.doc-body { margin-top: 1.75rem; }

.doc-body h1 { font-size: 1.35rem; margin-top: 2.6rem; }

.doc-body img { max-width: 100%; height: auto; border-radius: 8px; }

.doc-body blockquote {
  margin: 1.4rem 0;
  padding: 0.1rem 1.2rem;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 0 8px 8px 0;
  color: var(--muted);
}

pre, code {
  font-family: var(--mono);
  font-size: 0.86em;
}

code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.08em 0.4em;
}

pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  overflow-x: auto;
}

pre code { padding: 0; border: none; background: none; }

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.93rem;
  display: block;
  overflow-x: auto;
}

th, td { border: 1px solid var(--border); padding: 0.45rem 0.75rem; text-align: left; }
th { background: var(--surface); }

/* Lists of documents */

.doc-list, .category-list { list-style: none; padding: 0; }

.category-list { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }

.category-list a {
  display: inline-block;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 550;
  color: var(--fg-soft);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  transition: border-color 0.15s, color 0.15s, transform 0.15s;
}

.category-list a:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.doc-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.3rem;
  margin-bottom: 0.9rem;
  transition: border-color 0.15s, transform 0.15s;
}

.doc-item:hover { border-color: var(--accent); }

.doc-item a { text-decoration: none; color: var(--fg); font-size: 1.02rem; }
.doc-item a:hover { color: var(--accent); }

.doc-item-meta {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 0.3rem;
}

.doc-item p {
  margin: 0.5rem 0 0;
  font-size: 0.93rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Related */

.related {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 1.3rem 1rem;
  margin-top: 2.5rem;
}

.related h2 {
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 1rem;
}

.related ul { padding-left: 1.1rem; margin-bottom: 0.25rem; }
.related li { margin-bottom: 0.35rem; }

.doc-export { margin-top: 2.25rem; }

/* Confidence meter */

.conf-badge { white-space: nowrap; }

.conf-meter {
  display: inline-block;
  vertical-align: middle;
  width: 3.2rem;
  height: 0.32rem;
  margin-left: 0.45rem;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.conf-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

.conf-label { font-size: 0.85rem; }

/* Category count chips */

.chip-count {
  display: inline-block;
  min-width: 1.3em;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
  margin-left: 0.25rem;
}

/* Evolution timeline */

.evolution {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 1.3rem 1.1rem;
  margin-top: 2.5rem;
}

.evolution h2 {
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 1rem;
}

.timeline {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0.5rem;
  border-left: 2px solid var(--border);
}

.timeline li {
  position: relative;
  padding: 0 0 1.1rem 1.25rem;
}

.timeline li::before {
  content: "";
  position: absolute;
  left: -0.36rem;
  top: 0.4rem;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
}

.timeline .tl-head { font-size: 0.88rem; color: var(--muted); }
.timeline .tl-what { margin: 0.25rem 0 0; }
.timeline .tl-why { margin: 0.15rem 0 0; font-size: 0.9rem; }

details.git-history {
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}

details.git-history > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.7rem 0;
  font-size: 0.85rem;
  font-weight: 550;
  color: var(--muted);
  user-select: none;
}

details.git-history > summary::-webkit-details-marker { display: none; }
details.git-history > summary::after { content: " +"; }
details[open].git-history > summary::after { content: " −"; }

details.git-history ul {
  list-style: none;
  padding-left: 0.25rem;
  margin: 0 0 0.5rem;
  font-size: 0.88rem;
  color: var(--muted);
}

details.git-history .details-body { border-top: none; padding: 0; }

/* Search page */

.search-page h1 { margin-bottom: 0.5rem; }

#search-input {
  width: 100%;
  font-family: var(--sans);
  font-size: 1.05rem;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.8rem 1.1rem;
  margin: 1rem 0 0.5rem;
  outline: none;
  transition: border-color 0.15s;
}

#search-input:focus { border-color: var(--accent); }

#search-status { min-height: 1.4em; }

/* Footer */

.site-footer {
  border-top: 1px solid var(--border);
  padding-top: 1.25rem;
  padding-bottom: 2.75rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--accent); }

@media (max-width: 480px) {
  h1 { font-size: 1.6rem; }
  .hero h1 { font-size: 1.9rem; }
  body { font-size: 1rem; }
}
