:root {
  --ink: #222;
  --paper: #fdfcf8;
  --yellow: #ffd82a;
  --red: #e8403d;
  --muted: #666;
  --rule: #ddd;
  --rule-heavy: #333;
  --menu-width: 17rem;
  --toc-width: 16rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Noto Sans', system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.55;
}

/* --- header --- */
.site-header {
  border-bottom: 2px solid var(--rule-heavy);
  padding: 0 1.2rem;
  background: var(--yellow);
  position: sticky;
  top: 0;
  z-index: 10;
}
.site-header nav {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
  min-height: 2.8rem;
}
.site-header a {
  text-decoration: none;
  color: var(--ink);
  padding: 0.2rem 0;
}
.site-header a:hover { color: var(--red); }
.site-header a.active {
  color: var(--red);
  font-weight: bold;
}
.site-header .brand {
  font-weight: bold;
  font-size: 0.9rem;
  font-family: system-ui, sans-serif;
  letter-spacing: -0.01em;
  margin-right: 0.6rem;
  color: var(--ink);
}

/* --- layout --- */
main { max-width: 70rem; margin: 0 auto; padding: 1.5rem 1.2rem 4rem; }
main.with-flavor-menu { max-width: none; padding-right: calc(var(--menu-width) + 2rem); }

#manifescht-doc, .doc-layout { display: flex; gap: 2.5rem; align-items: flex-start; }

.toc-panel {
  flex: 0 0 var(--toc-width);
  position: sticky;
  top: 4rem;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
  font-size: 0.85rem;
  border-right: 1px solid var(--rule);
  padding-right: 1rem;
}
.toc-panel ul { list-style: none; padding-left: 0.9rem; margin: 0.2rem 0; }
.toc-panel a { text-decoration: none; color: var(--ink); }
.toc-panel a:hover { color: var(--red); }

article.document { flex: 1; min-width: 0; max-width: 44rem; }
article.document h1, article.document h2, article.document h3 { line-height: 1.25; }
article.document a { color: var(--red); }
article.document a:hover { text-decoration: underline; }
.doc-title { margin-bottom: 0.2rem; }
.doc-subtitle { color: var(--muted); font-style: italic; margin-top: 0; }

/* --- academic tables (booktabs-style) --- */
article.document table {
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9rem;
  width: 100%;
}
article.document table caption {
  caption-side: top;
  text-align: left;
  font-style: italic;
  padding-bottom: 0.4rem;
  font-size: 0.88rem;
  color: var(--muted);
}
article.document th,
article.document td {
  border: none;
  padding: 0.3rem 0.8rem;
  text-align: left;
}
/* toprule */
article.document thead tr:first-child th {
  border-top: 2px solid var(--rule-heavy);
}
/* midrule */
article.document thead th {
  border-bottom: 1px solid var(--rule-heavy);
}
/* bottomrule */
article.document tbody tr:last-child td {
  border-bottom: 2px solid var(--rule-heavy);
}

article.document blockquote {
  border-left: 3px solid var(--rule);
  margin-left: 0;
  padding-left: 1rem;
  color: var(--muted);
}

/* --- du/dir switch: show one variant --- */
body.sec-mode-t .sec-v { display: none; }
body.sec-mode-v .sec-t { display: none; }

/* --- sec-toggle in the navbar --- */
.sec-toggle {
  display: flex;
  align-items: center;
  margin-left: auto;
  gap: 0;
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
}
.sec-toggle button {
  padding: 0.25rem 0.7rem;
  border: 1.5px solid rgba(0, 0, 0, 0.25);
  background: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
  line-height: 1.4;
  transition: background 0.1s, color 0.1s;
}
.sec-toggle button:hover { background: rgba(255, 255, 255, 0.8); }
.sec-toggle button.selected {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}
.sec-toggle button:first-child { border-radius: 4px 0 0 4px; }
.sec-toggle button:last-child  { border-radius: 0 4px 4px 0; margin-left: -1.5px; }

/* --- flavor menu --- */
.flavor-menu {
  position: fixed;
  top: 3rem;
  right: 0;
  width: var(--menu-width);
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  padding: 1rem 1.2rem 2rem;
  border-left: 1px solid var(--rule);
  background: #fff;
  font-family: system-ui, sans-serif;
  font-size: 0.85rem;
}
.flavor-menu h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin: 1.2rem 0 0.4rem;
}
#translit-menu {
  top: 0;
  height: 100vh;
  max-height: none;
  padding: 0.6rem 1rem 1.5rem;
  font-size: 0.8rem;
  width: max-content;
  min-width: 14rem;
}
#translit-menu h2 {
  font-size: 0.7rem;
  margin: 0.8rem 0 0.25rem;
}
.flavor-list { list-style: none; margin: 0; padding: 0; }
.flavor-list li { margin: 0.15rem 0; }
.flavor-link {
  display: block;
  padding: 0.3rem 0.6rem;
  border-radius: 5px;
  text-decoration: none;
  color: var(--ink);
}
.flavor-link:hover { background: #f3efe7; }
.flavor-link.selected { background: var(--red); color: #fff; }
.flavor-link.pending { color: var(--muted); cursor: default; }

/* --- playground form --- */
#translit-form .question { display: flex; align-items: baseline; gap: 0.5rem; }
#translit-form .question span { white-space: nowrap; flex-shrink: 0; }
#translit-form .question select { flex: 1; min-width: 6rem; width: auto; }
#translit-form select { width: 100%; margin: 0.1rem 0 0.3rem; font: inherit; padding: 0.2rem; }
#translit-form select:disabled { opacity: 0.4; cursor: not-allowed; }
.apply-btn {
  margin-top: 1rem;
  width: 100%;
  padding: 0.5rem;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 5px;
  font: inherit;
  cursor: pointer;
}
.apply-btn:hover { opacity: 0.9; }
.form-error { color: #b00020; }

.shuffle-btn {
  margin-top: 0.6rem;
  width: 100%;
  padding: 0.4rem;
  background: #f3efe7;
  border: 1px solid var(--rule);
  border-radius: 5px;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
.shuffle-btn:hover { background: #e8e3d9; }
.shuffle-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* --- footnote popovers --- */
.fn-ref-wrap { position: relative; display: inline; }
.fn-ref {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: var(--red);
  vertical-align: super;
  font-size: 0.75em;
}
.fn-ref:hover { text-decoration: underline; }

/* popover styling — anchored near the button by the browser */
.fn-popover {
  position: fixed;        /* overridden by the browser's popover positioning */
  max-width: 32rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink);
}
.fn-popover p:first-child { margin-top: 0; }
.fn-popover p:last-child  { margin-bottom: 0; }

/* --- landing / misc --- */
.landing-links li { margin: 0.5rem 0; }
.donate-buttons { display: flex; gap: 1rem; margin: 1.5rem 0; }
.btn {
  display: inline-block;
  padding: 0.6rem 1.2rem;
  background: var(--red);
  color: #fff;
  text-decoration: none;
  border-radius: 6px;
}
.note { color: var(--muted); font-size: 0.92rem; }

.todo { display: none; }

/* --- mobile --- */
@media (max-width: 60rem) {
  main.with-flavor-menu { padding-right: 1.2rem; }
  .flavor-menu {
    position: static;
    width: auto;
    border-left: none;
    border-top: 1px solid var(--rule);
    margin-top: 2rem;
  }
  .toc-panel { display: none; }
}
