/* IPL specification site: a plain documentation layout (left sidebar + content), light and dark.
 * Latin text uses the system UI stack; Thai falls through to Sarabun / Noto Sans Thai (the Latin
 * system faces carry no Thai glyphs). Equations are inline SVGs that paint with currentColor. */

* { box-sizing: border-box; }
:root {
  color-scheme: light dark;
  --bg: #ffffff; --fg: #1d2127; --muted: #5d6673; --line: #dde1e6; --soft: #f5f7f9;
  --side: #f7f8fa; --code: #eef1f4; --link: #0b5cad; --accent: #0b5cad; --on: #e3eefb;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Sarabun', 'Noto Sans Thai', 'Leelawadee UI', sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181d; --fg: #e3e6ea; --muted: #9aa3ae; --line: #2d333b; --soft: #1b1f25;
    --side: #1a1d23; --code: #252a32; --link: #7cb7ff; --accent: #7cb7ff; --on: #1f2c3d;
  }
}
:root[data-theme="dark"] {
  --bg: #15181d; --fg: #e3e6ea; --muted: #9aa3ae; --line: #2d333b; --soft: #1b1f25;
  --side: #1a1d23; --code: #252a32; --link: #7cb7ff; --accent: #7cb7ff; --on: #1f2c3d;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--sans); font-size: 1.0625rem; line-height: 1.65; }
:lang(th) body, body:lang(th) { line-height: 1.75; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 17rem minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--side); border-right: 1px solid var(--line);
  padding: 1.25rem 1rem 2rem; font-size: .9rem; line-height: 1.45;
}
.doc { min-width: 0; padding: 2.5rem clamp(16px, 4vw, 3.5rem) 3rem; }

/* ---------- sidebar ---------- */
.brand { display: block; color: var(--fg); text-decoration: none; margin-bottom: 1rem; }
.brand b { display: block; font-size: 1.35rem; letter-spacing: .02em; }
.brand span { color: var(--muted); font-size: .85rem; }
.ver { margin: -.5rem 0 .25rem; color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
.dl strong { font-weight: 600; }
.menu > summary { display: none; }
.side h2 { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 1.1rem 0 .4rem; font-weight: 600; }
.pills { display: flex; flex-wrap: wrap; gap: .3rem; margin: 0; padding: 0; list-style: none; }
.pills a, .pills strong {
  display: inline-block; padding: .15rem .55rem; border: 1px solid var(--line); border-radius: 999px;
  text-decoration: none; color: var(--fg); font-weight: 400; background: var(--bg);
}
.pills strong { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.pills small { color: var(--muted); }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc ul ul { padding-left: .85rem; margin: .1rem 0 .3rem; border-left: 1px solid var(--line); }
.toc a { display: block; padding: .14rem .4rem; border-radius: 4px; color: var(--fg); text-decoration: none; }
.toc ul ul a { color: var(--muted); font-size: .86rem; }
.toc a:hover { background: var(--on); }
.toc a.on { background: var(--on); color: var(--accent); }
.toc .num { color: var(--muted); margin-right: .35em; font-variant-numeric: tabular-nums; }
.toc .pages > li { margin: .05rem 0; }
.toc .pages > li > a, .toc .pages > li > strong { display: block; padding: .2rem .4rem; border-radius: 4px; }
.toc .pages > li > strong { color: var(--accent); font-weight: 600; background: var(--on); }
.toc .pages > li > a { color: var(--fg); }
.toc ul.sub { padding-left: .6rem; margin: .25rem 0 .5rem .4rem; border-left: 2px solid var(--accent); }
.toc ul.sub > li > a { font-size: .88rem; }
.toc code { font-size: .85em; padding: 0 .15em; }
.dl { margin: 0; padding: 0; list-style: none; }
.dl li { margin: .15rem 0; }

/* ---------- content ---------- */
.doc > * { max-width: 72rem; }
.doc p, .doc ul, .doc ol, .doc blockquote, .doc dl, .doc figure { max-width: 48rem; }
.doc p { margin: .6em 0; }
.doc h1, .doc h2, .doc h3, .doc h4, .doc h5 { line-height: 1.3; scroll-margin-top: 1rem; }
.doc h1 { font-size: 2rem; margin: 0 0 .4em; }
.doc h2 { font-size: 1.5rem; margin: 2.2em 0 .5em; padding-bottom: .3em; border-bottom: 1px solid var(--line); }
.doc h3 { font-size: 1.2rem; margin: 1.8em 0 .4em; }
/* every page opens with a heading of one size: a split section's subpage (/7/N/) starts with its h3 */
.doc > h3:first-child { font-size: 1.5rem; padding-bottom: .3em; border-bottom: 1px solid var(--line); }
.doc > :is(h2, h3):first-child { margin-top: 0; }
.doc h4, .doc h5 { font-size: 1.05rem; margin: 1.5em 0 .3em; }
.doc .num { color: var(--muted); margin-right: .45em; font-variant-numeric: tabular-nums; }
.doc :target { scroll-margin-top: 1rem; }
p.cl { margin-top: 1em; }
p.cl .num { font-weight: 700; color: var(--fg); }
.doc h2 + p.cl, .doc h2 + .lv { margin-top: 0; }

.title { margin-bottom: 1.5rem; }
.title h1 { margin-bottom: .2em; }
.title p { margin: .2em 0; color: var(--muted); }
.title .tbl { margin-top: 1rem; }
.doc > .title ~ .title { margin-top: 3rem; padding-top: 1.5rem; border-top: 2px solid var(--line); }
.doc > .title ~ .title h1 { font-size: 1.6rem; }

.doc ul, .doc ol { padding-left: 1.4em; }
.doc li { margin: .25em 0; }
.doc li > p { margin: .3em 0; }
blockquote { margin: 1em 0; padding: .1em 1em; border-left: 3px solid var(--line); color: var(--muted); }

code { font-family: var(--mono); font-size: .88em; background: var(--code); padding: .1em .3em; border-radius: 4px; overflow-wrap: anywhere; }
pre { font-family: var(--mono); font-size: .85rem; line-height: 1.5; background: var(--code); padding: .8rem 1rem; border-radius: 6px; overflow-x: auto; max-width: 100%; }
pre code { font-size: inherit; padding: 0; background: none; overflow-wrap: normal; }

/* ---------- tables: full width, scroll inside their own wrapper ---------- */
.tbl { overflow-x: auto; margin: 1rem 0; max-width: 100%; -webkit-overflow-scrolling: touch; }
.doc table { border-collapse: collapse; font-size: .92rem; line-height: 1.45; }
.doc th, .doc td { border: 1px solid var(--line); padding: .4em .65em; vertical-align: top; text-align: left; }
.doc thead th { background: var(--soft); font-weight: 600; }
.doc tbody tr:nth-child(even) { background: var(--soft); }
.doc td code { white-space: nowrap; overflow-wrap: normal; }
.doc hr { border: 0; border-top: 1px solid var(--line); margin: 2rem 0; }

/* ---------- equations (Typst → SVG, currentColor) and figures ---------- */
svg.math { display: inline-block; overflow: visible; }
.math-display { margin: 1rem 0; padding: .3rem 0; overflow-x: auto; text-align: center; max-width: 48rem; }
.math-display svg.math { max-width: none; }
figure { margin: 1.5rem 0; }
figure img { display: block; max-width: 100%; height: auto; background: #fff; border-radius: 6px; border: 1px solid var(--line); }
figcaption { color: var(--muted); font-size: .9rem; margin-top: .5rem; }

/* ---------- previous / next page, overview page list ---------- */
.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3.5rem; max-width: 48rem; }
.pager a { flex: 1 1 0; min-width: 0; padding: .7rem .9rem; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; color: var(--fg); }
.pager a:hover { border-color: var(--accent); }
.pager .next { text-align: right; }
.pager small { display: block; color: var(--muted); font-size: .8rem; }
.pager .num { margin-right: .35em; }
.pagelist ul { columns: 2 16rem; }

.foot { margin-top: 4rem; padding-top: 1rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .8rem; max-width: 48rem; }

/* ---------- phones and narrow windows: sidebar becomes a collapsible bar ---------- */
@media (max-width: 899px) {
  .layout { display: block; }
  .side { position: static; height: auto; overflow: visible; border-right: 0; border-bottom: 1px solid var(--line); padding: .75rem 16px; }
  .brand { margin-bottom: .5rem; }
  .brand b { display: inline; font-size: 1.15rem; margin-right: .4rem; }
  .menu > summary { display: list-item; cursor: pointer; font-weight: 600; color: var(--accent); padding: .25rem 0; }
  .menu[open] > summary { margin-bottom: .25rem; }
  .doc { padding: 1.25rem 16px 2.5rem; }
  .doc h1 { font-size: 1.6rem; }
  .doc h2, .doc > h3:first-child { font-size: 1.3rem; }
  .doc td:nth-child(n+3) { min-width: 9em; }
  .math-display svg.math { font-size: .88em; }
}

@media print {
  .side { display: none; }
  .layout { display: block; }
  .doc { padding: 0; }
  .tbl, .math-display { overflow: visible; }
}
.toc ul.subpages { padding-left: .6rem; margin: .1rem 0 .3rem .4rem; border-left: 1px solid var(--line); }
.toc ul.subpages > li > a, .toc ul.subpages > li > strong { display: block; padding: .14rem .4rem; border-radius: 4px; font-size: .9rem; }
.toc ul.subpages > li > a { color: var(--fg); }
.toc ul.subpages > li > strong { color: var(--accent); font-weight: 600; background: var(--on); }
.pagelist ul ul { columns: auto; margin: .2rem 0 .4rem; }
