/* WikiLAN reader: layout, typography, and MediaWiki content styling for all themes. */

.reader {
  display: grid;
  /* The contents column never gets narrower than the 250px rail (it overflowed off-screen at ~1180–1330px). */
  grid-template-columns: minmax(250px, 1fr) minmax(0, var(--reader-width)) minmax(0, 1fr);
  gap: 0 40px;
  padding: 28px 20px 96px;
}
.reader > .article-wrap { grid-column: 2; min-width: 0; }
.toc-rail { grid-column: 1; justify-self: end; width: 250px; }
.toc-sticky { position: sticky; top: calc(var(--topbar-h) + 20px); max-height: calc(100vh - var(--topbar-h) - 40px); overflow-y: auto; padding-inline-end: 8px; overscroll-behavior: contain; }
@media (max-width: 1180px) {
  .reader { grid-template-columns: minmax(0, 1fr); padding-inline: 16px; }
  .reader > .article-wrap { grid-column: 1; max-width: var(--reader-width); margin-inline: auto; width: 100%; }
  .toc-rail { display: none; }
}

/* reading progress (under the top bar) */
.read-progress { position: fixed; top: var(--topbar-h); inset-inline: 0; height: 2px; z-index: 39; pointer-events: none; }
.read-progress span { display: block; height: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; will-change: transform; }
[dir="rtl"] .read-progress span { transform-origin: right; }

/* table of contents */
.toc-title { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
.toc { list-style: none; margin: 0; padding: 0; font-size: 14px; line-height: 1.35; }
.toc a {
  display: block; padding: 5px 10px; border-radius: 7px; color: var(--text-2); text-decoration: none;
  border-inline-start: 2px solid transparent; transition: background-color .12s, color .12s;
}
.toc a:hover { background: var(--surface); color: var(--text); }
.toc a.active { color: var(--accent); border-inline-start-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.toc .l3 a { padding-inline-start: 22px; font-size: 13.5px; }
.toc .l4 a { padding-inline-start: 34px; font-size: 13px; }

/* mobile TOC sheet */
.toc-sheet { position: fixed; inset: 0; z-index: 70; }
.toc-sheet .sheet-backdrop { position: absolute; inset: 0; background: var(--backdrop); animation: fade .15s ease; }
.toc-sheet .sheet-panel {
  position: absolute; inset-inline: 0; bottom: 0; max-height: 75vh; overflow-y: auto;
  background: var(--bg-elev); border-radius: 18px 18px 0 0; padding: 8px 12px max(20px, env(safe-area-inset-bottom));
  box-shadow: var(--shadow); animation: sheet-up .22s var(--ease);
}
.toc-sheet .sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 12px; }
@keyframes sheet-up { from { transform: translateY(30px); opacity: 0; } }

/* floating buttons */
.fab-stack { position: fixed; bottom: max(20px, env(safe-area-inset-bottom)); inset-inline-end: 20px; z-index: 30; display: flex; flex-direction: column; gap: 10px; }
.fab {
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--bg-elev); color: var(--text-2); box-shadow: var(--shadow);
  display: grid; place-items: center; cursor: pointer;
  transition: opacity .2s, transform .2s var(--ease);
}
.fab:hover { color: var(--accent); }
.fab.hide { opacity: 0; transform: translateY(10px); pointer-events: none; }
@media (min-width: 1181px) { .fab.toc-fab { display: none; } }

/* article header */
.article-head { margin-bottom: 20px; border-bottom: 1px solid var(--line); padding-bottom: 16px; }
.article-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.article-crumbs a { color: var(--muted); text-decoration: none; }
.article-crumbs a:hover { color: var(--accent); }
.article-title {
  font-family: var(--font-serif); font-weight: 500; font-size: clamp(30px, 4.6vw, 42px);
  line-height: 1.15; letter-spacing: -.01em; margin: 0;
}
.article-redirect { font-size: 14px; color: var(--muted); margin-top: 6px; }
.article-tools { display: flex; gap: 4px; margin-top: 12px; flex-wrap: wrap; }
.article-tools .icon-btn { width: 36px; height: 36px; }

/* ---------- article body ---------- */
.article {
  font-family: var(--reader-font, var(--font-ui));
  font-size: var(--reader-size);
  line-height: 1.7;
  color: var(--text);
  overflow-wrap: break-word;
}
.reader-serif .article { --reader-font: var(--font-serif); }
.article p { margin: 0 0 1em; }
.article h2, .article h3, .article h4 { font-family: var(--font-serif); font-weight: 500; line-height: 1.25; }
.article h2 { font-size: 1.6em; margin: 1.6em 0 .6em; padding-bottom: .25em; border-bottom: 1px solid var(--line); clear: both; }
.article h3 { font-size: 1.28em; margin: 1.4em 0 .5em; font-family: var(--font-ui); font-weight: 650; }
.article h4 { font-size: 1.1em; margin: 1.2em 0 .4em; font-family: var(--font-ui); font-weight: 650; }
.article a { text-decoration: none; color: var(--link); }
.article a:hover { text-decoration: underline; }
.article a.wl-missing { color: var(--text); text-decoration: underline dotted var(--muted); cursor: default; }
.article a.external::after { content: "↗"; font-size: .75em; margin-inline-start: 2px; color: var(--muted); }
.article img { max-width: 100%; height: auto; }
.article ul, .article ol { padding-inline-start: 1.5em; }
.article li { margin: .2em 0; }
.article blockquote { margin: 1em 0; padding: .2em 1em; border-inline-start: 3px solid var(--line); color: var(--text-2); }
.article pre, .article code { font-family: var(--font-mono); font-size: .88em; background: var(--surface); border-radius: 5px; }
.article code { padding: .1em .35em; }
.article pre { padding: 12px 14px; overflow-x: auto; }
.article hr { border: 0; border-top: 1px solid var(--line); }
.article sup, .article sub { line-height: 0; }
.article dl dt { font-weight: 650; }
.article dd { margin-inline-start: 1.5em; }
.article .mw-empty-elt { display: none; }
.article section { scroll-margin-top: calc(var(--topbar-h) + 12px); }

/* tables */
.article table { border-collapse: collapse; font-size: .9em; line-height: 1.45; }
.article .wikitable { display: block; max-width: 100%; overflow-x: auto; margin: 1em 0; background: var(--bg); }
.article .wikitable th, .article .wikitable td { border: 1px solid var(--line); padding: 6px 10px; vertical-align: top; }
.article .wikitable th { background: var(--surface); text-align: start; }
.article caption { font-weight: 650; padding: 6px 0; }

/* infobox */
.article .infobox {
  float: right; clear: right; margin: 0 0 1em 1.5em; width: 22em; max-width: 100%;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  border-collapse: separate; border-spacing: 0; overflow: hidden; font-size: .82em;
}
[dir="rtl"] .article .infobox, .article[dir="rtl"] .infobox { float: left; clear: left; margin: 0 1.5em 1em 0; }
.article .infobox th, .article .infobox td { padding: 5px 10px; vertical-align: top; text-align: start; }
.article .infobox .infobox-above { font-size: 1.25em; font-weight: 700; text-align: center; padding: 10px; font-family: var(--font-serif); }
.article .infobox .infobox-header { text-align: center; background: var(--surface-2); }
.article .infobox .infobox-image { text-align: center; padding: 8px; }
.article .infobox .infobox-label { width: 38%; }
.article .infobox tr + tr > * { border-top: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
@media (max-width: 720px) {
  .article .infobox { float: none !important; width: 100%; margin: 0 0 1.5em !important; }
}

/* figures */
.article figure { margin: .4em 0 1em; display: table; max-width: 100%; }
.article figure[typeof~="mw:File/Thumb"], .article figure[typeof~="mw:File/Frame"] {
  float: right; clear: right; margin: .3em 0 1em 1.4em; padding: 6px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.article figure.mw-halign-left { float: left; clear: left; margin: .3em 1.4em 1em 0; }
[dir="rtl"] .article figure[typeof~="mw:File/Thumb"], .article[dir="rtl"] figure[typeof~="mw:File/Thumb"] { float: left; clear: left; margin: .3em 1.4em 1em 0; }
.article figure.mw-halign-center { margin-inline: auto; float: none; }
.article figure img { border-radius: 6px; cursor: zoom-in; display: block; }
.article figcaption { display: table-caption; caption-side: bottom; font-size: .82em; line-height: 1.45; color: var(--text-2); padding: 6px 4px 2px; }
@media (max-width: 560px) {
  .article figure[typeof~="mw:File/Thumb"], .article figure.mw-halign-left { float: none; margin: 1em auto; }
}
.article .gallery { display: flex; flex-wrap: wrap; gap: 12px; padding: 0; list-style: none; }
.article .gallerybox { width: auto !important; }

/* hatnotes, boxes, quotes */
.article .hatnote, .article .dablink {
  font-size: .9em; color: var(--text-2); font-style: italic; padding: 6px 12px; margin-bottom: 1em;
  border-inline-start: 3px solid var(--line); background: var(--surface); border-radius: 0 8px 8px 0;
}
.article .ambox, .article .mbox-small, .article .metadata.plainlinks { display: none; }
.article .sidebar { float: right; clear: right; margin: 0 0 1em 1.5em; font-size: .82em; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 6px; width: 20em; max-width: 100%; }
.article .quotebox { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; background: var(--surface); }
.article .hlist ul { padding: 0; margin: 0; }
.article .hlist li { display: inline; }
.article .hlist li + li::before { content: " · "; color: var(--muted); }
.article .plainlist ul { list-style: none; padding: 0; margin: 0; }

/* references */
.article sup.reference a { font-size: .75em; padding: 0 1px; }
.article .references, .article .mw-references-wrap { font-size: .86em; line-height: 1.5; }
.article .mw-references-columns, .article .reflist-columns { columns: 2 22em; column-gap: 2em; }
.article ol.references li { break-inside: avoid; }
.article ol.references li:target, .article .reference-text:target { background: var(--accent-soft); border-radius: 6px; }
.article .mw-cite-backlink a { font-size: .85em; }
.article cite { font-style: normal; }

/* navboxes: collapsed into a <details> by reader.js */
.article details.wl-navbox { margin: 1.4em 0 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.article details.wl-navbox > summary { cursor: pointer; padding: 10px 14px; font-weight: 600; font-size: .9em; list-style: none; display: flex; justify-content: space-between; }
.article details.wl-navbox > summary::after { content: "▾"; color: var(--muted); transition: transform .15s; }
.article details.wl-navbox[open] > summary::after { transform: rotate(180deg); }
.article details.wl-navbox > .wl-navbox-body { padding: 0 10px 10px; overflow-x: auto; font-size: .85em; }
.article .navbox { width: 100%; }
.article .navbox th, .article .navbox td { padding: 4px 8px; text-align: start; }
.article .navbox-title { display: none; }
.article .navbox-group { white-space: nowrap; font-weight: 650; vertical-align: top; color: var(--text-2); }
.article .navbox-list { border-inline-start: 2px solid var(--line); }
.article .navbar { display: none; }

/* math */
.article .mwe-math-fallback-image-inline, .article .mwe-math-fallback-image-display { vertical-align: middle; }
.article .mwe-math-mathml-a11y { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* footer (license) */
.article-footer { margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.article-footer .zim-footer { font-size: 13px; }
.article-footer a { color: var(--muted); }

/* in-article find highlight */
.article mark.wl-find { background: var(--mark); color: var(--mark-text); border-radius: 2px; }

/* ---------- dark / sepia adjustments for content colors set inline by templates ---------- */
:root[data-theme="dark"] .article [style*="background"]:not(img):not(figure),
:root[data-theme="dark"] .article [bgcolor] {
  background-color: color-mix(in srgb, var(--surface-2) 85%, transparent) !important;
  color: var(--text) !important;
}
:root[data-theme="dark"] .article [style*="color:"]:not(img) { color: var(--text) !important; }
:root[data-theme="dark"] .article .mwe-math-fallback-image-inline,
:root[data-theme="dark"] .article .mwe-math-fallback-image-display,
:root[data-theme="dark"] .article img[src$=".svg.png"][data-file-type="drawing"],
:root[data-theme="dark"] .article img[src*=".svg"] {
  filter: invert(.9) hue-rotate(180deg);
}
:root[data-theme="dark"] .article img { opacity: .94; }
:root[data-theme="dark"] .article img:hover { opacity: 1; }
:root[data-theme="sepia"] .article [style*="background"]:not(img):not(figure) { background-color: var(--surface) !important; }
:root[data-theme="sepia"] .article img { mix-blend-mode: multiply; }

/* ---------- raw mode (Gutenberg and other non-Wikipedia books) ---------- */
.raw-page { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h)); height: calc(100svh - var(--topbar-h)); }
.raw-tools { display: flex; align-items: center; gap: 8px; padding: 4px 12px; border-bottom: 1px solid var(--line); min-height: 44px; }
.raw-crumbs { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); white-space: nowrap; overflow: hidden; }
.raw-crumbs a { color: inherit; text-decoration: none; overflow: hidden; text-overflow: ellipsis; }
.raw-crumbs .ico { width: 18px; height: 18px; flex: none; }
.raw-page .tr-status { margin: 8px 12px 0; }
.raw-frame { display: block; width: 100%; flex: 1; min-height: 0; border: 0; background: #fff; }

/* ---------- loading skeleton ---------- */
.reader-skel { max-width: var(--reader-width); margin: 28px auto; padding: 0 16px; }
.reader-skel .skel { height: 16px; margin: 12px 0; }
.reader-skel .skel.t { height: 40px; width: 60%; margin-bottom: 28px; }

.error-box { max-width: 560px; margin: 80px auto; text-align: center; padding: 0 16px; }
.error-box h1 { font-family: var(--font-serif); font-weight: 500; }
.error-box p { color: var(--text-2); }
