/* Bastion — documentation site.
   No inline styles anywhere: the server serves this under a CSP without
   'unsafe-inline', and the page has to live within it like any other. */

:root {
  color-scheme: light dark;
  --bg: #fbfbfa;
  --panel: #ffffff;
  --ink: #191918;
  --muted: #6b6b66;
  --line: #e4e4e0;
  --accent: #9a4c2a;
  --accent-soft: #f4ece7;
  --ok: #2f7d4f;
  --code-bg: #f6f5f3;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  /* Headings are set in a book serif. It is the one typographic decision on the
     page, it costs no network request, and it is why this does not look like
     every other documentation site. */
  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --measure: 68ch;
  --shadow: 0 1px 2px rgba(25, 25, 24, 0.04), 0 8px 24px -16px rgba(25, 25, 24, 0.28);
  --on-accent: #fdf7f3;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161614;
    --panel: #1e1d1b;
    --ink: #ecebe7;
    --muted: #9b9992;
    --line: #302e2b;
    --accent: #d98f68;
    --accent-soft: #2a211c;
    --ok: #6fbf8e;
    --code-bg: #232220;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px -18px rgba(0, 0, 0, 0.8);
    --on-accent: #1b1310;
  }
}

::selection { background: var(--accent-soft); color: var(--accent); }

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 2rem; }

body {
  margin: 0;
  /* A single warm wash off the top-left corner, fixed so it never scrolls into
     the text. Cheap, and it keeps the page from reading as flat white. */
  background: var(--bg) radial-gradient(70ch 50ch at 8% -8%, var(--accent-soft), transparent 70%) fixed no-repeat;
  color: var(--ink);
  font: 16px/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 48px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ---------- sidebar ---------- */

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  padding: 40px 0 40px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  margin: 0 0 4px;
}

.mark {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 7px;
  box-shadow: var(--shadow);
}

.brand-name {
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-sub {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 28px;
  padding-left: 40px;
}

.repo-link {
  position: relative;   /* the tooltip anchors to this */
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 26px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}

.repo-link:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.gh { width: 16px; height: 16px; flex: none; }

/* ---------- package manager switch ---------- */

/* Built by app.js: it rewrites the commands, so without script it would be
   four buttons that do nothing. */
.pm-switch {
  display: flex;
  gap: 2px;
  margin: 0 0 26px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.pm {
  position: relative;   /* the tooltip anchors to this */
  flex: 1;
  appearance: none;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  padding: 4px 0;
  cursor: pointer;
  transition: color 120ms ease, background 120ms ease;
}

.pm:hover { color: var(--ink); }

.pm[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.nav-group { margin-bottom: 22px; }

.nav-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 650;
  margin: 0 0 8px;
}

.sidebar nav a {
  display: block;
  padding: 4px 10px;
  margin-left: -10px;
  color: var(--ink);
  text-decoration: none;
  font-size: 14.5px;
  border-radius: 6px;
}

.sidebar nav a {
  border-left: 2px solid transparent;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

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

.sidebar nav a.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: 550;
}

/* ---------- content ---------- */

main {
  padding: 40px 0 120px;
  min-width: 0;
}

section { scroll-margin-top: 24px; margin-bottom: 64px; }

h1 {
  font-family: var(--serif);
  font-size: 46px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 14px;
}

h2 {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 14px;
  padding-bottom: 8px;
  /* The rule fades out rather than stopping dead at the column edge. */
  border-bottom: 1px solid transparent;
  border-image: linear-gradient(90deg, var(--line) 0%, var(--line) 55%, transparent 100%) 1;
}

h3 {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.005em;
  margin: 28px 0 8px;
}

/* The mark's crenellations, borrowed as a rule: three merlons over a baseline.
   It appears exactly twice — under the title and above the footer — which is
   what keeps it a signature rather than decoration. */
.crenel {
  height: 13px;
  max-width: 232px;
  margin: 0 0 22px;
  background:
    /* merlons, sitting directly on … */
    repeating-linear-gradient(90deg, var(--accent) 0 26px, transparent 26px 44px) 0 0 / 100% 9px no-repeat,
    /* … the wall. */
    linear-gradient(var(--accent), var(--accent)) 0 100% / 100% 4px no-repeat;
  opacity: 0.9;
}

.crenel-muted { opacity: 0.35; margin: 0 0 20px; }

p, li { max-width: var(--measure); }
p { margin: 0 0 14px; }

.lede { font-size: 19px; color: var(--muted); max-width: var(--measure); }

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

a:hover { text-decoration-thickness: 2px; }

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ---------- buttons ---------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 22px 0 4px;
}

.btn {
  position: relative;   /* the tooltip anchors to this */
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 14.5px;
  font-weight: 550;
  text-decoration: none;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

.btn:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
  .btn:hover { transform: none; }
}

code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}

pre {
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.6;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 15px 18px;
  overflow-x: auto;
  margin: 0 0 16px;
  /* A hairline of accent down the gutter: enough to tie code to the palette,
     not enough to compete with the text. */
  border-left: 3px solid var(--accent-soft);
}

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

/* ---------- copy buttons ---------- */

/* The wrapper is created by app.js and carries the block's margin, so the
   button can sit outside the scrolling area and stay put. */
.code-block { position: relative; margin: 0 0 16px; }
/* Room at the right so a long first line never runs under the button. */
.code-block pre { margin: 0; padding-right: 48px; }

.copy {
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms ease, color 120ms ease, border-color 120ms ease;
}

.code-block:hover .copy,
.copy:focus { opacity: 1; }

.copy:hover { color: var(--accent); border-color: var(--accent); }
.copy.copied { opacity: 1; color: var(--ok); border-color: var(--ok); }

/* ---------- tooltips ---------- */

/* Drawn from data-tip, so app.js can change a button's wording by setting one
   attribute and static markup can opt in without any script at all. Default
   direction is leftward, which is what the copy buttons need: they sit at the
   right edge of the column and anything drawn outward would be clipped.
   data-tip-pos="top" opens upward instead.

   Positioning context is the host's own business — `.copy` is absolutely
   placed inside its code block, so a blanket `position: relative` here would
   move it. */
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  right: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease;
}

[data-tip-pos="top"]::after {
  right: auto;
  left: 50%;
  top: auto;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
}

[data-tip]:hover::after,
[data-tip]:focus-visible::after,
.copy.copied::after { opacity: 1; }

.copy.copied::after { color: var(--ok); border-color: var(--ok); }

/* No hover to reveal it on a touch screen, so leave it showing. */
@media (hover: none) {
  .copy { opacity: 1; }
}

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

.scroll-x { overflow-x: auto; margin-bottom: 18px; }

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14.5px;
}

th, td {
  text-align: left;
  padding: 9px 14px 9px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th { font-weight: 600; color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.05em; }

td code { white-space: nowrap; }

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

.note {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 10px 10px 0;
  padding: 13px 18px;
  margin: 0 0 18px;
  font-size: 15px;
  max-width: var(--measure);
}

.note strong { color: var(--accent); }

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.tab {
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14.5px;
  padding: 8px 12px;
  cursor: pointer;
  margin-bottom: -1px;
}

.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 550; }

.panel[hidden] { display: none; }

/* ---------- benchmark figures ---------- */

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.metric .value {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--accent);
  display: block;
}

.metric .label {
  font-size: 12.5px;
  color: var(--muted);
  display: block;
  margin-top: 2px;
}

.bar-row { display: grid; grid-template-columns: 190px minmax(0, 1fr) 90px; gap: 12px; align-items: center; margin-bottom: 8px; font-size: 14px; }
.bar-track { background: var(--code-bg); border: 1px solid var(--line); border-radius: 999px; height: 12px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 999px; }
.bar-num { font-family: var(--mono); font-size: 13px; color: var(--muted); text-align: right; }

footer {
  padding: 8px 0 48px;
  color: var(--muted);
  font-size: 14px;
  max-width: var(--measure);
}

footer p { margin: 0 0 10px; }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 0; }
  .sidebar { position: static; height: auto; padding: 28px 0 0; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav-group { margin-bottom: 8px; width: 100%; }
  h1 { font-size: 34px; }
  h2 { font-size: 24px; }
  .brand-sub { padding-left: 0; }
  .repo-link { margin-top: 16px; }
  .actions .btn { flex: 1 1 auto; justify-content: center; }
  .bar-row { grid-template-columns: 130px minmax(0, 1fr) 70px; }
}
