:root, [data-theme="dark"] {
  --bg: #101418;
  --surface: #171c22;
  --surface2: #1d242c;
  --border: #303941;
  --text: #e6e9ed;
  --muted: #98a2ad;
  --link: #8fb3ff;
  --link-visited: #b1a1e0;
  --link-new: #ff8080;
  --accent: #58c07a;
  --head-font: 'Linux Libertine', Georgia, 'Times New Roman', serif;
  --body-font: -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
}
[data-theme="light"] {
  --bg: #f6f6f6;
  --surface: #ffffff;
  --surface2: #f8f9fa;
  --border: #c8ccd1;
  --text: #202122;
  --muted: #54595d;
  --link: #3366cc;
  --link-visited: #795cb2;
  --link-new: #d73333;
  --accent: #2e8b57;
}

* { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--body-font); font-size: 14px; line-height: 1.6;
  overflow-x: hidden;
}
img { max-width: 100%; }
a { color: var(--link); text-decoration: none; }
a:visited { color: var(--link-visited); }
a:hover { text-decoration: underline; }
a.new { color: var(--link-new); }

.page { display: flex; min-height: 100vh; max-width: 1440px; margin: 0 auto; }

/* sidebar */
.sidebar {
  width: 186px; flex: 0 0 186px; padding: 14px 10px;
  font-size: 12.5px;
}
.logo { display: flex; gap: 9px; align-items: center; margin-bottom: 16px; }
.logo:hover { text-decoration: none; }
.logo-mark { width: 52px; height: 52px; object-fit: contain; }
.logo-text { font-family: var(--head-font); font-size: 17px; color: var(--text); line-height: 1.1; }
.logo-text small { display: block; font-family: var(--body-font); font-size: 10px; color: var(--accent); letter-spacing: .3px; }
.sidebar nav a { display: block; padding: 2px 8px; color: var(--link); border-radius: 3px; }
.sidebar nav a.on { background: var(--surface2); }
.nav-head {
  margin: 14px 0 3px; padding: 0 8px 2px; color: var(--muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  border-bottom: 1px solid var(--border);
}
#theme-toggle {
  margin: 22px 8px; background: none; border: 1px solid var(--border);
  color: var(--muted); border-radius: 4px; padding: 3px 10px; cursor: pointer;
}
#theme-toggle:hover { color: var(--text); border-color: var(--muted); }

/* main column */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content, .footer { min-width: 0; }
.topbar { display: flex; justify-content: flex-end; padding: 10px 16px 0; }
.searchbox { display: flex; }
.searchbox input {
  width: 300px; max-width: 60vw; padding: 5px 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-right: none; border-radius: 3px 0 0 3px;
}
.searchbox button {
  padding: 5px 12px; background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: 0 3px 3px 0; cursor: pointer;
}
.searchbox button:hover { background: var(--border); }

.content {
  flex: 1; margin: 10px 16px 0 0; padding: 18px 28px 40px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 4px 4px 0 0;
}
.footer {
  margin: 0 16px 16px 0; padding: 10px 28px;
  background: var(--surface); border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 4px 4px; color: var(--muted); font-size: 12px;
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.footer-ca {
  flex-basis: 100%; border-top: 1px solid var(--border);
  padding-top: 8px; margin-top: 2px; text-align: center;
}
.footer-ca code {
  background: var(--surface2); padding: 1px 6px; border-radius: 3px;
  font-size: 11.5px; color: var(--text); word-break: break-all; user-select: all;
}

/* article */
h1.firstHeading {
  font-family: var(--head-font); font-weight: normal; font-size: 26px;
  margin: 0 0 2px; padding-bottom: 4px; border-bottom: 1px solid var(--border);
}
.fromline { color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.article h2 {
  font-family: var(--head-font); font-weight: normal; font-size: 20px;
  margin: 22px 0 8px; padding-bottom: 3px; border-bottom: 1px solid var(--border);
}
.article h3 { font-size: 15.5px; margin: 18px 0 6px; }
.article p { margin: 8px 0; }
.article ul, .article ol { margin: 8px 0 8px 24px; padding: 0; }
.article blockquote {
  margin: 10px 0; padding: 6px 14px; border-left: 3px solid var(--accent);
  background: var(--surface2); color: var(--muted);
}
.article code { background: var(--surface2); padding: 1px 5px; border-radius: 3px; font-size: 13px; }
.article { overflow-wrap: break-word; }
.article pre { overflow-x: auto; background: var(--surface2); padding: 10px 14px; border-radius: 4px; }
.article table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.article table td, .article table th { border: 1px solid var(--border); padding: 4px 10px; }
.lede { font-size: 15px; }
.article h2#references { font-size: 17px; }
.article h2#references ~ ul, .article h2#references + ul { font-size: 12.5px; color: var(--muted); }
.article h2#references ~ ul a { word-break: break-all; }

/* infobox */
.infobox {
  float: right; clear: right; width: 280px; margin: 4px 0 14px 18px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 4px;
  border-spacing: 0; font-size: 12.5px;
}
.infobox caption {
  font-weight: bold; font-size: 14px; padding: 8px 10px 4px; caption-side: top;
}
.infobox-image { padding: 6px 10px 4px !important; text-align: center; }
.infobox-image img {
  max-width: 100%; max-height: 260px; border-radius: 4px;
  background: var(--surface); object-fit: contain;
}
.img-credit { font-size: 10.5px; color: var(--muted); margin-top: 3px; text-align: center; }
.img-credit a { color: var(--muted); }
.infobox th {
  text-align: left; vertical-align: top; padding: 4px 8px 4px 10px;
  width: 40%; color: var(--muted); font-weight: 600;
}
.infobox td { padding: 4px 10px 4px 0; }
.infobox tr:first-child th, .infobox tr:first-child td { border-top: 1px solid var(--border); }

/* toc */
.toc {
  display: inline-block; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 4px; padding: 10px 18px 10px 14px; margin: 6px 0 12px; font-size: 13px;
}
.toc-title { text-align: center; font-weight: bold; margin-bottom: 4px; }
.toc ol { margin: 0; padding: 0; list-style: none; }
.toc li { margin: 2px 0; }
.toc li.toc3 { margin-left: 18px; }
.tocnum { color: var(--muted); margin-right: 6px; }

/* tabs */
.tabs { display: flex; gap: 2px; margin-bottom: 8px; font-size: 13px; }
.tabs a {
  padding: 4px 12px; background: var(--surface2); border: 1px solid var(--border);
  border-bottom: none; border-radius: 4px 4px 0 0; color: var(--muted);
}
.tabs a.on { background: var(--surface); color: var(--text); }

/* main page */
.mainpage-banner {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 4px;
  padding: 18px 24px; margin-bottom: 16px;
}
.mainpage-banner h1 { font-family: var(--head-font); font-weight: normal; margin: 0 0 6px; }
.mainpage-banner p { margin: 4px 0; }
.mainpage-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.panel { border: 1px solid var(--border); border-radius: 4px; padding: 14px 18px; background: var(--surface); }
.panel-head {
  font-family: var(--head-font); font-size: 16px; border-bottom: 1px solid var(--border);
  padding-bottom: 3px; margin: 14px 0 8px;
}
.panel-head:first-child { margin-top: 0; }
.panel.featured h3 { font-family: var(--head-font); font-weight: normal; font-size: 20px; margin: 4px 0 8px; }
.catgrid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.recent-list { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.recent-list li { margin: 3px 0; }

/* listings, misc */
.listing { list-style: none; margin: 10px 0; padding: 0; }
.listing li { padding: 4px 0; border-bottom: 1px solid var(--surface2); }
.listing.cols { column-width: 220px; }
.listing.cols li { border: none; padding: 2px 0; }
.muted { color: var(--muted); }
.pill {
  display: inline-block; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; font-size: 11px; padding: 0 8px; color: var(--muted);
}
.catlinks {
  clear: both; margin-top: 26px; padding: 8px 12px; font-size: 12.5px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 4px;
}

/* forms */
.editform { max-width: 860px; }
.editform.narrow { max-width: 360px; }
.editform label { display: block; margin: 10px 0 4px; color: var(--muted); font-size: 13px; }
.editform input, .editform select, .editform textarea {
  width: 100%; padding: 6px 10px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 3px; font-family: var(--body-font); font-size: 14px;
}
.editform textarea { font-family: Consolas, Menlo, monospace; font-size: 13px; line-height: 1.5; }
.editform button, button.danger {
  margin-top: 12px; padding: 7px 18px; background: var(--accent); color: #0b1210;
  border: none; border-radius: 3px; font-weight: 600; cursor: pointer;
}
button.danger { background: #c0584f; color: #fff; }
.editform button:hover, button.danger:hover { filter: brightness(1.1); }
.hp { position: absolute; left: -9999px; height: 1px; width: 1px; opacity: 0; }
.preview { border: 1px dashed var(--border); border-radius: 4px; padding: 8px 16px; }

@media (max-width: 900px) {
  .page { flex-direction: column; min-width: 0; }
  .sidebar { width: auto; flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 10px; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 2px; flex-basis: 100%; }
  .sidebar nav a { padding: 5px 9px; }
  .nav-head { display: none; }
  #theme-toggle { margin: 0 0 0 auto; }
  .topbar { padding: 8px 8px 0; }
  .searchbox { width: 100%; }
  .searchbox input { flex: 1; width: auto; min-width: 0; max-width: none; font-size: 16px; }
  .content { margin: 8px 8px 0; padding: 14px 14px 28px; }
  .footer { margin: 0 8px 8px; padding: 10px 14px; }
  .editform input, .editform select, .editform textarea { font-size: 16px; }
  .mainpage-grid { grid-template-columns: 1fr; }
  .mainpage-banner { padding: 14px 16px; }
  .infobox { float: none; width: 100%; margin: 10px 0; }
  h1.firstHeading { font-size: 23px; }
  .listing.cols { column-width: auto; column-count: 2; }
}
@media (max-width: 420px) {
  .listing.cols { column-count: 1; }
  .catgrid { grid-template-columns: 1fr; }
  .tabs a { padding: 4px 9px; }
}
