@font-face { font-family: 'Sefer'; src: url('/fonts/frank-ruhl-libre-hebrew-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Sefer'; src: url('/fonts/frank-ruhl-libre-hebrew-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Plain'; src: url('/fonts/heebo-hebrew-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Plain'; src: url('/fonts/heebo-hebrew-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; }

:root {
  --bg: #fbf6e9; --text: #1a1410; --card: #ffffff; --line: #d9ccb0;
  --accent: #5c1620; --accent-text: #fff; --gold: #b08a3e; --muted: #5a4d3a;
  --ok: #1f6b2e; --size: 32px; --font: 'Sefer', 'Times New Roman', serif;
  --weight: 400; --ui: 26px;
}
body.theme-white { --bg: #ffffff; --text: #000000; --card: #ffffff; --line: #000; --muted: #222; --accent: #000; --accent-text: #fff; --gold: #000; }
body.theme-night { --bg: #000000; --text: #fff4cf; --card: #151515; --line: #6b5a2e; --muted: #e8d9a8; --accent: #f2d16b; --accent-text: #000; --gold: #f2d16b; --ok: #8fe39e; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: 'Plain', Arial, sans-serif; font-size: var(--ui);
  direction: rtl; -webkit-text-size-adjust: 100%;
}
button { font-family: inherit; font-size: inherit; color: inherit; cursor: pointer; }
.loading { padding: 60px; text-align: center; font-size: 34px; }

/* ---------- top bar ---------- */
.topbar {
  position: relative; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--accent); color: var(--accent-text);
}
.topbar h1 { flex: 1; margin: 0; font-family: 'Sefer', serif; font-size: 40px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .crumb { flex: 1; font-size: 24px; line-height: 1.2; overflow: hidden; }
.tbtn {
  background: rgba(255,255,255,.16); color: inherit; border: 3px solid rgba(255,255,255,.55);
  border-radius: 16px; padding: 10px 18px; font-size: 26px; font-weight: 700; min-height: 68px; min-width: 96px;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1;
}
.tbtn .ic { font-size: 30px; }
body.theme-night .tbtn { background: transparent; border-color: #000; }

.page { max-width: 1000px; margin: 0 auto; padding: 22px 20px 140px; }

/* ---------- home ---------- */
.notice { background: var(--card); border: 3px solid var(--gold); border-radius: 18px; padding: 16px 20px; margin: 0 0 20px; font-size: 26px; }
.continue {
  display: block; width: 100%; text-align: right; border: 4px solid var(--accent);
  background: var(--card); border-radius: 22px; padding: 22px 26px; margin: 0 0 28px;
}
.continue .big { display: block; font-size: 40px; font-weight: 700; color: var(--accent); }
.continue .where { display: block; font-family: 'Sefer', serif; font-size: 32px; margin-top: 6px; }
.section-title { font-family: 'Sefer', serif; font-size: 36px; font-weight: 700; margin: 28px 4px 14px; border-bottom: 3px solid var(--gold); padding-bottom: 6px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.tile {
  background: var(--card); border: 3px solid var(--line); border-radius: 20px;
  padding: 20px 20px 16px; text-align: right; min-height: 130px; display: flex; flex-direction: column; justify-content: space-between;
}
.tile .name { font-family: 'Sefer', serif; font-size: 36px; font-weight: 700; line-height: 1.2; }
.tile .status { font-size: 24px; margin-top: 10px; font-weight: 700; }
.tile .status.ok { color: var(--ok); }
.tile .status.get { color: var(--muted); }
.tile.ready { border-color: var(--ok); }
.tile.dim { opacity: .55; }
.bar { height: 16px; background: var(--line); border-radius: 8px; overflow: hidden; margin-top: 10px; }
.bar > div { height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.wide-btn {
  display: block; width: 100%; margin: 18px 0 0; padding: 22px; border-radius: 20px;
  background: var(--accent); color: var(--accent-text); border: none; font-size: 30px; font-weight: 700;
}
.wide-btn.light { background: var(--card); color: var(--text); border: 3px solid var(--line); }
.small-note { color: var(--muted); font-size: 22px; margin-top: 30px; line-height: 1.5; }

/* ---------- table of contents ---------- */
.rows { display: flex; flex-direction: column; gap: 12px; }
.row {
  background: var(--card); border: 3px solid var(--line); border-radius: 18px; padding: 20px 24px;
  text-align: right; font-family: 'Sefer', serif; font-size: 32px; font-weight: 700; display: flex; justify-content: space-between; align-items: center;
}
.row .arrow { font-family: 'Plain', sans-serif; color: var(--gold); font-size: 30px; }
.nums { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px; }
.num {
  background: var(--card); border: 3px solid var(--line); border-radius: 16px; min-height: 96px;
  font-family: 'Sefer', serif; font-size: 36px; font-weight: 700;
}
.num.here, .row.here { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.toc-title { font-family: 'Sefer', serif; font-size: 44px; font-weight: 700; margin: 4px 0 18px; }

/* ---------- reader ---------- */
.reader { max-width: 1100px; margin: 0 auto; padding: 24px 28px 170px; }
.reader h2 { font-family: 'Sefer', serif; font-size: calc(var(--size) * 1.25); margin: 0 0 18px; color: var(--accent); }
body.theme-night .reader h2 { color: var(--gold); }
.text {
  font-family: var(--font); font-size: var(--size); font-weight: var(--weight);
  line-height: 1.85; text-align: justify; word-spacing: .04em;
}
.text p { margin: 0 0 .7em; }
.text .m { font-weight: 700; color: var(--accent); margin-left: .25em; font-family: 'Sefer', serif; }
body.theme-night .text .m { color: var(--gold); }
.text small { font-size: .8em; }
.text big { font-size: 1.15em; }
.text.bold { font-weight: 700; }

.bottombar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; gap: 14px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 3px solid var(--line);
}
.bottombar button {
  flex: 1; min-height: 84px; border-radius: 20px; font-size: 32px; font-weight: 700;
  background: var(--accent); color: var(--accent-text); border: none;
}
.bottombar button[disabled] { opacity: .3; }
.endnext { margin-top: 40px; }

/* ---------- overlay / dialogs ---------- */
#overlay:empty { display: none; }
#overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 20px; }
.dialog {
  background: var(--bg); color: var(--text); border-radius: 26px; padding: 28px; width: 100%; max-width: 760px;
  max-height: 92vh; overflow-y: auto; border: 4px solid var(--gold);
}
.dialog h3 { margin: 0 0 18px; font-family: 'Sefer', serif; font-size: 38px; }
.dialog p { font-size: 28px; line-height: 1.5; margin: 0 0 18px; }
.dialog .btns { display: flex; gap: 14px; margin-top: 20px; }
.dialog .btns button { flex: 1; min-height: 84px; border-radius: 18px; font-size: 30px; font-weight: 700; border: 3px solid var(--line); background: var(--card); }
.dialog .btns button.yes { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.set-label { font-size: 26px; font-weight: 700; margin: 22px 0 10px; }
.choice { display: flex; gap: 12px; flex-wrap: wrap; }
.choice button {
  flex: 1; min-width: 150px; min-height: 80px; border-radius: 16px; font-size: 26px; font-weight: 700;
  border: 4px solid var(--line); background: var(--card); padding: 8px 12px;
}
.choice button.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent) inset; }
.choice .sw-normal { background: #fbf6e9; color: #1a1410; }
.choice .sw-white { background: #fff; color: #000; }
.choice .sw-night { background: #000; color: #fff4cf; }
.size-row { display: flex; gap: 14px; align-items: center; }
.size-row button { width: 110px; min-height: 90px; border-radius: 18px; font-size: 40px; font-weight: 700; background: var(--accent); color: var(--accent-text); border: none; }
.size-row .preview { flex: 1; text-align: center; font-family: var(--font); font-size: var(--size); font-weight: var(--weight); line-height: 1.3; }

/* ---------- search ---------- */
.search { display: flex; gap: 12px; margin-bottom: 18px; }
.search input { flex: 1; font-size: 30px; padding: 16px 18px; border-radius: 16px; border: 3px solid var(--line); background: var(--card); color: var(--text); font-family: inherit; min-width: 0; }
.search button { font-size: 28px; font-weight: 700; padding: 0 26px; border-radius: 16px; border: none; background: var(--accent); color: var(--accent-text); }

@media (max-width: 700px) {
  :root { --ui: 22px; }
  .topbar h1 { font-size: 30px; }
  .tbtn { min-width: 76px; font-size: 20px; padding: 8px 10px; }
  .grid { grid-template-columns: 1fr; }
}

/* ---------- Breslev Center lists & PDF reader ---------- */
.row .sub, .tile .sub { font-family: 'Plain', sans-serif; font-weight: 400; font-size: 22px; color: var(--muted); }
.pdfrow { min-height: 0; padding: 18px 20px; }
.pdfrow .name { font-size: 30px; }
.pdfwrap { padding: 10px 0 130px; }
.pdfinfo { text-align: center; padding: 6px 10px 12px; }
.pagebtn { background: var(--card); border: 3px solid var(--line); border-radius: 16px; padding: 10px 26px; font-size: 28px; font-weight: 700; min-height: 64px; }
.pdfbox { overflow-x: auto; overflow-y: hidden; direction: ltr; -webkit-overflow-scrolling: touch; background: #fff; }
.pdfbox canvas { display: block; margin: 0 auto; }
body.theme-night .pdfbox { background: #000; }
body.theme-night .pdfbox canvas { filter: invert(1) hue-rotate(180deg); }
.text small { color: var(--muted); }
.dialog .btns.col { flex-direction: column; }
.notice .pagebtn { margin-top: 10px; }

/* ---------- home menu ---------- */
.home .continue { margin-bottom: 18px; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 18px; }
.card {
  display: flex; flex-direction: column; justify-content: center; gap: 8px; text-align: right;
  background: var(--card); border: 3px solid var(--line); border-right: 12px solid var(--gold);
  border-radius: 20px; padding: 22px 24px; min-height: 140px;
}
.card .ct { font-family: 'Sefer', serif; font-size: 38px; font-weight: 700; line-height: 1.15; color: var(--text); }
.card .cs { font-size: 22px; color: var(--muted); line-height: 1.35; }
.card .okc { color: var(--ok); font-weight: 700; }
.card.mine { width: 100%; min-height: 0; border-right-color: var(--ok); }
.card.mine .ct { font-size: 34px; }
.linkbtn { display: block; margin: 40px auto 0; background: none; border: none; color: var(--muted); font-size: 22px; text-decoration: underline; padding: 14px; }
@media (max-width: 700px) { .cards { grid-template-columns: 1fr; } .card .ct { font-size: 30px; } }

/* ---------- collapsible home sections ---------- */
.home .top2 { margin-top: 0; }
.card.mine, .card.bmcard { min-height: 0; }
.card.bmcard { border-right-color: var(--accent); }
.sec { margin-top: 22px; border: 3px solid var(--line); border-radius: 22px; background: var(--card); overflow: hidden; }
.sec.open { border-color: var(--gold); }
.sechead { width: 100%; display: flex; align-items: center; gap: 16px; padding: 22px 24px; background: transparent; border: none; text-align: right; min-height: 92px; }
.sec.open .sechead { background: var(--accent); color: var(--accent-text); }
.secicon { font-size: 28px; width: 34px; text-align: center; }
.sectitle { flex: 1; font-family: 'Sefer', serif; font-size: 40px; font-weight: 700; }
.sechint { font-size: 22px; opacity: .85; border: 2px solid currentColor; border-radius: 12px; padding: 6px 14px; }
.secbody { padding: 18px 18px 22px; background: var(--bg); }
.secsub { font-size: 22px; color: var(--muted); margin: 0 4px 6px; }
.secbody .cards { margin-top: 10px; }
.bmrow { display: flex; gap: 10px; }
.bmrow .row { flex: 1; }
.bmdel { width: 90px; border-radius: 18px; border: 3px solid var(--line); background: var(--card); font-size: 30px; }
.tbtn.bmon { background: var(--gold); color: #000; border-color: var(--gold); }
#toast { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); background: rgba(0,0,0,.85); color: #fff; font-size: 34px; font-weight: 700; padding: 22px 36px; border-radius: 22px; z-index: 99; opacity: 0; pointer-events: none; transition: opacity .3s; }
#toast.show { opacity: 1; }
@media (max-width: 700px) { .sectitle { font-size: 30px; } .sechint { display: none; } }
