:root {
  --scale: 1;
  --he-font: "Times New Roman", "Times", "Frank Ruhl Libre", "David", serif;
  --ui-font: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
  --bar-h: 52px;
  --tabs-h: 58px;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --fg: #000000;
  --muted: #8a8a8e;
  --sep: #d8d8dc;
  --bar: #f7f7f7;
  --whisper: #ececec;
  --accent: #007aff;
  --section: #a9a9ad;
}

:root[data-theme="dark"] {
  --bg: #000000;
  --fg: #ffffff;
  --muted: #9b9ba1;
  --sep: #38383a;
  --bar: #161618;
  --whisper: #262628;
  --accent: #0a84ff;
  --section: #6e6e73;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--ui-font);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

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

/* Top bar */
.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  background: var(--bar);
  border-bottom: 1px solid var(--sep);
}
.bar h1 {
  grid-column: 2;
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.back {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-size: 19px;
  min-height: 44px;
}
.back[hidden] { display: none; }
.back svg { width: 12px; height: 20px; }
.aa {
  justify-self: end;
  grid-column: 3;
  color: var(--accent);
  font-size: 19px;
  font-weight: 600;
  min-width: 44px;
  min-height: 44px;
  text-align: right;
}

/* Size and theme panel */
.panel {
  position: sticky;
  top: calc(var(--bar-h) + env(safe-area-inset-top));
  z-index: 9;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bar);
  border-bottom: 1px solid var(--sep);
}
.panel[hidden] { display: none; }
.panel .row { display: flex; align-items: center; gap: 10px; }
.step {
  width: 56px;
  height: 44px;
  border: 1px solid var(--sep);
  border-radius: 10px;
  background: var(--bg);
  font-family: Georgia, "Times New Roman", serif;
}
.a-small { font-size: 15px; }
.a-large { font-size: 26px; }
#pct {
  min-width: 56px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.theme {
  height: 44px;
  padding: 0 16px;
  border: 1px solid var(--sep);
  border-radius: 10px;
  background: var(--bg);
  font-size: 16px;
}

/* Home list */
.list { padding-bottom: 40px; }
.list h2 {
  margin: 0;
  padding: 22px 16px 6px;
  font-size: 34px;
  font-weight: 500;
  color: var(--section);
}
.list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  margin-left: 16px;
  padding-right: 16px;
  border-bottom: 1px solid var(--sep);
  color: var(--fg);
  text-decoration: none;
  font-size: calc(22px * min(var(--scale), 2));
  font-weight: 500;
}
.list a::after {
  content: "";
  width: 9px;
  height: 9px;
  border-top: 2px solid var(--section);
  border-right: 2px solid var(--section);
  transform: rotate(45deg);
  flex: none;
  margin-left: 12px;
}
.list a .he-name {
  font-family: var(--he-font);
  color: var(--muted);
  font-weight: 400;
  margin-left: auto;
  direction: rtl;
}

/* Reader */
.reader {
  padding: 18px 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 48px);
  max-width: 1100px;
  margin: 0 auto;
  /* At the largest sizes one Hebrew word can be wider than the phone. */
  overflow-wrap: break-word;
}
.block { margin: 0 0 calc(30px * var(--scale)); }
.block .before,
.block .note {
  font-size: calc(15px * var(--scale));
  color: var(--muted);
  font-style: italic;
  text-align: center;
  margin: 0 0 calc(10px * var(--scale));
}
.block .note { margin: calc(8px * var(--scale)) 0 0; }
.label {
  font-family: var(--ui-font);
  font-size: calc(15px * var(--scale));
  color: var(--accent);
  font-weight: 500;
}
.whisper {
  background: var(--whisper);
  border-radius: 4px;
  padding: calc(14px * var(--scale)) 14px calc(4px * var(--scale));
}
.whisper-tag {
  font-size: calc(16px * var(--scale));
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 calc(10px * var(--scale));
}

.he {
  font-family: var(--he-font);
  direction: rtl;
  font-size: calc(28px * var(--scale));
  line-height: 1.55;
  word-spacing: 0.08em;
}
.he .big { font-size: 1.18em; line-height: 1; }
.tr {
  font-size: calc(16px * var(--scale));
  line-height: 1.3;
}
.en {
  font-size: calc(16px * var(--scale));
  line-height: 1.3;
  color: var(--muted);
}

/* Interlinear: one centered phrase at a time */
.mode-interlinear .line { text-align: center; margin: 0 0 calc(20px * var(--scale)); }
.mode-interlinear .line .he { margin-bottom: calc(2px * var(--scale)); }
.mode-interlinear .block > .label { display: block; text-align: center; margin-bottom: 6px; }

/* Single-language modes: phrases flow as lines */
.mode-hebrew .block,
.mode-english .block,
.mode-translit .block { margin-bottom: calc(18px * var(--scale)); }
.mode-hebrew .line { text-align: right; }
.mode-hebrew .block .before,
.mode-hebrew .block .note { text-align: right; }
.mode-hebrew .he .label { margin-left: 0.4em; }
.mode-english .en { color: var(--fg); font-size: calc(20px * var(--scale)); line-height: 1.45; }
.mode-translit .tr { font-size: calc(20px * var(--scale)); line-height: 1.45; }
.mode-english .block .before, .mode-english .block .note,
.mode-translit .block .before, .mode-translit .block .note { text-align: left; }

/* Bottom mode tabs */
.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bar);
  border-top: 1px solid var(--sep);
}
.tabs[hidden] { display: none; }
.tabs button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--section);
  font-size: 11px;
}
.tabs button[aria-pressed="true"] { color: var(--accent); }
.tabs svg { width: 26px; height: 26px; }
.glyph { font-size: 25px; line-height: 26px; height: 26px; font-weight: 400; }
.glyph.serif { font-family: Georgia, "Times New Roman", serif; }
.glyph.he { font-family: var(--he-font); font-weight: 700; }
