/* Base — תצוגה נקייה: טקסט שחור על רקע לבן, יישור לימין (ברירת מחדל), מספר פסוק בימין.
   פונטים: קורן, פרנק רוהל, דוד (מערכת) + Frank Ruhl Libre, Noto Serif Hebrew, Heebo (Google Fonts). */
:root {
  --reader-font-size: 140%;
  --reader-font-family: Heebo, serif;
  --reader-text-align: center;
  --bg: #ffffff;
  --fg: #000000;
  --panel-bg: #fff;
  --accent: #2c5282;
  --sidebar-width: 320px;
  --header-height: 56px;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-right: env(safe-area-inset-right, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --safe-left: env(safe-area-inset-left, 0);
}

[data-theme="sepia"] {
  --bg: #f4ecd8;
  --fg: #2c1810;
  --panel-bg: #ebe3d0;
}

[data-theme="dark"] {
  --bg: #1a1a1a;
  --fg: #e8e6e3;
  --panel-bg: #2d2d2d;
}

/* תבניות רקע — טקסטורה, צבע, שקיפות (עיצוב פופולרי) */
body {
  --bg-overlay: none;
  --tex: none;
}
body[data-texture="glass"] { --bg-overlay: linear-gradient(135deg, rgba(255,255,255,0.4) 0%, rgba(255,255,255,0.1) 100%); --tex: none; }
body[data-texture="paper"] { --bg-overlay: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.02) 2px, rgba(0,0,0,0.02) 4px); --tex: none; }
body[data-texture="noise"] { --bg-overlay: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E"); --tex: none; }
body[data-texture="gradient-soft"] { --bg-overlay: radial-gradient(ellipse 120% 80% at 50% 20%, rgba(255,255,255,0.5), transparent 50%), linear-gradient(180deg, rgba(255,255,255,0.15), transparent); --tex: none; }
body[data-texture="gradient-mesh"] { --bg-overlay: radial-gradient(at 40% 20%, rgba(255,200,150,0.2), transparent), radial-gradient(at 80% 0%, rgba(200,220,255,0.2), transparent), radial-gradient(at 0% 50%, rgba(220,255,220,0.15), transparent); --tex: none; }
body[data-texture="warm-grain"] { --bg-overlay: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.06'/%3E%3C/svg%3E"); --tex: none; }
body[data-texture="cool-mist"] { --bg-overlay: linear-gradient(180deg, rgba(240,248,255,0.6) 0%, transparent 40%), linear-gradient(90deg, rgba(230,240,255,0.4), transparent 50%); --tex: none; }
body[data-texture="sand"] { --bg-overlay: linear-gradient(135deg, rgba(210,180,140,0.25), rgba(245,222,179,0.15)); --tex: none; }
body[data-texture="linen"] { --bg-overlay: repeating-linear-gradient(90deg, transparent 0, transparent 3px, rgba(0,0,0,0.015) 3px, rgba(0,0,0,0.015) 6px), repeating-linear-gradient(0deg, transparent 0, transparent 3px, rgba(0,0,0,0.015) 3px, rgba(0,0,0,0.015) 6px); --tex: none; }

/* רק --world-overlay כאן; --bg-overlay ו־--tex נקבעים למעלה (ותבנית רקע מדריסה אותם) */
body {
  --world-overlay: none;
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: var(--world-overlay), var(--bg-overlay);
  pointer-events: none;
  z-index: 0;
}
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: var(--tex);
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
}

/* עולמות חווייתיים — ממלכותי, שאנטי, ביתי, עירוני, אקשן, רוגע וכו' */
body[data-world="royal"] {
  --bg: #1a1625;
  --fg: #f0e6d8;
  --panel-bg: rgba(45, 38, 58, 0.92);
  --accent: #c9a227;
}
body[data-world="royal"] { --world-overlay: radial-gradient(ellipse 100% 60% at 50% 0%, rgba(201, 162, 39, 0.08), transparent 60%); }
body[data-world="royal"] .panel { border-color: rgba(201, 162, 39, 0.3); box-shadow: 0 4px 20px rgba(0,0,0,0.2); }

body[data-world="shanti"] {
  --bg: #e8f0e8;
  --fg: #1a2e1a;
  --panel-bg: rgba(255, 255, 255, 0.85);
  --accent: #2d5a2d;
}
body[data-world="shanti"] { --world-overlay: linear-gradient(180deg, rgba(200, 230, 200, 0.4), transparent 50%); }
body[data-world="shanti"] .panel { border-color: rgba(45, 90, 45, 0.2); }

body[data-world="homey"] {
  --bg: #f5ebe0;
  --fg: #3e2723;
  --panel-bg: #faf5f0;
  --accent: #8d6e63;
}
body[data-world="homey"] { --world-overlay: radial-gradient(circle at 20% 80%, rgba(210, 180, 140, 0.2), transparent 40%); }
body[data-world="homey"] .panel { border-color: rgba(139, 110, 99, 0.25); box-shadow: 0 2px 12px rgba(0,0,0,0.04); }

body[data-world="urban"] {
  --bg: #2d3436;
  --fg: #dfe6e9;
  --panel-bg: rgba(45, 52, 54, 0.95);
  --accent: #00cec9;
}
body[data-world="urban"] { --world-overlay: linear-gradient(135deg, rgba(0, 206, 201, 0.06), transparent 50%); }
body[data-world="urban"] .panel { border-color: rgba(0, 206, 201, 0.25); }

body[data-world="action"] {
  --bg: #0f0f12;
  --fg: #e8e8e8;
  --panel-bg: rgba(25, 25, 30, 0.95);
  --accent: #ff6b35;
}
body[data-world="action"] { --world-overlay: radial-gradient(ellipse 80% 50% at 50% 100%, rgba(255, 107, 53, 0.08), transparent 60%); }
body[data-world="action"] .panel { border-color: rgba(255, 107, 53, 0.35); box-shadow: 0 0 20px rgba(255, 107, 53, 0.1); }

body[data-world="calm"] {
  --bg: #f0f4f8;
  --fg: #2c3e50;
  --panel-bg: rgba(255, 255, 255, 0.9);
  --accent: #5d7a9e;
}
body[data-world="calm"] { --world-overlay: linear-gradient(180deg, rgba(200, 220, 240, 0.5), transparent 60%); }
body[data-world="calm"] .panel { border-color: rgba(93, 122, 158, 0.2); }

body[data-world="minimal"] {
  --bg: #fafafa;
  --fg: #212121;
  --panel-bg: #ffffff;
  --accent: #424242;
}
body[data-world="minimal"] { --world-overlay: none; }
body[data-world="minimal"] .panel { border: 1px solid rgba(0,0,0,0.08); box-shadow: none; }

body[data-world="nature"] {
  --bg: #e8f5e9;
  --fg: #1b5e20;
  --panel-bg: rgba(255, 255, 255, 0.88);
  --accent: #2e7d32;
}
body[data-world="nature"] { --world-overlay: radial-gradient(ellipse 100% 80% at 80% 20%, rgba(129, 199, 132, 0.2), transparent 50%); }
body[data-world="nature"] .panel { border-color: rgba(46, 125, 50, 0.25); }

body[data-world="night"] {
  --bg: #0d1117;
  --fg: #c9d1d9;
  --panel-bg: rgba(22, 27, 34, 0.95);
  --accent: #58a6ff;
}
body[data-world="night"] { --world-overlay: radial-gradient(ellipse 100% 100% at 50% 0%, rgba(88, 166, 255, 0.06), transparent 70%); }
body[data-world="night"] .panel { border-color: rgba(88, 166, 255, 0.2); }

body[data-world="ocean"] {
  --bg: #e0f2f7;
  --fg: #01579b;
  --panel-bg: rgba(255, 255, 255, 0.9);
  --accent: #0288d1;
}
body[data-world="ocean"] { --world-overlay: linear-gradient(180deg, rgba(178, 223, 219, 0.4), transparent 50%); }
body[data-world="ocean"] .panel { border-color: rgba(2, 136, 209, 0.25); }

body[data-world="premium"] {
  --bg: #1c1c1c;
  --fg: #e5e5e5;
  --panel-bg: rgba(40, 40, 40, 0.95);
  --accent: #d4af37;
}
body[data-world="premium"] { --world-overlay: radial-gradient(ellipse 100% 50% at 50% 0%, rgba(212, 175, 55, 0.06), transparent 60%); }
body[data-world="premium"] .panel { border-color: rgba(212, 175, 55, 0.35); box-shadow: 0 8px 32px rgba(0,0,0,0.3); }

body[data-world="nostalgic"] {
  --bg: #faf0e6;
  --fg: #4a3728;
  --panel-bg: #f5e6d3;
  --accent: #8b6914;
}
body[data-world="nostalgic"] { --world-overlay: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(139, 105, 20, 0.03) 2px, rgba(139, 105, 20, 0.03) 4px); }
body[data-world="nostalgic"] .panel { border-color: rgba(139, 105, 20, 0.25); }

body[data-world="garden"] {
  --bg: #f1f8e9;
  --fg: #33691e;
  --panel-bg: rgba(255, 255, 255, 0.9);
  --accent: #689f38;
}
body[data-world="garden"] { --world-overlay: radial-gradient(circle at 70% 30%, rgba(139, 195, 74, 0.15), transparent 50%); }
body[data-world="garden"] .panel { border-color: rgba(104, 159, 56, 0.25); }

* {
  box-sizing: border-box;
}

body {
  font-family: var(--reader-font-family), 'Times New Roman', serif;
  background: var(--world-overlay), var(--bg-overlay), var(--bg);
  color: var(--fg);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  direction: rtl;
}

/* כותרת בלי פס לבן — רק הכפתורים (מסך מלא, להתחלה) והתפריט בולטים. z-index גבוה כדי שהכפתורים יקבלו קליקים גם ב-Windows */
.header {
  position: relative;
  z-index: 100;
  min-height: 0;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  overflow: visible;
}
.header h1 {
  margin: 0;
  font-size: 1.5rem;
}
.subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  opacity: 0.85;
}
/* מסך מלא + להתחלה — פינה שמאלית עליונה (נגררים עם החלון) */
.header-actions-left {
  position: fixed;
  top: max(0.75rem, var(--safe-top));
  left: max(1rem, var(--safe-left));
  z-index: 101;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
}
body.reader-fullscreen .header-actions-left .btn-fullscreen {
  display: none;
}
.btn-fullscreen,
.btn-toggle-controls,
.btn-to-start {
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  border: 1px solid rgba(0,0,0,0.15);
  background: var(--panel-bg);
  color: var(--fg);
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-fullscreen,
.btn-to-start {
  flex-shrink: 0;
}
.btn-toggle-controls {
  position: absolute;
  top: 50%;
  right: max(1rem, var(--safe-right));
  transform: translateY(-50%);
  display: none;
}
.btn-toggle-controls:hover,
.btn-fullscreen:hover,
.btn-to-start:hover {
  background: rgba(0,0,0,0.06);
}

/* לייאאוט: תוכן משמאל, תפריט (הגדרות) צפות בימין */
.app-layout {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: row;
  min-height: calc(100vh - 2rem);
}
.reader-wrap {
  order: 2;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.controls-sidebar {
  order: 1;
  width: var(--sidebar-width);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  align-self: flex-start;
  max-height: 100vh;
  overflow-y: auto;
  padding: 1rem;
  padding-right: max(1rem, var(--safe-right));
  border-left: 1px solid rgba(0,0,0,0.08);
  background: var(--bg);
}
.controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel {
  background: var(--panel-bg);
  border-radius: 8px;
  padding: 1rem;
  border: 1px solid rgba(0,0,0,0.06);
}
.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}
/* פאנל פרקי התהילים — קונספט כרטיס כהה; overflow visible כדי ש-dropdown לא ייחתך */
.panel-what {
  background: #2d3748;
  color: #fff;
  border-radius: 14px;
  padding: 1.25rem;
  border: none;
  overflow: visible;
}
.panel-what .panel-what-title {
  margin: 0 0 1rem;
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
  text-align: center;
}
.what-dropdowns {
  margin-bottom: 1rem;
}
.what-select-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.what-select-label {
  font-size: 0.85rem;
  opacity: 0.9;
}
.what-select {
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 8px;
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23fff' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 0.6rem center;
}
.what-select:focus {
  outline: none;
  border-color: rgba(255,255,255,0.6);
}
/* רשימת האפשרויות — טקסט כהה על רקע לבן (למניעת טקסט לבן על לבן) */
.what-select option {
  color: #1a1a1a;
  background: #fff;
}
.what-dropdowns {
  overflow: visible;
}
.what-content {
  min-height: 80px;
  min-width: 0;
}
.what-mode {
  display: block;
}
.what-mode[hidden] {
  display: none !important;
}
.what-subtitle {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
}
.what-hint {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  opacity: 0.9;
  color: rgba(255,255,255,0.9);
}
.chapter-cubes-wrapper {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-width: 0;
}
.chapter-cubes-group {
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 10px;
  padding: 1rem;
  background: rgba(0,0,0,0.2);
  min-width: 0;
}
.chapter-cubes-group .group-title {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
}
.chapter-cubes {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 0.5rem;
  min-width: 0;
}
.chapter-cubes-week {
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.35rem;
}
.chapter-cubes-week .chapter-cube {
  font-size: 0.7rem;
  padding: 0.2rem;
}
.chapter-cubes-book {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.chapter-cube {
  width: 100%;
  max-width: 100%;
  aspect-ratio: 1;
  min-height: 0;
  min-width: 0;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  user-select: none;
  overflow: hidden;
}
.chapter-cube:hover {
  border-color: rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.15);
}
.chapter-cube:active {
  transform: scale(0.97);
}
.chapter-cube.selected {
  background: rgba(255,255,255,0.35);
  border-color: rgba(255,255,255,0.6);
  color: #fff;
}
.chapter-cube.selected:hover {
  background: rgba(255,255,255,0.4);
}
.chapter-cubes-month-wrapper {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.month-display-only {
  margin: 0;
  padding: 0.5rem 0;
  font-size: 0.95rem;
  opacity: 0.9;
  line-height: 1.5;
}
.tikkun-display-only {
  margin: 0 0 0.75rem;
  padding: 0.5rem 0;
  font-size: 0.95rem;
  opacity: 0.95;
  line-height: 1.5;
}
.tikkun-details {
  margin: 0.5rem 0;
  font-size: 0.9rem;
}
.tikkun-details summary {
  cursor: pointer;
  font-weight: 600;
  padding: 0.25rem 0;
}
.tikkun-intro,
.tikkun-outro {
  padding: 0.5rem 0 0.25rem;
  line-height: 1.7;
}
.tikkun-intro p,
.tikkun-outro p {
  margin: 0 0 0.5em;
}
.tikkun-intro p:last-child,
.tikkun-outro p:last-child {
  margin-bottom: 0;
}
.chapter-cubes-month-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.chapter-cubes-month-row .row-label {
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.85;
}
.chapter-cubes-month-row .chapter-cubes {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}
@media (max-width: 700px) {
  .chapter-cubes {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
  .chapter-cubes-week {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .chapter-cubes-book {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .chapter-cubes-month-row .chapter-cubes {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
  .chapter-cube {
    font-size: 0.75rem;
  }
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.row:last-child {
  margin-bottom: 0;
}

label {
  white-space: nowrap;
}

select, input[type="number"] {
  padding: 0.35rem 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
}
.row select {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
input[type="range"] {
  width: 100%;
  max-width: 120px;
}

button {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
}
button:hover {
  filter: brightness(1.1);
}
button:active {
  filter: brightness(0.95);
}
button.key-pressed {
  transform: scale(0.96);
  filter: brightness(0.9);
}
button.key-pressed,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.speed-buttons-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.speed-display {
  min-width: 2.5em;
  text-align: center;
  font-weight: 600;
  font-size: 1.05rem;
}
.btn-speed {
  min-width: 5rem;
  transition: transform 0.1s ease, filter 0.1s ease;
}
.reading-duration-estimate {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  opacity: 0.9;
  color: var(--fg);
}

.play-pause-row {
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}
.play-pause-row .btn-play-pause {
  flex: 1;
  width: 100%;
  min-height: 2.25rem;
  font-size: 1rem;
}

.panel-stats-toggle .btn-reading-analysis {
  width: 100%;
  padding: 0.65rem 1rem;
  font-size: 1rem;
  font-weight: 500;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--fg);
  cursor: pointer;
  margin-bottom: 0;
}
.panel-stats-toggle .btn-reading-analysis:hover {
  background: rgba(0,0,0,0.05);
}
.panel-stats-toggle .stats-panel-body {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(0,0,0,0.08);
}
.panel-stats-toggle .stats-panel-body h2 {
  margin-top: 0;
}

.stats-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.stat-item {
  font-size: 0.95rem;
}
.stat-item span {
  font-weight: bold;
  margin-left: 0.25rem;
}

.reader-area {
  flex: 1;
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1rem;
  padding-bottom: var(--safe-bottom);
  min-height: 40vh;
  width: 100%;
}

.reader-content {
  font-size: var(--reader-font-size);
  text-align: var(--reader-text-align);
  line-height: 1.6;
  padding: 1rem 0;
}

.placeholder {
  color: var(--fg);
  opacity: 0.8;
}
.placeholder.error {
  color: #c53030;
}

.chapter-view {
  margin: 0;
  line-height: 1.8;
  color: var(--fg);
  text-align: var(--reader-text-align);
}

.chapter-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 1.5rem 0 1rem;
  direction: rtl;
}
.chapter-separator:first-child {
  margin-top: 0;
}
.chapter-separator-line {
  flex: 1;
  max-width: 4rem;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--fg), transparent);
  opacity: 0.35;
}
[dir="rtl"] .chapter-separator-line {
  background: linear-gradient(to left, transparent, var(--fg), transparent);
}
.chapter-separator-title {
  font-family: var(--reader-font-family), serif;
  font-size: 1.15em;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--fg);
  opacity: 0.92;
  white-space: nowrap;
  padding: 0.25em 0.75em;
  border-bottom: 1px solid rgba(0,0,0,0.12);
}
[data-theme="dark"] .chapter-separator-title {
  border-bottom-color: rgba(255,255,255,0.2);
}

.verse-line {
  display: flex;
  flex-direction: row;
  direction: rtl;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.6em;
  min-height: 1.5em;
  scroll-margin: 2rem 0;
}
/* מספר הפסוק (א, ב, ג…) בשוליים הימניים — order כך שיופיע ראשון ב-RTL */
.verse-line .segment-num {
  order: -1;
  flex-shrink: 0;
  width: 2.5em;
  text-align: left;
  font-weight: 600;
  opacity: 0.85;
  font-size: 0.92em;
  color: var(--fg);
}
.verse-line-inner {
  order: 0;
  display: flex;
  flex-direction: row;
  direction: rtl;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 0.5em;
  flex: 1;
  min-width: 0;
  text-align: var(--reader-text-align);
}
/* יישור לימין — שורת הפסוק צמודה לימין */
.reader-content[data-text-align="right"] .verse-line-inner {
  justify-content: flex-end;
}
.reader-content[data-text-align="right"] .verse-line .segment {
  text-align: right;
}
/* מרכוז לאמצע — כל שורת הפסוק (חלק א׳ | חלק ב׳) בקו אחד במרכז */
.reader-content[data-text-align="center"] .verse-line-inner {
  justify-content: center;
}
.reader-content[data-text-align="center"] .verse-line .segment {
  text-align: center;
}
.verse-sep {
  flex-shrink: 0;
  width: 1px;
  min-height: 1em;
  margin: 0 0.5em;
  background: currentColor;
  opacity: 0.25;
  align-self: center;
}
.verse-line .segment {
  font-weight: normal;
  transition: font-weight 0.4s ease, background 0.4s ease;
  padding: 0.2em 0.4em;
  margin: 0 -0.2em;
  border-radius: 6px;
  text-align: var(--reader-text-align);
}
.verse-line .segment.segment-prev,
.verse-line .segment.segment-next {
  font-weight: 500;
}
.verse-line .segment.segment-current {
  font-weight: bold;
}

/* הדגשה לפי שורה שלמה: נוכחית בולט, שורה למעלה ולמטה מודגשות פחות, מעבר חלק */
.reader-content .verse-line.verse-line-current,
.reader-content .verse-line.verse-line-prev,
.reader-content .verse-line.verse-line-next {
  border-radius: 10px;
  padding: 0.25em 0.6em;
  margin-left: -0.6em;
  margin-right: -0.6em;
  transition: background 0.5s ease;
}
.reader-content .verse-line .segment.segment-current,
.reader-content .verse-line .segment.segment-prev,
.reader-content .verse-line .segment.segment-next {
  background: transparent;
}
.reader-content.highlight-theme-1 .verse-line.verse-line-current { background: #bfdbfe; }
.reader-content.highlight-theme-1 .verse-line.verse-line-prev,
.reader-content.highlight-theme-1 .verse-line.verse-line-next { background: rgba(219, 234, 254, 0.45); }
.reader-content.highlight-theme-2 .verse-line.verse-line-current { background: #a7f3d0; }
.reader-content.highlight-theme-2 .verse-line.verse-line-prev,
.reader-content.highlight-theme-2 .verse-line.verse-line-next { background: rgba(209, 250, 229, 0.45); }
.reader-content.highlight-theme-3 .verse-line.verse-line-current { background: #fde68a; }
.reader-content.highlight-theme-3 .verse-line.verse-line-prev,
.reader-content.highlight-theme-3 .verse-line.verse-line-next { background: rgba(254, 243, 199, 0.45); }
.reader-content.highlight-theme-4 .verse-line.verse-line-current { background: #d6c4a8; }
.reader-content.highlight-theme-4 .verse-line.verse-line-prev,
.reader-content.highlight-theme-4 .verse-line.verse-line-next { background: rgba(232, 223, 208, 0.45); }
.reader-content.highlight-theme-5 .verse-line.verse-line-current { background: #ddd6fe; }
.reader-content.highlight-theme-5 .verse-line.verse-line-prev,
.reader-content.highlight-theme-5 .verse-line.verse-line-next { background: rgba(237, 233, 254, 0.45); }
.reader-content.highlight-theme-6 .verse-line.verse-line-current { background: #fed7aa; }
.reader-content.highlight-theme-6 .verse-line.verse-line-prev,
.reader-content.highlight-theme-6 .verse-line.verse-line-next { background: rgba(255, 237, 213, 0.45); }
.reader-content.highlight-theme-7 .verse-line.verse-line-current { background: #99f6e4; }
.reader-content.highlight-theme-7 .verse-line.verse-line-prev,
.reader-content.highlight-theme-7 .verse-line.verse-line-next { background: rgba(204, 251, 241, 0.45); }
.reader-content.highlight-theme-8 .verse-line.verse-line-current { background: #7dd3fc; }
.reader-content.highlight-theme-8 .verse-line.verse-line-prev,
.reader-content.highlight-theme-8 .verse-line.verse-line-next { background: rgba(186, 230, 253, 0.45); }
.reader-content.highlight-theme-9 .verse-line.verse-line-current { background: #d4d4d8; }
.reader-content.highlight-theme-9 .verse-line.verse-line-prev,
.reader-content.highlight-theme-9 .verse-line.verse-line-next { background: rgba(228, 228, 231, 0.45); }
.reader-content.highlight-theme-10 .verse-line.verse-line-current { background: #fbcfe8; }
.reader-content.highlight-theme-10 .verse-line.verse-line-prev,
.reader-content.highlight-theme-10 .verse-line.verse-line-next { background: rgba(252, 231, 243, 0.45); }

/* ניגודיות: טקסט כהה על רקע ההדגשה (למניעת טקסט לבן על רקע לבן/בהיר) */
.reader-content .verse-line.verse-line-current .segment,
.reader-content .verse-line.verse-line-prev .segment,
.reader-content .verse-line.verse-line-next .segment {
  color: #1a1a1a !important;
}
.reader-content .verse-line .segment.segment-current,
.reader-content .verse-line .segment.segment-prev,
.reader-content .verse-line .segment.segment-next {
  color: #1a1a1a !important;
}

.progress-bar {
  height: 6px;
  background: rgba(0,0,0,0.1);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 1rem;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}

/* בראש אזור הקריאה: עילוי נשמת, תמונה, כיתוב — אנכית ממורכז */
.reader-top-dedication {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem 1rem;
  text-align: center;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
  direction: rtl;
}
.reader-top-dedication-memorial {
  margin: 0;
  font-family: var(--reader-font-family), serif;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  color: var(--fg);
  opacity: 0.9;
}
.reader-top-dedication-icon {
  width: 200px;
  height: 200px;
  object-fit: contain;
  flex-shrink: 0;
}
.reader-top-dedication-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--fg);
}
@media (max-width: 480px) {
  .reader-top-dedication-icon { width: 140px; height: 140px; }
  .reader-top-dedication-memorial,
  .reader-top-dedication-title { font-size: 0.85rem; }
}

/* כיתוב לעילוי נשמת — במרכז, באותו רוחב כמו טקסט התהילים */
.memorial-dedication {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem 1.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  color: var(--fg);
  opacity: 0.88;
  direction: rtl;
  max-width: 720px;
  margin: 0 auto;
  margin-inline: auto;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
}
.memorial-dedication-top {
  padding-top: 0.6rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
[data-theme="dark"] .memorial-dedication-top {
  border-bottom-color: rgba(255,255,255,0.1);
}
.memorial-dedication-bottom {
  padding-bottom: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(0,0,0,0.06);
}
[data-theme="dark"] .memorial-dedication-bottom {
  border-top-color: rgba(255,255,255,0.1);
}
.memorial-text {
  font-family: var(--reader-font-family), serif;
  letter-spacing: 0.02em;
  text-align: center;
  flex: 0 1 auto;
  min-width: 0;
}
.memorial-candle {
  display: inline-block;
  width: 14px;
  height: 22px;
  position: relative;
  flex-shrink: 0;
  background: transparent;
}
.memorial-candle::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 20px;
  background: linear-gradient(180deg, transparent 0%, rgba(255, 236, 200, 0.5) 20%, rgba(255, 218, 160, 0.75) 45%, rgba(250, 190, 100, 0.6) 70%, rgba(220, 170, 80, 0.25) 100%);
  border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
  filter: blur(0.5px);
  box-shadow: 0 0 12px rgba(255, 220, 150, 0.35);
}
.memorial-candle::after {
  content: '';
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 6px;
  height: 14px;
  background: linear-gradient(180deg, rgba(255, 248, 230, 0.95) 0%, rgba(255, 230, 180, 0.9) 40%, rgba(240, 200, 120, 0.4) 100%);
  border-radius: 50% 50% 45% 45% / 60% 60% 40% 40%;
  box-shadow: 0 0 8px rgba(255, 235, 180, 0.4);
}

/* אינדיקטור "כמה נשאר לגלול" — צד שמאל, סגנון ווייז (פקק), מתרוקן ככל שמתקדמים */
.scroll-remaining-indicator {
  position: fixed;
  top: 66vh;
  left: max(0.5rem, var(--safe-left));
  right: auto;
  bottom: auto;
  width: 14px;
  height: 28vh;
  z-index: 50;
  pointer-events: none;
  opacity: 0.92;
  transition: opacity 0.25s ease;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.scroll-remaining-indicator:hover {
  opacity: 1;
}
.scroll-remaining-indicator.hidden {
  display: none;
}
.scroll-remaining-track {
  width: 10px;
  height: 100%;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}
[data-theme="dark"] .scroll-remaining-track {
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}
.scroll-remaining-fill {
  width: 100%;
  min-height: 6px;
  border-radius: 999px;
  transition: height 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  background: linear-gradient(180deg,
    #f59e0b 0%,
    #f97316 35%,
    #ea580c 70%,
    #c2410c 100%);
  box-shadow:
    0 0 12px rgba(245, 158, 11, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
[data-theme="dark"] .scroll-remaining-fill {
  background: linear-gradient(180deg,
    #fbbf24 0%,
    #f59e0b 40%,
    #d97706 100%);
  box-shadow:
    0 0 14px rgba(251, 191, 36, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.footer {
  text-align: center;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  opacity: 0.85;
}
.footer span + span {
  margin-right: 1rem;
}

/* תיבת יום — פופאפ בחירת פרקים ליום (צבעים קבועים למניעת לבן על לבן) */
.day-popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
}
.day-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 420px);
  max-height: 85vh;
  background: #f5f5f5;
  color: #1a1a1a;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  z-index: 1001;
  display: flex;
  flex-direction: column;
  padding: 1rem;
}
.day-popup[hidden] { display: none !important; }
.day-popup-overlay[hidden] { display: none !important; }
.day-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.day-popup-header h2 {
  margin: 0;
  font-size: 1.1rem;
  color: #1a1a1a;
}
.day-popup-close {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: #1a1a1a;
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  border-radius: 6px;
}
.day-popup-close:hover {
  background: rgba(0,0,0,0.08);
}
.day-popup-hint {
  font-size: 0.8rem;
  opacity: 0.9;
  margin: 0 0 0.75rem;
  color: #333;
}
.day-popup-cubes {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.4rem;
  overflow-y: auto;
  flex: 1;
  min-height: 120px;
  margin-bottom: 1rem;
}
.day-popup-cubes .chapter-cube {
  font-size: 0.8rem;
  background: #2d3748;
  color: #fff;
  border-color: rgba(255,255,255,0.25);
}
.day-popup-cubes .chapter-cube.selected {
  background: #1e3a5f;
  color: #fff;
  border-color: rgba(255,255,255,0.4);
}
.day-popup-cubes .chapter-cube.selected:hover {
  background: #2c5282;
  color: #fff;
}
.day-popup-done {
  align-self: stretch;
  padding: 0.6rem;
  color: #1a1a1a;
}
/* מבטל ירושת צבע מהעולם/תבנית — רק קוביות הפרקים שומרות על צבען */
.day-popup,
.day-popup * {
  box-sizing: border-box;
}
.day-popup .day-popup-header h2,
.day-popup .day-popup-hint,
.day-popup .day-popup-close,
.day-popup .day-popup-done {
  color: #1a1a1a !important;
}
.day-popup-cubes .chapter-cube {
  color: #fff !important;
  background: #2d3748 !important;
}
.day-popup-cubes .chapter-cube.selected {
  color: #fff !important;
  background: #1e3a5f !important;
}
.day-popup-cubes .chapter-cube.selected:hover {
  color: #fff !important;
  background: #2c5282 !important;
}

/* מסך מלא — רק תצוגה וכפתור יציאה בצד; שאר הפאנלים מוסתרים */
body.reader-fullscreen .header,
body.reader-fullscreen .memorial-dedication-top,
body.reader-fullscreen .reader-top-dedication { display: none !important; }
body.reader-fullscreen .app-layout { min-height: 100vh; }
body.reader-fullscreen .reader-wrap {
  max-width: none;
  padding: 0;
  position: relative;
}
body.reader-fullscreen .reader-area {
  max-width: none;
  padding: 2rem;
  padding-top: 3.5rem;
}
/* במסך מלא: רק פאנל תצוגה בסיידבר */
body.reader-fullscreen .controls-sidebar .panel-what,
body.reader-fullscreen .controls-sidebar .panel[data-panel="speed"],
body.reader-fullscreen .controls-sidebar .panel[data-panel="stats"] {
  display: none !important;
}
body.reader-fullscreen .controls-sidebar {
  width: min(var(--sidebar-width), 280px);
  max-height: 100vh;
  overflow: visible;
}
body.reader-fullscreen .controls-sidebar .controls {
  max-height: 100vh;
  overflow-y: auto;
  overflow-x: visible;
}
body.reader-fullscreen .controls-sidebar .panel[data-panel="display"] {
  overflow: visible;
}
body.reader-fullscreen .controls-sidebar .panel[data-panel="display"] select {
  max-height: none;
}
.btn-exit-fullscreen {
  display: none;
  position: fixed;
  top: max(0.5rem, var(--safe-top));
  right: max(0.5rem, var(--safe-right));
  z-index: 100;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  border: 1px solid rgba(0,0,0,0.2);
  background: var(--panel-bg);
  color: var(--fg);
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
body.reader-fullscreen .btn-exit-fullscreen {
  display: block;
}

/* אייקון פליי/פאוס — מוצג רק במובייל */
.mobile-play-pause-icon {
  display: none;
  pointer-events: none;
}

@media (max-width: 900px) {
  .header {
    z-index: 503;
  }
  .app-layout {
    flex-direction: column;
    position: relative;
  }
  .controls-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(100vw - 2rem, 320px);
    max-width: 320px;
    z-index: 500;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    -webkit-overflow-scrolling: touch;
  }
  .controls-sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: min(100vw - 2rem, 320px);
    background: rgba(0,0,0,0.3);
    z-index: 499;
    -webkit-tap-highlight-color: transparent;
  }
  .sidebar-overlay.visible {
    display: block;
  }
  /* כפתור התפריט תמיד גלוי במובייל גם כשגוללים */
  .btn-toggle-controls {
    display: block;
    position: fixed;
    top: max(0.75rem, var(--safe-top));
    right: 1rem;
    left: auto;
    z-index: 502;
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  }
  .reader-wrap {
    padding-left: 0;
    padding-right: 0;
  }
  /* אייקון פליי/פאוס — רק במובייל */
  .mobile-play-pause-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: max(1rem, var(--safe-bottom));
    right: 1rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--panel-bg);
    border: 1px solid rgba(0,0,0,0.15);
    color: var(--fg);
    font-size: 1.5rem;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(0,0,0,0.2);
    opacity: 0.9;
  }
  .mobile-play-pause-icon.hidden {
    visibility: hidden;
  }
}

@media (max-width: 600px) {
  .controls {
    flex-direction: column;
  }
  .row {
    flex-direction: column;
    align-items: stretch;
  }
  input[type="range"] {
    max-width: none;
  }
  .chapter-cubes-week .chapter-cube {
    font-size: 0.65rem;
  }
  .day-popup-cubes {
    grid-template-columns: repeat(6, 1fr);
  }
}
