:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #1c1c1c;
  --muted: #6b6b6b;
  --line: #e2ddd2;
  --brand: #1f3a5f;
  --brand-ink: #ffffff;
  --accent: #b8860b;
  --ok: #2e7d32;
  --ok-bg: #e6f4e8;
  --bad: #c62828;
  --bad-bg: #fbe9e7;
  --sel-start: #2e7d32;
  --sel-end: #c62828;
  --sel-range: #fff3c4;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.05);
  --gemara-font: 'Noto Serif Hebrew', 'Frank Ruhl Libre', 'David', 'Times New Roman', serif;
  --ui-font: 'Noto Sans Hebrew', 'Segoe UI', Roboto, Arial, sans-serif;
}
:root[data-theme="dark"] {
    --bg: #15171b; --card: #1f2228; --ink: #ececec; --muted: #a0a0a0; --line: #30343c;
    --brand: #2c4e7d; --accent: #e0b348; --ok-bg: #1e3322; --bad-bg: #3a1f1d; --sel-range: #4a3f14;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: var(--ui-font); font-size: 17px; line-height: 1.45; }
body { min-height: 100vh; padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.top { position: sticky; top: 0; z-index: 10; background: var(--brand); color: var(--brand-ink); padding: calc(10px + env(safe-area-inset-top)) 16px 10px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.brand { font-weight: 800; font-size: 20px; letter-spacing: .3px; }
.top-status { font-size: 13px; opacity: .9; }
.icon-btn { background: rgba(255,255,255,.15); border: 0; border-radius: 10px; width: 36px; height: 36px; font-size: 18px; color: #fff; }
.picked-empty { display: none; }

.view { padding: 14px 16px 24px; max-width: 760px; margin: 0 auto; }
.tabs { position: fixed; bottom: 0; right: 0; left: 0; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.tabs button { flex: 1; background: none; border: 0; padding: 8px 2px 6px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tabs button .ic { font-size: 20px; }
.tabs button.active { color: var(--brand); font-weight: 700; }
:root[data-theme="dark"] .tabs button.active { color: var(--accent); }

h1 { font-size: 22px; margin: 6px 0 12px; }
h2 { font-size: 18px; margin: 18px 0 8px; }
h3 { font-size: 16px; margin: 12px 0 6px; }
p { margin: 6px 0; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.center { text-align: center; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.hidden { display: none !important; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px; }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.card.ok { border-right: 5px solid var(--ok); }
.card.warn { border-right: 5px solid var(--accent); }
.card.bad { border-right: 5px solid var(--bad); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--brand); color: #fff; border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700; font-size: 16px; min-height: 46px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; }
.btn.secondary { background: transparent; color: var(--brand); border: 2px solid var(--brand); }
:root[data-theme="dark"] .btn.secondary { color: var(--accent); border-color: var(--accent); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); font-weight: 600; }
.btn.accent { background: var(--accent); color: #1c1c1c; }
.btn.danger { background: var(--bad); }
.btn.sm { padding: 7px 12px; font-size: 14px; min-height: 36px; border-radius: 10px; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--card); border-radius: 12px; padding: 10px 8px; text-align: center; box-shadow: var(--shadow); }
.stat .n { font-size: 24px; font-weight: 800; color: var(--brand); }
:root[data-theme="dark"] .stat .n { color: var(--accent); }
.stat .l { font-size: 12px; color: var(--muted); }

.list { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--card); border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.item .t { font-weight: 700; }
.item .s { font-size: 13px; color: var(--muted); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--line); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.brand { background: var(--brand); color: #fff; }
.badge.accent { background: var(--accent); color: #1c1c1c; }

label.field { display: block; margin: 10px 0; }
label.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.switch { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.switch input { width: 22px; height: 22px; }

/* daf picker */
.daf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 6px; max-height: 260px; overflow-y: auto; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.daf-grid button { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 8px 2px; font-family: var(--gemara-font); font-size: 17px; }
.daf-grid button.sel { background: var(--brand); color: #fff; border-color: var(--brand); }
.daf-grid button.learned { border-color: var(--ok); }
.daf-grid button:disabled { opacity: .3; }
.steps { display: flex; gap: 6px; margin-bottom: 10px; }
.steps span { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.steps span.on { background: var(--brand); }
.picked { position: sticky; top: 56px; z-index: 5; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; margin-bottom: 10px; box-shadow: var(--shadow); font-size: 15px; }
.picked b.start { color: var(--sel-start); }
.picked b.end { color: var(--sel-end); }

/* gemara text */
.gemara { background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); font-family: var(--gemara-font); font-size: 22px; line-height: 1.9; text-align: justify; }
.gemara .seg { margin: 0 0 8px; }
.gemara .w { padding: 1px 2px; border-radius: 4px; cursor: pointer; }
.gemara .w:active { background: var(--line); }
.gemara .w.start { background: var(--sel-start); color: #fff; }
.gemara .w.end { background: var(--sel-end); color: #fff; }
.gemara .w.in { background: var(--sel-range); }
.gemara .w.dis { opacity: .35; cursor: default; }
.gemara-title { font-family: var(--gemara-font); font-size: 20px; font-weight: 700; text-align: center; margin: 6px 0 10px; }

/* quiz */
.progress { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 6px 0 12px; }
.progress div { height: 100%; background: var(--brand); transition: width .3s; }
.q { font-size: 19px; font-weight: 600; line-height: 1.6; margin: 8px 0 14px; }
.opts { display: flex; flex-direction: column; gap: 8px; }
.opt { text-align: right; background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 17px; line-height: 1.5; display: flex; gap: 10px; align-items: flex-start; }
.opt .k { flex: 0 0 26px; height: 26px; border-radius: 50%; background: var(--line); display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 800; }
.opt.chosen { border-color: var(--brand); }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.right .k { background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt.wrong .k { background: var(--bad); color: #fff; }
.opt:disabled { cursor: default; }
.explain { background: var(--sel-range); border-radius: 12px; padding: 10px 14px; margin-top: 12px; font-size: 16px; }
:root[data-theme="dark"] .explain { color: #f3e9c6; }
.verdict { font-weight: 800; font-size: 18px; margin-top: 12px; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--bad); }
.score-big { font-size: 56px; font-weight: 900; color: var(--brand); line-height: 1; }
:root[data-theme="dark"] .score-big { color: var(--accent); }
.spinner { width: 42px; height: 42px; border: 4px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; }
th { color: var(--muted); font-weight: 600; }

.toast { position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%) translateY(20px); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .25s; z-index: 50; max-width: 90vw; font-size: 15px; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.error-box { background: var(--bad-bg); color: var(--bad); border-radius: 10px; padding: 10px 14px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
