/* ---------- tokens ---------- */
:root {
  --bg: #fbfaf7;
  --bg-raised: #ffffff;
  --bg-sunk: #f2f0ea;
  --text: #1f1d1a;
  --text-2: #5b5750;
  --text-3: #8a857c;
  --rule: #e4e0d7;
  --link: #2a5db0;
  --link-hover: #173f80;
  --accent: #b5562b;
  --mark: rgba(181, 86, 43, .14);
  --shadow: 0 1px 2px rgba(30,25,15,.06), 0 8px 28px rgba(30,25,15,.10);
  --img-filter: none;

  --serif: "Source Serif 4", "Noto Serif SC", Georgia, serif;
  --sans: Inter, -apple-system, "PingFang SC", system-ui, sans-serif;
  --body-font: var(--serif);
  --fs: 19px;
  --measure: 680px;
  --rail: 280px;
  --toc-w: 230px;
  color-scheme: light;
}
:root[data-theme="sepia"] {
  --bg: #f4ecd8; --bg-raised: #fbf5e6; --bg-sunk: #ebe1c8;
  --text: #3b2f22; --text-2: #6b5a45; --text-3: #95826a; --rule: #dccfb2;
  --link: #8a4b14; --link-hover: #5e300a; --accent: #9a3d1a; --mark: rgba(154,61,26,.15);
}
:root[data-theme="dark"] {
  --bg: #161615; --bg-raised: #1f1f1d; --bg-sunk: #121211;
  --text: #e7e4dd; --text-2: #aaa59b; --text-3: #7c776e; --rule: #2e2d2a;
  --link: #8db4f2; --link-hover: #b9d1fa; --accent: #e08a5f; --mark: rgba(224,138,95,.18);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.5);
  --img-filter: brightness(.88);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #161615; --bg-raised: #1f1f1d; --bg-sunk: #121211;
    --text: #e7e4dd; --text-2: #aaa59b; --text-3: #7c776e; --rule: #2e2d2a;
    --link: #8db4f2; --link-hover: #b9d1fa; --accent: #e08a5f; --mark: rgba(224,138,95,.18);
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.5);
    --img-filter: brightness(.88);
    color-scheme: dark;
  }
}
:root[data-font="sans"] { --body-font: var(--sans); }
:root[data-width="narrow"] { --measure: 600px; }
:root[data-width="wide"] { --measure: 780px; }

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { scroll-padding-top: 76px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 15px;
  -webkit-font-smoothing: antialiased;
  transition: background .2s, color .2s;
}
button { font: inherit; color: inherit; }
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); }

#progress {
  position: fixed; top: 0; left: 0; height: 2px; width: 0;
  background: var(--accent); z-index: 60; transition: width .1s linear;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  height: 58px; padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.topbar.scrolled { border-bottom-color: var(--rule); }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 600; letter-spacing: -.01em; }
.brand svg { color: var(--accent); }
.brand:hover { color: var(--text); }

.search { position: relative; flex: 1; max-width: 520px; margin: 0 auto; display: flex; align-items: center; }
.search > svg { position: absolute; left: 12px; color: var(--text-3); pointer-events: none; }
.search input {
  width: 100%; height: 38px; padding: 0 40px 0 36px;
  border: 1px solid var(--rule); border-radius: 10px;
  background: var(--bg-raised); color: var(--text); font: inherit; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--mark); }
.search input::-webkit-search-cancel-button { display: none; }
.search kbd {
  position: absolute; right: 10px; font: 500 11px var(--sans); color: var(--text-3);
  border: 1px solid var(--rule); border-radius: 5px; padding: 1px 6px;
}
#suggest {
  position: absolute; top: 44px; left: 0; right: 0; margin: 0; padding: 6px; list-style: none;
  background: var(--bg-raised); border: 1px solid var(--rule); border-radius: 12px; box-shadow: var(--shadow);
}
#suggest li { display: flex; gap: 12px; align-items: center; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
#suggest li[aria-selected="true"], #suggest li:hover { background: var(--bg-sunk); }
#suggest .thumb { width: 36px; height: 36px; border-radius: 6px; background: var(--bg-sunk) center/cover; flex: none; }
#suggest .t { font-weight: 500; }
#suggest .d { color: var(--text-3); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#suggest .meta { min-width: 0; }

.tools { display: flex; gap: 6px; }
.tbtn {
  display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px;
  border: 1px solid transparent; border-radius: 9px; background: none; cursor: pointer; color: var(--text-2);
  font-size: 13px; font-weight: 500;
}
.tbtn:hover, .tbtn.on { background: var(--bg-sunk); color: var(--text); }
.aa { font-family: var(--serif); font-size: 17px; font-weight: 600; }

/* ---------- popovers ---------- */
.pop {
  position: fixed; top: 62px; right: 16px; z-index: 55; width: 300px;
  background: var(--bg-raised); border: 1px solid var(--rule); border-radius: 14px; box-shadow: var(--shadow);
  padding: 10px;
}
#langFilter {
  width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--rule); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit; outline: none; margin-bottom: 6px;
}
#langList { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow: auto; }
#langList li a { display: flex; justify-content: space-between; gap: 10px; padding: 7px 8px; border-radius: 7px; color: var(--text); }
#langList li a:hover { background: var(--bg-sunk); }
#langList li a span:last-child { color: var(--text-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
#langList .sep { height: 1px; background: var(--rule); margin: 6px 4px; }

.pop[hidden], .toc-fab[hidden], #suggest[hidden], .card[hidden] { display: none !important; }
.settings { width: 320px; padding: 14px; display: grid; gap: 14px; }
.settings .row { display: grid; gap: 7px; }
.settings .row > span { font-size: 12px; color: var(--text-3); font-weight: 500; text-transform: uppercase; letter-spacing: .06em; }
.seg { display: flex; background: var(--bg-sunk); border-radius: 9px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 6px 0; border-radius: 7px; cursor: pointer; font-size: 13px; color: var(--text-2); }
.seg button.on { background: var(--bg-raised); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.stepper { display: flex; align-items: center; background: var(--bg-sunk); border-radius: 9px; padding: 3px; }
.stepper button { flex: 1; border: 0; background: none; padding: 6px 0; border-radius: 7px; cursor: pointer; }
.stepper button:hover { background: var(--bg-raised); }
.stepper output { flex: 1; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- home ---------- */
.home { max-width: 640px; margin: 14vh auto 0; padding: 0 20px; text-align: center; }
.home h1 { font: 600 44px/1.1 var(--serif); letter-spacing: -.02em; margin: 0 0 10px; }
.home p { color: var(--text-2); margin: 0 0 32px; font-size: 16px; }
.home .picks { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.home .picks a {
  padding: 7px 14px; border: 1px solid var(--rule); border-radius: 999px; color: var(--text-2); font-size: 14px;
  background: var(--bg-raised);
}
.home .picks a:hover { border-color: var(--accent); color: var(--text); }

/* ---------- article layout ---------- */
.page {
  display: grid;
  grid-template-columns: var(--toc-w) minmax(0, 1fr);
  gap: 56px;
  max-width: calc(var(--toc-w) + 56px + var(--measure) + 40px + var(--rail) + 40px);
  margin: 0 auto; padding: 36px 20px 120px;
}
.article { max-width: calc(var(--measure) + 40px + var(--rail)); min-width: 0; }
.article > * { max-width: var(--measure); }
.article .wide-ok { max-width: none; }

/* TOC */
.toc { position: sticky; top: 82px; align-self: start; max-height: calc(100vh - 100px); overflow: auto; padding-right: 6px; font-size: 13.5px; }
.toc h4 { margin: 0 0 10px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc a {
  display: block; padding: 5px 0 5px 12px; color: var(--text-2); line-height: 1.35;
  border-left: 2px solid var(--rule); transition: color .15s, border-color .15s;
}
.toc ol ol a { padding-left: 24px; font-size: 13px; color: var(--text-3); }
.toc a:hover { color: var(--text); }
.toc a.active { color: var(--text); border-left-color: var(--accent); font-weight: 500; }
.toc ol ol { display: none; }
.toc li.open > ol { display: block; }
.toc .top { margin-bottom: 8px; }
.toc .top a { border-left-color: transparent; padding-left: 12px; font-weight: 500; color: var(--text); }

/* Header */
.hgroup { margin-bottom: 28px; padding-bottom: 22px; border-bottom: 1px solid var(--rule); }
.hgroup h1 { font: 700 46px/1.08 var(--body-font); letter-spacing: -.022em; margin: 0 0 10px; text-wrap: balance; }
.hgroup .desc { font: italic 400 19px/1.4 var(--serif); color: var(--text-2); margin: 0 0 14px; }
.hgroup .meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--text-3); }
.hgroup .meta a { color: var(--text-3); }
.hgroup .meta a:hover { color: var(--link); }

/* ---------- prose ---------- */
.prose { font: 400 var(--fs)/1.68 var(--body-font); font-optical-sizing: auto; color: var(--text); hanging-punctuation: first; }
:root[lang^="zh"] .prose, :root[lang^="ja"] .prose { line-height: 1.85; }
.prose p { margin: 0 0 1.05em; text-wrap: pretty; }
.prose section[data-mw-section-id="0"] > p:first-of-type { font-size: 1.07em; }
.prose h2 {
  font: 600 1.55em/1.2 var(--body-font); letter-spacing: -.015em;
  margin: 2.2em 0 .7em; padding-top: .2em; clear: none;
}
.prose h3 { font: 600 1.18em/1.3 var(--body-font); margin: 1.8em 0 .5em; }
.prose h4 { font: 600 1em/1.35 var(--sans); margin: 1.6em 0 .4em; letter-spacing: .01em; }
.prose h2, .prose h3 { max-width: var(--measure); }
.prose h2 a.anchor, .prose h3 a.anchor { opacity: 0; margin-left: .35em; color: var(--text-3); font-weight: 400; transition: opacity .15s; }
.prose h2:hover a.anchor, .prose h3:hover a.anchor { opacity: 1; }
.prose ul, .prose ol { padding-left: 1.3em; margin: 0 0 1.05em; max-width: var(--measure); }
.prose li { margin: .25em 0; }
.prose a { color: var(--link); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--link) 25%, transparent); text-underline-offset: .18em; text-decoration-thickness: 1px; }
.prose a:hover { text-decoration-color: currentColor; }
.prose a.new { color: inherit; text-decoration: none; cursor: default; }
.prose a.external::after { content: "↗"; font-size: .7em; margin-left: .1em; vertical-align: super; opacity: .6; }
.prose blockquote, .prose .templatequote {
  margin: 1.4em 0; padding: .1em 0 .1em 1.2em; border-left: 3px solid var(--accent); color: var(--text-2); font-style: italic;
  max-width: var(--measure);
}
.prose .hatnote { font: italic 400 .82em/1.5 var(--sans); color: var(--text-3); margin: 0 0 .6em; padding: 0; }
.prose .hatnote a { color: var(--text-2); }
.prose sup.reference { font: 500 .62em var(--sans); line-height: 0; margin-left: 1px; }
.prose sup.reference a { text-decoration: none; color: var(--accent); padding: 0 1px; }
.prose sup.reference .cite-bracket { display: none; }
.prose code, .prose pre { font-size: .82em; background: var(--bg-sunk); border-radius: 4px; }
.prose pre { padding: 12px 14px; overflow-x: auto; }
.prose img { filter: var(--img-filter); }
:root[data-theme="dark"] .prose .mwe-math-fallback-image-inline,
:root[data-theme="dark"] .prose .mwe-math-fallback-image-display { filter: invert(.9); }
.prose dl dt { font-weight: 600; }
.prose dd { margin-left: 1.2em; }

/* tables */
.table-wrap { overflow-x: auto; margin: 1.4em 0; max-width: var(--measure); }
.prose table.wikitable, .prose .table-wrap table {
  border-collapse: collapse; font: 400 .78em/1.45 var(--sans); min-width: 60%;
}
.prose .table-wrap th, .prose .table-wrap td { border-bottom: 1px solid var(--rule); padding: 7px 10px; text-align: left; vertical-align: top; }
.prose .table-wrap th { font-weight: 600; background: var(--bg-sunk); }
.prose .table-wrap caption { text-align: left; font-weight: 600; padding-bottom: 6px; }

/* figures & infobox: in-flow by default */
.prose .thumbfig, .prose aside.infobox-card {
  margin: 1.6em 0; max-width: var(--measure);
}
.prose .thumbfig { cursor: zoom-in; }
.prose .thumbfig img { display: block; max-width: 100%; height: auto; border-radius: 6px; background: var(--bg-sunk); }
.prose .thumbfig figcaption, .prose .gallery .gallerytext {
  font: 400 13px/1.5 var(--sans); color: var(--text-2); margin-top: 8px;
}
.prose .thumbfig figcaption a { color: var(--text-2); }
.prose ul.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; list-style: none; padding: 0; }
.prose ul.gallery li { margin: 0; }
.prose ul.gallery img { width: 100%; height: auto; border-radius: 6px; }
.prose figure[typeof~="mw:File"]:not(.thumb) img, .prose span[typeof~="mw:File"] img { max-width: 100%; height: auto; }

/* infobox card */
.infobox-card {
  background: var(--bg-raised); border: 1px solid var(--rule); border-radius: 12px; overflow: hidden;
  font: 400 13px/1.45 var(--sans);
}
.infobox-card table { width: 100% !important; border-collapse: collapse; margin: 0 !important; float: none !important; background: none !important; font-size: inherit !important; color: inherit; border: 0 !important; }
.infobox-card th, .infobox-card td { padding: 6px 14px; vertical-align: top; text-align: left; background: none !important; border: 0 !important; color: inherit !important; }
.infobox-card .infobox-above { font: 600 17px/1.3 var(--serif); padding: 14px 14px 8px; text-align: left; }
.infobox-card .infobox-image, .infobox-card .infobox-image td { padding: 0 !important; text-align: center !important; }
.infobox-card .infobox-image img { width: 100%; height: auto; display: block; filter: var(--img-filter); }
.infobox-card .infobox-caption { font-size: 12px; color: var(--text-3); padding: 8px 14px 4px; text-align: left !important; }
.infobox-card .infobox-header { font: 600 11px var(--sans); letter-spacing: .07em; text-transform: uppercase; color: var(--text-3) !important; padding-top: 14px; border-top: 1px solid var(--rule) !important; }
.infobox-card .infobox-label { color: var(--text-3) !important; font-weight: 500; width: 36%; }
.infobox-card .infobox-data { color: var(--text) !important; }
.infobox-card a { text-decoration: none; }
.infobox-card ul, .infobox-card ol { padding-left: 0; list-style: none; margin: 0; }
.infobox-card .infobox-below { color: var(--text-3); }
.infobox-card tr:last-child th, .infobox-card tr:last-child td { padding-bottom: 14px; }
.infobox-card .more {
  display: none; width: 100%; border: 0; border-top: 1px solid var(--rule); background: var(--bg-sunk);
  padding: 9px; font: 500 13px var(--sans); color: var(--text-2); cursor: pointer;
}
.infobox-card.clip .more { display: block; }
.infobox-card.clip .ib-body { max-height: 380px; overflow: hidden; -webkit-mask: linear-gradient(#000 75%, transparent); mask: linear-gradient(#000 75%, transparent); }

/* references */
.refs-block { position: relative; }
.prose ol.mw-references, .prose ol.references {
  font: 400 13.5px/1.55 var(--sans); color: var(--text-2); padding-left: 2.2em; columns: 2 300px; column-gap: 32px;
}
.prose ol.mw-references li { break-inside: avoid; margin: 0 0 .55em; }
.prose ol.mw-references li:target { background: var(--mark); border-radius: 4px; }
.prose .mw-cite-backlink { margin-right: 4px; }
.prose .mw-cite-backlink a { text-decoration: none; color: var(--text-3); }
.prose ol.mw-references a { word-break: break-word; }
.refs-block.clip ol { max-height: 260px; overflow: hidden; -webkit-mask: linear-gradient(#000 60%, transparent); mask: linear-gradient(#000 60%, transparent); }
.refs-toggle {
  display: inline-flex; align-items: center; gap: 6px; margin: 4px 0 1.2em; padding: 7px 14px; border-radius: 999px;
  border: 1px solid var(--rule); background: var(--bg-raised); font: 500 13px var(--sans); color: var(--text-2); cursor: pointer;
}
.refs-toggle:hover { border-color: var(--accent); color: var(--text); }
.prose .citation { font-style: normal; }
.prose .reference-accessdate { color: var(--text-3); }

/* attribution */
.attrib { margin-top: 64px; padding-top: 20px; border-top: 1px solid var(--rule); font-size: 13px; line-height: 1.6; color: var(--text-3); max-width: var(--measure); }
.attrib a { color: var(--text-2); text-decoration: underline; text-decoration-color: var(--rule); }

/* ---------- wide: right margin column ---------- */
@media (min-width: 1280px) {
  :root:not([data-margin="off"]) .article { padding-right: calc(40px + var(--rail)); max-width: calc(var(--measure) + 40px + var(--rail)); }
  :root:not([data-margin="off"]) .prose .thumbfig,
  :root:not([data-margin="off"]) .prose aside.infobox-card {
    float: right; clear: right; width: var(--rail);
    margin: .3em calc(-40px - var(--rail)) 1.4em 0;
  }
  :root:not([data-margin="off"]) .prose aside.infobox-card { margin-top: 0; }
  :root:not([data-margin="off"]) .prose .thumbfig figcaption { font-size: 12.5px; }
  :root:not([data-margin="off"]) .infobox-card.clip .ib-body { max-height: none; -webkit-mask: none; mask: none; }
  :root:not([data-margin="off"]) .infobox-card .more { display: none; }
  :root:not([data-margin="off"]) .prose .table-wrap.big { max-width: none; clear: right; }
}
/* medium, or margin off: classic float inside column */
@media (min-width: 760px) {
  :root[data-margin="off"] .prose .thumbfig, :root[data-margin="off"] .prose aside.infobox-card {
    float: right; clear: right; width: 260px; margin: .3em 0 1.2em 28px;
  }
}
@media (min-width: 760px) and (max-width: 1279px) {
  .prose .thumbfig, .prose aside.infobox-card { float: right; clear: right; width: 260px; margin: .3em 0 1.2em 28px; }
}
@media (max-width: 1080px) {
  .page { grid-template-columns: minmax(0, 1fr); gap: 0; max-width: calc(var(--measure) + 40px); }
  .toc { display: none; }
  .toc.sheet {
    display: block; position: fixed; inset: auto 0 0 0; top: auto; max-height: 70vh; z-index: 58;
    background: var(--bg-raised); border-top: 1px solid var(--rule); border-radius: 18px 18px 0 0;
    padding: 18px 20px 30px; box-shadow: var(--shadow);
  }
  .toc.sheet ol ol { display: block; }
  .toc-fab:not([hidden]) { display: flex; }
}
@media (min-width: 1081px) { .toc-fab { display: none !important; } }
@media (max-width: 1080px) and (min-width: 760px) {
  .page { max-width: calc(var(--measure) + 40px); }
}
@media (max-width: 759px) {
  :root { --fs: 17px; }
  .topbar { padding: 0 12px; gap: 10px; }
  .brand span { display: none; }
  .search kbd { display: none; }
  .page { padding: 22px 16px 100px; }
  .hgroup h1 { font-size: 34px; }
  .hgroup .desc { font-size: 17px; }
  .prose ol.mw-references { columns: 1; }
  .pop { left: 12px; right: 12px; width: auto; }
  .infobox-card.clip .ib-body { max-height: 300px; }
}

.toc-fab {
  position: fixed; right: 16px; bottom: 18px; z-index: 57; display: none; align-items: center; gap: 8px;
  height: 42px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--rule); background: var(--bg-raised);
  box-shadow: var(--shadow); font-weight: 500; font-size: 14px; cursor: pointer;
}
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 57; }

/* ---------- hover card ---------- */
.card {
  position: fixed; z-index: 70; width: 340px; max-width: calc(100vw - 24px);
  background: var(--bg-raised); border: 1px solid var(--rule); border-radius: 14px; box-shadow: var(--shadow);
  overflow: hidden; font: 400 14px/1.55 var(--sans); color: var(--text);
  animation: pop .14s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.card .img { height: 150px; background: var(--bg-sunk) center 25%/cover; filter: var(--img-filter); }
.card .body { padding: 14px 16px 12px; }
.card h5 { margin: 0 0 2px; font: 600 17px/1.3 var(--serif); }
.card .d { color: var(--text-3); font-size: 12.5px; margin-bottom: 8px; }
.card p { margin: 0; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.card .foot { display: flex; justify-content: space-between; padding: 8px 16px 12px; font-size: 12.5px; color: var(--text-3); }
.card.ref { width: 380px; }
.card.ref .body { font-size: 13px; color: var(--text-2); max-height: 260px; overflow: auto; }
.card.ref .label { font: 600 11px var(--sans); letter-spacing: .07em; text-transform: uppercase; color: var(--text-3); margin-bottom: 6px; }
.card .skel { height: 12px; border-radius: 4px; background: var(--bg-sunk); margin: 8px 0; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .5; } }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 80; background: rgba(12,11,10,.92);
  display: flex; align-items: center; justify-content: center; padding: 40px; cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox figure { margin: 0; max-width: min(1200px, 100%); max-height: 100%; display: flex; flex-direction: column; align-items: center; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 160px); object-fit: contain; border-radius: 4px; background: #222; }
.lightbox figcaption { color: #d8d4cc; font: 400 14px/1.55 var(--sans); max-width: 720px; margin-top: 14px; text-align: center; }
.lightbox figcaption a { color: #9fc0f5; }
.lb-close { position: absolute; top: 14px; right: 18px; border: 0; background: none; color: #fff; font-size: 32px; cursor: pointer; }

/* ---------- loading / error ---------- */
.loading { max-width: var(--measure); margin: 60px auto; padding: 0 20px; }
.loading .skel { height: 14px; border-radius: 5px; background: var(--bg-sunk); margin: 14px 0; animation: pulse .9s infinite alternate; }
.loading .skel.h { height: 40px; width: 60%; margin-bottom: 30px; }
.error { max-width: 560px; margin: 16vh auto; text-align: center; color: var(--text-2); padding: 0 20px; }
.error h2 { font: 600 28px var(--serif); color: var(--text); }

/* ---------- stacked panes ---------- */
:root { --pane-w: 640px; --spine: 40px; }
body.stacked { overflow: hidden; }
body.stacked .topbar { border-bottom-color: var(--rule); }
body.stacked #progress { display: none; }
.stack {
  display: flex; height: calc(100vh - 58px); height: calc(100dvh - 58px);
  overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain;
  background: var(--bg-sunk);
}
.stack::after { content: ""; flex: none; width: 1px; }
.pane {
  flex: none; width: min(var(--pane-w), calc(100vw - 2 * var(--spine)));
  height: 100%; position: sticky; left: calc(var(--i) * var(--spine));
  background: var(--bg); border-left: 1px solid var(--rule);
  box-shadow: -6px 0 18px rgba(30, 25, 15, .06);
  animation: slidein .22s ease-out;
}
.pane:first-child { border-left: 0; box-shadow: none; }
@keyframes slidein { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
.pane-scroll {
  position: relative; height: 100%; overflow-y: auto; overscroll-behavior: contain;
  padding: 18px 36px 96px calc(var(--spine) + 12px);
  transition: opacity .18s;
}
.pane .loading { margin: 24px 0; padding: 0; }
.pane .error { margin: 18vh 0; }
.pane-bar { display: flex; justify-content: flex-end; height: 28px; margin-bottom: 4px; }
.pane-close {
  width: 28px; height: 28px; border: 0; border-radius: 7px; background: none; cursor: pointer;
  font-size: 20px; line-height: 1; color: var(--text-3);
}
.pane-close:hover { background: var(--bg-sunk); color: var(--text); }
.pane .hgroup { margin-bottom: 22px; padding-bottom: 16px; }
.pane .hgroup h1 { font-size: 34px; }
.pane .hgroup .desc { font-size: 17px; }
.pane .prose { font-size: calc(var(--fs) * .9); }
.pane .prose h2 { font-size: 1.4em; }
.pane .attrib { margin-top: 48px; }

/* spine: the strip of a pane that stays visible once the next pane slides over it */
.spine {
  position: absolute; top: 0; bottom: 0; left: 0; width: var(--spine); z-index: 2;
  border: 0; padding: 18px 0 0; background: none; cursor: pointer; color: var(--text-2);
  display: flex; justify-content: center; opacity: 0; pointer-events: none; transition: opacity .18s;
}
.spine span {
  writing-mode: vertical-rl; font: 600 13px/1 var(--sans); letter-spacing: .02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-height: calc(100% - 40px);
}
.pane.covered .spine { opacity: 1; pointer-events: auto; }
.pane.covered .spine:hover { background: var(--bg-sunk); color: var(--text); }
.pane.covered .pane-scroll { opacity: 0; pointer-events: none; }

/* inside a pane there is no margin rail: float figures inside the column */
:root .stack .pane .prose .thumbfig,
:root .stack .pane .prose aside.infobox-card {
  float: right; clear: right; width: 230px; margin: .3em 0 1.1em 24px;
}
:root .stack .pane .prose .thumbfig figcaption { font-size: 12px; }
:root .stack .pane .infobox-card.clip .ib-body { max-height: 360px; -webkit-mask: linear-gradient(#000 75%, transparent); mask: linear-gradient(#000 75%, transparent); }
:root .stack .pane .infobox-card.clip .more { display: block; }
:root .stack .pane .prose .table-wrap.big { clear: right; }
.prose a.opened {
  background: var(--mark); color: var(--text); border-radius: 3px;
  text-decoration: none; box-shadow: 0 0 0 2px var(--mark);
}
@media (max-width: 1080px) { :root { --pane-w: 560px; } }

/* ---------- TOC v2: chevrons, per-section minutes, read state, hide ---------- */
.toc-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.toc-head h4 { margin: 0; }
.toc-hide { border: 0; background: none; color: var(--text-3); width: 26px; height: 26px; border-radius: 6px; cursor: pointer; display: grid; place-items: center; }
.toc-hide:hover { background: var(--bg-sunk); color: var(--text); }
.toc .row { display: flex; align-items: center; position: relative; }
.toc .row a { flex: 1; min-width: 0; }
.toc li.has-sub > .row > a { padding-left: 12px; }
.toc .chev {
  position: absolute; left: -16px; width: 16px; height: 22px; border: 0; background: none; cursor: pointer; padding: 0;
  color: var(--text-3); opacity: .55;
}
.toc .chev::before { content: "›"; display: inline-block; font-size: 15px; transition: transform .15s; }
.toc .chev:hover { opacity: 1; }
.toc li.open > .row .chev::before, .toc li.user-open > .row .chev::before { transform: rotate(90deg); }
.toc li.user-closed > .row .chev::before { transform: none; }
.toc li.user-open > ol { display: block; }
.toc li.user-closed > ol { display: none !important; }
.toc .tm { flex: none; font-size: 11px; color: var(--text-3); opacity: 0; padding-left: 8px; font-variant-numeric: tabular-nums; transition: opacity .15s; }
.toc:hover .tm { opacity: 1; }
.toc a.read { color: var(--text-3); }
.toc a.read::after { content: " ✓"; font-size: 10px; opacity: .6; }
.toc ol ol a.read::after { content: ""; }
.toc { padding-left: 16px; margin-left: -16px; }

.toc-show {
  position: fixed; left: 16px; top: 76px; z-index: 40; display: none; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px; border: 1px solid var(--rule); border-radius: 999px; background: var(--bg-raised);
  color: var(--text-2); font: 500 13px var(--sans); cursor: pointer;
}
.toc-show:hover { color: var(--text); border-color: var(--accent); }
@media (min-width: 1081px) {
  :root[data-toc="hidden"] .toc { display: none; }
  :root[data-toc="hidden"] .page { grid-template-columns: minmax(0, 1fr); max-width: calc(var(--measure) + 40px + var(--rail) + 40px); }
  :root[data-toc="hidden"] body:not(.stacked) .toc-show { display: flex; }
}

/* ---------- related chips ---------- */
.related { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; align-items: center; }
.related:empty { display: none; }
.related .rel-label { font: 600 11px var(--sans); letter-spacing: .07em; text-transform: uppercase; color: var(--text-3); margin-right: 2px; }
.related .chip {
  display: flex; align-items: center; gap: 8px; max-width: 220px; padding: 4px 12px 4px 4px;
  border: 1px solid var(--rule); border-radius: 999px; background: var(--bg-raised); color: var(--text);
  font-size: 12.5px; line-height: 1.25; text-decoration: none;
}
.related .chip:hover { border-color: var(--accent); color: var(--text); }
.related .chip img, .related .chip .ph { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex: none; filter: var(--img-filter); }
.related .chip .ph { display: grid; place-items: center; background: var(--bg-sunk); color: var(--text-3); font-weight: 600; }
.related .chip .chip-meta { min-width: 0; display: flex; flex-direction: column; }
.related .chip b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.related .chip small { color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11px; }
.related .chip.opened { border-color: var(--accent); background: var(--mark); box-shadow: none; }

/* ---------- pane sections menu ---------- */
.pane-bar { position: relative; align-items: center; gap: 6px; }
.pane-bar .grow { flex: 1; }
.pane-sections {
  display: flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 1px solid var(--rule); border-radius: 999px;
  background: var(--bg-raised); color: var(--text-2); font: 500 12.5px var(--sans); cursor: pointer;
}
.pane-sections:hover { color: var(--text); border-color: var(--accent); }
.pane-menu {
  position: absolute; top: 34px; left: 0; z-index: 5; width: 300px; max-height: 60vh; overflow: auto; padding: 6px;
  background: var(--bg-raised); border: 1px solid var(--rule); border-radius: 12px; box-shadow: var(--shadow);
}
.pane-menu[hidden] { display: none; }
.pane-menu a { display: flex; justify-content: space-between; gap: 10px; padding: 7px 10px; border-radius: 7px; color: var(--text); font-size: 13.5px; }
.pane-menu a:hover { background: var(--bg-sunk); }
.pane-menu .tm { color: var(--text-3); font-size: 11.5px; font-variant-numeric: tabular-nums; }

/* ---------- reading options ---------- */
:root[data-images="hide"] .prose .thumbfig,
:root[data-images="hide"] .prose ul.gallery,
:root[data-images="hide"] .prose .infobox-image,
:root[data-images="hide"] .prose .infobox-image + tr .infobox-caption { display: none !important; }
:root[data-linkstyle="color"] .prose a { text-decoration: none; }
:root[data-linkstyle="color"] .prose a:hover { text-decoration: underline; }

/* ---------- polish: dark-mode images, infobox overflow ---------- */
/* transparent diagrams (black lines) vanish on dark backgrounds: give images a light plate */
:root[data-theme="dark"] .prose img:not(.mwe-math-fallback-image-inline):not(.mwe-math-fallback-image-display),
:root[data-theme="dark"] .related .chip img,
:root[data-theme="dark"] .card .img { background-color: #f3f1ec; }
:root[data-theme="dark"] .prose .mwe-math-fallback-image-inline,
:root[data-theme="dark"] .prose .mwe-math-fallback-image-display { filter: invert(.9); background: none; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .prose img:not(.mwe-math-fallback-image-inline):not(.mwe-math-fallback-image-display),
  :root[data-theme="auto"] .related .chip img,
  :root[data-theme="auto"] .card .img { background-color: #f3f1ec; }
  :root[data-theme="auto"] .prose .mwe-math-fallback-image-inline,
  :root[data-theme="auto"] .prose .mwe-math-fallback-image-display { filter: invert(.9); background: none; }
}
/* long unbreakable strings (InChI keys, URLs) must not widen the infobox */
.infobox-card td, .infobox-card th, .infobox-card div { overflow-wrap: anywhere; }
.infobox-card .infobox-label { overflow-wrap: normal; word-break: normal; hyphens: auto; }
.infobox-card img { max-width: 100%; height: auto; }
.infobox-card table { max-width: 100%; }

/* ---------- polish: pane width is computed in JS (layoutStack) ---------- */
.stack .pane { width: var(--pane-w, 640px); }
.stack .pane .hgroup h1 { overflow-wrap: break-word; text-wrap: balance; }

/* ---------- polish: related = one tidy row of single-line chips ---------- */
.related { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 2px 0; margin-right: -4px;
  -webkit-mask: linear-gradient(90deg, #000 calc(100% - 32px), transparent); mask: linear-gradient(90deg, #000 calc(100% - 32px), transparent); }
.related::-webkit-scrollbar { display: none; }
.related .rel-label { flex: none; }
.related .chip { flex: none; max-width: 240px; padding: 3px 12px 3px 3px; gap: 7px; }
.related .chip img, .related .chip .ph { width: 24px; height: 24px; }
.related .chip .chip-meta { flex: 1 1 auto; min-width: 0; overflow: hidden; }
.related .chip b { display: block; }
.related .chip small { display: none; }
.related .chip:last-child { margin-right: 28px; }
/* a pane can be wider than a comfortable measure (one pane + spines): keep the text column readable */
.stack .pane-scroll > * { max-width: 760px; }

/* =====================================================================
   Polish round 2 (from QA across phones, desktops, stack mode, odd articles)
   ===================================================================== */

/* -- never let content widen the page -- */
html, body { overflow-x: clip; }
.prose { overflow-wrap: break-word; }
.prose ol.mw-references a.external, .prose .refbegin a.external { overflow-wrap: anywhere; }
.prose math[display="block"], .prose .mwe-math-element-block, .prose .mwe-math-element {
  max-width: 100%; overflow-x: auto; overflow-y: hidden; }
.prose math[display="block"], .prose .mwe-math-element-block { display: block; }
.prose dd { overflow-x: auto; }
.prose video { max-width: 100%; height: auto; }

/* -- dark text tokens: --text-3 passes 4.5:1 on raised surfaces -- */
:root[data-theme="dark"] { --text-3: #8f897f; --rule: #34332f; }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] { --text-3: #8f897f; --rule: #34332f; } }

/* -- Wikipedia's inline table colors, adapted per theme (set up in clean()) -- */
.prose .wbg, .prose .wbg-deep { background-color: var(--wbg); }
.prose .wfg-dark, .prose .wfg-light { color: var(--wfg); }
:root[data-theme="sepia"] .prose .wbg { background-color: color-mix(in srgb, var(--wbg) 70%, var(--bg)); }
:root[data-theme="dark"] .prose .wbg { background-color: color-mix(in srgb, var(--wbg) 30%, var(--bg-raised)); }
:root[data-theme="dark"] .prose .wbg-deep { background-color: color-mix(in srgb, var(--wbg) 60%, var(--bg)); }
:root[data-theme="dark"] .prose .wfg-dark { color: inherit; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .prose .wbg { background-color: color-mix(in srgb, var(--wbg) 30%, var(--bg-raised)); }
  :root[data-theme="auto"] .prose .wbg-deep { background-color: color-mix(in srgb, var(--wbg) 60%, var(--bg)); }
  :root[data-theme="auto"] .prose .wfg-dark { color: inherit; }
}
.prose .legend-color {
  display: inline-block; width: 1.3em; height: 1em; vertical-align: -0.1em; border-radius: 2px; margin-right: .35em;
  border: 1px solid rgba(0,0,0,.15);
}
/* images Wikipedia marks as safe to invert (line art, glyphs) */
:root[data-theme="dark"] .prose .skin-invert img, :root[data-theme="dark"] .prose .skin-invert-image img,
:root[data-theme="dark"] .prose img.skin-invert { background: none !important; filter: invert(1) hue-rotate(180deg); }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .prose .skin-invert img, :root[data-theme="auto"] .prose .skin-invert-image img,
  :root[data-theme="auto"] .prose img.skin-invert { background: none !important; filter: invert(1) hue-rotate(180deg); }
}

/* -- legacy div.thumb / multi-image figures -- */
.prose .thumbfig .thumbinner { width: auto !important; max-width: 100%; }
.prose .thumbfig .thumbcaption { font: 400 13px/1.5 var(--sans); color: var(--text-2); margin-top: 8px; }
.prose .thumbfig .trow { display: flex; gap: 4px; }
.prose .thumbfig .tsingle { flex: 1 1 0; min-width: 0; width: auto !important; float: none !important; margin: 0 !important; }
.prose .thumbfig .tsingle .thumbcaption { font-size: 11.5px; }
.prose .thumbfig .theader { font: 600 12px var(--sans); text-align: center; margin-bottom: 6px; }
/* labelled diagrams keep their pixel size; never float, scroll if wider than the column */
:root .prose .thumbfig.fixed-fig { float: none !important; width: auto !important; margin: 1.6em 0 !important; overflow-x: auto; max-width: var(--measure); }
.prose .fixed-fig img { max-width: none !important; }
.prose .fixed-fig div[style*="absolute"] { font: 11px/1.2 var(--sans); }

/* -- location maps (Module:Location map) and map switchers -- */
.prose .locmap .od { position: absolute; }
.prose .locmap .id { position: absolute; line-height: 0; }
.prose .locmap .l0 { position: absolute; font-size: 0; }
.prose .locmap .pv { position: absolute; line-height: 110%; text-align: center; font: 11px/1.1 var(--sans); }
.prose .locmap .pl { position: absolute; top: -.75em; line-height: 110%; text-align: right; font: 11px/1.1 var(--sans); }
.prose .locmap .pr { position: absolute; top: -.75em; line-height: 110%; text-align: left; font: 11px/1.1 var(--sans); }
.prose .locmap .pv > div, .prose .locmap .pl > div, .prose .locmap .pr > div { display: inline; padding: 1px; }
.prose .locmap img { max-width: none; }
.prose .switcher-container > :not(:first-child) { display: none; }

/* -- galleries, quotes, code -- */
.prose .gallery .gallerycaption { grid-column: 1 / -1; font: 600 13px var(--sans); color: var(--text-2); }
.prose .gallerybox .thumb { height: auto !important; width: auto !important; }
.prose .gallerybox .thumb > div { margin: 0 !important; }
.prose .quotebox {
  margin: 1.4em 0; padding: .9em 1.1em; border-left: 3px solid var(--accent); background: var(--bg-sunk);
  border-radius: 0 8px 8px 0; font-size: .92em; max-width: var(--measure); width: auto !important;
}
.prose details.quote-fold { margin: 1.2em 0; max-width: var(--measure); }
.prose details.quote-fold > summary { cursor: pointer; font: 500 13px var(--sans); color: var(--text-2); padding: 6px 0; }
.prose .mw-highlight pre { line-height: 1.5; }
.prose .linenos::before { content: attr(data-line); color: var(--text-3); padding-right: 1em; user-select: none; }
:root[lang="ja"] { --serif: "Source Serif 4", "Hiragino Mincho ProN", "Noto Serif JP", serif; --sans: Inter, "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif; }

/* -- tap targets, references -- */
.prose sup.reference a { padding: 4px 2px; margin: -4px 0; }
.refs-block:not(.clip) + .refs-toggle { position: sticky; bottom: 16px; box-shadow: var(--shadow); }
.hgroup .desc { font-family: var(--body-font); }

/* -- popovers fit small screens and sit above the Contents button -- */
.pop { max-height: calc(100dvh - 74px); overflow: auto; z-index: 59; }
@media (max-width: 759px) {
  #suggest { position: fixed; left: 12px; right: 12px; top: 58px; max-height: 70dvh; overflow: auto; }
  .lightbox { padding: 12px; }
  .settings .row:has([data-key="links"]), .settings .row:has([data-key="margin"]) { display: none; }
}
@media (max-width: 1080px) {
  .toc.sheet { margin-left: 0; padding-left: 26px; }
  .toc.sheet .toc-hide svg { transform: rotate(-90deg); }
}

/* -- "Contents" reopener lives in the top bar, so it never covers text -- */
.toc-show { position: static; height: 34px; }
.toc-show span { display: none; }
@media (min-width: 1081px) { :root[data-toc="hidden"] body:not(.stacked) .toc-show { display: flex; } }
@media (min-width: 1300px) { .toc-show span { display: inline; } }

/* -- margin off / TOC hidden: keep the column centred -- */
:root[data-margin="off"] .page { max-width: calc(var(--toc-w) + 56px + var(--measure) + 40px); }
:root[data-margin="off"] .article { max-width: var(--measure); }
@media (min-width: 1081px) {
  :root[data-toc="hidden"][data-margin="off"] .page { max-width: calc(var(--measure) + 40px); }
}

/* -- stacked panes -- */
.stack.fits { justify-content: center; }
.stack.fits .pane:last-child { border-right: 1px solid var(--rule); }
.pane-scroll { scroll-padding-top: 56px; container: pane / inline-size; }
.pane-bar {
  position: sticky; top: 0; z-index: 3; margin: -18px -36px 4px calc(-1 * var(--spine) - 12px);
  padding: 12px 36px 8px calc(var(--spine) + 12px); height: auto; background: var(--bg);
}
:root[data-theme="dark"] .pane { box-shadow: -8px 0 24px rgba(0,0,0,.45); border-left-color: #3a3935; }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .pane { box-shadow: -8px 0 24px rgba(0,0,0,.45); border-left-color: #3a3935; } }
/* a pane too narrow for text beside a float: figures and infobox go in-flow */
@container pane (max-width: 699px) {
  :root .stack .pane .prose .thumbfig, :root .stack .pane .prose aside.infobox-card {
    float: none; width: auto; max-width: 440px; margin: 1.4em 0;
  }
  :root .stack .pane .prose .thumbfig img { max-height: 380px; width: auto; }
}
.prose ol.mw-references li, .prose ol.references li { overflow-wrap: anywhere; min-width: 0; }
@media (max-width: 759px) { .prose ol.references { columns: 1; } }

/* -- performance: skip layout/paint of off-screen sections where nothing floats into the rail -- */
.prose .refs-block { content-visibility: auto; contain-intrinsic-size: auto 600px; }
@media (max-width: 1279px) {
  .prose > section[data-mw-section-id]:not([data-mw-section-id="0"]) { content-visibility: auto; contain-intrinsic-size: auto 1500px; }
}
.stack .prose > section[data-mw-section-id]:not([data-mw-section-id="0"]) { content-visibility: auto; contain-intrinsic-size: auto 1500px; }
/* clip the reference preview on the wrapper, not the multi-column list: a height-limited
   multi-column box spills extra columns sideways */
.refs-block.clip ol { max-height: none !important; overflow: visible !important; -webkit-mask: none !important; mask: none !important; }
.refs-block.clip { max-height: 260px; overflow: hidden; -webkit-mask: linear-gradient(#000 60%, transparent); mask: linear-gradient(#000 60%, transparent); }
