/* Design tokens come from theme.css, which is loaded before this file. */

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--app-bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

/* ---------------- masthead ---------------- */
.masthead {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 26px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--app-bg) 88%, transparent);
  backdrop-filter: blur(8px);
}
.masthead .title { font-size: 15px; letter-spacing: .4px; color: var(--muted); }
.masthead .title b { color: var(--text); font-weight: 600; }
.back-link {
  color: var(--accent); text-decoration: none; font-size: 13px; font-weight: 600;
  border: 1px solid var(--border); padding: 7px 13px; border-radius: 7px; background: var(--panel);
}
.back-link:hover { border-color: var(--accent); }

.lang-switcher { display: inline-flex; }
.lang-select {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 6px 9px; font-size: 13px; cursor: pointer;
}
.lang-select:hover { border-color: var(--accent); }

/* right-to-left (Arabic) */
[dir="rtl"] .toc a { border-left: none; border-right: 2px solid transparent; }
[dir="rtl"] .toc a.active { border-right-color: var(--accent); }
[dir="rtl"] .eq .lbl { float: left; }

/* ---------------- layout ---------------- */
.layout { display: flex; max-width: 1140px; margin: 0 auto; gap: 40px; padding: 0 26px; }

/* index / table of contents */
.toc {
  width: 232px; flex-shrink: 0;
  position: sticky; top: 66px; align-self: flex-start;
  max-height: calc(100vh - 86px); overflow-y: auto;
  padding: 26px 0;
}
.toc h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin: 0 0 12px; }
.toc ol { list-style: none; margin: 0; padding: 0; counter-reset: idx; }
.toc li { counter-increment: idx; }
.toc a {
  display: block; color: var(--muted); text-decoration: none;
  padding: 5px 10px; border-left: 2px solid transparent; font-size: 12.5px; line-height: 1.4;
}
.toc a::before { content: counter(idx) ".\00a0\00a0"; color: var(--accent-2); }
.toc a:hover { color: var(--text); }
.toc a.active { color: var(--text); border-left-color: var(--accent); }

/* ---------------- article ---------------- */
.doc {
  flex: 1; min-width: 0; max-width: 760px;
  counter-reset: section;
  padding: 40px 0 100px;
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 17px; line-height: 1.72;
}

.doc-head { margin-bottom: 14px; }
.doc-head h1 {
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 30px; line-height: 1.25; margin: 0 0 10px; letter-spacing: .2px;
}
.doc-head .lead { color: var(--muted); font-size: 18px; margin: 0 0 12px; }
.doc-head .byline { font-family: "Segoe UI", sans-serif; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: 8px 0; }

.doc section { scroll-margin-top: 74px; margin-top: 36px; }
.doc section > h2 {
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 21px; margin: 0 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--rule);
}
.doc section > h2::before {
  counter-increment: section; content: counter(section) ".\00a0\00a0";
  color: var(--accent-2); font-weight: 600;
}
.doc h3 { font-family: "Segoe UI", sans-serif; font-size: 15px; color: var(--accent); margin: 22px 0 6px; }
.doc p { margin: 10px 0; }
.doc a { color: var(--accent); }
.doc ul { margin: 10px 0; padding-left: 22px; }
.doc li { margin: 5px 0; }
.doc strong { color: var(--text); }

/* equations */
.eq {
  font-family: "Cambria Math", Georgia, serif; font-style: italic;
  text-align: center; font-size: 17px; color: var(--text-soft);
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 12px 16px; margin: 16px 0; overflow-x: auto;
}
.eq .lbl { float: right; font-style: normal; color: var(--muted); font-family: "Segoe UI", sans-serif; font-size: 13px; }
.doc code { font-family: "Cascadia Code", Consolas, monospace; font-size: 14px; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; color: var(--accent-2); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; font-size: 15px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text);
}
.icon-btn:hover { border-color: var(--accent); }

/* tables */
.doc table {
  width: 100%; border-collapse: collapse; margin: 16px 0;
  font-family: "Segoe UI", sans-serif; font-size: 13.5px;
}
.doc caption { caption-side: top; text-align: left; color: var(--muted); font-family: "Segoe UI", sans-serif; font-size: 12.5px; font-style: italic; margin-bottom: 6px; }
.doc th, .doc td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.doc thead th { color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: .5px; border-bottom: 1px solid var(--border); }
.doc tbody tr:hover { background: var(--panel); }

/* a sparing aside */
.aside { font-size: 15px; color: var(--muted); border-left: 2px solid var(--rule); padding: 2px 0 2px 16px; margin: 16px 0; font-style: italic; }

.refs { font-family: "Segoe UI", sans-serif; font-size: 13.5px; color: var(--muted); }
.refs li { margin: 8px 0; }

.colophon { font-family: "Segoe UI", sans-serif; color: var(--muted); font-size: 12.5px; margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--rule); }

@media (max-width: 860px) {
  .toc { display: none; }
  .doc { font-size: 16px; }
}

@media (max-width: 640px) {
  .masthead { flex-wrap: wrap; gap: 8px 10px; padding: 10px 16px; }
  .layout { padding: 0 16px; gap: 0; }
  .doc { padding: 26px 0 80px; }
  .doc-head h1 { font-size: 24px; }
  .doc-head .lead { font-size: 16px; }
  .doc section > h2 { font-size: 19px; }
  .eq { font-size: 15px; padding: 10px 12px; }
  /* Wide data tables scroll within their column instead of the whole page. */
  .doc table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .lang-select, .back-link { font-size: 13px; }
}
