:root {
  color-scheme: dark;
  --bg: #121214;
  --splash-bg: #1c0508;
  --panel: #121214;
  --panel-2: #18181b;
  --fg: #e6e1dc;
  --strong: #faf0eb;
  --muted: #828287;
  --accent: #c42736;
  --border: #8c202b;
  --border-dim: #42141a;
  --highlight: #801b25;
  --highlight-fg: #faf0eb;
  --gold: #f5c44a;
  --book-red: #9e111f;
  --book-spine: #5c0810;
  --paper: #eee0be;
  --splash-muted: #cc9789;
  --cell: 10px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

:root[data-theme="red"] {
  --bg: #5a0811;
  --splash-bg: #1c0508;
  --panel: #5a0811;
  --panel-2: #68111b;
  --fg: #fcf0ec;
  --strong: #fff8f2;
  --muted: #f4bebe;
  --accent: #ffcd5c;
  --border: #b41929;
  --border-dim: #7b101c;
  --highlight: #dd3548;
  --highlight-fg: #fff8f2;
}

:root[data-theme="mono"] {
  --bg: #000;
  --splash-bg: #000;
  --panel: #000;
  --panel-2: #090909;
  --fg: #fff;
  --strong: #fff;
  --muted: #777;
  --accent: #fff;
  --border: #777;
  --border-dim: #333;
  --highlight: #fff;
  --highlight-fg: #000;
  --gold: #fff;
  --book-red: #000;
  --book-spine: #151515;
  --paper: #fff;
  --splash-muted: #777;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
}

button,
input,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.screen {
  min-height: 100dvh;
  background: var(--bg);
}

.splash-screen {
  display: grid;
  grid-template-rows: minmax(18px, 1fr) auto auto minmax(18px, 1fr);
  justify-items: center;
  gap: 22px;
  padding: 18px;
  background: var(--splash-bg);
}

.splash-book {
  grid-row: 2;
  position: relative;
  width: min(52vw, 520px);
  min-width: 300px;
  height: min(42vh, 330px);
  min-height: 230px;
  display: grid;
  place-items: center;
  border: 2px solid var(--gold);
  outline: 1px solid var(--book-spine);
  background: var(--book-red);
  color: var(--paper);
}

.splash-book:focus {
  outline: 1px solid var(--paper);
}

.book-spine {
  position: absolute;
  inset: 8px auto 8px 24px;
  width: 30px;
  background: var(--book-spine);
}

.book-pages {
  position: absolute;
  inset: 20px 20px 20px auto;
  width: 18px;
  background: var(--paper);
}

.book-copy {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 16px;
  padding: 32px 54px;
  text-align: center;
}

.book-mark {
  color: var(--gold);
  font-size: clamp(56px, 8vw, 92px);
  line-height: 0.9;
}

.book-copy h1 {
  color: var(--paper);
  font-size: clamp(42px, 7vw, 82px);
  line-height: 1;
  letter-spacing: 0;
}

.book-copy p {
  color: var(--gold);
  font-size: clamp(12px, 1.7vw, 16px);
  line-height: 1.5;
}

.splash-footer {
  grid-row: 3;
  display: grid;
  gap: 9px;
  text-align: center;
  color: var(--paper);
  font-size: 14px;
  line-height: 1.45;
}

.splash-footer p:nth-child(2) {
  color: var(--splash-muted);
}

.install-line {
  color: var(--gold);
}

.reader-screen {
  height: 100dvh;
  display: grid;
  grid-template-rows: 3rem minmax(0, 1fr) 2.25rem;
  padding: 0;
  background: var(--bg);
}

.top-status,
.bottom-status {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 2ch;
  padding: 0 12px;
  color: var(--muted);
  background: var(--bg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

.top-status {
  justify-content: center;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  color: var(--fg);
}

.top-status span:first-child {
  color: var(--accent);
}

.bottom-status {
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.bottom-status a {
  color: var(--accent);
  text-decoration: none;
}

.reader-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(180px, 25%) minmax(210px, 25%) minmax(0, 50%);
  background: var(--bg);
}

.pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  color: var(--fg);
  background: var(--panel);
}

.works-pane {
  border-left: 1px solid var(--border);
}

.pane-title {
  min-height: 34px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  border-bottom: 1px solid var(--border);
  color: var(--accent);
  font-weight: 700;
}

.pane-title-row {
  justify-content: space-between;
  gap: 12px;
}

.search-label {
  padding: 10px 10px 6px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.search-input {
  width: calc(100% - 20px);
  margin: 0 10px 10px;
  padding: 7px 8px;
  border: 1px solid var(--border-dim);
  color: var(--fg);
  background: var(--bg);
  outline: 0;
}

.search-input:focus {
  border-color: var(--accent);
}

.work-button:focus,
.section-button:focus,
.result-button:focus,
.reader-actions button:focus,
.reader-actions a:focus,
.text-scroll:focus {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

.list {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 4px 0;
}

.work-button,
.section-button,
.result-button,
.reader-actions button,
.reader-actions a {
  border: 0;
  color: var(--fg);
  background: transparent;
}

.work-button,
.section-button {
  width: 100%;
  display: block;
  padding: 5px 10px;
  text-align: left;
  line-height: 1.35;
}

.work-button::before,
.section-button::before {
  content: "  ";
}

.work-button:hover,
.section-button:hover,
.result-button:hover {
  background: var(--panel-2);
}

.work-button.active,
.section-button.active {
  color: var(--highlight-fg);
  background: var(--highlight);
  font-weight: 700;
}

.work-button.active::before,
.section-button.active::before {
  content: "» ";
}

.work-button small,
.section-button small {
  display: block;
  padding-left: 2ch;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.progress {
  height: 8px;
  margin: 10px;
  border: 1px solid var(--border-dim);
  background: var(--bg);
}

#progressBar {
  width: 0%;
  height: 100%;
  background: var(--highlight);
}

.text-pane {
  border-right: 1px solid var(--border);
}

.reader-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-dim);
  background: var(--panel);
}

.reader-meta h2 {
  color: var(--fg);
  font-size: 15px;
  line-height: 1.35;
}

#workMeta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.reader-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 1ch;
  max-width: 34ch;
}

.reader-actions button,
.reader-actions a {
  padding: 0;
  color: var(--muted);
  text-decoration: none;
}

.reader-actions button:hover,
.reader-actions a:hover {
  color: var(--accent);
}

.reader-actions button::before,
.reader-actions a::before {
  content: "[";
  color: var(--border);
}

.reader-actions button::after,
.reader-actions a::after {
  content: "]";
  color: var(--border);
}

.text-scroll {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 12px 14px 22px;
}

.search-results {
  margin-bottom: 14px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.result-button {
  width: 100%;
  display: block;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-dim);
  text-align: left;
  line-height: 1.4;
}

.result-button strong {
  color: var(--accent);
}

.result-button span {
  color: var(--muted);
}

.section-heading {
  margin-bottom: 14px;
}

.section-heading h3 {
  color: var(--accent);
  font-size: 16px;
  line-height: 1.45;
}

#sectionNumber {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.paragraphs {
  max-width: none;
  color: var(--fg);
  font-size: 15px;
  line-height: 1.6;
}

.paragraphs p {
  margin: 0 0 1.25em;
}

mark,
.paragraphs mark,
.result-button mark {
  color: var(--highlight-fg);
  background: var(--highlight);
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .reader-screen {
    min-height: 100dvh;
    height: auto;
    grid-template-rows: auto auto auto;
  }

  .top-status,
  .bottom-status {
    min-height: 44px;
    flex-wrap: wrap;
    white-space: normal;
  }

  .reader-grid {
    min-height: 0;
    grid-template-columns: 1fr 1fr;
  }

  .text-pane {
    grid-column: 1 / -1;
    min-height: 70vh;
    border-left: 1px solid var(--border);
  }

  .works-pane,
  .sections-pane {
    min-height: 38vh;
  }
}

@media (max-width: 640px) {
  .splash-screen {
    padding: 12px;
  }

  .splash-book {
    width: calc(100vw - 28px);
    min-width: 0;
    min-height: 210px;
  }

  .book-copy {
    padding: 26px 40px;
  }

  .reader-grid {
    grid-template-columns: 1fr;
  }

  .works-pane,
  .sections-pane,
  .text-pane {
    min-height: 44vh;
    border-left: 1px solid var(--border);
  }

  .reader-meta {
    grid-template-columns: 1fr;
  }

  .reader-actions {
    justify-content: flex-start;
  }
}
