/* nx-gir web: light, dark and black themes.
   Colors are tokens; dark is set twice: for the
   theme button, and for the system choice when
   scripts are off. Black is dark on a fully black
   background, for OLED screens and night reading;
   only the theme button sets it. */

:root {
  color-scheme: light;
  --bg: #faf9f5;
  --surface: #f0eee6;
  --text: #141413;
  --muted: #6b6a65;
  --rule: #e3e0d6;
  --accent: #d97757;
  --accent-ink: #b85c3e;
  --hover: #f3f1ea;
  --mark: #f5ddd2;
  --on-accent: #ffffff;
  --shadow: rgba(20, 20, 19, 0.08);
  --serif: "Noto Serif Armenian", "Noto Serif",
    Georgia, "Times New Roman", serif;
  /* the font of the books' text only: Arian Grqi,
     or the one picked in the text settings
     (fonts.css, data-font); the page keeps --serif */
  --book: "nx Arian Grqi", "nx Noto Serif Armenian",
    "Noto Serif Armenian", "Noto Serif",
    Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI",
    "Noto Sans Armenian", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1f1e1d;
    --surface: #262624;
    --text: #f0eee6;
    --muted: #a3a199;
    --rule: #3a3936;
    --accent: #e08a6d;
    --accent-ink: #e9a088;
    --hover: #2a2927;
    --mark: #4a3127;
    --on-accent: #1f1e1d;
    --shadow: rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1f1e1d;
  --surface: #262624;
  --text: #f0eee6;
  --muted: #a3a199;
  --rule: #3a3936;
  --accent: #e08a6d;
  --accent-ink: #e9a088;
  --hover: #2a2927;
  --mark: #4a3127;
  --on-accent: #1f1e1d;
  --shadow: rgba(0, 0, 0, 0.4);
}

:root[data-theme="black"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #0e0e0d;
  --text: #e8e6de;
  --muted: #94928b;
  --rule: #262624;
  --accent: #e08a6d;
  --accent-ink: #e9a088;
  --hover: #161615;
  --mark: #3d261d;
  --on-accent: #000000;
  --shadow: rgba(0, 0, 0, 0.6);
}

/* the default, Arian Grqi, is in :root; Arian
   fonts are by Ruben Tarumian, with their own Latin
   and Cyrillic letters */
:root[data-font="noto"] {
  --book: "nx Noto Serif Armenian",
    "Noto Serif Armenian", "Noto Serif",
    Georgia, "Times New Roman", serif;
}

:root[data-font="arianserif"] {
  --book: "nx Arian AMU Serif",
    "nx Noto Serif Armenian", Georgia, serif;
}

/* a decorative Armenian face, with Latin and
   Cyrillic letters */
:root[data-font="faulmann"] {
  --book: "nx Faulmann", "nx Noto Serif Armenian",
    Georgia, serif;
}

/* its spaces are wide: about 1.2em drawn bigger */
:root[data-font="faulmann"] :is(.text, .editor) {
  word-spacing: -0.7em;
}

/* a calligraphic Armenian face: letters and
   digits; punctuation, Latin and Cyrillic from Noto */
:root[data-font="geghagrutyun"] {
  --book: "nx Geghagrutyun", "nx Noto Serif Armenian",
    "Noto Serif Armenian", Georgia, serif;
}

:root[data-font="geghagrutyun"] :is(.text, .editor) {
  word-spacing: -0.3em;
}

/* Hovhannes Tumanyan's handwriting, as a font by
   Ruben Tarumian, with Latin and Cyrillic letters */
:root[data-font="tumanian"] {
  --book: "nx Tumanian", "nx Noto Serif Armenian",
    Georgia, serif;
}

/* old style book fonts; Armenian letters from
   FreeSerif, whose Armenian is the classical kind */
:root[data-font="garamond"] {
  --book: "nx EB Garamond", "nx FreeSerif Armenian",
    "nx Noto Serif Armenian", Georgia, serif;
}

:root[data-font="oldstandard"] {
  --book: "nx Old Standard", "nx FreeSerif Armenian",
    "nx Noto Serif Armenian", Georgia, serif;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  transition: background 0.2s, color 0.2s;
}

a {
  color: inherit;
}

/* hidden wins over display: flex and the like */
[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* no blue flash from the phone's browser on a tap;
   a press shows in the page's own colors */
button,
a {
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:active,
.link-btn:active {
  background: var(--hover);
}

main {
  max-width: 44rem;
  margin: 0 auto;
  padding: 0 16px 4rem;
  outline: none;
}

/* -- top bar -- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 44rem;
  margin: 0 auto;
  padding: 14px 16px;
}

.brand {
  display: flex;
  align-items: baseline;
  /* the mark is նղ: ֊գիր follows it as one word */
  gap: 0.15rem;
  text-decoration: none;
}

.brand-mark {
  align-self: center;
  width: 1.6rem;
  height: 1.75rem;
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-hy {
  font: 600 1.25rem var(--serif);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 6px 10px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--hover);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

/* -- page head -- */

.crumbs {
  margin: 1.5rem 0 0.25rem;
  color: var(--muted);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.crumbs a {
  text-decoration: none;
}

.crumbs a:hover {
  color: var(--accent-ink);
}

.crumbs .sep {
  margin: 0 0.35rem;
  opacity: 0.6;
}

h1 {
  margin: 0;
  font: 500 2rem/1.2 var(--serif);
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.sub {
  margin: 0.35rem 0 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* -- shelf -- */

.shelf {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--rule);
}

.shelf li {
  border-bottom: 1px solid var(--rule);
}

.row {
  display: grid;
  grid-template-columns: 1.25rem 1fr auto;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 0.5rem;
  text-decoration: none;
  border-radius: 6px;
}

.row:hover {
  background: var(--hover);
}

.row .ico {
  width: 1.25rem;
  height: 1.25rem;
  color: var(--muted);
}

.row:hover .ico {
  color: var(--accent);
}

.name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.name .ext {
  margin-left: 0.4rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.meta {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.progress {
  display: block;
  width: 4.5rem;
  height: 3px;
  margin: 0.35rem 0 0 auto;
  border-radius: 2px;
  background: var(--rule);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.empty,
.error {
  padding: 2rem 0;
  color: var(--muted);
}

.error a {
  color: var(--accent-ink);
}

/* -- reader -- */

body.reading main,
body.reading .bar {
  max-width: 68rem;
}

.text {
  max-width: 34em;
  font: var(--text-size, 1.15rem) /
    var(--text-line, 1.75) var(--book);
}

/* Markdown in .md texts: headings, quotes, bold and
   italic */

.text .md-h {
  margin: 0.4em 0 0.2em;
  font-weight: 600;
  line-height: 1.35;
}

.text .md-h1 {
  font-size: 1.5em;
}

.text .md-h2 {
  font-size: 1.3em;
}

.text .md-h3,
.text .md-h4,
.text .md-h5,
.text .md-h6 {
  font-size: 1.1em;
}

.text .md-q {
  padding-left: 1em;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-style: italic;
}

.text .md-q em {
  font-style: normal;
}

.text strong {
  font-weight: 700;
}

.text.centered {
  margin-inline: auto;
  text-align: center;
}

/* A− A+ and the alignment, at the right of the
   reading toolbar */
.view {
  display: flex;
  gap: 0.35rem;
  margin-left: auto;
  min-width: 0;
}

@media (max-width: 30rem) {
  .tools .long {
    display: none;
  }
}

.view .icon-btn {
  min-width: 2.5rem;
  justify-content: center;
  padding-inline: 8px;
}

/* the list of book fonts, drawn like the buttons */
.font-pick {
  /* a long name shrinks it, not the row */
  min-width: 0;
  max-width: 10rem;
  text-overflow: ellipsis;
  height: 2.1rem;
  padding: 0 28px 0 12px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  appearance: none;
  background-image: linear-gradient(
      45deg, transparent 50%, currentColor 50%),
    linear-gradient(
      135deg, currentColor 50%, transparent 50%);
  background-position: right 15px center,
    right 10px center;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.font-pick:hover {
  color: var(--text);
  background-color: var(--hover);
}

.font-pick option {
  background: var(--bg);
  color: var(--text);
}

.text p {
  margin: 0;
  min-height: 1.75em;
  overflow-wrap: break-word;
}

.w {
  cursor: pointer;
  border-radius: 3px;
  -webkit-tap-highlight-color: transparent;
}

.w:hover {
  color: var(--accent-ink);
}

.w.ref {
  background: var(--mark);
}

.w.sel {
  background: var(--accent-ink);
  color: var(--on-accent);
  box-shadow: 0 0 0 2px var(--accent-ink);
}

/* a bookmarked word, the first word of a sentence
   with a note, the sentence a note is written on */

.w.bm {
  text-decoration: underline 2px var(--accent);
  text-underline-offset: 5px;
}

.w.noted::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 5px 0 1px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 0.25em;
}

.w.sent {
  background: var(--mark);
}

.w.flash {
  animation: flash 1.6s ease-out;
}

@keyframes flash {
  0%,
  40% {
    background: var(--accent);
    color: var(--on-accent);
  }
}

/* stays at the top while reading */
.tools {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: -0.5rem 0 1rem;
  padding: 8px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.25rem 0 0.75rem;
}

.icon-btn[aria-pressed="true"] {
  color: var(--accent-ink);
  border-color: var(--accent);
}

.icon-btn.primary {
  background: var(--accent-ink);
  border-color: var(--accent-ink);
  color: var(--on-accent);
}

.icon-btn.primary:hover {
  background: var(--accent);
  color: var(--on-accent);
}

textarea {
  display: block;
  width: 100%;
  margin: 0.25rem 0 0.75rem;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.5 var(--sans);
  resize: vertical;
}

textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

/* editing interpretations */

/* the theme and back buttons: only their icons */
#theme,
.tools .back {
  min-width: 2.5rem;
  justify-content: center;
  padding-inline: 8px;
}

a.icon-btn {
  text-decoration: none;
}

.editor {
  min-height: 60vh;
  margin: 0 0 0.75rem;
  padding: 14px 16px;
  font: var(--text-size, 1.15rem) /
    var(--text-line, 1.7) var(--book);
}

.form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin: 0 0 1rem;
}

.form label {
  color: var(--muted);
  font-size: 0.85rem;
}

.field {
  flex: 1 1 14rem;
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: 0.95rem/1.4 ui-monospace, "DejaVu Sans Mono",
    monospace;
}

.field:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

.form .item-meta {
  flex-basis: 100%;
  overflow-wrap: anywhere;
}

.status {
  align-self: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.status.error {
  flex-basis: 100%;
  color: var(--accent-ink);
}

/* lists of bookmarks and notes */

.items {
  margin: 0;
  padding: 0;
  list-style: none;
}

.items li {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.25rem 0.75rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--rule);
}

.items li:first-child {
  border-top: 0;
}

.item-main {
  display: flex;
  flex: 1 1 12rem;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.item-main:hover .item-quote {
  color: var(--accent-ink);
}

.item-meta {
  color: var(--muted);
  font-size: 0.75rem;
}

.item-quote {
  font-family: var(--serif);
  overflow-wrap: anywhere;
}

p.item-quote {
  margin: 0.25rem 0 0.5rem;
  color: var(--muted);
}

.item-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.item-btns {
  display: flex;
  gap: 0.75rem;
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.link-btn:hover {
  color: var(--accent-ink);
}

/* the word panel: a sheet at the bottom of a
   phone, a column beside the text when wide. Its
   text grows and shrinks with the book's (A− / A+):
   1em here is 1rem at the default size, 1.15rem;
   sizes inside are in em, small ones no smaller
   than the smallest text, 0.7rem */

.panel {
  font-size: max(0.75rem,
    calc(var(--text-size, 1.15rem) / 1.15));
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  max-height: 45vh;
  overflow-y: auto;
  padding: 0 16px 16px;
  background: var(--surface);
  border-top: 1px solid var(--rule);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -6px 24px var(--shadow);
}

.panel[hidden] {
  display: none;
}

body.panel-open main {
  padding-bottom: 50vh;
}

.panel-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 14px 0 8px;
  background: var(--surface);
}

.panel-head h2 {
  margin: 0;
  font: 500 1.5em/1.2 var(--serif);
  overflow-wrap: anywhere;
}

.panel .icon-btn.close {
  font-size: 1.2em;
  line-height: 1;
}

.part {
  padding: 0.75rem 0;
  border-top: 1px solid var(--rule);
}

.part h3 {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: max(0.75em, 0.7rem);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.entry p {
  margin: 0.5rem 0 0.15rem;
}

.entry .head {
  font-family: var(--serif);
  font-weight: 600;
}

.entry ul {
  margin: 0;
  padding-left: 1.1rem;
}

.entry li::marker {
  color: var(--accent);
}

.entry .source,
.none,
.loading {
  color: var(--muted);
  font-size: 0.8rem;
}

.seg {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--rule);
  border-radius: 999px;
}

.seg button {
  padding: 3px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.seg button[aria-pressed="true"] {
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 1px 2px var(--shadow);
}

.places {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.places span {
  flex: 1;
  font-variant-numeric: tabular-nums;
}

/* shared with the rest of the page, in em here */
.panel .icon-btn {
  font-size: max(0.85em, 0.7rem);
}

.panel .link-btn,
.panel .none,
.panel .loading,
.panel .entry .source,
.panel .seg button {
  font-size: max(0.8em, 0.7rem);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

@media (min-width: 64rem) {
  .reader {
    display: grid;
    grid-template-columns: minmax(0, 34em) 20rem;
    justify-content: space-between;
    gap: 3rem;
    align-items: start;
  }

  .panel {
    position: sticky;
    top: 68px; /* below the toolbar */
    max-height: calc(100vh - 84px);
    border: 1px solid var(--rule);
    border-radius: 12px;
    box-shadow: none;
  }

  body.panel-open main {
    padding-bottom: 4rem;
  }
}

@media (min-width: 40rem) {
  h1 {
    font-size: 2.4rem;
  }

  .crumbs {
    margin-top: 2.5rem;
  }
}

/* two versions (.par: the other one), when
   Parallel is on: on a phone each line of it under
   its pair, from 40rem beside it */

.text .par {
  display: none;
}

.text.parallel .par {
  display: block;
}

.text.parallel .par:not(.par-head) {
  margin-bottom: 0.6em;
  padding-left: 0.75em;
  border-left: 2px solid var(--rule);
  color: var(--muted);
  font-size: 0.9em;
}

/* no second empty line under an empty one */
.text.parallel .par:empty {
  display: none;
}

.text .par-head {
  font: 600 0.8rem var(--sans);
  color: var(--muted);
  letter-spacing: 0.02em;
}

.text .par-head a {
  color: inherit;
}

/* on a phone only the other version's name */
.text.parallel .par-head:first-child {
  display: none;
}

/* two columns from 40rem: an open folding phone
   (a Galaxy Fold is about 53rem wide) or a phone on
   its side */
@media (min-width: 40rem) {
  .text.parallel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4em 1.5rem;
    max-width: none;
  }

  .text.parallel .par:not(.par-head) {
    margin: 0;
    padding: 0;
    border: 0;
    color: inherit;
    font-size: inherit;
  }

  /* both columns need every row, empty or not */
  .text.parallel .par:empty,
  .text.parallel .par-head:first-child {
    display: block;
  }
}

/* a computer: room for the word panel beside */
@media (min-width: 64rem) {
  body.reading.parallel main,
  body.reading.parallel .bar {
    max-width: 100rem;
  }

  body.parallel .reader {
    grid-template-columns: minmax(0, 1fr) 20rem;
  }

  .text.parallel {
    column-gap: 2.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  body {
    transition: none;
  }

  .w.flash {
    animation: none;
    outline: 2px solid var(--accent);
  }
}

/* the home button: only while the toolbar is at
   the top of the screen */
.tools .home {
  display: none;
  min-width: 2.5rem;
  justify-content: center;
  padding-inline: 8px;
}

.tools.stuck .home {
  display: inline-flex;
}

.tools .home svg {
  width: 18px;
  height: 20px;
}

/* the text settings button: only on a phone */
.tools .more {
  display: none;
  min-width: 2.5rem;
  justify-content: center;
  padding-inline: 8px;
}

.tools .more[aria-expanded="true"] {
  color: var(--accent-ink);
  border-color: var(--accent);
}

/* on a phone the text tools hide behind the
   settings button and open in a row below */
@media (max-width: 30rem) {
  .tools {
    gap: 0.35rem;
  }

  .tools .more {
    display: inline-flex;
    margin-left: auto;
  }

  .tools .view {
    display: none;
  }

  .tools.open .view {
    display: flex;
    flex-basis: 100%;
    justify-content: flex-end;
  }
}
