:root {
  --bg: #fffefb;
  --text: #161616;
  --muted: #8a8a86;
  --hairline: #e8e8e4;
  --flash: #f0f0ec;
  --mark: #eceae3;
  --accent: #161616;
  --gutter: 32px;
  --measure: 36rem;
  --rail: 2.5rem;
  --rail-gap: 0.85rem;
  --indent: calc(var(--rail) + var(--rail-gap));
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: "Segoe UI", system-ui, -apple-system, sans-serif;
  --scan: none;
  --tick: #161616;
}

html[data-theme="dark"] {
  --bg: #07090d;
  --text: #d7fff6;
  --muted: #5ce1c5;
  --hairline: #13352f;
  --flash: #0c241f;
  --mark: rgba(0, 255, 200, 0.22);
  --accent: #ff2bd6;
  --serif: "Segoe UI", system-ui, -apple-system, sans-serif;
  --sans: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
  --scan: none;
  --tick: #5ce1c5;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
}

body {
  overflow: hidden;
}

html[data-theme="dark"] body::after {
  content: "";
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 255, 200, 0.018) 0 1px,
    transparent 1px 7px
  );
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-decoration: none; }

.frame {
  position: relative;
  z-index: 1;
  width: min(var(--measure), calc(100% - 2 * var(--gutter)));
  margin-inline: auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.indent { padding-left: var(--indent); }

.chrome {
  flex-shrink: 0;
  z-index: 6;
  background: var(--bg);
  padding: 0;
  padding-top: env(safe-area-inset-top, 0px);
  border-bottom: 1px solid var(--hairline);
}

html[data-theme="dark"] .chrome {
  background: color-mix(in srgb, var(--bg) 92%, transparent);
}

.chrome-row {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content;
  align-items: center;
  height: 44px;
  gap: 12px;
  min-width: 0;
  overflow: hidden;
}

.chrome-row:has(.loc[hidden]) {
  grid-template-columns: max-content max-content;
  justify-content: space-between;
}

.wordmark {
  justify-self: start;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1;
  white-space: nowrap;
}

.loc {
  justify-self: stretch;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.35em;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1;
}

.loc[hidden] {
  display: none !important;
}

.loc #btn-book {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  letter-spacing: 0.06em;
}

.loc #btn-ch,
.loc #btn-tr,
.loc .tr {
  flex: 0 0 auto;
  white-space: nowrap;
}

.loc #btn-ch {
  color: var(--text);
}

.loc #btn-tr,
.loc .tr {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.06em;
  margin-left: 0.5em;
}

.chrome-tools {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 14px;
  white-space: nowrap;
  flex-shrink: 0;
}

.wordmark:hover,
#theme-btn:hover,
#keep-list-btn:hover,
.loc button:hover { color: var(--text); }

html[data-theme="dark"] .wordmark:hover,
html[data-theme="dark"] #theme-btn:hover {
  text-shadow: 0 0 8px rgba(0, 255, 200, 0.25);
}

#keep-list-btn {
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1;
  color: var(--muted);
}

.keep-n {
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  margin-left: 4px;
  color: var(--muted);
}

#theme-btn {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1;
}

#stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--muted) 35%, transparent) transparent;
}

#stage::-webkit-scrollbar,
.hits::-webkit-scrollbar,
.chapter-pop::-webkit-scrollbar {
  width: 4px;
}

#stage::-webkit-scrollbar-track,
.hits::-webkit-scrollbar-track,
.chapter-pop::-webkit-scrollbar-track {
  background: transparent;
}

#stage::-webkit-scrollbar-thumb,
.hits::-webkit-scrollbar-thumb,
.chapter-pop::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--muted) 35%, transparent);
}

.passage {
  padding: 8px 0 20vh;
}

.dock {
  flex-shrink: 0;
  z-index: 5;
  padding: 0 0 calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  border-top: 1px solid var(--hairline);
}

.dock[hidden] {
  display: none !important;
}

.actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  height: 48px;
  margin: 0;
  color: var(--muted);
}

.actions button {
  width: auto;
  height: 100%;
  display: grid;
  place-items: center;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1;
  color: color-mix(in srgb, var(--muted) 72%, var(--bg));
  text-align: center;
}

.actions button:hover,
.actions button:active { color: var(--text); }

.actions #btn-keep.on,
.actions #btn-sit.on {
  color: var(--accent);
}

.actions #btn-sit {
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: lowercase;
}

.keys {
  margin: 8px 0 0;
  font-family: var(--sans);
  font-size: 11px;
  line-height: 1.55;
  color: var(--muted);
  text-align: center;
}

.keys[hidden] {
  display: none !important;
}

.keys-toggle {
  opacity: 0.7;
}

.reader { padding: 12px 0 24vh; }

.chapter-head { margin: 12px 0 28px; }

.chapter-head .section {
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1;
  color: var(--muted);
  margin: 0 0 10px;
}

.chapter-head h1 {
  font-size: 22px;
  font-weight: 400;
  line-height: 1.25;
  margin: 0;
}

.verses {
  font-size: 20px;
  line-height: 1.8;
}

.verse {
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  column-gap: var(--rail-gap);
  align-items: start;
  margin: 0;
  padding: 0.28em 0;
  opacity: 1;
  color: color-mix(in srgb, var(--text) 30%, var(--bg));
  font-size: inherit;
  transition: color 0.35s ease, text-shadow 0.35s ease;
  cursor: pointer;
}

.verse .n {
  font-family: var(--sans);
  font-size: 11px;
  line-height: 1.8;
  font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, var(--muted) 45%, var(--bg));
  text-align: right;
  padding-top: 0.42em;
  height: auto;
  justify-self: end;
  align-self: start;
  position: relative;
}

.verse.near {
  color: color-mix(in srgb, var(--text) 48%, var(--bg));
}

.verse.revealed {
  color: color-mix(in srgb, var(--text) 46%, var(--bg));
}

.verse:hover {
  color: color-mix(in srgb, var(--text) 88%, var(--bg));
}

.verse.focus,
.verse.focus .n {
  color: var(--text);
}

.verse.focus .n::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 0.55em;
  width: 2px;
  height: 0.9em;
  background: var(--tick);
}

html[data-theme="dark"] .verse.focus span:last-child {
  text-shadow: 0 0 18px rgba(0, 255, 200, 0.1);
}

.passage.reading .verse {
  color: var(--text);
}

.passage.reading .verse .n {
  color: color-mix(in srgb, var(--muted) 70%, var(--bg));
}

.passage.reading .verse.focus .n {
  color: var(--text);
}

.chapter-end {
  margin-top: 2.5rem;
  padding: 1.25rem 0 2rem;
}

.chapter-end button,
.book-end {
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.chapter-end button:hover { color: var(--text); }

.book-end { margin: 0; }

.verse.flash { background: var(--flash); }

.keeps-head {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 12px;
}

.keep-row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 0;
  border-bottom: 1px solid var(--hairline);
}

.keep-row .ref {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.keep-row .sn {
  font-size: 16px;
  line-height: 1.45;
}

.keep-row .drop {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

.keep-row .drop:hover { color: var(--text); }

.contents { padding: 20px 0 24vh; }

.contents h1 {
  font-size: 22px;
  font-weight: 400;
  line-height: 1.25;
  margin: 0 0 10px;
}

.contents .blurb {
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
  margin: 0 0 32px;
}

.collections {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  margin: 0 0 32px;
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1;
  color: var(--muted);
}

.collections button.on,
.collections button:hover { color: var(--text); }

html[data-theme="dark"] .collections button.on {
  color: var(--text);
}

.book-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px 0;
  font-size: 18px;
  line-height: 1.5;
  max-width: 28rem;
}

.book-list a { display: block; }

.book-list a:hover { text-decoration: none; }

.book-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 3.25rem;
  align-items: center;
  gap: 12px;
  min-width: 0;
  overflow: hidden;
  text-decoration: none;
}

.book-row .name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-row:hover .name { text-decoration: underline; }

.book-row .bar {
  display: block;
  height: 2px;
  background: var(--hairline);
}

.book-row .bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--muted);
}

.overlay {
  inset: 0;
  border: 0;
  padding: var(--gutter);
  margin: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  background: var(--bg);
  color: inherit;
}

.overlay:not([open]) { display: none !important; }

.overlay[open] {
  display: grid;
  place-items: center;
}

.overlay::backdrop { background: var(--bg); }

.palette {
  position: relative;
  width: min(var(--measure), calc(100% - 2 * var(--gutter)));
  max-height: min(70vh, 36rem);
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.dialog-close {
  align-self: flex-end;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 0 4px;
  min-height: 44px;
}

.dialog-close:hover,
.dialog-close:active { color: var(--text); }

.palette input {
  width: 100%;
  margin: 0;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  border-radius: 0;
  padding: 12px 0;
  font-size: 22px;
  line-height: 1.3;
  font-family: var(--serif);
  background: transparent;
  color: var(--text);
  outline: none;
  appearance: none;
  box-shadow: none;
}

.palette input:focus,
.palette input:focus-visible {
  outline: none;
  border-bottom-color: var(--text);
}

.palette input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.hits {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  margin-top: 12px;
  padding-left: 0;
}

.hit {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 0;
  border-bottom: 1px solid var(--hairline);
}

.hit .ref {
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1;
  color: var(--muted);
  margin-bottom: 6px;
}

.hit .sn { font-size: 16px; line-height: 1.45; }

.hit mark {
  background: var(--mark);
  color: inherit;
}

.hint {
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
  margin: 16px 0 0;
}

.empty {
  padding: 16px 0;
  color: var(--muted);
  font-size: 16px;
}

.chapter-pop {
  position: fixed;
  z-index: 25;
  width: min(22rem, calc(100vw - 2 * var(--gutter)));
  max-height: 50vh;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--hairline);
  padding: 14px;
}

html[data-theme="dark"] .chapter-pop {
  box-shadow: 0 0 24px rgba(0, 255, 200, 0.12);
}

.chapter-pop h2 {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  margin: 0 0 12px;
  letter-spacing: 0.04em;
  line-height: 1;
}

.chapter-pop .grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
}

.chapter-pop button {
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1;
  padding: 8px 0;
  text-align: center;
  color: var(--muted);
}

.chapter-pop button.on,
.chapter-pop button:hover { color: var(--text); }

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

@media (max-width: 720px) {
  :root {
    --gutter: 16px;
    --rail: 2rem;
    --rail-gap: 0.65rem;
  }

  .chrome {
    padding-top: max(8px, env(safe-area-inset-top, 0px));
  }

  .chrome-row {
    grid-template-columns: max-content minmax(0, 1fr) max-content;
    grid-template-rows: 44px;
    height: 44px;
    gap: 8px;
    padding-bottom: 0;
  }

  .wordmark,
  .chrome-tools,
  .loc {
    grid-column: auto;
    grid-row: auto;
  }

  .loc {
    justify-self: stretch;
    flex-wrap: nowrap;
    font-size: 12px;
  }

  .loc #btn-book,
  .loc #btn-ch {
    min-height: 0;
    height: 44px;
  }

  .loc #btn-tr,
  .loc .tr {
    flex: 0 0 auto;
    margin-left: 0.5em;
  }

  #keep-list-btn,
  #theme-btn {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .book-list {
    max-width: none;
    font-size: 17px;
  }

  .book-list a {
    padding: 10px 0;
    min-height: 44px;
  }

  .collections {
    gap: 8px 16px;
  }

  .collections button {
    min-height: 44px;
    padding: 8px 0;
  }

  .chapter-pop .grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
  }

  .chapter-pop button {
    min-height: 44px;
    font-size: 14px;
    padding: 12px 0;
  }

  .actions {
    height: 52px;
  }

  .actions button {
    font-size: 16px;
  }

  .keys {
    display: none !important;
  }
}

@media (pointer: coarse) {
  .keys-toggle {
    display: none !important;
  }

  .verse:hover {
    color: color-mix(in srgb, var(--text) 30%, var(--bg));
  }

  .verse:active {
    color: color-mix(in srgb, var(--text) 88%, var(--bg));
  }
}

@media (max-width: 720px) and (pointer: coarse) {
  .palette {
    max-height: min(70dvh, 36rem);
  }
}
