/* Web edition styled after the 1986 «Zaļais stars» print: cream paper, geometric sans,
   orange definition boxes, green screens, terms in the outer margin. */
:root {
  --paper: #f5efdc;
  --paper-2: #ece4cc;
  --ink: #1f1c17;
  --ink-2: #5b5547;
  --orange: #f0a057;
  --orange-ink: #1f1c17;
  --green: #2f9b4e;
  --green-ink: #e9ffe9;
  --accent: #c8461b;
  --rule: #cfc4a5;
  --measure: 36rem;
  --margin: 9.5rem;
  --sans: 'League Spartan', Futura, 'Century Gothic', 'Avenir Next', 'Trebuchet MS', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'DejaVu Sans Mono', monospace;
  --screen: 'VT323', 'IBM Plex Mono', monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --paper: #1c1a16; --paper-2: #26231d; --ink: #ece4cf; --ink-2: #a89f89;
  --orange: #8a4a1c; --orange-ink: #fff2e4; --green: #1d6b34; --green-ink: #d8ffd8;
  --accent: #f08a5d; --rule: #3c372d; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1c1a16; --paper-2: #26231d; --ink: #ece4cf; --ink-2: #a89f89;
    --orange: #8a4a1c; --orange-ink: #fff2e4; --green: #1d6b34; --green-ink: #d8ffd8;
    --accent: #f08a5d; --rule: #3c372d; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { font-size: 112.5%; -webkit-text-size-adjust: 100%; scroll-padding-top: 4rem; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 1rem/1.55 var(--sans); letter-spacing: .01em; hyphens: auto; -webkit-hyphens: auto;
  text-rendering: optimizeLegibility; font-kerning: normal;
}
a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: .15em; }
::selection { background: var(--orange); color: var(--orange-ink); }

/* top bar */
.bar {
  position: sticky; top: 0; z-index: 10; display: flex; gap: 1rem; align-items: center;
  padding: .55rem 1.2rem; background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(6px); border-bottom: 1px solid var(--rule); font-size: .8rem;
}
.bar a { text-decoration: none; white-space: nowrap; }
.bar a:hover { color: var(--accent); }
.bar .home { font-weight: 700; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.bar .sp { flex: 1; }
.bar .theme { font: inherit; background: none; border: 1px solid var(--rule); color: inherit; border-radius: 1rem; padding: 0 .5rem; cursor: pointer; }

main { padding: 2rem 1.2rem 5rem; }
.chapter, .toc, .titlepage, .pager { max-width: var(--measure); margin-inline: auto; }

/* wide screens: margin column on the left for terms, page numbers on the right */
@media (min-width: 64rem) {
  .chapter { max-width: calc(var(--measure) + 2 * var(--margin)); padding-inline: var(--margin); }
}

/* chapter heading: heavy uppercase like the print */
.ch-head { margin: 1.5rem 0 2rem; }
.ch-head h2, .toc h2 {
  font-weight: 800; text-transform: uppercase; letter-spacing: .01em;
  font-size: clamp(1.45rem, 3.6vw, 1.9rem); line-height: 1.15; margin: 0; display: inline;
}
.ch-num { font-weight: 800; font-size: clamp(1.45rem, 3.6vw, 1.9rem); margin-right: .35em; }
h3 {
  font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em;
  margin: 2.4rem 0 1rem; line-height: 1.35; max-width: 26rem;
}

/* paragraphs: justified with first-line indent, dialogue keeps the dash in the indent */
.chapter p { margin: 0; text-align: justify; text-indent: 1.2em; position: relative; }
.chapter h3 + p, .chapter .ch-head + p { text-indent: 1.2em; }
.chapter p + p { margin-top: .05em; }
.chapter p.dlg { text-indent: 1.2em; }
.missing { font-style: italic; color: var(--ink-2); text-indent: 0 !important; }

/* orange highlight: inline mark and whole paragraph box */
mark {
  background: var(--orange); color: var(--orange-ink); padding: .08em .3em; margin: 0 -.1em;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
p.hl { background: var(--orange); color: var(--orange-ink); padding: .5rem .8rem; margin: .5rem -.8rem !important; }

/* margin terms (FAILS, FAILA APRAKSTS ...) */
.mn {
  display: block; text-indent: 0; font-size: .68rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: .04em; line-height: 1.25; color: var(--ink-2); margin: .6rem 0 .2rem;
}
.mn::before { content: '▸ '; color: var(--accent); }
@media (min-width: 64rem) {
  .mn {
    position: absolute; left: calc(-1 * var(--margin)); width: calc(var(--margin) - 1.6rem);
    margin: .2rem 0 0; text-align: right; color: var(--ink);
  }
  .mn::before { content: none; }
  .mn + .mn { margin-top: 2.6rem; }
  .mn + .mn + .mn { margin-top: 5rem; }
}

/* page markers from the print edition */
.pg {
  font-size: .62rem; font-weight: 500; color: var(--ink-2); text-decoration: none;
  vertical-align: super; line-height: 0; padding: 0 .15em; border-left: 1px solid var(--rule);
  text-indent: 0; font-style: normal; user-select: none; -webkit-user-select: none;
}
.pg:hover, .pg:target { color: var(--accent); }
.pgline { text-align: right; line-height: 1; }

/* green screens */
pre { margin: 1.3rem 0; overflow-x: auto; }
pre.screen {
  background: var(--green); color: var(--green-ink);
  font: 1.3rem/1.15 var(--screen); font-feature-settings: 'zero';
  padding: 1.1rem 1.4rem 1.3rem; border-radius: 0 0 0 1.6rem; white-space: pre;
  box-shadow: inset 0 0 2.5rem rgb(0 0 0 / .18);
  text-shadow: 0 0 .25em rgb(220 255 220 / .35);
}
pre.code {
  font: .86rem/1.5 var(--mono); font-feature-settings: 'zero'; background: var(--paper-2);
  border-left: 3px solid var(--rule); padding: .7rem 1rem; white-space: pre;
}
code { font-family: var(--mono); font-size: .88em; font-feature-settings: 'zero'; }
pre code { font: inherit; }

/* formulas */
.math { text-align: center; margin: 1rem 0; font-size: 1.05rem; }
.center { text-align: center; margin: 1rem 0; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 .15em; line-height: 1.15; }
.frac > span:first-child { border-bottom: 1px solid currentColor; padding: 0 .2em; }

/* figures: drawings sit on the paper, captions in italic like the margin notes */
figure { margin: 1.6rem 0; text-align: center; position: relative; }
figure img { max-width: 100%; height: auto; mix-blend-mode: multiply; }
:root[data-theme="dark"] figure img { mix-blend-mode: normal; filter: invert(.88) sepia(.25) hue-rotate(180deg) contrast(.95); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) figure img { mix-blend-mode: normal; filter: invert(.88) sepia(.25) hue-rotate(180deg) contrast(.95); } }
figcaption { font-size: .78rem; font-style: italic; font-weight: 500; color: var(--ink-2); margin-top: .3rem; }
@media (min-width: 64rem) {
  figcaption { position: absolute; right: calc(-1 * var(--margin)); bottom: 0; width: calc(var(--margin) - 1.6rem); text-align: left; margin: 0; }
}

/* tables: ruled like the print */
.tbl { overflow-x: auto; margin: 1.4rem 0; }
table { border-collapse: collapse; font-size: .82rem; line-height: 1.3; margin: 0 auto; }
th, td { border: 1px solid var(--ink); padding: .35rem .55rem; vertical-align: top; text-align: left; hyphens: manual; }
th { font-weight: 700; }
caption { caption-side: bottom; font-size: .75rem; font-style: italic; color: var(--ink-2); padding-top: .4rem; }

ol, ul { margin: .4rem 0; padding-left: 1.6rem; }
li { text-align: justify; }
hr { border: 0; height: 1.2rem; }

/* index (priekšmetu rādītājs): multi-column */
.index-page .chapter { max-width: 60rem; padding-inline: 0; }
.ch-raditajs p { text-indent: 0; text-align: left; break-inside: avoid; font-size: .85rem; }

/* home: cover + title + contents */
.cover { display: grid; grid-template-columns: minmax(0, 20rem) minmax(0, 1fr); gap: 2.5rem; align-items: center; max-width: 60rem; margin: 1rem auto 3rem; }
.cover-img { width: 100%; box-shadow: 0 1rem 2.5rem rgb(0 0 0 / .25); border-radius: 2px; }
.cover h1 { font-weight: 500; text-transform: uppercase; font-size: clamp(1.8rem, 4.5vw, 2.8rem); line-height: 1.08; margin: .3rem 0 1rem; letter-spacing: -.01em; }
.cover h1 em { color: var(--accent); }
.cover .author { text-transform: uppercase; letter-spacing: .05em; margin: 0; }
.cover .sub { font-size: 1.05rem; margin: 0 0 1rem; }
.cover .imprint { font-size: .8rem; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; }
.cover .start a { display: inline-block; margin: .6rem .8rem 0 0; padding: .55rem 1.1rem; background: var(--green); color: #fff; text-decoration: none; font-weight: 700; border-radius: 0 0 0 .8rem; }
.cover .start a.alt { background: none; color: var(--ink); border: 1px solid var(--rule); font-weight: 500; }
.cover.mini { display: block; max-width: var(--measure); }
@media (max-width: 40rem) { .cover { grid-template-columns: 1fr; } .cover-img { max-width: 14rem; margin: auto; } }
.titlepage { font-size: .85rem; color: var(--ink-2); margin-bottom: 3rem; }
.titlepage p { margin: .3rem 0; }

.toc ol { list-style: none; padding: 0; margin: 1.2rem 0 0; }
.toc li { text-align: left; margin: .15rem 0; }
.toc li.un { margin-top: .5rem; }
.toc a { display: flex; align-items: baseline; gap: .4rem; text-decoration: none; font-weight: 700; padding: .2rem 0; }
.toc a:hover .t { color: var(--accent); }
.toc .n { width: 1.8rem; flex: none; text-align: right; }
.toc .dots { flex: 1; border-bottom: 2px dotted var(--rule); transform: translateY(-.3em); min-width: 1rem; }
.toc .pnum { font-weight: 500; font-variant-numeric: tabular-nums; }

/* chapter pager */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 4rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); }
.pager a { text-decoration: none; font-weight: 700; font-size: .9rem; line-height: 1.3; }
.pager a:hover { color: var(--accent); }
.pager small { display: block; font-weight: 400; color: var(--ink-2); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
.pager .nx { text-align: right; }

.whole .chapter + .chapter { margin-top: 5rem; padding-top: 2rem; border-top: 1px solid var(--rule); }

@media print {
  .bar, .pager, .theme, .start { display: none !important; }
  body { background: #fff; font-size: 10.5pt; }
  .chapter { break-before: page; }
  pre.screen { box-shadow: none; text-shadow: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  mark, p.hl { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* back matter */
.ch-raditajs .idx { columns: 15rem; column-gap: 2.5rem; margin-top: 1rem; }
.ch-raditajs .idx p { margin: 0 0 .15rem; padding-left: 1.2em; text-indent: -1.2em; font-size: .82rem; letter-spacing: .02em; text-align: left; break-inside: avoid; }
.ch-raditajs .idx p.sub { padding-left: 2.6em; }
.ch-raditajs .idx a { color: var(--accent); text-decoration: none; margin-left: .3em; font-variant-numeric: tabular-nums; }
.ch-raditajs .idx a:hover { text-decoration: underline; }
.ch-atgadne p { text-indent: -1.4em !important; padding-left: 1.4em; text-align: left; }
.ch-atgadne h3 { text-transform: none; font-size: .95rem; letter-spacing: 0; margin-top: 1.8rem; }
p.sig { text-align: left; text-indent: 0 !important; font-size: .82rem; margin: 1.2rem 0 0 2rem !important; }

/* narrow screens: justified text leaves rivers, use ragged right */
@media (max-width: 34rem) {
  .chapter p, li { text-align: left; }
  html { font-size: 106%; }
}
