/* פסוק מתהילים - עיצוב. Sections: tokens, accessibility themes, layout, buttons, commentary, chapter view, accessibility menu. */

:root {
  --bg: #f7f3ea;
  --card: #fffdf8;
  --card-line: #efe7d7;
  --accent: #8a7a5c;
  --accent-dark: #6f6248;
  --accent-soft: #f1ebdf;
  --on-accent: #ffffff;
  --track: #ece4d4;
  --ink: #2f2a21;
  --muted: #6b6457;
  --line: #e9e1d0;
  --error-ink: #8f3a2b;
  --error-bg: #fbefe9;
  --error-line: #efd3c7;
  --shadow: 0 1px 2px rgba(70, 52, 20, 0.05), 0 12px 32px rgba(70, 52, 20, 0.09);
  --serif: "David", "Frank Ruehl CLM", "Times New Roman", serif;
  --latin: Georgia, "Times New Roman", serif;
  --a11y-blue: #1d4ed8;
  --fab-size: 84px;
  color-scheme: light;
}

/* accessibility themes (set from the accessibility menu) */
html.a11y-contrast {
  --bg: #ffffff;
  --card: #ffffff;
  --card-line: #000000;
  --accent: #3d3220;
  --accent-dark: #2a2214;
  --accent-soft: #fff3a0;
  --on-accent: #ffffff;
  --track: #e4e4e4;
  --ink: #000000;
  --muted: #1a1a1a;
  --line: #000000;
  --error-ink: #7a0000;
  --error-bg: #ffffff;
  --error-line: #7a0000;
  --shadow: none;
}

html.a11y-dark {
  --bg: #121212;
  --card: #1d1c1a;
  --card-line: #3a3833;
  --accent: #d9bf8c;
  --accent-dark: #ecd6a8;
  --accent-soft: #2e2a22;
  --on-accent: #1a1712;
  --track: #2a2824;
  --ink: #f3efe6;
  --muted: #d2cbbd;
  --line: #3a3833;
  --error-ink: #ffb4a6;
  --error-bg: #3a1f1a;
  --error-line: #6b3328;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

html.a11y-text-1 { font-size: 115%; }
html.a11y-text-2 { font-size: 130%; }
html.a11y-text-3 { font-size: 150%; }

html.a11y-font {
  --serif: Arial, "Segoe UI", Tahoma, "Noto Sans Hebrew", sans-serif;
  --latin: Arial, "Segoe UI", sans-serif;
}

html.a11y-gray .wrap { filter: grayscale(1); }

html.a11y-links a,
html.a11y-links .link-btn {
  background: #fff200 !important;
  color: #000000 !important;
  outline: 2px solid #000000;
  outline-offset: 1px;
  text-decoration: underline !important;
}

html.a11y-spacing .verse,
html.a11y-spacing .translation,
html.a11y-spacing .cv-text,
html.a11y-spacing .cv-en,
html.a11y-spacing .commentator p,
html.a11y-spacing .a11y-dialog p,
html.a11y-spacing .a11y-dialog li {
  line-height: 2.2 !important;
  letter-spacing: 0.06em;
  word-spacing: 0.16em;
}

html.a11y-cursor,
html.a11y-cursor * {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 24 24'%3E%3Cpath d='M4 2l15 9.5-6.6 1.5L9 20.5z' fill='%23000' stroke='%23fff' stroke-width='1.3' stroke-linejoin='round'/%3E%3C/svg%3E") 6 3, auto !important;
}

html.a11y-still *,
html.a11y-still *::before,
html.a11y-still *::after {
  transition: none !important;
  animation: none !important;
  scroll-behavior: auto !important;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  line-height: 1.6;
  padding:
    max(28px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(calc(var(--fab-size) + 36px), env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.wrap {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding-top: clamp(0px, 5vh, 48px);
}

.wrap:focus { outline: none; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: 8px;
  inset-inline-start: 8px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  font-size: 1rem;
  font-weight: 700;
  transform: translateY(-200%);
}

.skip-link:focus { transform: none; }

/* ---------- header + mode switch ---------- */

.site-head {
  text-align: center;
  margin-bottom: 16px;
}

.site-head h1 {
  margin: 0;
  font-size: 1.875rem;
  font-weight: 700;
  color: var(--accent-dark);
  letter-spacing: 0.01em;
}

.site-head p {
  margin: 2px 0 0;
  font-size: 1.0625rem;
  color: var(--muted);
}

.modes {
  display: flex;
  gap: 4px;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 18px;
  padding: 4px;
  border-radius: 999px;
  background: var(--track);
}

.mode {
  min-height: 42px;
  padding: 6px 20px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 1.0625rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.mode[aria-pressed="true"] {
  background: var(--card);
  color: var(--accent-dark);
  box-shadow: 0 1px 3px rgba(70, 52, 20, 0.14);
}

html.a11y-contrast .mode[aria-pressed="true"] { outline: 2px solid #000000; }
html.a11y-dark .mode[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--accent); }

/* ---------- card ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: clamp(22px, 6vw, 40px);
}

.verse-box {
  text-align: center;
  transition: opacity 0.2s ease;
}

.verse-box.is-loading { opacity: 0.45; }

.ref {
  margin: 0 0 14px;
  font-size: 1.1875rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.ref:empty { display: none; }

.ref::after {
  content: "";
  display: block;
  width: 44px;
  height: 2px;
  margin: 10px auto 0;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.45;
}

.verse {
  margin: 0;
  font-size: 1.625rem;
  line-height: 1.8;
  color: var(--ink);
  white-space: pre-line;
  text-wrap: pretty;
  overflow-wrap: break-word;
}

.verse.is-placeholder {
  color: var(--muted);
  font-size: 1.25rem;
}

.translation {
  margin: 18px 0 0;
  font-family: var(--latin);
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--muted);
  white-space: pre-line;
  overflow-wrap: break-word;
}

.error {
  margin: 20px 0 0;
  padding: 10px 14px;
  border: 1px solid var(--error-line);
  border-radius: 12px;
  background: var(--error-bg);
  color: var(--error-ink);
  font-size: 1.125rem;
  text-align: center;
}

/* ---------- buttons ---------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 28px;
}

.btn {
  flex: 1 1 140px;
  max-width: 240px;
  min-height: 48px;
  padding: 10px 24px;
  border: 2px solid var(--accent);
  border-radius: 999px;
  font: inherit;
  font-size: 1.1875rem;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

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

.btn-secondary {
  background: transparent;
  color: var(--accent-dark);
}

.btn-small {
  flex: none;
  min-height: 44px;
  padding: 8px 20px;
  font-size: 1.0625rem;
}

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  min-width: 44px;
  min-height: 44px;
  padding: 0 0 4px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: transparent;
  color: var(--accent-dark);
  font: inherit;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-dark);
  font: inherit;
  font-size: 1rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

@media (hover: hover) {
  .btn-primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
  .btn-secondary:hover:not(:disabled),
  .icon-btn:hover:not(:disabled),
  .cv-comm:hover:not(:disabled) { background: var(--accent-soft); }
  .mode:hover:not([aria-pressed="true"]) { color: var(--accent-dark); }
}

.btn:active:not(:disabled),
.icon-btn:active:not(:disabled) { transform: translateY(1px); }

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

html.a11y-contrast :focus-visible { outline-color: #000000; }

.btn:disabled,
.icon-btn:disabled,
.chapter-select:disabled,
.cv-comm:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 22px;
  margin-top: 18px;
}

/* ---------- commentary (shared) ---------- */

.commentary {
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.commentary h2 {
  margin: 0;
  font-size: 1.3125rem;
  color: var(--accent-dark);
  text-align: center;
}

.commentary-status {
  margin: 12px 0 0;
  font-size: 1.125rem;
  color: var(--muted);
  text-align: center;
}

.commentary-status.is-error { color: var(--error-ink); }

.commentary-status:empty { display: none; }

.commentator { margin-top: 22px; }

.commentator h3 {
  margin: 0 0 6px;
  padding-inline-start: 10px;
  border-inline-start: 3px solid var(--accent);
  font-size: 1.25rem;
  line-height: 1.4;
  color: var(--ink);
}

.commentator p {
  margin: 0 0 10px;
  font-size: 1.125rem;
  line-height: 1.75;
  white-space: pre-line;
  overflow-wrap: break-word;
}

.commentator strong { color: var(--accent-dark); }

/* ---------- chapter view ---------- */

.chapter-title {
  margin: 0;
  text-align: center;
  font-size: 1.6875rem;
  color: var(--accent-dark);
}

.chapter-meta {
  margin: 2px 0 0;
  text-align: center;
  font-size: 1rem;
  color: var(--muted);
}

.chapter-meta:empty { display: none; }

.chapter-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

.select-wrap {
  position: relative;
  min-width: 0;
}

.select-wrap::after {
  content: "";
  position: absolute;
  top: 50%;
  inset-inline-end: 18px;
  width: 8px;
  height: 8px;
  border: solid var(--accent-dark);
  border-width: 0 2px 2px 0;
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.chapter-select {
  width: 100%;
  min-width: 150px;
  min-height: 44px;
  padding: 6px 18px;
  padding-inline-end: 40px;
  border: 2px solid var(--accent);
  border-radius: 999px;
  background: var(--card);
  color: var(--accent-dark);
  font: inherit;
  font-size: 1.125rem;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.chapter-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 20px;
  margin-top: 12px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-size: 1.0625rem;
  color: var(--muted);
  cursor: pointer;
}

.toggle input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.chapter-verses {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  transition: opacity 0.2s ease;
}

.chapter-verses[aria-busy="true"] { opacity: 0.45; }

.cv {
  margin: 0 -12px 2px;
  padding: 6px 12px;
  border-radius: 12px;
  transition: background-color 0.3s ease;
  scroll-margin-top: 90px;
}

.cv.is-current { background: var(--accent-soft); }

.cv-text {
  margin: 0;
  font-size: 1.375rem;
  line-height: 1.9;
  overflow-wrap: break-word;
}

.cv-num {
  margin-inline-end: 4px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-dark);
}

.cv-comm {
  position: relative;
  margin-inline-start: 6px;
  padding: 1px 11px 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--accent-dark);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.5;
  vertical-align: 3px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.cv-comm::after {
  content: "";
  position: absolute;
  inset: -9px -4px;
}

.cv-comm[aria-expanded="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.cv-en {
  display: none;
  margin: 0 0 4px;
  font-family: var(--latin);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--muted);
  white-space: pre-line;
  text-align: left;
  overflow-wrap: break-word;
}

.show-en .cv-en { display: block; }

.cv-panel {
  margin: 6px 0 12px;
  padding: 2px 14px 4px;
  border-inline-start: 2px solid var(--accent);
}

.cv-panel .commentary-status {
  margin: 8px 0;
  text-align: start;
  font-size: 1.0625rem;
}

.cv-panel .commentator { margin-top: 12px; }
.cv-panel .commentator h3 { font-size: 1.125rem; }
.cv-panel .commentator p { font-size: 1.0625rem; }

.chapter-foot {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.site-foot {
  margin-top: 22px;
  text-align: center;
  font-size: 0.9375rem;
  color: var(--muted);
}

.site-foot a,
.site-foot .link-btn {
  color: var(--accent-dark);
  font-size: inherit;
  text-underline-offset: 3px;
}

/* ---------- accessibility menu ---------- */

.a11y-fab {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  inset-inline-end: max(16px, env(safe-area-inset-left));
  z-index: 60;
  display: block;
  width: var(--fab-size);
  height: var(--fab-size);
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 50%;
  background: var(--a11y-blue);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

/* the owner's round button image (img/a11y-button.webp); its gold rim is part of the picture */
.a11y-fab .a11y-icon {
  display: block;
  width: 100%;
  height: 100%;
}

@media (hover: hover) {
  .a11y-fab:hover { transform: scale(1.06); }
}

.a11y-fab:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

.a11y-panel {
  position: fixed;
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + var(--fab-size) + 12px);
  inset-inline-end: 16px;
  z-index: 60;
  width: min(350px, calc(100vw - 32px));
  max-height: calc(100vh - 120px);
  max-height: calc(100dvh - 120px);
  overflow-y: auto;
  padding: 16px;
  border: 1px solid var(--card-line);
  border-radius: 18px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.28);
  font-family: var(--serif);
}

.a11y-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.a11y-head h2 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--ink);
}

.a11y-close {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.a11y-size {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px 10px;
  border: 2px solid var(--line);
  border-radius: 12px;
  font-weight: 700;
}

.a11y-size-ctrl {
  display: flex;
  align-items: center;
  gap: 8px;
}

.a11y-step {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: transparent;
  color: var(--accent-dark);
  font: inherit;
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.a11y-step:disabled { opacity: 0.4; cursor: not-allowed; }

.a11y-size output {
  min-width: 3.2em;
  text-align: center;
  direction: ltr;
}

.a11y-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.a11y-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 74px;
  padding: 10px 6px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  cursor: pointer;
}

.a11y-opt svg { width: 26px; height: 26px; flex: none; }

.a11y-opt[aria-pressed="true"] {
  border-color: var(--a11y-blue);
  background: #e8efff;
  color: #0b2a78;
}

html.a11y-dark .a11y-opt[aria-pressed="true"] {
  background: #1e2a4a;
  color: #dbe5ff;
  border-color: #8fb0ff;
}

.a11y-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-top: 12px;
}

.a11y-reset {
  min-height: 40px;
  padding: 6px 16px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.a11y-dialog {
  width: min(580px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  padding: 24px;
  border: 1px solid var(--card-line);
  border-radius: 18px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  overflow-y: auto;
}

.a11y-dialog::backdrop { background: rgba(20, 16, 10, 0.55); }

.a11y-dialog h2 {
  margin: 0 0 12px;
  font-size: 1.5rem;
  color: var(--accent-dark);
}

.a11y-dialog h3 {
  margin: 16px 0 6px;
  font-size: 1.1875rem;
}

.a11y-dialog p,
.a11y-dialog li {
  font-size: 1.0625rem;
  line-height: 1.7;
}

.a11y-dialog p { margin: 0 0 10px; }

.a11y-dialog ul {
  margin: 0 0 10px;
  padding-inline-start: 1.3em;
}

.a11y-dialog .btn {
  width: 100%;
  max-width: none;
  margin-top: 10px;
}

[hidden] { display: none !important; }

@media (max-width: 420px) {
  :root { --fab-size: 76px; }
  .site-head h1 { font-size: 1.625rem; }
  .verse { font-size: 1.5rem; }
  .btn { padding-inline: 16px; }
  .mode { padding-inline: 16px; }
  .chapter-title { font-size: 1.5rem; }
  .cv-text { font-size: 1.3125rem; }
  .chapter-select { min-width: 120px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
