/* 1. Tokens --------------------------------------------------------------- */

:root {
  /* Layout */
  --page-width: 56rem;
  --page-pad: 1.5rem;
  --sidebar-width: 14rem;
  --gap: 1.75rem;
  --radius: 4px;
  --box-pad: 1.1rem;
  --grid-min: 12rem;

  /* Type */
  --font-body: Verdana, "DejaVu Sans", sans-serif;
  --font-heading: Tahoma, Verdana, "DejaVu Sans", sans-serif;
  --font-ui: Tahoma, Verdana, "DejaVu Sans", sans-serif;
  --font-mono: "Courier New", "Liberation Mono", "DejaVu Sans Mono", monospace;
  --text-size: 0.84375rem;
  --leading: 1.7;
  --heading-weight: bold;
  --heading-style: normal;

  /* Labels: panel titles, table headers, legends, small headings, taglines */
  --label-font: var(--font-ui);
  --label-weight: bold;
  --label-style: normal;
  --label-variant: normal;
  --label-transform: none;
  --label-spacing: 0;
  --label-scale: 1.15;

  /* Ornaments */
  --marker: "» ";
  --separator: " / ";
  --rule-style: dashed;

  /* Colors */
  --color-bg: #cfcbd2;
  --color-panel: #eceaee;
  --color-text: #1d1a20;
  --color-text-soft: #39343e;
  --color-muted: #5e5866;
  --color-title: #4a2650;
  --color-link: #1f5288;
  --color-visited: #7a3060;
  --color-hover: #b0451f;
  --color-accent: #4a2650;
  --color-primary: #6a3a72;
  --color-primary-dark: #4a2650;
  --color-edge: #2f2a34;
  --color-border: #7b7482;
  --color-border-strong: #5c5563;
  --color-rule: #cdc8d2;
  --color-tint: #dcd8e0;
  --color-field: #fff;
  --color-button-top: #f6f5f8;
  --bar-text: #fff;
  --bar-text-nested: #3a1d40;
  --bar-meta: #e6d8ea;
  --color-mark: #fff08a;
  --color-info: #2c5e9e;
  --color-note: #e3ebf5;
  --color-alert: #f6e1da;
  --color-alert-edge: #c4472a;
  --color-warning: #cc6600;
  --color-success: #4e8a3e;
  --color-success-bg: #e9f3e3;
  --color-danger: #b8432f;

  /* Derived */
  --radius-inner: max(0px, calc(var(--radius) - 1px)); /* for bars inside a 1px border */
  --bar-gradient: linear-gradient(90deg, #3e1f45, #967aa0);
  --bar-gradient-nested: linear-gradient(90deg, #cfb9d6, #e6daea);
  --color-stripe: color-mix(in srgb, var(--color-tint) 30%, var(--color-field));
  --color-table-head: color-mix(in srgb, var(--color-panel), var(--color-tint) 55%);
  --color-footer-bar: color-mix(in srgb, var(--color-tint), var(--color-border) 10%);
}

/* 2. Elements ------------------------------------------------------------- */

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

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font: var(--text-size)/var(--leading) var(--font-body);
}

a:link { color: var(--color-link); text-decoration: none; }
a:visited { color: var(--color-visited); }
a:hover { color: var(--color-hover); text-decoration: underline; }
a:focus-visible { outline: 2px solid var(--color-hover); outline-offset: 2px; border-radius: 2px; }

h1, h2, h3, h4, h5, h6 { margin: 1.5em 0 0.5em; line-height: 1.3; font-family: var(--font-heading); font-weight: var(--heading-weight); font-style: var(--heading-style); }
:is(h1, h2, h3, h4, h5, h6) a:is(:link, :visited) { color: inherit; }
:is(h1, h2, h3, h4, h5, h6) a:hover { color: var(--color-hover); }
h1 { font-size: 2em; }
h2 { font-size: 1.45em; color: var(--color-accent); }
h3 { font-size: 1.15em; color: var(--color-primary-dark); }
h4 { font-size: 1em; font-weight: bold; }

/* Everything drawn in the label style. Sizes and colors are set per element. */
h5, h6, th, legend, body > header > p, .sidebar-layout > aside .box > header > :is(h2, h3, h4), .caps {
  font-family: var(--label-font);
  font-weight: var(--label-weight);
  font-style: var(--label-style);
  font-variant: var(--label-variant);
  text-transform: var(--label-transform);
  letter-spacing: var(--label-spacing);
  line-height: normal;
}
h5, h6 { font-size: calc(0.75em * var(--label-scale)); color: var(--color-muted); }

p, ul, ol, dl, blockquote, pre, table, figure, details, fieldset { margin: 0 0 1em; }
ul, ol { padding-left: 1.5em; }
ul ul { margin: 0.25em 0; }
li { margin: 0.25em 0; }
dt { font-weight: bold; }
dd { margin: 0 0 0.5em 1.5em; }

blockquote {
  margin-inline: 0;
  padding: 0.75em 1em;
  background: var(--color-tint);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius);
  color: var(--color-text-soft);
  font-style: italic;
}
blockquote > :last-child { margin-bottom: 0; }
blockquote footer { font: 0.8em var(--font-ui); color: var(--color-muted); }

/* The image fills the frame; the caption is a footer bar. */
figure {
  width: fit-content;
  max-width: 100%;
  margin-inline: 0;
  overflow: hidden;
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
figure img { display: block; max-width: 100%; height: auto; }
figcaption {
  /* Wrap to the image's width instead of widening the figure. */
  contain: inline-size;
  padding: 0.35em 0.75em;
  font: 0.8em/1.45 var(--font-ui);
  color: var(--color-muted);
  background: var(--color-tint);
  border-top: 1px solid var(--color-border);
}
img { max-width: 100%; height: auto; }

hr { margin: 2em 0; border: 0; border-top: 1px var(--rule-style) var(--color-border); }

code, kbd, pre { font-family: var(--font-mono); font-size: 0.95em; }
code { font-size: 1.05em; padding: 0 0.2em; background: var(--color-field); border-radius: 2px; }
pre {
  padding: 0.75em 1em;
  overflow-x: auto;
  background: var(--color-field);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  line-height: 1.4;
}
/* Inline elements in another font or position would otherwise make their line taller. */
code, kbd, sub, sup { line-height: 0; }
pre code { padding: 0; background: none; line-height: inherit; }
kbd { padding: 0 0.35em; border: 1px solid var(--color-border); border-bottom-width: 2px; border-radius: 3px; background: var(--color-panel); }
mark { background: var(--color-mark); }
abbr[title] { border-bottom: 1px dotted; text-decoration: none; cursor: help; }
small { font-size: 0.85em; }

table { border-collapse: collapse; width: 100%; font-size: 0.9em; background: var(--color-field); border: 1px solid var(--color-edge); }
caption { padding-bottom: 0.4em; text-align: left; font: italic 0.95em var(--font-body); color: var(--color-muted); }
th, td { padding: 0.4em 0.65em; text-align: left; vertical-align: top; border: 1px solid var(--color-border); }
th { font-size: calc(0.75em * var(--label-scale)); color: var(--color-text); background: var(--color-table-head); }
tbody tr:nth-child(even) { background: var(--color-stripe); }

details { border: 1px solid var(--color-edge); border-radius: var(--radius); background: var(--color-panel); }
summary { padding: 0.4em 0.75em; cursor: pointer; font-family: var(--font-ui); font-size: 0.9em; color: var(--color-link); background: var(--color-tint); border-radius: var(--radius-inner); }
details[open] summary { border-bottom: 1px solid var(--color-border); border-radius: var(--radius-inner) var(--radius-inner) 0 0; }
details > :not(summary) { margin: 0.75em; }

/* Progress bars and meters. A meter's color follows its low/high/optimum. */
progress, meter {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  max-width: 20em;
  height: 0.85em;
  margin-block: 0.3em;
  overflow: hidden;
  background: var(--color-field);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.08);
}
progress, meter {
  --fill-primary: linear-gradient(color-mix(in srgb, var(--color-primary), #fff 15%), var(--color-primary));
  --fill-good: linear-gradient(color-mix(in srgb, var(--color-success), #fff 15%), var(--color-success));
  --fill-warning: linear-gradient(color-mix(in srgb, var(--color-warning), #fff 15%), var(--color-warning));
  --fill-bad: linear-gradient(color-mix(in srgb, var(--color-danger), #fff 15%), var(--color-danger));
}
progress::-webkit-progress-bar { background: transparent; }
progress::-webkit-progress-value { background: var(--fill-primary); }
progress::-moz-progress-bar { background: var(--fill-primary); }
/* Chromium's default meter styles draw the bar at half height. All three rules below are needed to fill it. */
meter::-webkit-meter-inner-element { display: block; height: 100%; }
meter::-webkit-meter-bar { all: initial; display: block; height: 100%; }
meter::-webkit-meter-optimum-value,
meter::-webkit-meter-suboptimum-value,
meter::-webkit-meter-even-less-good-value { height: 100%; }
meter::-webkit-meter-optimum-value { background: var(--fill-good); }
meter::-webkit-meter-suboptimum-value { background: var(--fill-warning); }
meter::-webkit-meter-even-less-good-value { background: var(--fill-bad); }
meter:-moz-meter-optimum::-moz-meter-bar { background: var(--fill-good); }
meter:-moz-meter-sub-optimum::-moz-meter-bar { background: var(--fill-warning); }
meter:-moz-meter-sub-sub-optimum::-moz-meter-bar { background: var(--fill-bad); }

/* Forms */
fieldset { padding: 1em 1.25em 0.25em; border: 1px solid var(--color-edge); border-radius: var(--radius); background: var(--color-tint); }
legend {
  padding: 0.15em 0.6em;
  font-size: calc(0.75em * var(--label-scale));
  color: var(--color-text);
  background: var(--color-panel);
  border: 1px solid var(--color-edge);
  border-radius: var(--radius);
}
label { display: block; margin-bottom: 0.2em; font: 0.85em var(--font-ui); color: var(--color-text-soft); }
label:has(input[type="checkbox"], input[type="radio"]) { display: inline-block; margin-right: 1em; }
input, select, textarea, button { font: inherit; font-size: 0.9em; }
input:not([type="checkbox"], [type="radio"]), select, textarea {
  width: 100%;
  max-width: 26em;
  padding: 0.3em 0.45em;
  border: 1px solid var(--color-border-strong);
  border-radius: 3px;
  background: var(--color-field);
  box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.08);
  color: var(--color-text);
}
textarea { max-width: none; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 20%, transparent);
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--color-primary); }

button, .button {
  display: inline-block;
  padding: 0.25em 0.9em;
  font-family: var(--font-ui);
  font-size: 0.9em;
  /* Between regular and bold. Tahoma and Verdana have no medium weight, so a
     thin stroke thickens the regular face instead. */
  font-weight: normal;
  -webkit-text-stroke: 0.35px currentColor;
  color: var(--color-text);
  border: 1px solid var(--color-edge);
  border-radius: 3px;
  background: linear-gradient(var(--color-button-top), var(--color-panel));
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.25);
  cursor: pointer;
}
button:not(.secondary) { font-weight: bold; -webkit-text-stroke: 0; }
a.button:link, a.button:visited { color: var(--color-text); text-decoration: none; }
button:hover, .button:hover { background: var(--color-button-top); }
button:active, .button:active { background: var(--color-tint); box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.25); }
button:disabled { opacity: 0.5; cursor: default; }

/* 3. Layout --------------------------------------------------------------- */

/* Page bands: full width, with content centered and capped at --page-width. */
body > header, body > main, .sidebar-layout, body > footer {
  padding-inline: max(var(--page-pad), (100% - var(--page-width)) / 2);
}
body > main, .sidebar-layout { padding-block: 1.5rem; }

/* Keep the footer at the bottom of the window on short pages. */
body:has(> footer) { display: flex; flex-direction: column; min-height: 100vh; }
body > main, .sidebar-layout { flex-grow: 1; }

/* Site header: title, tagline, and a nav that renders as tabs. */
body > header {
  padding-top: 1.5rem;
  background: var(--color-panel);
  border-bottom: 1px solid var(--color-edge);
}
body > header:not(:has(nav)) { padding-bottom: 1.25rem; }
body > header h1 { margin: 0; font-size: 2.2em; }
body > header h1 a:link, body > header h1 a:visited { color: var(--color-title); }
body > header h1 a:hover { color: var(--color-accent); text-decoration: none; }
body > header > p {
  margin: 0.2em 0 1.25em;
  font-size: calc(0.75em * var(--label-scale));
  font-weight: normal;
  letter-spacing: calc(var(--label-spacing) * 1.3);
  color: var(--color-muted);
}
body > header > p:last-child { margin-bottom: 0; }
body > header nav ul { display: flex; flex-wrap: wrap; gap: 0.3em; margin: 0 0 -1px; padding: 0; list-style: none; }
body > header nav li { margin: 0; }
body > header nav a:is(:link, :visited) {
  display: block;
  padding: 0.35em 1em;
  font: 0.85em var(--font-ui);
  color: var(--color-link);
  background: var(--color-tint);
  border: 1px solid var(--color-border);
  border-radius: var(--radius) var(--radius) 0 0;
}
body > header nav a:hover { background: color-mix(in srgb, var(--color-tint), var(--color-primary) 8%); text-decoration: none; }
body > header nav a[aria-current] { color: var(--color-text); background: var(--color-bg); border-color: var(--color-edge); border-bottom-color: var(--color-bg); }

.sidebar-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-width);
  gap: var(--gap);
}

/* Equal columns that wrap to fit; each column is at least --grid-min wide. */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(var(--grid-min), 100%), 1fr));
  gap: 1rem;
  margin: 0 0 1.75em;
}
.grid > * { margin: 0; }
/* Boxes in a grid stretch to equal height; keep their footer bars at the bottom. */
.grid > .box { display: flex; flex-direction: column; }
.grid > .box > footer { margin-top: auto; }

/* Box: a bordered container. A header or footer directly inside becomes a bar. */
.box {
  display: flow-root;
  margin: 0 0 1.75em;
  padding: 0 var(--box-pad);
  background: var(--color-panel);
  border: 1px solid var(--color-edge);
  border-radius: var(--radius);
}
.box .box { margin-bottom: 1em; }
.box > :first-child:not(header) { margin-top: var(--box-pad); }
.box > :last-child:not(footer) { margin-bottom: var(--box-pad); }
.box > header {
  margin: 0 calc(-1 * var(--box-pad)) 1.1em;
  padding: 0.6em var(--box-pad);
  background: var(--bar-gradient);
  border-bottom: 1px solid var(--color-edge);
  border-radius: var(--radius-inner) var(--radius-inner) 0 0;
}
.box > header > * { margin: 0; }
.box > header > :is(h1, h2, h3, h4, h5, h6) { color: var(--bar-text); }
.box > header > :not(h1, h2, h3, h4, h5, h6) { font: 0.8em var(--font-ui); color: var(--bar-meta); }
/* Nested boxes get a lighter bar. */
.box .box > header { background: var(--bar-gradient-nested); border-bottom-color: var(--color-border); }
.box .box > header > :is(h1, h2, h3, h4, h5, h6) { color: var(--bar-text-nested); }
.box .box > header > :not(h1, h2, h3, h4, h5, h6) { color: var(--color-text); }
.box > footer {
  margin: 1.25em calc(-1 * var(--box-pad)) 0;
  padding: 0.4em var(--box-pad);
  font: 0.8em var(--font-ui);
  color: var(--color-muted);
  background: var(--color-footer-bar);
  border-top: 1px solid var(--color-border);
  border-radius: 0 0 var(--radius-inner) var(--radius-inner);
}
.box > footer > * { margin: 0; }

/* Sidebar: the aside column of a .sidebar-layout, tightened up for its narrow width. */
.sidebar-layout > aside { --box-pad: 0.8rem; font-size: 0.85em; }
.sidebar-layout > aside .box { margin-bottom: 1.25em; }
.sidebar-layout > aside .box > header { margin-bottom: 0.7em; padding-block: 0.35em; }
.sidebar-layout > aside .box > header > :is(h2, h3, h4) { font-size: calc(0.8em * var(--label-scale)); }
.sidebar-layout > aside ul { padding: 0; list-style: none; }
.sidebar-layout > aside li { margin: 0; padding: 0.2em 0 0.2em 1em; text-indent: -1em; border-bottom: 1px var(--rule-style) var(--color-rule); }
.sidebar-layout > aside li:last-child { border-bottom: 0; }
.sidebar-layout > aside li::before { content: var(--marker); color: var(--color-border); }
.sidebar-layout > aside img { padding: 3px; border: 1px solid var(--color-border); border-radius: var(--radius); }
.sidebar-layout > aside form { display: flex; gap: 0.3em; margin-bottom: 0.6em; }
.sidebar-layout > aside form button { padding-inline: 0.7em; }
.sidebar-layout > aside dd { margin-left: 0; color: var(--color-muted); }

/* Site footer. */
body > footer {
  padding-block: 1.25em;
  font: 0.8em var(--font-ui);
  background: var(--color-panel);
  border-top: 1px solid var(--color-edge);
  text-align: center;
  color: var(--color-text-soft);
}
body > footer > * { margin: 0 0 0.3em; }
body > footer > :last-child { margin-bottom: 0; }

@media (max-width: 44rem) {
  :root { --page-pad: 1rem; }
  .sidebar-layout { grid-template-columns: minmax(0, 1fr); }
  /* Wide tables scroll sideways instead of overflowing their container. */
  table { display: block; overflow-x: auto; }
}

/* 4. Modifiers ------------------------------------------------------------ */

/* .secondary buttons look the same as default buttons but aren't bold (see button:not(.secondary)). */

/* Callouts. The same three names also color badges, below. */
:is(.note, .alert, .success):not(.badge) {
  margin: 0 0 1em;
  padding: 0.6em 1em;
  border: 1px solid;
  border-left-width: 4px;
  border-radius: var(--radius);
}
.note:not(.badge) {
  background: var(--color-note);
  border-color: color-mix(in srgb, var(--color-info) 35%, var(--color-panel));
  border-left-color: var(--color-info);
}
.alert:not(.badge) {
  background: var(--color-alert);
  border-color: color-mix(in srgb, var(--color-alert-edge) 35%, var(--color-panel));
  border-left-color: var(--color-alert-edge);
}
.success:not(.badge) {
  background: var(--color-success-bg);
  border-color: color-mix(in srgb, var(--color-success) 35%, var(--color-panel));
  border-left-color: var(--color-success);
}
:is(.note, .alert, .success):not(.badge) > :last-child { margin-bottom: 0; }

.badge {
  display: inline-block;
  margin: 0 0.15em 0.35em 0;
  padding: 0 0.45em;
  font: bold 0.7em/1.6 var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-soft);
  border: 1px solid var(--color-border-strong);
  border-radius: 2px;
  background: linear-gradient(var(--color-panel), color-mix(in srgb, var(--color-tint), var(--color-border) 20%));
}
a.badge:is(:link, :visited) { color: var(--color-text-soft); }
a.badge:hover { color: #fff; background: var(--color-hover); border-color: var(--color-hover); text-decoration: none; }
.badge:is(.note, .alert, .success), a.badge:is(.note, .alert, .success):is(:link, :visited) { color: #fff; }
.badge:is(.note, .alert, .success) {
  background: linear-gradient(color-mix(in srgb, var(--badge-color), #fff 15%), var(--badge-color));
  border-color: color-mix(in srgb, var(--badge-color), #000 20%);
}
.badge.note { --badge-color: var(--color-info); }
.badge.alert { --badge-color: var(--color-warning); }
.badge.success { --badge-color: var(--color-success); }

/* Badges and tags never inherit a hanging indent, e.g. from aside lists. */
.badge, .tag { text-indent: 0; }

.tag {
  display: inline-block;
  margin: 0 0.1em 0.35em 0;
  padding: 0 0.5em;
  font: 0.8em/1.7 var(--font-ui);
  background: var(--color-tint);
  border: 1px solid var(--color-rule);
  border-radius: var(--radius);
}
a.tag:hover { border-color: var(--color-hover); text-decoration: none; }

/* 5. Utilities ------------------------------------------------------------ */

.muted { color: var(--color-muted); }
.small { font-size: 0.85em; }
.large { font-size: 1.75em; line-height: 1.2; }
.caps { font-size: calc(0.8em * var(--label-scale)); }
.center { text-align: center; }
.float-left { float: left; margin: 0 1em 0.5em 0; }
.float-right { float: right; margin: 0 0 0.5em 1em; }

.inline { padding: 0; list-style: none; }
.inline li { display: inline; margin: 0; }
.inline li + li::before { content: var(--separator); color: var(--color-border); }
