/* Legibl documentation — one stylesheet, no build step, no dependencies.
   Light and dark are both first-class: the OS preference is the default and
   the toggle in the header overrides it via data-theme on <html>. */

:root {
  color-scheme: light dark;

  --bg:          #ffffff;
  --bg-soft:     #f6f7f9;
  --bg-code:     #f2f3f5;
  --fg:          #16191d;
  --fg-soft:     #545c66;
  --border:      #dfe3e8;
  --border-soft: #eceef1;
  --accent:      #1f5fbf;
  --accent-soft: #e8f0fc;

  --ok:      #1a7f4b;
  --ok-bg:   #e7f5ee;
  --warn:    #8a5b00;
  --warn-bg: #fdf3e0;
  --bad:     #b3261e;
  --bad-bg:  #fdeceb;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
          Arial, sans-serif;

  --measure: 42rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #14171a;
    --bg-soft:     #1b1f23;
    --bg-code:     #1e2226;
    --fg:          #e6e9ec;
    --fg-soft:     #9aa4ae;
    --border:      #2c3238;
    --border-soft: #23282d;
    --accent:      #79aaf5;
    --accent-soft: #1b2738;

    --ok:      #6dd39b;
    --ok-bg:   #16261e;
    --warn:    #e8b661;
    --warn-bg: #2a2113;
    --bad:     #f28b82;
    --bad-bg:  #2c1a19;
  }
}

/* The header toggle wins over the OS preference, in both directions. */
:root[data-theme="light"] {
  color-scheme: light;
  --bg:          #ffffff;
  --bg-soft:     #f6f7f9;
  --bg-code:     #f2f3f5;
  --fg:          #16191d;
  --fg-soft:     #545c66;
  --border:      #dfe3e8;
  --border-soft: #eceef1;
  --accent:      #1f5fbf;
  --accent-soft: #e8f0fc;
  --ok:      #1a7f4b;
  --ok-bg:   #e7f5ee;
  --warn:    #8a5b00;
  --warn-bg: #fdf3e0;
  --bad:     #b3261e;
  --bad-bg:  #fdeceb;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:          #14171a;
  --bg-soft:     #1b1f23;
  --bg-code:     #1e2226;
  --fg:          #e6e9ec;
  --fg-soft:     #9aa4ae;
  --border:      #2c3238;
  --border-soft: #23282d;
  --accent:      #79aaf5;
  --accent-soft: #1b2738;
  --ok:      #6dd39b;
  --ok-bg:   #16261e;
  --warn:    #e8b661;
  --warn-bg: #2a2113;
  --bad:     #f28b82;
  --bad-bg:  #2c1a19;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  overflow-wrap: break-word;
}

/* ---------- header ---------- */

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

.masthead-inner {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.wordmark {
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 1.05rem;
  color: var(--fg);
  text-decoration: none;
}

.wordmark span { color: var(--fg-soft); font-weight: 400; }

.masthead .version {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--fg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
}

.masthead .spacer { flex: 1 1 auto; }

.theme-toggle {
  font: inherit;
  font-size: 0.8rem;
  color: var(--fg-soft);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
}

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

/* ---------- layout ---------- */

.layout {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  gap: 2.5rem;
  align-items: start;
}

@media (max-width: 60rem) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 1.5rem; }
  .sidebar { position: static !important; border-right: 0; }
}

.sidebar {
  position: sticky;
  top: 1.5rem;
  font-size: 0.9rem;
}

.sidebar h2 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-soft);
  margin: 1.25rem 0 0.4rem;
}

.sidebar h2:first-child { margin-top: 0; }

.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li { margin: 0.15rem 0; }

.sidebar a {
  display: block;
  padding: 0.15rem 0.5rem;
  border-radius: 5px;
  color: var(--fg-soft);
  text-decoration: none;
}

.sidebar a:hover { background: var(--bg-soft); color: var(--fg); }

.sidebar a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

main { min-width: 0; }

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

h1 {
  font-size: 1.9rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem;
}

h2 {
  font-size: 1.3rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin: 2.5rem 0 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-soft);
}

h3 { font-size: 1.05rem; margin: 1.75rem 0 0.5rem; }
h4 { font-size: 0.95rem; margin: 1.25rem 0 0.4rem; color: var(--fg-soft); }

p, ul, ol { max-width: var(--measure); }
p { margin: 0.75rem 0; }
li { margin: 0.3rem 0; }

.lede {
  font-size: 1.1rem;
  color: var(--fg-soft);
  margin-bottom: 1.5rem;
  max-width: var(--measure);
}

a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }

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

strong { font-weight: 650; }

/* ---------- code ---------- */

code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--bg-code);
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  padding: 0.08em 0.32em;
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.6;
  margin: 0.9rem 0;
}

pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: 1em;
}

.code-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-soft);
  margin: 1.25rem 0 -0.4rem;
}

.linecount {
  font-size: 0.8rem;
  color: var(--fg-soft);
  margin-top: -0.4rem;
}

/* ---------- tables ---------- */

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 1rem 0;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.88rem;
}

th, td {
  text-align: left;
  vertical-align: top;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border-soft);
}

thead th {
  background: var(--bg-soft);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-soft);
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: 0; }

td code, th code { white-space: nowrap; }

/* ---------- callouts ---------- */

.note, .warn, .stop {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin: 1.25rem 0;
  max-width: var(--measure);
  font-size: 0.94rem;
}

.note   { background: var(--bg-soft);  border-left-color: var(--accent); }
.warn   { background: var(--warn-bg);  border-left-color: var(--warn); }
.stop   { background: var(--bad-bg);   border-left-color: var(--bad); }

.note > :first-child, .warn > :first-child, .stop > :first-child { margin-top: 0; }
.note > :last-child,  .warn > :last-child,  .stop > :last-child  { margin-bottom: 0; }

.note p, .warn p, .stop p, .note ul, .warn ul, .stop ul { max-width: none; }

.callout-title {
  display: block;
  font-weight: 650;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.3rem;
}

.warn .callout-title { color: var(--warn); }
.stop .callout-title { color: var(--bad); }
.note .callout-title { color: var(--accent); }

/* ---------- status pills ---------- */

.pill {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.08rem 0.5rem;
  white-space: nowrap;
}

.pill-yes { background: var(--ok-bg);   color: var(--ok); }
.pill-no  { background: var(--bad-bg);  color: var(--bad); }
.pill-part{ background: var(--warn-bg); color: var(--warn); }

/* ---------- cards ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
  max-width: none;
  list-style: none;
  padding: 0;
}

.card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin: 0;
  background: var(--bg-soft);
}

.card h3 { margin: 0 0 0.3rem; font-size: 1rem; }
.card p { margin: 0; font-size: 0.9rem; color: var(--fg-soft); max-width: none; }

/* ---------- definition lists ---------- */

dl.fixes { max-width: var(--measure); }
dl.fixes dt {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 1rem;
}
dl.fixes dd { margin: 0.2rem 0 0 0; }

/* ---------- footer ---------- */

.docs-footer {
  border-top: 1px solid var(--border);
  margin-top: 3rem;
  padding-top: 1.25rem;
  font-size: 0.85rem;
  color: var(--fg-soft);
}

.docs-footer p { max-width: none; margin: 0.3rem 0; }

.skip-link {
  position: absolute;
  left: -999px;
}
.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--accent);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  z-index: 10;
}
