:root {
  --bg: #f7f3ea;
  --card: #fffdf7;
  --ink: #1d1a14;
  --muted: #6f675a;
  --line: #e4dccb;
  --accent: #2F80FF;
  --gold: #b8791a;
  --pill: #efe9dc;
  --pill-ink: #2b2620;
  --serif: "Source Serif 4", Charter, Georgia, "Times New Roman", serif;
  --heb: "Frank Ruhl Libre", "Times New Roman", "Arial Hebrew", serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B1220;
    --card: #131c2e;
    --ink: #ede7d8;
    --muted: #9a9484;
    --line: #22304a;
    --gold: #FFB13D;
    --pill: #1c2740;
    --pill-ink: #ede7d8;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--serif); -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; }
.app { min-height: 100dvh; display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 4px; }
.date { font-size: 0.85rem; color: var(--muted); text-align: center; letter-spacing: 0.01em; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 1.5rem; line-height: 1; width: 40px; height: 40px; border-radius: 20px; cursor: pointer; }
.icon-btn:active { background: var(--pill); }

.stage { flex: 1; display: flex; align-items: stretch; padding: 8px 14px; }
.card { flex: 1; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 20px 22px; box-shadow: 0 6px 24px rgba(0,0,0,0.06); cursor: default; user-select: none; -webkit-user-select: none; }
.card-head { display: flex; justify-content: space-between; gap: 10px; font-size: 0.8rem; color: var(--muted); margin-bottom: 14px; }
.card-head .book { color: var(--gold); font-weight: 600; letter-spacing: 0.02em; }
.card-body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 14px; overflow-y: auto; }
.en { margin: 0; font-size: clamp(1.15rem, 2.6vh + 0.6rem, 1.6rem); line-height: 1.45; }
.en.long { font-size: clamp(1.02rem, 2vh + 0.5rem, 1.3rem); line-height: 1.4; }
.en .rest { transition: opacity 0.35s ease; }
.en .rest.hidden { display: none; }
.reveal-hint { margin: 0; font-size: 0.85rem; color: var(--accent); font-style: italic; }
.he { margin: 0; font-family: var(--heb); font-size: clamp(1.15rem, 2.4vh + 0.6rem, 1.5rem); line-height: 1.75; color: var(--ink); border-top: 1px dashed var(--line); padding-top: 12px; }
.card-foot { margin-top: 14px; font-size: 0.7rem; color: var(--muted); line-height: 1.3; }
.fb { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.fb-btn { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 5px 10px; font: inherit; font-size: 0.75rem; cursor: pointer; }
.fb-btn.sent { border-color: var(--gold); color: var(--gold); }
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); }

.actions { display: flex; gap: 8px; padding: 6px 14px 16px; }
.pill { background: var(--pill); color: var(--pill-ink); border: 0; border-radius: 999px; padding: 12px 14px; font: inherit; font-size: 0.95rem; cursor: pointer; flex: 1; }
.pill.primary { background: var(--accent); color: #fff; font-weight: 600; }
.pill.wide { width: 100%; margin-top: 16px; }
.pill[aria-pressed="true"] { outline: 2px solid var(--gold); }
#btn-he { flex: 0 0 52px; font-family: var(--heb); font-size: 1.2rem; }
.pill:active { filter: brightness(0.93); }

.sheet { position: fixed; inset: 0; background: var(--bg); z-index: 10; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
.sheet-bar { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sheet-body { overflow-y: auto; padding: 14px 18px calc(24px + env(safe-area-inset-bottom)); }
.sheet h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 22px 0 8px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row input[type=text], .row input:not([type]) { flex: 1; font: inherit; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.row select { font: inherit; padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 1.3rem; letter-spacing: 0.08em; color: var(--gold); margin: 4px 0 10px; }
.link { color: var(--accent); }

.stream { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin: 8px 0; background: var(--card); }
.stream-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.stream-head input { transform: scale(1.2); }
.books { margin-top: 6px; }
.bookrow { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; font-size: 0.92rem; }
.bookrow .meta { display: flex; flex-direction: column; }
.bookrow .meta small { color: var(--muted); font-size: 0.75rem; }
.wchips { display: flex; gap: 4px; }
.wchips button { border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 999px; width: 30px; height: 30px; font: inherit; font-size: 0.8rem; cursor: pointer; }
.wchips button.on { background: var(--gold); color: #0B1220; border-color: var(--gold); font-weight: 600; }
.stream.off .books { opacity: 0.4; pointer-events: none; }

.ctx p { margin: 0 0 10px; font-size: 0.95rem; line-height: 1.45; }
.ctx .now { border-left: 3px solid var(--gold); padding-left: 10px; }
.ctx .dim { color: var(--muted); }
.related ul { list-style: none; padding: 0; margin: 10px 0; }
.related li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 0.92rem; }
.related li small { color: var(--muted); display: block; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 999px; font-size: 0.85rem; z-index: 20; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.toast.show { opacity: 1; }

.top-right { display: flex; }
#btn-save[aria-pressed="true"] { color: var(--gold); }
.fb-btn.share { margin-left: auto; }
.saved-item { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 10px 0; background: var(--card); }
.saved-item .t { font-size: 1rem; line-height: 1.45; margin: 0 0 8px; cursor: pointer; }
.saved-item .m { font-size: 0.75rem; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.saved-item .m .btns { display: flex; gap: 6px; }

.menu { position: fixed; right: 12px; top: calc(52px + env(safe-area-inset-top)); background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,0.25); z-index: 15; min-width: 200px; padding: 6px; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--ink); font: inherit; font-size: 0.95rem; padding: 11px 12px; border-radius: 10px; cursor: pointer; }
.menu-item:active { background: var(--pill); }
.fb-opts { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 14px; }
.fb-opt { text-align: left; }
.fb-opt.on { outline: 2px solid var(--gold); }
#fb-note { width: 100%; font: inherit; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.fb-card { border-left: 3px solid var(--gold); padding-left: 10px; }
.date { display: none; }
