/* =========================
   Text-first, multilingual, black & white
   No webfonts; relies on system/native fonts
   Language-driven styling via lang attribute
   ========================= */

/* --- Root variables --- */
:root{
  --bg: #ffffff;
  --text: #000000;
  --max-width: 980px;
  --pad: 1rem;
  --measure: 70ch;
  --line: 1.65;
  --scale-eng: 1.0;           /* value by trial and error; depends on font */
  --header-logo-size: 72px;
  --focus-color: #000000;
  --transition: 180ms ease;

  /* UA-size tokens for headings (rem-based, stable relative to root) */
  --h1-size-ua: 2rem;
  --h2-size-ua: 1.5rem;
  --h3-size-ua: 1.17rem;
  --h4-size-ua: 1rem;
  --h5-size-ua: 0.83rem;

  /* Uniform heading metrics (tweak per type if desired) */
  --h1-line-height: 1.05;
  --h2-line-height: 1.15;
  --h3-line-height: 1.25;
  --h4-line-height: 1.3;
  --h5-line-height: 1.35;

  --h1-weight: 600;
  --h2-weight: 600;
  --h3-weight: 600;
  --h4-weight: 600;
  --h5-weight: 500;
}

/* Dark mode override (toggle with body.dark-mode) */
body.dark-mode{
  --bg: #0f0f0f;
  --text: #ffffff;
}

/* Dark-mode toggle button */
.toggle-dark{
  background: transparent;
  color: var(--text);
  border: 1px solid currentColor;
  padding: 0.35rem 0.6rem;
  font: inherit;
  cursor: pointer;
  border-radius: 4px;
}

/* border box throughout */
*,
*::before,
*::after { box-sizing: border-box; }

/* Accessibility: smooth scroll */
html{ scroll-behavior: smooth; }

/* --- Base / Reset --- */
html, body { height: 100%; }

body{
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem; /* baseline for Indic scripts */
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  line-height: var(--line);
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

/* --- Content container & measure --- */
main{
  max-width: min(var(--max-width), var(--measure));
  width: calc(100% - 2 * var(--pad));
  padding: var(--pad);
  margin: 0 auto;
}

/* --- header with logo slots --- */
header{
  position: relative;
  padding: 1rem 0 0.6rem;
  text-align: center;
  background: var(--bg);
}

/* Constrained inner header to align with main */
.header-inner{
  display: flex;
  align-items: flex-start; /* top-align the header slots and the center column */
  justify-content: space-between;
  max-width: min(var(--max-width), var(--measure));
  width: calc(100% - 2 * var(--pad));
  margin: 0 auto;
  padding: 0;
  padding-top: 0.25rem;     /* room at top */
  gap: 1rem;
}

/* header layout: separate top (logo + title) and bottom (stacked navs) */

/* center and stack items vertically */
.header-top .header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

/* make header-bottom stack the two nav bars and allow them to use full inner width */
.header-bottom {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  align-items: center;
  max-width: min(var(--max-width), var(--measure));
  width: calc(100% - 2 * var(--pad));
  margin: 0 auto;
  padding: 0;
}

/* ensure navs inside header-bottom take full available width of the constrained container */
.header-bottom .site-nav,
.header-bottom .lang-nav {
  width: 100%;
  display: flex;
  justify-content: center;
}

/* center navs and allow them to expand */
.header-bottom .site-nav ul,
.header-bottom .lang-nav ul {
  justify-content: center;
}

/* align logo slots  */
.header-slot{
  width: var(--header-logo-size);
  height: var(--header-logo-size);
  display: flex;
  align-items: flex-start;  /* top align */
  padding-top: 0.12rem;     /* breathing room at the top */
  justify-content: center;
}

/* control vertical position of logos */
.header-slot img{
  display: block;
  max-width: 100%;
  max-height: 100%;
  margin-top: 0;           /* no unwanted centering margin */
}

/* center column stacks title, subtitle, nav vertically */
.header-center{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  text-align: center;
  flex: 1 1 auto;
  min-width: 0;
  margin-top: 0.18rem;     /* nudge content down to balance the look */
}

/* heading typography */
/* Use UA-size tokens for base sizes and remove default margins for headings;
   set uniform line-height and font-weight per heading type so those metrics
   are consistent everywhere for a given heading. */
h1, h2, h3, h4, h5 {
  margin: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* concrete sizes and uniform metrics per heading type */
h1 {
  font-size: var(--h1-size-ua);
  line-height: var(--h1-line-height);
  font-weight: var(--h1-weight);
}
h2 {
  font-size: var(--h2-size-ua);
  line-height: var(--h2-line-height);
  font-weight: var(--h2-weight);
}
h3 {
  font-size: var(--h3-size-ua);
  line-height: var(--h3-line-height);
  font-weight: var(--h3-weight);
}
h4 {
  font-size: var(--h4-size-ua);
  line-height: var(--h4-line-height);
  font-weight: var(--h4-weight);
}
h5 {
  font-size: var(--h5-size-ua);
  line-height: var(--h5-line-height);
  font-weight: var(--h5-weight);
}

h5.header{
  padding-top: 0.7rem;     /* room after title */
}

/* --- Navigation (site and language) --- */
nav.site-nav,
nav.lang-nav{
  display: flex;
  justify-content: center;
  padding: 0;
  margin-top: 0.25rem;
}

nav.site-nav ul,
nav.lang-nav ul{
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

nav.site-nav a,
nav.lang-nav a{
  color: inherit;
  text-decoration: none;
  padding: 0.2rem 0.5rem;
  font-size: 0.95rem;
}

/* active-page marker */
nav.site-nav a.current-page-url { font-weight: 550; }

/* active-language marker */
nav.lang-nav a.current-page-lang{ font-weight: 550; }


/* --- Baseline content typography (Indic baseline) --- */
:where(p, div, li, dd, dt, blockquote, table, td, th){
  margin: 0 0 0.9rem 0;
  font-size: 1rem;          /* baseline for Indic scripts */
  hyphens: auto;
  word-break: keep-all;     /* better for Indic rendering */
}

/* --- Tables --- */
table{ border-collapse: collapse; width: 100%; margin-bottom: 0.9rem; }
td, th{ padding: 0.35rem 0.5rem; vertical-align: top; text-align: left; }

/* TOC: interaction + title emphasis + mobile stacked cards (default combo) */

/* Interaction affordance: hover + keyboard focus */
tbody tr { transition: background .15s ease, transform .08s ease; }
tbody tr:hover { background: rgba(0,0,0,0.04); }
tbody tr:focus-within { background: rgba(0,0,0,0.06); outline: none; }

/* Improve clickable area for links inside cells (helps keyboard focus) */
tbody td a { display: inline-block; padding: 0.18rem 0; }

/* Title column typographic emphasis */
tbody td:nth-child(2) a {
  font-weight: 600;
  color: inherit;
  text-decoration: none;
}
tbody td:nth-child(2) a:hover,
tbody td:nth-child(2) a:focus { text-decoration: underline; }

/* Subtle zebra fallback for long lists (optional but gentle) */
tbody tr:nth-child(2n) { background: rgba(0,0,0,0.015); }


/* --- Language-driven rules (no .lang-eng required) --- */
/* English: set family and line-height; scale non-heading content via :not(:is(...))
   so headings are controlled by per-heading rules (below). */
:lang(en),
:lang(eng),
[lang|="en"],
[lang|="eng"] {
  font-family: Georgia, "Times New Roman", "Merriweather", serif;
}

/* Keep .lang-eng as an alias to avoid surprises for any edge cases */
.lang-eng,
.lang-eng * { /* alias so class continues to work if accidentally emitted */
  font-family: Georgia, "Times New Roman", "Merriweather", serif;
}

/* scale non-heading content in English without enumerating element types */
:lang(en) :where(:not(:is(h1,h2,h3,h4,h5))),
:lang(eng) :where(:not(:is(h1,h2,h3,h4,h5))),
[lang|="en"] :where(:not(:is(h1,h2,h3,h4,h5))),
[lang|="eng"] :where(:not(:is(h1,h2,h3,h4,h5))) {
  font-size: calc(1rem * var(--scale-eng));
  line-height: calc(var(--line) * var(--scale-eng));
}

/* Per-heading language-only overrides (robust: matches element-level or ancestor-level language)
   Change only font-size (and heading-specific line-height scaled for English); these rules
   must follow the base language block so cascade/order is clear. */

/* h1 */
h1:lang(en),
h1:lang(eng),
h1[lang="en"],
h1[lang="eng"],
:lang(en) h1,
:lang(eng) h1,
h1[lang="latn-x"],
:lang("latn-x") h1 {
  font-size: calc(var(--h1-size-ua) * var(--scale-eng));
  line-height: calc(var(--h1-line-height) * var(--scale-eng));
}

/* h2 */
h2:lang(en),
h2:lang(eng),
h2[lang="en"],
h2[lang="eng"],
:lang(en) h2,
:lang(eng) h2,
h2[lang="latn-x"],
:lang("latn-x") h2 {
  font-size: calc(var(--h2-size-ua) * var(--scale-eng));
  line-height: calc(var(--h2-line-height) * var(--scale-eng));
}

/* h3 */
h3:lang(en),
h3:lang(eng),
h3[lang="en"],
h3[lang="eng"],
:lang(en) h3,
:lang(eng) h3,
h3[lang="latn-x"],
:lang("latn-x") h3 {
  font-size: calc(var(--h3-size-ua) * var(--scale-eng));
  line-height: calc(var(--h3-line-height) * var(--scale-eng));
}

/* h4 */
h4:lang(en),
h4:lang(eng),
h4[lang="en"],
h4[lang="eng"],
:lang(en) h4,
:lang(eng) h4,
h4[lang="latn-x"],
:lang("latn-x") h4 {
  font-size: calc(var(--h4-size-ua) * var(--scale-eng));
  line-height: calc(var(--h4-line-height) * var(--scale-eng));
}

/* h5 */
h5:lang(en),
h5:lang(eng),
h5[lang="en"],
h5[lang="eng"],
:lang(en) h5,
:lang(eng) h5,
h5[lang="latn-x"],
:lang("latn-x") h5 {
  font-size: calc(var(--h5-size-ua) * var(--scale-eng));
  line-height: calc(var(--h5-line-height) * var(--scale-eng));
}


/* Transliteration detection: any lang tag containing -Latn-x- */
/* Matches san-Latn-x-IAST, kan-Latn-x-iso15919, etc. */
[lang*="-Latn-x-"],
[lang*="-Latn-x-"] * {
  /* pick a diacritic-capable serif for scholarly transliteration; fall back to robust families */
  font-family: "Gentium Plus", "Charis SIL", "Noto Serif", "Noto Sans", serif;
  /* tuned typographic defaults for transliteration */
  hyphens: manual;
  font-variant-ligatures: none;
  letter-spacing: 0;
}

/* If we need to tune transliteration blocks differently (example selector) */
/* Example: transliterated Indic primary languages (optional) */
[lang^="san-"][lang*="-Latn-x-"],
[lang^="kan-"][lang*="-Latn-x-"],
[lang^="hin-"][lang*="-Latn-x-"],
[lang^="tel-"][lang*="-Latn-x-"] {
  /* language-specific small tweaks can go here */
  /* e.g., slightly increased line-height if needed */
}

/* --- Links & focus --- */
a{
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
}
a:hover{ text-decoration-thickness: 2px; }

a:focus, button:focus, input:focus, textarea:focus{
  outline: 2px dashed var(--focus-color);
  outline-offset: 3px;
}

/* --- utilities --- */
.hidden{ display: none; }
.center{ text-align: center; }
.small{ font-size: 0.88rem; opacity: 0.95; }
.lead{ font-weight: 500; font-size: 1.08em; margin-bottom: 1rem; }


/* more room for main content on very large screens while keeping lines readable */
@media (min-width: 1200px){
  main{ max-width: calc(var(--max-width) + 120px); }
}


/* responsive header for narrow viewports */
@media (max-width: 640px) {
  .header-inner {
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    padding-top: 0.4rem;
  }

  .header-center {
    margin-top: 0;
  }

  .header-slot {
    padding-top: 0;
    align-items: center;        /* center logos inside slot */
  }

  .header-slot--right {
      display: none !important; /* hide right logo */
  }

  .header-slot img {
    margin-top: 0;
  }
}

/* responsivs headings on very small screens */
@media (max-width: 420px) {
  :root {
    --h1-size-ua: calc(var(--h1-size-ua) * 0.95);
    --h2-size-ua: calc(var(--h2-size-ua) * 0.95);
    --h3-size-ua: calc(var(--h3-size-ua) * 0.95);
    --h4-size-ua: calc(var(--h4-size-ua) * 0.95);
    --h5-size-ua: calc(var(--h5-size-ua) * 0.95);
  }
}

/* Print rules */
@media print{
  body{ background: #fff; color: #000; }
  .toggle-dark{ display: none; }
  a{ text-decoration: none; }
  .header-slot{ display: none; } /* hide inline header logos in print */
}
