/* Torah Hebrew - chapter reader
   Shared by every chapter page under torah/<book>/.
   The player and text scripts (js/site-dev.js, js/player-dev.js) rely on:
   - element ids (playBtn, pauseBtn, loading, volume, barEmpty, barFull, sliderBtn, ...)
   - the classes .hide, .highlight, .sticky (on <header>), .fadein/.fadeout (on #volume)
   - .heb <-> .rashi being swapped on every Hebrew element
   - #sliderBtn being 50px wide with a -25px margin (its left edge is computed in px)
   Keep those contracts intact when editing. */

:root {
  --ink: #17251f;
  --muted: #62726b;
  --paper: #f5f8f5;
  --surface: #ffffff;
  --surface-soft: #edf3ef;
  --line: #d6e0da;
  --line-strong: #b9c9c1;
  --green: #176b55;
  --green-dark: #103f35;
  --green-light: #dcefe7;
  --gold: #f2ba4a;
  --gold-soft: #fff2bf;
  --gloss: #35618f;
  --shadow: 0 14px 36px rgba(23, 37, 31, 0.1);
  --ui-font: "Trebuchet MS", Candara, "Segoe UI", sans-serif;
  --display-font: Georgia, "Times New Roman", serif;
  --heb-font: "Taamey D Web", David, "Times New Roman", serif;
  --rashi-font: "Noto Rashi Hebrew", "Taamey D Web", serif;
  --heb-size: 30px;
  --control-h: 34px;
  --radius: 7px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  min-width: 320px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(180deg, #eef5f1 0, var(--paper) 260px, #f8faf8 100%) fixed;
  font-family: var(--ui-font);
  font-size: 14px;
  line-height: 1.45;
}

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

button,
input,
select {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.hide {
  display: none !important;
}

/* Hebrew scripts - the script selector swaps .heb and .rashi on every element */
.heb {
  font-family: var(--heb-font);
  direction: rtl;
  text-align: right;
}

.rashi {
  font-family: var(--rashi-font);
  direction: rtl;
  text-align: right;
}

/* ------------------------------------------------------------------ */
/* Status overlays                                                     */
/* ------------------------------------------------------------------ */

#jsDisabled {
  width: min(560px, calc(100% - 32px));
  margin: 24px auto;
  padding: 14px 18px;
  border: 1px solid #e7c9c4;
  border-radius: var(--radius);
  background: #fbe8e5;
  color: #7a2f26;
  text-align: center;
}

/* The player toggles this with inline display:block/none, so the spinner
   is centred with absolute positioning rather than relying on flex. */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: block;
  background: rgba(245, 248, 245, 0.88);
  backdrop-filter: blur(3px);
}

.spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border: 4px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ------------------------------------------------------------------ */
/* Header                                                              */
/* ------------------------------------------------------------------ */

.reader-header {
  position: relative;
  z-index: 30;
  border-bottom: 1px solid rgba(214, 224, 218, 0.95);
  background: #ffffff;
  box-shadow: 0 6px 18px rgba(23, 37, 31, 0.06);
}

.reader-header.sticky {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
}

.reader-nav,
.toolbar-row {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding-right: 20px;
  padding-left: 20px;
}

.reader-nav {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 62px;
  padding-top: 8px;
  padding-bottom: 8px;
}

.brand {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
  border-radius: 999px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--green-dark);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.18);
  font-family: var(--heb-font);
  font-size: 22px;
  line-height: 1;
}

.brand-text {
  font-family: var(--display-font);
  font-size: 17px;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.chapter-title {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
  padding-left: 18px;
  border-left: 1px solid var(--line);
  line-height: 1.15;
}

.chapter-en {
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chapter-he {
  overflow: hidden;
  margin-top: 2px;
  font-size: 23px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-nav {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

.nav-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: var(--control-h);
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--green-dark);
  font-weight: 700;
  white-space: nowrap;
  transition: background 140ms ease, border-color 140ms ease;
}

.nav-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.nav-button .chev {
  font-size: 20px;
  line-height: 1;
}

/* ------------------------------------------------------------------ */
/* Form controls                                                       */
/* ------------------------------------------------------------------ */

.field,
.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  white-space: nowrap;
  cursor: pointer;
}

.field > span,
.check > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.check > span {
  color: var(--ink);
  font-weight: 600;
}

select,
input[type="number"] {
  height: var(--control-h);
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

select {
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%2362726b' stroke-width='1.6' stroke-linecap='round' d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

select:hover,
input[type="number"]:hover {
  border-color: var(--line-strong);
}

select:focus,
input[type="number"]:focus {
  border-color: var(--green);
  outline: none;
  box-shadow: 0 0 0 3px rgba(23, 107, 85, 0.16);
}

input[type="number"] {
  width: 58px;
  padding: 0 6px;
  text-align: center;
  -moz-appearance: textfield;
}

input[type="checkbox"] {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--green);
  cursor: pointer;
}

input[type="checkbox"]:disabled,
input[type="checkbox"]:disabled + span {
  color: #9aa6a0;
  cursor: not-allowed;
}

/* ------------------------------------------------------------------ */
/* Toolbar                                                             */
/* ------------------------------------------------------------------ */

.reader-toolbar {
  position: relative;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 22px;
  min-height: 54px;
  padding-top: 8px;
  padding-bottom: 8px;
}

.tool-group {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.toolbar-end {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.range-dash {
  color: var(--muted);
}

/* Play / pause / loading - all three share one footprint; the player
   shows exactly one of them at a time with inline display:block. */
.play-control {
  position: relative;
  width: 44px;
  height: 44px;
}

#playBtn,
#pauseBtn,
#loading {
  position: absolute;
  inset: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
}

#playBtn,
#pauseBtn {
  background-color: var(--green);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 22px;
  box-shadow: 0 3px 0 var(--green-dark), 0 8px 18px rgba(16, 63, 53, 0.22);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  transition: background-color 140ms ease, transform 100ms ease, box-shadow 100ms ease;
}

#playBtn {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23fff' d='M8 5.5v13a1 1 0 0 0 1.53.85l10.2-6.5a1 1 0 0 0 0-1.7L9.53 4.65A1 1 0 0 0 8 5.5z'/%3E%3C/svg%3E");
  background-position: 13px center;
}

#pauseBtn {
  display: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='6' y='5' width='4.5' height='14' rx='1' fill='%23fff'/%3E%3Crect x='13.5' y='5' width='4.5' height='14' rx='1' fill='%23fff'/%3E%3C/svg%3E");
}

#playBtn:hover,
#pauseBtn:hover {
  background-color: #125d4a;
}

#playBtn:active,
#pauseBtn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--green-dark), 0 4px 10px rgba(16, 63, 53, 0.2);
}

#loading {
  display: none;
  border: 4px solid var(--green-light);
  border-top-color: var(--green);
  animation: spin 0.9s linear infinite;
}

#volumeBtn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23103f35' d='M4 9.5v5a1 1 0 0 0 1 1h2.6l4.7 3.9a.7.7 0 0 0 1.2-.55V5.15a.7.7 0 0 0-1.2-.55L7.6 8.5H5a1 1 0 0 0-1 1z'/%3E%3Cpath fill='none' stroke='%23103f35' stroke-width='1.9' stroke-linecap='round' d='M16.2 9.2a4 4 0 0 1 0 5.6M18.8 6.6a7.6 7.6 0 0 1 0 10.8'/%3E%3C/svg%3E") center / 21px no-repeat;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  transition: background-color 140ms ease, border-color 140ms ease;
}

#volumeBtn:hover {
  border-color: var(--line-strong);
  background-color: var(--green-light);
}

/* Text options - a CSS-only disclosure (checkbox + label) */
.options-toggle-input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.options-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: var(--control-h);
  padding: 0 12px 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--green-dark);
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  transition: background 140ms ease, border-color 140ms ease;
}

.options-toggle:hover {
  border-color: var(--line-strong);
  background: var(--green-light);
}

.options-icon {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  background: var(--green-dark);
  color: #fff;
  font-family: var(--display-font);
  font-size: 12px;
  line-height: 1;
}

.options-toggle-input:checked ~ .toolbar-row .options-toggle {
  border-color: var(--green-dark);
  background: var(--green-dark);
  color: #fff;
}

.options-toggle-input:checked ~ .toolbar-row .options-icon {
  background: #fff;
  color: var(--green-dark);
}

.options-toggle-input:focus-visible ~ .toolbar-row .options-toggle {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.options-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: none;
  cursor: default;
}

.options-panel {
  position: absolute;
  z-index: 2;
  top: 100%;
  right: max(20px, calc((100% - 1280px) / 2 + 20px));
  display: none;
  flex-direction: column;
  gap: 12px;
  width: 320px;
  margin-top: 8px;
  padding: 16px 18px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.options-panel::before {
  position: absolute;
  top: -7px;
  right: 34px;
  width: 12px;
  height: 12px;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: var(--surface);
  transform: rotate(45deg);
  content: "";
}

.options-toggle-input:checked ~ .options-backdrop {
  display: block;
}

.options-toggle-input:checked ~ .options-panel {
  display: flex;
}

.options-heading {
  margin: 0 0 2px;
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.options-panel .field,
.options-panel .check {
  justify-content: space-between;
  min-height: var(--control-h);
}

.options-panel .field > span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

.options-panel .check {
  justify-content: flex-start;
  gap: 10px;
}

.options-panel select {
  min-width: 150px;
}

.options-divider {
  height: 1px;
  margin: 2px 0;
  background: var(--line);
}

/* Practice link */
.practice-entry {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: var(--control-h);
  padding: 0 14px;
  border: 1px solid var(--green-dark);
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 2px 0 var(--green-dark);
  transition: background 140ms ease;
}

.practice-entry:hover {
  background: #125d4a;
}

.practice-entry .star {
  color: var(--gold-soft);
}

/* ------------------------------------------------------------------ */
/* Verses                                                              */
/* ------------------------------------------------------------------ */

main {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 10px 20px 72px;
}

main.clickable div[id],
main.clickable span[id] {
  cursor: pointer;
}

.verse {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 0 14px;
  border-bottom: 1px solid var(--line);
  direction: rtl;
  text-align: right;
}

.verse:last-of-type {
  border-bottom: 0;
}

.verse-number {
  flex: 0 0 auto;
  padding-top: 6px;
}

.no {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 36px;
  padding: 5px 6px 4px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--green-dark);
  line-height: 1;
}

.no br {
  display: none;
}

.no a {
  display: block;
  line-height: 1;
}

.no .heb,
.no .rashi {
  font-size: 19px;
  text-align: center;
}

.enn {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.verse-text {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 6px 0;
  min-width: 0;
}

.col {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2px 9px 4px;
  border-left: 1px solid var(--line);
  border-radius: 6px;
  transition: background 120ms ease;
}

.verse-text .col:last-child {
  border-left-color: transparent;
}

main.clickable .col:hover {
  background: rgba(23, 107, 85, 0.06);
}

.verse-text .heb,
.verse-text .rashi {
  font-size: var(--heb-size);
  line-height: 1.5;
  text-align: center;
  white-space: nowrap;
}

.verse-text .rashi {
  font-size: calc(var(--heb-size) * 0.92);
}

.eng {
  color: var(--gloss);
  direction: ltr;
  font-size: 14px;
  line-height: 1.3;
  text-align: center;
}

.tran {
  color: var(--muted);
  direction: ltr;
  font-size: 13px;
  line-height: 1.3;
  text-align: center;
}

.verse-number .tran {
  color: transparent;
  font-size: 13px;
  line-height: 1.3;
}

/* Word highlighting during playback */
.highlight {
  border-radius: 4px;
  background: var(--gold-soft);
}

.col:has(.highlight) {
  background: var(--gold-soft);
  box-shadow: inset 0 -3px 0 var(--gold);
}

.col:has(.highlight) .highlight {
  background: transparent;
}

/* Parasha markers (pe / samekh) */
.parsh {
  color: #9aa6a0 !important;
  text-align: center !important;
  cursor: initial !important;
}

.col:has(.parsh) {
  border-left-color: transparent;
}

main.clickable .col:has(.parsh):hover {
  background: transparent;
}

/* ------------------------------------------------------------------ */
/* Footer navigation                                                   */
/* ------------------------------------------------------------------ */

.reader-footer {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 0 20px 48px;
}

.reader-footer nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.reader-footer .nav-button {
  height: 40px;
  padding: 0 18px;
}

/* ------------------------------------------------------------------ */
/* Volume overlay (opened by #volumeBtn)                               */
/* ------------------------------------------------------------------ */

#volume {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 2000;
  width: 100%;
  height: 100%;
  display: none;
  background: rgba(16, 63, 53, 0.72);
  backdrop-filter: blur(3px);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

#volume::before {
  position: absolute;
  top: calc(50% - 58px);
  left: 0;
  width: 100%;
  color: #fff;
  font-family: var(--display-font);
  font-size: 22px;
  text-align: center;
  content: "Volume";
}

#volume::after {
  position: absolute;
  top: calc(50% + 40px);
  left: 0;
  width: 100%;
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  text-align: center;
  content: "Drag the knob or tap the bar \00B7 tap anywhere else to close";
}

.bar {
  position: absolute;
  top: 50%;
  left: 5%;
  height: 10px;
  margin: -5px auto;
  border-radius: 999px;
  background-color: rgba(255, 255, 255, 0.95);
}

#barEmpty {
  width: 90%;
  opacity: 0.35;
  cursor: pointer;
}

#barFull {
  width: 90%;
  background: var(--gold);
}

#sliderBtn {
  position: absolute;
  top: 50%;
  left: 93.25%;
  width: 50px;
  height: 50px;
  margin: -25px auto;
  border: 3px solid var(--gold);
  border-radius: 25px;
  background-color: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.fadein {
  animation: fadein 0.3s;
}

.fadeout {
  animation: fadeout 0.5s;
}

@keyframes fadein {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes fadeout {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
  }
}

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */

@media (max-width: 1100px) {
  .reader-nav,
  .toolbar-row {
    padding-right: 16px;
    padding-left: 16px;
  }

  main,
  .reader-footer {
    padding-right: 16px;
    padding-left: 16px;
  }

  .options-panel {
    right: 16px;
  }
}

@media (max-width: 860px) {
  :root {
    --heb-size: 27px;
  }

  .brand-text {
    display: none;
  }

  .chapter-title {
    padding-left: 12px;
  }

  .goto-chapter > span {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .nav-button {
    padding: 0 10px;
  }

  .nav-button .label {
    display: none;
  }

  .toolbar-row .practice-entry {
    position: fixed;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    z-index: 25;
    height: 42px;
    padding: 0 18px;
    box-shadow: 0 3px 0 var(--green-dark), 0 12px 28px rgba(16, 63, 53, 0.3);
  }
}

@media (max-width: 640px) {
  :root {
    --heb-size: 25px;
    --control-h: 36px;
  }

  body {
    font-size: 13px;
  }

  .reader-nav {
    gap: 12px;
    min-height: 56px;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .chapter-he {
    font-size: 20px;
  }

  .chapter-nav {
    gap: 6px;
  }

  .toolbar-row {
    gap: 8px 14px;
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .tool-group {
    gap: 8px;
  }

  .tool-group.range {
    order: 2;
  }

  .toolbar-end {
    order: 3;
  }

  .options-toggle {
    padding: 0 8px;
  }

  .options-toggle .label {
    display: none;
  }

  .field > span.short {
    display: none;
  }

  .options-panel {
    right: 12px;
    left: 12px;
    width: auto;
  }

  .options-panel::before {
    right: 26px;
  }

  main {
    padding: 4px 12px 96px;
  }

  .verse {
    gap: 8px;
    padding: 12px 0 10px;
  }

  .verse-number {
    padding-top: 4px;
  }

  .no {
    min-width: 30px;
    padding: 4px 4px 3px;
  }

  .no .heb,
  .no .rashi {
    font-size: 16px;
  }

  .col {
    padding: 2px 5px 3px;
  }

  .eng {
    font-size: 12.5px;
  }

  .tran {
    font-size: 12px;
  }

  .reader-footer {
    padding: 0 12px 96px;
  }

  .reader-footer nav {
    justify-content: center;
  }

  #volume::after {
    padding: 0 24px;
  }
}

@media (max-width: 400px) {
  .chapter-nav .nav-button {
    padding: 0 8px;
  }

  #volumeBtn {
    width: 36px;
    height: 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner,
  #loading {
    animation-duration: 2s;
  }

  .fadein,
  .fadeout {
    animation: none;
  }
}
