/* ====================================================================
   ATGRIEŠANĀS — the return

   ONE theme axis, two surfaces.

   Theme  (html[data-theme="light"|"dark"]) — the reader's choice, stored,
          defaulting to the operating system. It applies to the WHOLE site,
          not just the reading pages.
   Surface (.surface-deep | .surface-paper) — the role a page plays.
          `deep`  is the display surface: the landing page, the return, the
                  data and the appendix. High contrast, coloured accents.
          `paper` is the reading surface: the manuscript itself. Quiet, warm,
                  built to hold 74,000 words without fatigue.

   Every surface defines the SAME token names in both themes, and each also
   aliases the other surface's token names, so a snippet written against
   --text-soft or against --p-soft works wherever it lands.
   ==================================================================== */

:root {
  --maxw:       1180px;
  --measure:    37rem;          /* reading measure — ~68 characters at 19px */

  --font-disp:  "Fraunces", Georgia, serif;
  --font-read:  "Literata", Georgia, "Times New Roman", serif;
  --font-body:  "Inter", system-ui, -apple-system, sans-serif;

  /* rhythm */
  --gap-section: clamp(3.6rem, 9vh, 6.5rem);
}

/* ====================================================================
   SURFACE: DEEP — the display pages
   ==================================================================== */
.surface-deep {
  /* dark values are the base; the light block below overrides them */
  --bg:         #0e0f12;
  --bg-2:       #15171c;
  --bg-3:       #1c1f26;
  --line:       rgba(255,255,255,0.10);
  --line-2:     rgba(255,255,255,0.20);
  --text:       #ece9e2;
  --text-soft:  #b3afa5;
  --text-dim:   #837e75;
  --amber:      #e9a13b;
  --amber-soft: #f0c074;
  --accent:     var(--amber);
  --accent-2:   var(--amber-soft);

  --reef:       #58c0d0;
  --mangrove:   #7cba67;
  --baltic:     #dcb63c;

  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

html[data-theme="light"] .surface-deep {
  --bg:         #fbf7ef;
  --bg-2:       #f4eee1;
  --bg-3:       #ece5d4;
  --line:       rgba(40,33,22,0.13);
  --line-2:     rgba(40,33,22,0.26);
  --text:       #17150f;
  --text-soft:  #4c463c;
  --text-dim:   #7b7365;
  --amber:      #92621a;
  --amber-soft: #7a5115;
  --accent:     var(--amber);
  --accent-2:   var(--amber-soft);

  --reef:       #1d6f7d;
  --mangrove:   #3f7a2f;
  --baltic:     #8a6a12;
}

/* ====================================================================
   SURFACE: PAPER — the manuscript
   ==================================================================== */
.surface-paper {
  --paper:      #f8f4ec;
  --paper-2:    #f0eade;
  --p-text:     #1c1a16;
  --p-soft:     #4b463f;
  --p-dim:      #7c766c;
  --p-line:     rgba(28,26,22,0.14);
  --p-accent:   #8a5e18;

  background: var(--paper);
  color: var(--p-text);
  font-family: var(--font-body);
}

html[data-theme="dark"] .surface-paper {
  --paper:      #14161a;
  --paper-2:    #1b1e24;
  --p-text:     #e2ddd3;
  --p-soft:     #aca69c;
  --p-dim:      #837d73;
  --p-line:     rgba(255,255,255,0.13);
  --p-accent:   #e9a13b;
}

/* --- cross-aliases, so either token family works on either surface --- */
.surface-deep {
  --paper: var(--bg); --paper-2: var(--bg-2);
  --p-text: var(--text); --p-soft: var(--text-soft); --p-dim: var(--text-dim);
  --p-line: var(--line); --p-accent: var(--accent-2);
}
.surface-paper {
  --bg: var(--paper); --bg-2: var(--paper-2); --bg-3: var(--paper-2);
  --text: var(--p-text); --text-soft: var(--p-soft); --text-dim: var(--p-dim);
  --line: var(--p-line); --line-2: var(--p-line);
  --amber: var(--p-accent); --amber-soft: var(--p-accent);
  --accent: var(--p-accent); --accent-2: var(--p-accent);
}

::selection { background: var(--accent); color: var(--bg); }

/* ====================================================================
   BASE
   ==================================================================== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; scroll-padding-top: 5rem; }
body {
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  font-size: 1.0625rem;          /* 17px UI baseline */
  line-height: 1.68;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 3px; }

h1, h2, h3, h4 {
  font-family: var(--font-disp); font-weight: 400;
  line-height: 1.14; letter-spacing: -.015em;
}

/* ====================================================================
   ORNAMENT — Latvian signs used as structural marks
   ==================================================================== */
.orn { display: block; color: var(--accent); opacity: .55; }
.orn--mark { width: 26px; height: 26px; opacity: .7; }

/* a full-width divider: an ornament centred on a hairline */
.divider {
  display: flex; align-items: center; gap: 1.2rem;
  margin: var(--gap-section) 0;
  color: var(--accent);
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}
.divider svg { width: 34px; height: 34px; opacity: .55; flex: none; }

/* ====================================================================
   NAV
   ==================================================================== */
.nav {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem clamp(1.1rem, 4vw, 3rem);
  font-size: .95rem;
  backdrop-filter: blur(14px);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  border-bottom: 1px solid var(--line);
}

.nav__brand {
  display: flex; align-items: baseline; gap: .55rem;
  font-family: var(--font-disp); font-weight: 500; font-size: 1.08rem;
  letter-spacing: .06em; white-space: nowrap;
}
.nav__brand b { font-weight: 500; color: var(--accent); }
.nav__brand span { font-size: .74rem; letter-spacing: .22em; text-transform: uppercase; opacity: .62; }

.nav__right { display: flex; align-items: center; gap: clamp(.7rem, 2vw, 1.4rem); }
.nav__links { display: flex; gap: clamp(.75rem, 2.2vw, 1.7rem); align-items: center; flex-wrap: wrap; }
.nav__links a { color: var(--text-soft); transition: color .2s; }
.nav__links a:hover, .nav__links a[aria-current] { color: var(--accent); }

/* theme toggle */
.theme-btn {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 2.15rem; height: 2.15rem; border-radius: 999px;
  border: 1px solid var(--line-2); background: transparent;
  color: var(--text-soft); cursor: pointer; transition: color .2s, border-color .2s;
}
.theme-btn:hover { color: var(--accent); border-color: var(--accent); }
.theme-btn svg { width: 17px; height: 17px; }
.theme-btn .i-sun  { display: none; }
html[data-theme="dark"] .theme-btn .i-sun  { display: block; }
html[data-theme="dark"] .theme-btn .i-moon { display: none; }

/* ====================================================================
   SHELL
   ==================================================================== */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 clamp(1.2rem, 4vw, 3rem); }
.eyebrow {
  font-size: .78rem; letter-spacing: .26em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 1.2rem;
}

/* ====================================================================
   HERO
   ==================================================================== */
.hero {
  position: relative;
  padding: clamp(4.5rem, 13vh, 9rem) 0 clamp(3.2rem, 8vh, 6rem);
  overflow: hidden;
}
.hero__title { font-size: clamp(2.6rem, 8vw, 5.4rem); margin-bottom: 1.3rem; }
.hero__title em { font-style: normal; color: var(--amber-soft); }
.hero__sub {
  font-family: var(--font-disp); font-size: clamp(1.15rem, 2.4vw, 1.7rem);
  color: var(--text-soft); margin-bottom: 2rem; max-width: 32ch; line-height: 1.32;
}
.hero__lede { font-size: clamp(1.06rem, 1.5vw, 1.2rem); color: var(--text-soft); max-width: 62ch; line-height: 1.72; }
.hero__lede + .hero__lede { margin-top: 1.15rem; }

.hero::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 62%;
  background: radial-gradient(120% 100% at 20% 100%, color-mix(in srgb, var(--reef) 16%, transparent), transparent 60%),
              radial-gradient(90% 90% at 85% 100%, color-mix(in srgb, var(--amber) 12%, transparent), transparent 60%);
  pointer-events: none; z-index: 0;
}
.hero > * { position: relative; z-index: 1; }

/* ====================================================================
   CARDS
   ==================================================================== */
.grid { display: grid; gap: 1.3rem; }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 23rem), 1fr)); }

.card {
  display: block; padding: 1.7rem 1.6rem; border-radius: 14px;
  background: var(--bg-2); border: 1px solid var(--line);
  transition: border-color .22s, transform .22s, background .22s;
}
.card:hover { border-color: var(--line-2); transform: translateY(-2px); background: var(--bg-3); }
.card__k { font-size: .74rem; letter-spacing: .2em; text-transform: uppercase; color: var(--text-dim); margin-bottom: .8rem; }
.card__t { font-family: var(--font-disp); font-size: 1.4rem; margin-bottom: .65rem; }
.card__d { color: var(--text-soft); font-size: 1rem; line-height: 1.62; }
.card[data-place="fiji"]   { border-left: 3px solid var(--reef); }
.card[data-place="belize"] { border-left: 3px solid var(--mangrove); }
.card[data-place="latvia"] { border-left: 3px solid var(--baltic); }
.card[data-place] .card__k { color: var(--text-soft); }

/* ====================================================================
   PROSE (site-written commentary, not the manuscript)
   ==================================================================== */
.section { padding: var(--gap-section) 0; }
.section + .section { border-top: 1px solid var(--line); }
.section__h { font-size: clamp(1.8rem, 3.4vw, 2.6rem); margin-bottom: 1.6rem; }
.prose { max-width: 66ch; }
.prose p { margin-bottom: 1.15rem; color: var(--text-soft); font-size: 1.08rem; line-height: 1.74; }
.prose strong { color: var(--text); font-weight: 600; }
.prose a { border-bottom: 1px solid currentColor; color: var(--accent-2); }
.prose a:hover { color: var(--accent); }

.note {
  border-left: 2px solid var(--accent); padding: 1rem 0 1rem 1.25rem;
  color: var(--text-soft); font-size: 1rem; margin: 2rem 0; max-width: 64ch; line-height: 1.7;
}

/* ====================================================================
   READER
   ==================================================================== */
.reader { display: grid; grid-template-columns: minmax(0,1fr); }
@media (min-width: 64rem) {
  .reader { grid-template-columns: 19rem minmax(0,1fr); align-items: start; }
}

/* --- contents rail --- */
.toc {
  position: sticky; top: 3.6rem; align-self: start;
  max-height: calc(100vh - 3.6rem); overflow-y: auto;
  padding: 1.8rem clamp(1.2rem,3vw,1.8rem) 3rem;
  border-right: 1px solid var(--p-line);
  font-size: .92rem;
  scrollbar-width: thin;
}
@media (max-width: 63.99rem) {
  .toc { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--p-line); }
}
.toc__h { font-size: .72rem; letter-spacing: .22em; text-transform: uppercase; color: var(--p-dim); margin-bottom: 1rem; }
.toc ol, .toc ul { list-style: none; }
.toc__sec {
  margin: 1.5rem 0 .55rem; font-family: var(--font-disp); font-size: .86rem;
  color: var(--p-dim); letter-spacing: .04em; line-height: 1.35;
}
.toc a { display: block; padding: .36rem 0; color: var(--p-soft); line-height: 1.4; transition: color .18s; }
.toc a:hover { color: var(--p-accent); }
.toc a[aria-current] { color: var(--p-accent); font-weight: 600; }
.toc__n { color: var(--p-dim); font-variant-numeric: tabular-nums; margin-right: .5rem; }

/* the sections of the chapter you are in, nested under it */
.toc__subs { margin: .1rem 0 .5rem .9rem; border-left: 1px solid var(--p-line); padding-left: .8rem; }
.toc__subs a { font-size: .84rem; padding: .24rem 0; color: var(--p-dim); }
.toc__subs a:hover { color: var(--p-accent); }
.toc__subs a.is-here { color: var(--p-accent); font-weight: 600; }

/* --- the page --- */
.page { padding: clamp(2.2rem, 6vh, 4.5rem) clamp(1.2rem, 5vw, 3rem) 7rem; min-width: 0; }
.page__inner { max-width: var(--measure); margin: 0 auto; }
@media (min-width: 64rem) { .page__inner { margin: 0 auto 0 clamp(0rem, 4vw, 5rem); } }

.chapter__k { font-size: .78rem; letter-spacing: .24em; text-transform: uppercase; color: var(--p-accent); margin-bottom: .9rem; }
.chapter__t { font-size: clamp(1.95rem, 4.2vw, 2.8rem); margin-bottom: 2.4rem; line-height: 1.15; }
.chapter__sub {
  font-family: var(--font-disp); font-size: 1.12rem; line-height: 1.4;
  color: var(--p-soft); margin: -1.7rem 0 2.4rem; max-width: 42ch;
}

/* the manuscript itself */
.doc {
  font-family: var(--font-read);
  font-size: 1.185rem;            /* ~19px */
  line-height: 1.78;
  color: var(--p-text);
}
.doc p { margin-bottom: 1.2em; text-wrap: pretty; }
.doc p + p { text-indent: 1.4em; }
.doc p.lead, .doc h2 + p, .doc h3 + p { text-indent: 0; }
.doc h2 {
  font-family: var(--font-disp); font-size: 1.52rem; margin: 2.8em 0 1em;
  padding-top: .3em; line-height: 1.22;
}
.doc h3 { font-family: var(--font-disp); font-size: 1.2rem; margin: 2.2em 0 .8em; color: var(--p-soft); }
.doc h2:first-child, .doc h3:first-child { margin-top: 0; }
.doc em { font-style: italic; }

.doc h2, .doc h3 { position: relative; scroll-margin-top: 5.5rem; }
.doc .anchor {
  position: absolute; left: -1.4em; top: .15em; opacity: 0;
  color: var(--p-dim); font-family: var(--font-body); font-size: .78em;
  transition: opacity .18s;
}
.doc h2:hover .anchor, .doc h3:hover .anchor, .anchor:focus { opacity: 1; }

.doc .abstract {
  background: var(--paper-2); border-radius: 10px; padding: 1.5rem 1.6rem;
  font-size: 1.06rem; margin-bottom: 2.4rem; line-height: 1.72;
}
.doc .abstract p { text-indent: 0; margin-bottom: .8em; }
.doc .abstract p:last-child { margin-bottom: 0; }
.doc .abstract .abstract__k {
  font-family: var(--font-body); font-size: .7rem; letter-spacing: .22em;
  text-transform: uppercase; color: var(--p-dim); display: block; margin-bottom: .7rem;
}

.refs { font-family: var(--font-body); font-size: .95rem; line-height: 1.6; }
.refs li {
  list-style: none; padding-left: 1.6em; text-indent: -1.6em;
  margin-bottom: .7em; color: var(--p-soft);
}

.corr { border-bottom: 1px dotted var(--p-accent); cursor: help; }

/* Manuscript tables. Cell content comes straight from the .DOC's own cell marks,
   so a table can be wide (the survey instrument, the factor loadings); it scrolls
   inside its own box rather than pushing the page sideways. */
.doc .tbl { margin: 2rem 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.doc table {
  border-collapse: collapse; width: 100%; min-width: 18rem;
  font-family: var(--font-body); font-size: .9rem; line-height: 1.5;
  color: var(--p-soft);
}
.doc table th, .doc table td {
  border-bottom: 1px solid var(--p-line);
  padding: .5rem .75rem; text-align: left; vertical-align: top;
}
.doc table thead th {
  color: var(--p-text); font-weight: 600; white-space: nowrap;
  border-bottom-width: 2px;
}
.doc table tbody tr:nth-child(even) { background: var(--paper-2); }
.doc table tbody tr:last-child td { border-bottom: 0; }
.doc table p { margin: 0; text-indent: 0; }

/* The per-cent-cover formula in Chapter Three: a displayed fraction, which Word
   had styled as two headings. */
.doc .frac {
  margin: 1.8rem auto; text-align: center; display: table;
  font-family: var(--font-body); font-size: .95rem; color: var(--p-soft);
}
.doc .frac__n, .doc .frac__d { display: block; padding: .3rem 1rem; }
.doc .frac__n { border-bottom: 1px solid var(--p-line); }



figure.fig { margin: 2.4rem 0; }
figure.fig img { border-radius: 6px; background: #fff; border: 1px solid var(--p-line); }
figure.fig figcaption {
  font-family: var(--font-body); font-size: .87rem; color: var(--p-dim);
  margin-top: .7rem; line-height: 1.55;
}

.pager {
  display: flex; justify-content: space-between; gap: 1.2rem; margin-top: 4.5rem;
  padding-top: 1.8rem; border-top: 1px solid var(--p-line); font-size: .96rem;
}
.pager a { color: var(--p-soft); max-width: 46%; }
.pager a:hover { color: var(--p-accent); }
.pager .pager__k {
  display: block; font-size: .7rem; letter-spacing: .2em;
  text-transform: uppercase; color: var(--p-dim); margin-bottom: .35rem;
}
.pager a:last-child { text-align: right; }

.progress {
  position: fixed; top: 0; left: 0; height: 2px; background: var(--p-accent);
  z-index: 70; width: 0; transition: width .1s linear;
}

/* reader controls (text size, one-document link) */
.rc { display: flex; gap: .55rem; align-items: center; flex-wrap: wrap; }
.rc button, .rc a.rc-link {
  font: inherit; font-family: var(--font-body); font-size: .84rem;
  padding: .35rem .7rem; border-radius: 7px;
  background: transparent; border: 1px solid var(--p-line); color: var(--p-soft);
  cursor: pointer; transition: border-color .18s, color .18s;
}
.rc button:hover, .rc a.rc-link:hover { color: var(--p-accent); border-color: var(--p-accent); }
.rc button[aria-pressed="true"] { color: var(--p-accent); border-color: var(--p-accent); }

/* per-reader text-size steps, applied to <html> */
html[data-textsize="l"]  .doc { font-size: 1.3rem;  line-height: 1.8; }
html[data-textsize="xl"] .doc { font-size: 1.42rem; line-height: 1.82; }
html[data-textsize="l"]  { --measure: 40rem; }
html[data-textsize="xl"] { --measure: 43rem; }

/* ====================================================================
   ONE-DOCUMENT EDITION
   ==================================================================== */
.onepage__ch {
  padding-top: clamp(3rem, 8vh, 5rem);
  margin-top: clamp(3rem, 8vh, 5rem);
  border-top: 1px solid var(--p-line);
  scroll-margin-top: 4.5rem;
}
.onepage__ch:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.onepage__k {
  font-size: .76rem; letter-spacing: .24em; text-transform: uppercase;
  color: var(--p-accent); margin-bottom: .8rem;
}
.onepage__t { font-size: clamp(1.8rem, 3.6vw, 2.5rem); margin-bottom: 2rem; }
.onepage__secdiv {
  display: flex; align-items: center; gap: 1.2rem;
  margin: clamp(4rem, 10vh, 7rem) 0 0; color: var(--p-accent);
}
.onepage__secdiv::before, .onepage__secdiv::after { content: ""; flex: 1; height: 1px; background: var(--p-line); }
.onepage__secdiv span {
  font-family: var(--font-disp); font-size: .92rem; letter-spacing: .08em;
  color: var(--p-dim); text-align: center; max-width: 36ch; line-height: 1.35;
}

/* search */
.finder { margin: 0 0 1.4rem; }
.finder input {
  width: 100%; font: inherit; font-family: var(--font-body); font-size: .92rem;
  padding: .55rem .75rem; border-radius: 8px;
  border: 1px solid var(--p-line); background: var(--paper-2); color: var(--p-text);
}
.finder input::placeholder { color: var(--p-dim); }
.finder input:focus { border-color: var(--p-accent); outline: none; }
.finder__out { font-size: .82rem; color: var(--p-dim); margin-top: .45rem; min-height: 1.2em; }
.finder__hits { margin-top: .5rem; max-height: 42vh; overflow-y: auto; }
.finder__hits a {
  display: block; padding: .45rem .1rem; font-size: .84rem;
  color: var(--p-soft); border-bottom: 1px solid var(--p-line); line-height: 1.45;
}
.finder__hits a:hover { color: var(--p-accent); }
.finder__hits b { color: var(--p-accent); font-weight: 600; }
.finder__hits .fh__k {
  display: block; font-size: .7rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--p-dim); margin-bottom: .2rem;
}
mark.hit { background: color-mix(in srgb, var(--p-accent) 30%, transparent); color: inherit; border-radius: 2px; }
mark.hit--on { background: var(--p-accent); color: var(--paper); }

.to-top {
  position: fixed; right: 1.3rem; bottom: 1.3rem; z-index: 55;
  width: 2.7rem; height: 2.7rem; border-radius: 999px;
  display: none; align-items: center; justify-content: center;
  background: var(--paper-2); border: 1px solid var(--p-line); color: var(--p-soft);
  cursor: pointer; font-size: 1.1rem;
}
.to-top.on { display: flex; }
.to-top:hover { color: var(--p-accent); border-color: var(--p-accent); }

/* ====================================================================
   FOOTER
   ==================================================================== */
.foot { padding: 3.4rem 0 4.5rem; font-size: .92rem; border-top: 1px solid var(--line); color: var(--text-dim); }
.foot__row { display: flex; flex-wrap: wrap; gap: 1.5rem; justify-content: space-between; }
.foot a { border-bottom: 1px solid transparent; }
.foot a:hover { color: var(--accent); }

/* ====================================================================
   MISC
   ==================================================================== */
.tag {
  display: inline-block; font-size: .7rem; letter-spacing: .16em; text-transform: uppercase;
  padding: .25rem .6rem; border-radius: 999px; border: 1px solid var(--line-2); color: var(--text-soft);
}

.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .78rem 1.3rem; border-radius: 999px; font-size: .96rem;
  border: 1px solid var(--line-2); color: var(--text); transition: all .2s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn--solid { background: var(--amber); color: var(--bg); border-color: var(--amber); font-weight: 500; }
.btn--solid:hover { background: var(--amber-soft); border-color: var(--amber-soft); color: var(--bg); }
.btn-row { display: flex; flex-wrap: wrap; gap: .8rem; margin-top: 2.2rem; }

.stat { font-family: var(--font-disp); font-size: clamp(2rem, 4vw, 2.9rem); color: var(--accent-2); line-height: 1; }
.stat + .stat__l {
  display: block; font-size: .82rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--text-dim); margin-top: .55rem; line-height: 1.45;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
