/* Self-hosted fonts (SIL OFL — see fonts/OFL-*.txt). Full builds, not
   subsets: Google Fonts' unicode-range slices drop the combining IPA
   diacritics (e̞, n̪), which renders as boxes in Chromium. */
@font-face {
  font-family: "Fraunces";
  src: url("fonts/Fraunces.ttf") format("truetype-variations");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("fonts/Fraunces-Italic.ttf") format("truetype-variations");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Source Sans 3";
  src: url("fonts/SourceSans3.ttf") format("truetype-variations");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Source Sans 3";
  src: url("fonts/SourceSans3-Italic.ttf") format("truetype-variations");
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Gentium Plus";
  src: url("fonts/GentiumPlus-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Gentium Plus";
  src: url("fonts/GentiumPlus-Italic.ttf") format("truetype");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

:root {
  --paper: #f5f1e8;
  --paper-raised: #faf7f0;
  --ink: #26332c;
  --muted: #6b7268;
  --sage: #7a8b6f;
  --gold: #b0975b;
  --hairline: #ddd6c6;
  --serif: "Fraunces", georgia, serif;
  --sans: "Source Sans 3", system-ui, sans-serif;
  --ipa: "Gentium Plus", "Charis SIL", serif;
}

* { box-sizing: border-box; }

/* Root size in percent so browser font settings scale the whole site;
   130% of the 16px default gives a ~21px base for comfortable reading. */
html { font-size: 130%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.6;
}

header { text-align: center; padding: 3.5rem 1rem 0; }
.mark {
  font-family: var(--serif);
  font-weight: 350;
  font-size: 3rem;
  letter-spacing: .35em;
  margin: 0 0 .3rem .35em; /* re-center against tracking */
}
.sub { color: var(--muted); margin: 0; font-size: .95rem; }

main { max-width: 44rem; margin: 0 auto; padding: 1.75rem 1.25rem 4rem; }

.searchbar input {
  width: 100%;
  font: inherit;
  font-size: 1.05rem;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--hairline);
  border-radius: 2px;
  padding: .75rem 1rem;
  outline: none;
}
.searchbar input:focus { border-color: var(--sage); }
.searchbar input::placeholder { color: var(--muted); opacity: .7; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .6rem;
  align-items: center;
}
.filters select, .filters button {
  font: inherit;
  font-size: .85rem;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--hairline);
  border-radius: 2px;
  padding: .3rem .55rem;
}
.filters select:focus, .filters button:hover { border-color: var(--sage); outline: none; }
.filters button { color: var(--muted); cursor: pointer; margin-left: auto; }

.vine { color: var(--sage); margin: 1.6rem auto 1rem; max-width: 26rem; opacity: .8; }
.vine svg { display: block; width: 100%; height: 14px; }

.status { color: var(--muted); font-size: .85rem; text-align: center; min-height: 1.2em; margin: 0 0 .8rem; }

.results { list-style: none; margin: 0; padding: 0; }
.results > li { border-bottom: 1px solid var(--hairline); }

.entry-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: .35rem 1rem;
  align-items: baseline;
  width: 100%;
  padding: 1rem .25rem;
  background: none;
  border: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.entry-head:hover .w { color: var(--sage); }
.entry-head .w {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.45rem;
  line-height: 1.1;
}
.entry-head .g { color: var(--ink); }
.entry-head .pos { color: var(--muted); font-size: .8rem; letter-spacing: .05em; }
.entry-head .ipa-line {
  grid-column: 1 / -1;
  font-family: var(--ipa);
  color: var(--muted);
  font-size: .95rem;
}
.entry-head .syll { margin-left: 1rem; letter-spacing: .06em; }

.entry-body { padding: 0 .25rem 1.4rem; max-width: 40rem; }
.entry-body h3 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.02rem;
  margin: 1.1rem 0 .25rem;
}
.entry-body p { margin: .25rem 0; }
.entry-body .concept { font-style: italic; color: var(--muted); margin-top: 0; }
.entry-body .phi { font-family: var(--serif); font-style: italic; color: var(--sage); }
.entry-body .rule-note {
  font-style: italic;
  color: var(--muted);
  border-left: 2px solid var(--gold);
  padding-left: .7rem;
  margin: .8rem 0;
}
.pillar { margin: .35rem 0; }
.pillar b { font-weight: 600; font-size: .82rem; letter-spacing: .04em; color: var(--sage); display: block; }
.tagrow { margin-top: 1rem; }
.tag {
  display: inline-block;
  font-size: .78rem;
  color: var(--muted);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: .05rem .6rem;
  margin: 0 .3rem .3rem 0;
}

.more {
  display: block;
  margin: 1.5rem auto 0;
  font: inherit;
  font-size: .9rem;
  color: var(--sage);
  background: none;
  border: 1px solid var(--hairline);
  border-radius: 2px;
  padding: .4rem 1.4rem;
  cursor: pointer;
}
.more:hover { border-color: var(--sage); }

footer {
  border-top: 1px solid var(--hairline);
  color: var(--muted);
  font-size: .85rem;
  text-align: center;
  padding: 1.4rem 1rem 2.5rem;
}
footer a { color: var(--sage); }

@media (max-width: 560px) {
  .entry-head { grid-template-columns: 1fr auto; }
  .entry-head .g { grid-column: 1 / -1; }
}

/* --- the landing page (kia.md, rendered) --- */
.landing main { max-width: 40rem; padding-top: 3.5rem; }
.landing h1 {
  font-family: var(--serif);
  font-weight: 350;
  font-size: 3rem;
  letter-spacing: .35em;
  text-align: center;
  margin: 0 0 2rem .35em;
}
.landing h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.35rem;
  margin: 2.2rem 0 .6rem;
}
.landing p { margin: .8rem 0; }
.landing strong { font-family: var(--serif); color: var(--sage); font-weight: 600; }
.landing em { font-style: italic; }
.landing blockquote {
  margin: 1.2rem 0 1.2rem 1rem;
  padding-left: 1rem;
  border-left: 2px solid var(--gold);
  font-family: var(--serif);
  line-height: 1.9;
}
.landing hr { border: none; border-top: 1px solid var(--hairline); margin: 2rem auto; max-width: 26rem; }
.landing a { color: var(--sage); }
.landing .doorlink { text-align: center; margin-top: 2.5rem; font-size: 1.1rem; }

/* --- top navigation, both pages --- */
.topnav {
  text-align: center;
  padding: 1rem 1rem .95rem;
  border-bottom: 1px solid var(--hairline);
  font-family: var(--serif);
  font-size: .95rem;
  letter-spacing: .12em;
}
.topnav a, .topnav .here { margin: 0 .65rem; }
.topnav a { color: var(--sage); text-decoration: none; }
.topnav a:hover { color: var(--ink); }
.topnav .here { color: var(--ink); font-weight: 600; }
.topnav a.here { color: var(--ink); }
.topnav .sep { color: var(--gold); opacity: .75; }

/* --- the primer reader --- */
.primer main { max-width: 38rem; }
.primer h1 { font-size: 2rem; letter-spacing: .04em; text-align: left; margin-bottom: 1.2rem; }
.primer h2 { font-size: 1.15rem; }
.primer blockquote strong { font-size: 1.08rem; letter-spacing: .02em; }
.primer table {
  border-collapse: collapse;
  margin: 1rem 0 1.4rem;
  font-size: .92rem;
  width: 100%;
}
.primer th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; letter-spacing: .05em; }
.primer th, .primer td { padding: .3rem .8rem .3rem 0; border-bottom: 1px solid var(--hairline); }
.primer td:first-child { font-family: var(--serif); color: var(--sage); font-weight: 600; }
.toc { line-height: 2; padding-left: 1.2rem; }
.toc a { text-decoration: none; }
.chapnav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--hairline);
  font-size: .9rem;
}
.chapnav a { color: var(--sage); text-decoration: none; }
.chapnav a:hover { color: var(--ink); }

/* --- manual reader extras --- */
.crumb { color: var(--muted); font-size: .8rem; letter-spacing: .08em; margin: 0 0 .3rem; }
.toc-ch { font-family: var(--serif); font-weight: 500; font-size: 1rem; margin: 1.1rem 0 .2rem; color: var(--ink); }

/* ---- appendix A: gloss rows carry a hover/click popover ---- */
.gloss-row { cursor: pointer; }
.gloss-row:hover, .gloss-row.open { background: var(--paper-raised); }
.gloss-table td:first-child { position: relative; }
.glossmark { color: var(--gold); font-size: .78em; }
.gloss-pop {
  display: none;
  position: absolute;
  left: 0;
  top: 100%;
  z-index: 5;
  width: max-content;
  max-width: min(22rem, 80vw);
  margin-top: .3rem;
  padding: .6rem .8rem;
  background: var(--paper-raised);
  border: 1px solid var(--hairline);
  border-left: 2px solid var(--gold);
  border-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
  font-size: .88rem;
  line-height: 1.5;
  color: var(--ink);
  font-family: var(--sans);
}
.gloss-row:hover .gloss-pop,
.gloss-row:focus-visible .gloss-pop,
.gloss-row.open .gloss-pop { display: block; }
.primer pre {
  background: var(--paper-raised);
  border: 1px solid var(--hairline);
  border-left: 2px solid var(--gold);
  padding: .8rem 1rem;
  font-size: .9rem;
  line-height: 1.7;
  overflow-x: auto;
  font-family: var(--ipa);
}

/* --- dark theme: the forest at night --- */
html[data-theme="dark"] {
  --paper: #232b24;
  --paper-raised: #2a332b;
  --ink: #e9e4d6;
  --muted: #9aa294;
  --sage: #a3b795;
  --gold: #c9b078;
  --hairline: #3a443a;
}
html[data-theme="dark"] body { background: var(--paper); color: var(--ink); }

.themetoggle {
  background: none;
  border: none;
  color: var(--sage);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
  padding: 0 0 0 .4rem;
  line-height: 1;
}
.themetoggle:hover { color: var(--ink); }

.teng-svg { vertical-align: middle; max-width: 100%; }

/* ---- tengwar mode pamphlet: both hands shown at once, no toggle ---- */
.teng-dual { font-size: 2em; }

/* ---- reading memory (reader.js): continue-reading box, bookmarks ---- */
.readerhome {
  margin: 1rem 0 1.5rem;
  padding: .7rem 1rem;
  background: var(--paper-raised);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  font-family: var(--sans);
  font-size: .95rem;
}
.readerhome p { margin: .25rem 0; }
.readerhome a { color: var(--sage); text-decoration: none; }
.readerhome a:hover { color: var(--ink); }
.reader-marks-label {
  color: var(--muted);
  font-size: .75rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-top: .55rem;
}
ul.reader-marks { list-style: none; margin: .2rem 0 0; padding: 0; }
ul.reader-marks li { margin: .18rem 0; }
.unmark {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: .95rem;
  padding: 0 .35rem;
  line-height: 1;
}
.unmark:hover { color: var(--gold); }
.markbtn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gold);
  font-size: .65em;
  padding: 0 .15rem;
  margin-left: .45rem;
  vertical-align: middle;
  opacity: 0;
  transition: opacity .15s ease;
}
h1:hover .markbtn, h2:hover .markbtn, h3:hover .markbtn,
.markbtn:focus-visible { opacity: .55; }
.markbtn.marked { opacity: .9; }
h1:hover .markbtn.marked, h2:hover .markbtn.marked,
h3:hover .markbtn.marked { opacity: 1; }
@media (hover: none) {
  .markbtn { opacity: .4; }
  .markbtn.marked { opacity: 1; }
}
