/* docs.ohmmmm.com: the same ink, paper and type as ohmmmm.com (DESIGN.md), laid out for reading
   and finding your place. Values live in these custom properties; the rules use them.

   Page shell, the same on every page:
     .site-header   across the top: the ohm dot (ohmmmm.com) and Docs (this site's first page)
     .site-sidebar  left column: every page, in its group, the current one marked
     main           middle column: the page itself (one <article>)
     .site-toc      right column, on wide screens: the reader, this page's sections, the one being read marked
   On narrow screens: the header (with a menu that opens the sidebar), then the page. */
@font-face {
  font-family: "Coconat";
  src: url("/assets/fonts/coconat-regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ohm-font-serif: "Coconat", Georgia, "Times New Roman", serif;
  --ohm-font-sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --ohm-font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* One ink, like a printed page: the Fatale forest green on warm paper. */
  --ohm-forest: #013220;
  --ohm-paper-editorial: #fafaf9;
  --ohm-ink-quiet: #4c6e61; /* forest at 70% on paper, 5.4:1 */
  --ohm-line: rgb(1 50 32 / 0.14); /* the reader's rail */
  --ohm-selection: rgb(161 214 174 / 0.42);
  --ohm-tint: rgb(161 214 174 / 0.3); /* behind the current page in the sidebar */
  --ohm-tint-soft: rgb(161 214 174 / 0.14); /* behind a sidebar row under the pointer */

  --ohm-size: 16px;
  --ohm-size-small: 14px; /* the sidebar and the reader */
  --ohm-leading: 1.65;
  --ohm-size-section: 24px; /* a section's heading */
  --ohm-size-part: 18px; /* a heading inside a section */
  --ohm-text: 400 var(--ohm-size)/var(--ohm-leading) var(--ohm-font-sans);
  --ohm-tracking: -0.015em;
  --ohm-strong: 600;
  --ohm-title: 400 clamp(40px, 5vw, 52px)/1.05 var(--ohm-font-serif); /* Coconat has one weight */
  --ohm-title-tracking: -0.02em;
  --ohm-site-name: 400 22px/1 var(--ohm-font-serif); /* "Docs" in the header */

  --ohm-measure: 680px;
  --ohm-frame: 40px;
  --ohm-mark: 20px;
  --ohm-header: 64px;
  --ohm-rail: 220px;
  --ohm-toc: 220px;
  --ohm-gap: clamp(32px, 4vw, 64px);
  --ohm-top: 32px; /* between the header and the columns */
  --ohm-item-inset: 12px; /* a sidebar row's padding; pulled back so its text lines up with the dot */
  --ohm-paragraph: 1em;

  font-family: var(--ohm-font-sans);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  background: var(--ohm-paper-editorial);
  color: var(--ohm-forest);
}

* { box-sizing: border-box; }

::selection { background: var(--ohm-selection); }

body,
h1, h2, h3, p, ul, ol, li {
  font: var(--ohm-text);
  letter-spacing: var(--ohm-tracking);
}

h1, h2, h3, p, ul, ol { margin: 0; }

h1 {
  font: var(--ohm-title);
  letter-spacing: var(--ohm-title-tracking);
}

h2 {
  font-size: var(--ohm-size-section);
  font-weight: var(--ohm-strong);
  line-height: 1.3;
  letter-spacing: -0.02em;
}

h3 {
  font-size: var(--ohm-size-part);
  font-weight: var(--ohm-strong);
  line-height: 1.4;
}

a {
  color: inherit;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

a:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 4px;
  border-radius: 2px;
}

/* Icons are Lucide, drawn in the ink of the text around them. */
.icon {
  display: block;
  flex: none;
}

/* ---------- Shell ---------- */

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0 var(--ohm-frame);
  display: grid;
  grid-template-columns: var(--ohm-rail) minmax(0, 1fr);
  grid-template-rows: var(--ohm-header) 1fr;
  column-gap: var(--ohm-gap);
}

.skip {
  position: absolute;
  left: var(--ohm-frame);
  top: 8px;
  z-index: 3;
  transform: translateY(-200%);
  background: var(--ohm-paper-editorial);
}

.skip:focus { transform: none; }

.site-header {
  grid-column: 1 / -1;
  grid-row: 1;
  position: sticky;
  top: 0;
  z-index: 2;
  /* paper to the window's edges, so the page scrolls under it cleanly */
  margin-inline: calc(var(--ohm-frame) * -1);
  padding-inline: var(--ohm-frame);
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--ohm-paper-editorial);
}

.site-sidebar {
  grid-column: 1;
  grid-row: 2;
  align-self: start;
  padding-top: var(--ohm-top);
}

main {
  grid-column: 2;
  grid-row: 2;
  justify-self: center;
  width: min(100%, var(--ohm-measure));
  padding: var(--ohm-top) 0 96px;
}

.site-toc { display: none; }

/* The menu button and its checkbox only exist on narrow screens. */
.menu-toggle,
.menu-button { display: none; }

@media (min-width: 761px) and (min-height: 480px) {
  .site-sidebar,
  .site-toc {
    position: sticky;
    top: var(--ohm-header);
    max-height: calc(100dvh - var(--ohm-header));
    overflow-y: auto;
    scrollbar-width: thin;
  }

  /* Room for a row's tint to the left of its text. */
  .site-sidebar {
    padding-left: var(--ohm-item-inset);
    margin-left: calc(var(--ohm-item-inset) * -1);
    padding-bottom: var(--ohm-top);
  }
}

/* The reader gets a third column when there is room for it. */
@media (min-width: 1240px) {
  body { grid-template-columns: var(--ohm-rail) minmax(0, 1fr) var(--ohm-toc); }

  .site-toc {
    display: block;
    grid-column: 3;
    grid-row: 2;
    align-self: start;
    padding-top: var(--ohm-top);
  }
}

/* ---------- Header ---------- */

.site-mark {
  display: block;
  flex: none;
  width: var(--ohm-mark);
  height: var(--ohm-mark);
  border-radius: 50%;
}

.site-mark img {
  display: block;
  width: 100%;
  height: 100%;
}

.site-mark:focus-visible { outline-offset: 3px; }

/* The site's name, in the title face. Coconat has one weight, so it is set apart by face and size. */
.site-name {
  font: var(--ohm-site-name);
  letter-spacing: var(--ohm-title-tracking);
  text-decoration: none;
}

.site-name:hover { text-decoration: underline; }

/* ---------- Sidebar ---------- */

.site-sidebar ul,
.site-toc ul {
  list-style: none;
  padding: 0;
}

.sidebar-group {
  font-size: var(--ohm-size-small);
  font-weight: var(--ohm-strong);
}

.site-sidebar ul { margin-top: 4px; }

.site-sidebar ul + .sidebar-group { margin-top: 28px; }

.site-sidebar li + li { margin-top: 2px; }

/* Each page is a row; the current one sits on a tint. */
.site-sidebar a {
  display: block;
  margin-left: calc(var(--ohm-item-inset) * -1);
  padding: 3px var(--ohm-item-inset);
  border-radius: 8px;
  color: var(--ohm-ink-quiet);
  font-size: var(--ohm-size-small);
  line-height: 1.5;
  text-decoration: none;
}

.site-sidebar a:hover {
  background: var(--ohm-tint-soft);
  color: var(--ohm-forest);
}

.site-sidebar a[aria-current="page"] {
  background: var(--ohm-tint);
  color: var(--ohm-forest);
  font-weight: var(--ohm-strong);
}

/* ---------- The reader: On this page ---------- */

.site-toc > p {
  color: var(--ohm-ink-quiet);
  font-size: var(--ohm-size-small);
}

/* A thin rail down the left; the section being read is marked on it in full ink. */
.site-toc > ul {
  margin-top: 12px;
  border-left: 1px solid var(--ohm-line);
}

.site-toc ul ul { padding-left: 14px; }

.site-toc a {
  position: relative;
  display: block;
  padding: 5px 0 5px 16px;
  color: var(--ohm-ink-quiet);
  font-size: var(--ohm-size-small);
  line-height: 1.4;
  text-decoration: none;
  /* one line each, as on the page's own headings; the full heading shows on hover */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-toc a:hover { color: var(--ohm-forest); }

.site-toc a[aria-current] { color: var(--ohm-forest); }

.site-toc a[aria-current]::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  border-radius: 1px;
  background: var(--ohm-forest);
}

/* ---------- The page ---------- */

.group,
.note { color: var(--ohm-ink-quiet); }

/* The group a page is in, above its title. */
article > header > .group {
  font-size: var(--ohm-size-small);
  font-weight: var(--ohm-strong);
}

article > header > .group + h1 { margin-top: 10px; }

article > header > h1 + * { margin-top: 20px; }

article > header > * + * { margin-top: var(--ohm-paragraph); }

section {
  margin-top: 3em;
  scroll-margin-top: calc(var(--ohm-header) + 8px);
}

section :is(h2, h3) { scroll-margin-top: calc(var(--ohm-header) + 8px); }

section > * + * { margin-top: var(--ohm-paragraph); }

section > h2 + * { margin-top: 0.75em; }

section > * + h3 { margin-top: 1.75em; }

section p,
section li {
  text-wrap: pretty;
  overflow-wrap: break-word;
}

section :is(ul, ol) { padding-left: 1.2em; }

section li + li { margin-top: 0.4em; }

/* The first page: each page and what it covers. */
section ul.pages {
  list-style: none;
  padding-left: 0;
}

code, pre { font-family: var(--ohm-font-mono); }

code { font-size: 0.92em; }

pre {
  margin: 0;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--ohm-tint-soft);
  font-size: var(--ohm-size-small);
  line-height: 1.6;
  overflow-x: auto;
}

/* A table is set apart by space alone: no rules, the first column in the heading weight. */
.table { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  min-width: 7em;
  padding: 5px 24px 5px 0;
  font: var(--ohm-text);
  letter-spacing: var(--ohm-tracking);
  text-align: left;
  vertical-align: top;
}

th { font-weight: var(--ohm-strong); }

:is(th, td):last-child { padding-right: 0; }

/* The page before and the page after. */
.page-pager {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-top: 4em;
}

.page-pager a {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.page-pager a:hover { text-decoration: underline; }

.page-pager a[rel="next"] { margin-left: auto; }

/* ---------- Narrow screens ---------- */

@media (max-width: 760px) {
  :root {
    --ohm-header: 56px;
    --ohm-frame: 24px;
  }

  body { display: block; }

  .site-header { height: var(--ohm-header); }

  main { padding: 24px 0 56px; }

  /* The menu opens the sidebar under the header. The checkbox stays focusable; the label is what shows. */
  .menu-toggle {
    display: block;
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
  }

  .menu-button {
    display: block;
    margin-left: auto;
    padding: 13px 0 13px 13px; /* 44px touch target */
    cursor: pointer;
  }

  .menu-button span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .menu-toggle:focus-visible ~ .site-header .menu-button {
    outline: 2px solid currentColor;
    outline-offset: 4px;
    border-radius: 2px;
  }

  .site-sidebar {
    display: none;
    padding: 8px 0 24px;
  }

  .menu-toggle:checked ~ .site-sidebar { display: block; }

  .site-sidebar a {
    margin-left: 0;
    padding-block: 10px;
    font-size: var(--ohm-size);
  }
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}
