/* Reach — base: reset, type, page grid (M1_PLAN §2.1, §5)
 *
 * Register: investigation console. Dense, sharp, identifiers in mono.
 * Reading quality of a documentation site: measured prose, real headings,
 * generous line-height in body copy, no decoration that isn't information.
 */

/* ---- reset ------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

html {
  font-family: var(--font-sans);
  font-size: var(--fs-3);
  line-height: var(--lh-body);
  color: var(--fg-0);
  background: var(--bg-0);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  tab-size: 2;
}

body {
  min-height: 100vh;
  background: var(--bg-0);
  color: var(--fg-0);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

img,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
  text-underline-offset: 0.15em;
}

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

table {
  border-collapse: collapse;
  border-spacing: 0;
}

ul,
ol {
  padding-left: var(--sp-5);
}

/* ---- focus -------------------------------------------------------------- */
/* Every focusable thing gets the same 2px ring. Mouse users see it too:
 * an investigation console is driven from the keyboard, so the ring is
 * part of the interface, not a fallback. */

:focus {
  outline: var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}

:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}

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

/* ---- type scale --------------------------------------------------------- */

h1,
h2,
h3,
h4 {
  font-weight: 600;
  line-height: var(--lh-tight);
  letter-spacing: -0.01em;
  color: var(--fg-0);
  overflow-wrap: anywhere;
}

h1 {
  font-size: var(--fs-6);
}

h2 {
  font-size: var(--fs-5);
}

h3 {
  font-size: var(--fs-4);
}

h4 {
  font-size: var(--fs-3);
}

p {
  max-width: 72ch;
}

small,
.r-small {
  font-size: var(--fs-1);
}

.r-muted {
  color: var(--fg-2);
}

.r-secondary {
  color: var(--fg-1);
}

/* Identifiers: field names, event names, values, SPL. Always mono at 13. */

code,
kbd,
pre,
samp,
.r-id {
  font-family: var(--font-mono);
  font-size: var(--fs-2);
  font-variant-ligatures: none;
}

code {
  overflow-wrap: anywhere;
}

pre {
  line-height: var(--lh-body);
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

pre code {
  overflow-wrap: normal;
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 0.4em;
  font-size: var(--fs-1);
  line-height: 1.5;
  text-align: center;
  color: var(--fg-1);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: var(--radius-2);
  vertical-align: 0.1em;
  white-space: nowrap;
}

hr {
  border: 0;
  border-top: 1px solid var(--line);
}

/* ---- page grid ---------------------------------------------------------- */
/*
 *  ┌────────────────────────────────────────────────┐
 *  │ .r-bar     (omnibox, sticky)                   │
 *  ├────────────────────────────┬───────────────────┤
 *  │ .r-main                    │ .r-side  (sticky) │
 *  │                            │  380px            │
 *  └────────────────────────────┴───────────────────┘
 *  Under 900px the side column drops beneath main.
 */

.r-page {
  --gutter: var(--sp-4);
  --bar-h: 56px;
  --side-w: 380px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side-w);
  grid-template-areas:
    "bar bar"
    "main side";
  column-gap: var(--sp-5);
  width: 100%;
  max-width: 1440px;
  margin-inline: auto;
  padding-inline: var(--gutter);
  min-height: 100vh;
}

.r-bar {
  grid-area: bar;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--bar-h);
  padding-block: var(--sp-2);
  margin-inline: calc(-1 * var(--gutter));
  padding-inline: var(--gutter);
  background: var(--bg-0);
  border-bottom: 1px solid var(--line);
}

.r-main {
  grid-area: main;
  min-width: 0;
  padding-block: var(--sp-5) var(--sp-7);
}

.r-side {
  grid-area: side;
  min-width: 0;
  position: sticky;
  top: var(--bar-h);
  align-self: start;
  max-height: calc(100vh - var(--bar-h));
  overflow-y: auto;
  padding-block: var(--sp-5) var(--sp-7);
}

@media (max-width: 899px) {
  .r-page {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "bar"
      "main"
      "side";
  }

  .r-side {
    position: static;
    max-height: none;
    padding-top: 0;
    border-top: 1px solid var(--line);
    padding-block: var(--sp-5) var(--sp-7);
  }

  .r-main {
    padding-bottom: var(--sp-5);
  }
}

/* Section rhythm inside main. A heading, then content, then space. */

.r-section {
  margin-bottom: var(--sp-6);
}

.r-section > h2,
.r-section > h3 {
  margin-bottom: var(--sp-3);
}

.r-section p + p {
  margin-top: var(--sp-2);
}

/* Visually-hidden text for screen readers. */

.r-sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- motion ------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
