:root {
  --bg: #ffffff;
  --text: #202122;
  --muted: #54595d;
  --link: #3366cc;
  --link-visited: #795cb2;
  --border: #a2a9b1;
  --border-light: #c8ccd1;
  --panel: #f8f9fa;
  --header-border: #c8ccd1;
  --code-bg: #f8f9fa;
  --article-width: 960px;
  --font-size: 16px;
}
/* Text size has to set font-size on body directly: --font-size is read
   by html, and a variable set on body (html's child) can never flow
   back up to html, so the old --font-size override here did nothing. */
body[data-text-size="small"] { font-size: 14px; }
body[data-text-size="large"] { font-size: 18px; }
body[data-width="wide"] { --article-width: 1200px; }
body[data-color="dark"] {
  --bg: #101418;
  --text: #eaecf0;
  --muted: #a2a9b1;
  --link: #88a3e8;
  --link-visited: #b19cd9;
  --border: #54595d;
  --border-light: #3a4045;
  --panel: #1c2126;
  --header-border: #3a4045;
  --code-bg: #1c2126;
}
@media (prefers-color-scheme: dark) {
  body[data-color="automatic"] {
    --bg: #101418;
    --text: #eaecf0;
    --muted: #a2a9b1;
    --link: #88a3e8;
    --link-visited: #b19cd9;
    --border: #54595d;
    --border-light: #3a4045;
    --panel: #1c2126;
    --header-border: #3a4045;
    --code-bg: #1c2126;
  }
}
* { box-sizing: border-box; }
html { font-size: var(--font-size); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: sans-serif;
  line-height: 1.6;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
a:visited { color: var(--link-visited); }
img { max-width: 100%; height: auto; }

/* Top bar */
.topbar { border-bottom: 1px solid var(--header-border); background: var(--bg); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1400px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.menu-btn { display: none; background: none; border: 1px solid var(--border-light); border-radius: 4px; font-size: 18px; padding: 2px 10px; cursor: pointer; color: var(--text); }
.appearance-btn { display: none; background: none; border: 1px solid var(--border-light); border-radius: 4px; font-size: 14px; padding: 5px 12px; cursor: pointer; color: var(--text); margin-left: auto; }
.wordmark { display: flex; align-items: center; flex: none; }
.wordmark:hover { text-decoration: none; }
.wordmark-logo { height: 36px; width: auto; display: block; }
/* dark.svg is the black logo, for light backgrounds; light.svg is
   the white logo, for dark backgrounds. Which one shows follows
   the Color setting, and the OS under Automatic. */
.logo-light { display: none; }
body[data-color="dark"] .logo-dark { display: none; }
body[data-color="dark"] .logo-light { display: block; }
@media (prefers-color-scheme: dark) {
  body[data-color="automatic"] .logo-dark { display: none; }
  body[data-color="automatic"] .logo-light { display: block; }
}
.search { flex: 1; display: flex; max-width: 520px; position: relative; min-width: 0; }
.search input { flex: 1; min-width: 0; padding: 7px 10px; border: 1px solid var(--border); border-right: none; border-radius: 2px 0 0 2px; font-size: 15px; background: var(--bg); color: var(--text); }
.search button { padding: 7px 14px; border: 1px solid var(--border); background: var(--panel); color: var(--text); cursor: pointer; border-radius: 0 2px 2px 0; }
.search-results { position: absolute; top: 100%; left: 0; right: 0; background: var(--bg); border: 1px solid var(--border); border-radius: 0 0 4px 4px; box-shadow: 0 4px 12px rgba(0,0,0,.2); z-index: 30; }
.search-results a { display: block; padding: 8px 12px; color: var(--text); }
.search-results a:hover { background: var(--panel); text-decoration: none; }
.search-results .result-path { color: var(--muted); font-size: 13px; }

/* Three-column page, article centred. The max-width is derived
   from the article width, so the three tracks (200px + article +
   200px, plus gaps and padding) can never add up wider than the
   page itself - with Width: Wide the old fixed 1500px cap was
   narrower than the tracks, and the grid spilled over both sides. */
.page { display: grid; grid-template-columns: 200px minmax(0, var(--article-width)) 200px; justify-content: center; gap: 32px; max-width: calc(var(--article-width) + 504px); margin: 0 auto; padding: 24px 20px 60px; }
.contents-col, .appearance-col { font-size: 14px; }
.contents-box, .appearance-box { position: sticky; top: 70px; }
.contents-head, .appearance-head { border-bottom: 1px solid var(--border-light); padding-bottom: 6px; margin-bottom: 10px; font-weight: bold; }
.contents-box ul { list-style: none; margin: 0; padding: 0; }
.contents-box li { margin: 4px 0; }
.contents-box li.level-3 { padding-left: 16px; }
.contents-box a { color: var(--link); }
.appearance-group { border-bottom: 1px solid var(--border-light); padding: 10px 0; }
.appearance-group h3 { margin: 0 0 6px; font-size: 14px; }
.appearance-group label { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
/* Custom radios: the native ones render bright white in dark mode.
   The input itself is the circle, drawn from the theme variables,
   so checked and unchecked both stay muted in light and dark. The
   input names/values are unchanged, so the JS handlers still work. */
.appearance-group input[type="radio"] {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  width: 16px;
  height: 16px;
  margin: 0;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  display: inline-grid;
  place-content: center;
  cursor: pointer;
}
.appearance-group input[type="radio"]:checked { border-color: var(--link); }
.appearance-group input[type="radio"]:checked::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--link);
}
.appearance-group input[type="radio"]:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.appearance-note { color: var(--muted); font-size: 13px; }

/* Article */
.article-col { min-width: 0; }
.breadcrumb { color: var(--muted); font-size: 13px; margin-bottom: 8px; word-break: break-all; }
.article-title { font-family: Georgia, "Times New Roman", serif; font-weight: normal; font-size: 32px; line-height: 1.2; margin: 0 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.tabs { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; border-bottom: 1px solid var(--border-light); margin-bottom: 16px; font-size: 14px; }
.tabs-left, .tabs-right { display: flex; gap: 16px; }
.tab { padding: 6px 2px; color: var(--link); }
.tab.active { color: var(--text); border-bottom: 2px solid var(--text); }
.article-body h2 { font-family: Georgia, "Times New Roman", serif; font-weight: normal; font-size: 24px; border-bottom: 1px solid var(--border-light); padding-bottom: 4px; margin: 28px 0 12px; }
.article-body h3 { font-size: 18px; margin: 22px 0 8px; }
.article-body p { margin: 0 0 12px; }
.article-body ul, .article-body ol { margin: 0 0 12px; padding-left: 28px; }
.article-body li { margin: 3px 0; }
.article-body blockquote { border-left: 3px solid var(--border); margin: 12px 0; padding: 4px 16px; color: var(--muted); }
.article-body code { background: var(--code-bg); border: 1px solid var(--border-light); border-radius: 3px; padding: 1px 5px; font-size: 14px; }
.article-body pre { background: var(--code-bg); border: 1px solid var(--border-light); border-radius: 3px; padding: 12px; overflow-x: auto; }
.article-body pre code { border: none; padding: 0; background: none; }
.article-body hr { border: none; border-top: 1px solid var(--border-light); margin: 24px 0; }
.article-body table { border-collapse: collapse; margin: 12px 0 18px; width: 100%; font-size: 14px; }
.article-body th, .article-body td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.article-body th { background: var(--panel); }
.article-body figure { margin: 12px 0 18px; }
.article-body figure img { cursor: zoom-in; display: block; max-width: 100%; height: auto; }
.article-body figcaption { color: var(--muted); font-size: 13px; margin-top: 6px; }

/* Infobox. The selector must beat `.article-body table` (width: 100%),
   which otherwise wins on specificity and stretches the infobox to
   the full article width, with the image huge and centred - the
   "big image" bug. A plain `.infobox` selector loses to it. */
.article-body table.infobox { float: right; clear: right; width: 300px; max-width: 100%; margin: 0 0 16px 20px; border: 1px solid var(--border); background: var(--panel); font-size: 14px; }
.infobox caption, .infobox-title { font-weight: bold; font-size: 17px; padding: 8px 10px; text-align: center; border-bottom: 1px solid var(--border-light); }
.infobox th, .infobox td { border: none; padding: 5px 10px; vertical-align: top; }
.infobox th { width: 40%; color: var(--muted); font-weight: normal; }
.infobox img { width: 100%; display: block; }
.infobox .infobox-image { padding: 0; }
.infobox .infobox-image img { cursor: zoom-in; }
.badge { display: inline-block; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 1px 10px; font-size: 13px; margin: 2px 2px 2px 0; }
.article-foot { border-top: 1px solid var(--border-light); margin-top: 32px; padding-top: 12px; color: var(--muted); font-size: 13px; }

/* Media viewer */
/* See-through on purpose: the page shows dimly behind the image. */
.media-viewer { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 100; display: flex; align-items: center; justify-content: center; }
.media-viewer[hidden] { display: none; }
.viewer-figure { max-width: 90vw; max-height: 90vh; margin: 0; text-align: center; }
.viewer-figure img { max-width: 90vw; max-height: 78vh; object-fit: contain; background: #000; }
.viewer-figure figcaption { color: #fff; margin-top: 10px; }
.viewer-info { color: #a2a9b1; font-size: 13px; margin-top: 4px; }
.viewer-close { position: absolute; top: 12px; right: 20px; background: none; border: none; color: #fff; font-size: 40px; cursor: pointer; }
.viewer-nav { position: absolute; top: 50%; transform: translateY(-50%); background: none; border: none; color: #fff; font-size: 48px; cursor: pointer; padding: 10px; }
.viewer-prev { left: 12px; }
.viewer-next { right: 12px; }

/* Cards on the All versions index */
.version-cards { display: grid; gap: 12px; }
.version-card { border: 1px solid var(--border); padding: 12px 14px; }
.version-card h3 { margin: 0 0 4px; }

@media (max-width: 1100px) {
  /* One column that fills the container exactly. The old
     minmax(0, var(--article-width)) capped the track at an
     absolute 960/1200px instead of the viewport, which could
     leave the grid wider than the window. */
  .page { grid-template-columns: minmax(0, 1fr); }
  .contents-col, .appearance-col { display: none; }
  .menu-btn, .appearance-btn { display: inline-block; }
  /* The toggled Contents is a panel above the article, not an
     unstyled box inside the article flow. */
  /* The toggled panels float over the page, they are not stuck at
     the top of it: opening one while scrolled down still shows it,
     just under the topbar, instead of sitting above the article
     where you cannot see it. Fixed, not sticky: sticky only works
     for Contents, which sits first in the page; Appearance sits
     after the article, so sticky would leave it below the article
     until you scroll to the bottom. */
  body.show-contents .contents-col { display: block; position: fixed; top: 70px; left: 16px; right: 16px; z-index: 30; max-height: calc(100vh - 90px); overflow-y: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 12px 16px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
  body.show-contents .contents-box { position: static; }
  /* Same floating treatment for Appearance. */
  body.show-appearance .appearance-col { display: block; position: fixed; top: 70px; left: 16px; right: 16px; z-index: 30; max-height: calc(100vh - 90px); overflow-y: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 12px 16px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
  body.show-appearance .appearance-box { position: static; }
}
@media (max-width: 640px) {
  .article-title { font-size: 26px; }
  /* Same specificity trap as the desktop infobox rule: a plain
     .infobox loses to .article-body table.infobox, so the float
     survived on mobile and the lead text squeezed into a narrow
     column beside it. On mobile the infobox is full width. */
  .article-body table.infobox { float: none; width: 100%; margin: 0 0 16px; }
  /* Below 640px the topbar wraps to two rows, so the floating
     panels sit lower to clear the search row. */
  body.show-contents .contents-col, body.show-appearance .appearance-col { top: 120px; max-height: calc(100vh - 140px); }
  /* Image viewer on mobile: the image uses the full width instead
     of a small 90vw box, and the close / prev / next buttons shrink
     so they do not crowd it. The shadow keeps them readable where
     they sit on top of the image. */
  .viewer-figure { max-width: 100vw; }
  .viewer-figure img { max-width: 100vw; max-height: 82vh; }
  .viewer-close { top: 8px; right: 12px; font-size: 32px; text-shadow: 0 0 8px rgba(0,0,0,.8); }
  /* The arrows sit below the image, not over it: pinned to the
     bottom corners of the screen. The transform is reset because
     the desktop rule centres them vertically with translateY. */
  .viewer-nav { top: auto; bottom: 20px; transform: none; font-size: 36px; padding: 8px; text-shadow: 0 0 8px rgba(0,0,0,.8); }
  .viewer-prev { left: 20px; }
  .viewer-next { right: 20px; }
  .topbar-inner { flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
}
