/* Chalukas HaShas Academy - phone first. Same look as the live app (cream, deep green, gold),
   written fresh. Light and dark themes. */
:root {
  --bg: oklch(96.6% .013 91);
  --surface: oklch(98.8% .008 91);
  --surface-2: oklch(93% .03 85);
  --text: oklch(25% .025 150);
  --muted: oklch(48% .02 120);
  --line: oklch(88.5% .02 86);
  --primary: oklch(43% .085 155);
  --primary-text: oklch(98% .01 91);
  --gold: oklch(60% .12 75);
  --gold-soft: oklch(75% .08 85);
  --good: oklch(55% .12 150);
  --warn: oklch(62% .14 60);
  --bad: oklch(55% .17 25);
  --hl: oklch(90% .09 95);
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(60 50 20 / .06);
  --radius: 18px;
  --serif: "Cormorant Garamond", "Frank Ruhl Libre", Georgia, serif;
  --hebrew: "Frank Ruhl Libre", "Times New Roman", serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --nav-h: 64px;
  --player-h: 0px;
  color-scheme: light;
}
:root.dark {
  --bg: oklch(18.5% .012 155);
  --surface: oklch(22% .014 155);
  --surface-2: oklch(28% .02 120);
  --text: oklch(93% .016 88);
  --muted: oklch(72% .02 100);
  --line: oklch(100% 0 0 / .1);
  --primary: oklch(66% .11 155);
  --primary-text: oklch(16% .02 155);
  --gold: oklch(77% .12 80);
  --gold-soft: oklch(60% .08 85);
  --hl: oklch(40% .07 95);
  --shadow: 0 1px 2px rgb(0 0 0 / .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 var(--sans);
  min-height: 100dvh; -webkit-tap-highlight-color: transparent; font-variant-numeric: lining-nums; overflow-x: clip;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0; }
h1 { font-size: 2rem; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.15rem; }
.he { font-family: var(--hebrew); unicode-bidi: plaintext; text-align: left; white-space: nowrap; }
.center .he, .he.center { text-align: center; }
svg[aria-hidden="true"] { width: 20px; height: 20px; flex: none; vertical-align: -4px; }
.gold { color: var(--gold); }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.tiny { font-size: .76rem; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: .6rem; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: .75rem; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- frame ---------- */
#app { max-width: 720px; margin: 0 auto; padding-bottom: calc(var(--nav-h) + var(--player-h) + env(safe-area-inset-bottom) + 16px); }
.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in oklch, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); padding: calc(env(safe-area-inset-top) + 10px) 18px 8px;
  display: flex; align-items: center; gap: 10px;
}
.brand { flex: 1; min-width: 0; text-decoration: none; color: var(--text); }
.brand { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; overflow: hidden; }
.brand b { font-family: var(--serif); font-size: 1.05rem; font-weight: 600; }
.brand .he { color: var(--gold); font-size: .8rem; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; display: grid; place-items: center;
  cursor: pointer; color: var(--text);
}
.iconbtn:active { background: var(--surface-2); }
.iconbtn svg, .navbtn svg { width: 22px; height: 22px; }
main { padding: 6px 18px 18px; }
.banner {
  display: flex; gap: 10px; align-items: center; margin: 0 18px 8px; padding: 10px 14px; border-radius: 14px;
  background: var(--surface-2); color: var(--text); text-decoration: none; font-size: .88rem;
}
.banner svg { width: 20px; height: 20px; color: var(--gold); flex: none; }

/* bottom nav */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.nav-inner { max-width: 720px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); height: var(--nav-h); }
.navbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 500;
}
.navbtn[aria-current="page"] { color: var(--primary); }

/* ---------- pieces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-weight: 600; text-decoration: none; color: var(--text);
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.block { display: flex; width: 100%; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: .9rem; }
.btn:disabled { opacity: .5; }
.btn .sub { display: block; font-weight: 400; font-size: .78rem; opacity: .9; }
.link { background: none; border: 0; padding: 0; color: var(--primary); font-weight: 600; cursor: pointer; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: .78rem; background: var(--surface-2); }
.chip.good { background: color-mix(in oklch, var(--good) 18%, transparent); color: var(--good); }
.chip.warn { background: color-mix(in oklch, var(--warn) 20%, transparent); color: color-mix(in oklch, var(--warn) 70%, var(--text)); }
.chip.bad { background: color-mix(in oklch, var(--bad) 15%, transparent); color: var(--bad); }
.label { text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; color: var(--muted); font-weight: 600; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 7px 16px; cursor: pointer; font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--primary); color: var(--primary-text); }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 14px 0; text-decoration: none; color: inherit; width: 100%; background: none; border: 0; text-align: start; cursor: pointer; }
.item .chev { color: var(--muted); }
.field { display: grid; gap: 6px; }
.input { min-height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 0 12px; width: 100%; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: white; transition: transform .15s; box-shadow: 0 1px 2px rgb(0 0 0 / .2); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(18px); }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.days button { min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: .85rem; }
.days button[aria-pressed="true"] { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.sep { height: 1px; background: var(--line); margin: 18px 0; border: 0; }
.big-number { font-family: var(--serif); font-size: 4rem; color: var(--primary); line-height: 1; }

/* progress ring */
.ring { position: relative; display: inline-grid; place-items: center; }
.ring svg { transform: rotate(-90deg); }
.ring .ring-label { position: absolute; font-weight: 600; font-size: .8rem; }

/* sheets / dialogs */
.sheet-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / .35); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--surface); width: 100%; max-width: 720px; border-radius: 22px 22px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 88dvh; overflow: auto; animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--player-h) + 18px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 80; font-size: .9rem; max-width: 90vw;
}

/* ---------- reader ---------- */
.readerbar { position: sticky; top: 58px; z-index: 15; background: var(--bg); border-bottom: 1px solid var(--line); padding: 8px 18px; display: flex; align-items: center; gap: 8px; }
.readerbar h2 { font-size: 1.2rem; flex: 1; }
.amud-head { display: flex; align-items: center; gap: 10px; color: var(--muted); font-family: var(--serif); margin: 22px 0 10px; }
.amud-head::before, .amud-head::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.gemara { font-family: var(--hebrew); direction: rtl; text-align: right; font-size: calc(1.25rem * var(--text-scale, 1)); line-height: 2; }
.gemara p { margin: 0 0 1rem; }
.gemara p.hl { background: var(--hl); border-radius: 6px; box-shadow: 0 0 0 4px var(--hl); }
.gemara p.trail { background: color-mix(in oklch, var(--hl) 40%, transparent); border-radius: 6px; }
.english { font-family: var(--sans); direction: ltr; text-align: left; font-size: calc(.95rem * var(--text-scale, 1)); line-height: 1.6; color: var(--muted); margin: -0.4rem 0 1.2rem; }
.amud-mark { display: flex; justify-content: center; margin: 8px 0 18px; }

/* ---------- player ---------- */
.player {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 25;
  background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -4px 18px rgb(0 0 0 / .06);
}
.player-inner { max-width: 720px; margin: 0 auto; padding: 8px 14px 10px; }
.player .title { text-align: center; font-size: .86rem; font-weight: 600; text-decoration: none; color: var(--text); display: block; }
.player input[type=range] { width: 100%; accent-color: var(--primary); }
.player .times { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); margin-top: -4px; }
.player .controls { display: grid; grid-template-columns: 1fr auto auto auto 1fr; align-items: center; gap: 14px; }
.player .play { width: 52px; height: 52px; border-radius: 50%; border: 2px solid var(--primary); background: var(--surface); color: var(--primary); display: grid; place-items: center; cursor: pointer; }
.player .play svg { width: 24px; height: 24px; }
.player .speed { justify-self: start; min-width: 52px; height: 36px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); font-weight: 600; cursor: pointer; }
.player .more { justify-self: end; }

/* ---------- welcome ---------- */
.welcome { padding: calc(env(safe-area-inset-top) + 28px) 22px 28px; max-width: 520px; margin: 0 auto; text-align: center; }
.welcome h1 { font-size: 2.4rem; margin: 6px 0 14px; }
.welcome .why { text-align: start; margin: 24px 0; }
.welcome .why li { display: flex; gap: 12px; align-items: center; padding: 8px 0; }
.welcome .why .ic { width: 36px; height: 36px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; flex: none; color: var(--primary); }
.welcome .why .ic svg { width: 18px; height: 18px; }

@media (min-width: 900px) {
  h1 { font-size: 2.3rem; }
}

/* ---------- added pieces ---------- */
.serif { font-family: var(--serif); }
.serif-name { font-family: var(--serif); font-size: 1.15rem; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
button.chip { border: 1px solid var(--line); cursor: pointer; min-height: 32px; }
.bar { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--primary); border-radius: inherit; }
.bar.gold i { background: var(--gold); }
.kv { display: grid; gap: 8px; text-align: start; }
.kv > div { display: flex; justify-content: space-between; gap: 10px; border-top: 1px solid var(--line); padding-top: 8px; font-size: .92rem; }
.kv > div:first-child { border-top: 0; padding-top: 0; }
.goalcard h2 { font-size: 1.35rem; }
.streak { width: 52px; height: 52px; border-radius: 50%; border: 3px solid var(--line); display: grid; place-items: center; font: 600 1.25rem var(--sans); flex: none; }
.streak.on { border-color: var(--gold); color: var(--gold); }
.medal { width: 42px; height: 42px; border-radius: 50%; border: 2px dashed var(--line); display: grid; place-items: center; color: var(--muted); flex: none; }
.medal.on { border: 2px solid var(--gold); color: var(--gold); background: color-mix(in oklch, var(--gold) 12%, transparent); }
.medal svg { width: 20px; height: 20px; }
.medal.big { width: 76px; height: 76px; margin: 0 auto; }
.medal.big svg { width: 36px; height: 36px; }
.checkin { width: 100%; margin-top: 12px; cursor: pointer; text-align: start; font-weight: 500; }
.box { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; color: transparent; flex: none; }
.box svg { width: 16px; height: 16px; }
.box.on { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.ring-wrap { position: relative; display: inline-grid; place-items: center; flex: none; }
.ring-ic { position: absolute; color: var(--primary); }
.ring-ic svg { width: 16px; height: 16px; }
.plus { width: 40px; height: 40px; border-radius: 50%; border: 1px dashed var(--line); display: grid; place-items: center; color: var(--muted); flex: none; }
.plus svg { width: 18px; height: 18px; }
.ab { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--line); font-size: .68rem; margin-left: 2px; }
.ab.on { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.dafrow { gap: 4px; }
.dafrow .item { padding: 10px 0; }
.dafbox { width: 44px; height: 44px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--surface); display: grid; place-items: center; cursor: pointer; color: var(--primary-text); flex: none; }
.dafbox.half { background: oklch(90% .055 155); border-color: oklch(80% .06 155); }
:root.dark .dafbox.half { background: oklch(36% .055 155); }
.dafbox.full { background: var(--primary); border-color: var(--primary); }
.dafbox svg { width: 20px; height: 20px; }
.iconbtn.gold { color: var(--gold); }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.swatch.on { border-color: var(--text); }
.amudtick { background: none; border: 0; color: var(--muted); font: inherit; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; min-height: 40px; }
.amudtick svg { width: 20px; height: 20px; }
.amudtick.on { color: var(--primary); }
.amudchk { width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--surface); font-weight: 600; font-size: .8rem; cursor: pointer; }
.amudchk.on { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.spin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.video-slot video { width: 100%; max-height: 35vh; border-radius: 12px; background: #000; display: block; margin-bottom: 6px; }
.readerbar .iconbtn:disabled { opacity: .3; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.gbtn { background: #fff; color: #1f1f1f; border-color: #747775; }
:root.dark .gbtn { background: #131314; color: #e3e3e3; border-color: #8e918f; }
.abtn { background: #000; color: #fff; border-color: #000; }
:root.dark .abtn { background: #fff; color: #000; border-color: #fff; }
.gbtn svg, .abtn svg { width: 20px; height: 20px; }
/* calendars */
.cal-head, .cal, .mcal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-head { font-size: .72rem; color: var(--muted); margin: 8px 0 4px; }
.cal-day { position: relative; min-height: 52px; border-radius: 10px; border: 1px solid transparent; background: none; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 2px; }
.cal-day b { font-weight: 600; font-size: .9rem; }
.cal-day small { font-size: .66rem; color: var(--muted); }
.cal-day.gold-day { background: color-mix(in oklch, var(--gold) 12%, transparent); }
.cal-day.today { border-color: var(--primary); }
.cal-day.on { background: var(--primary); color: var(--primary-text); }
.cal-day.on small { color: inherit; }
.cal-day:disabled { opacity: .3; cursor: default; }
.cal-day .dot { position: absolute; top: 4px; right: 5px; width: 5px; height: 5px; border-radius: 50%; background: var(--gold); }
.mday { aspect-ratio: 1; display: grid; place-items: center; border-radius: 50%; font-size: .85rem; }
.mday.on { background: var(--good); color: #fff; }
.mday.today { box-shadow: 0 0 0 2px var(--primary); }
.mday.future { opacity: .35; }
/* celebration */
.celebrate { position: relative; overflow: hidden; padding-top: 12px; }
.cf { position: absolute; top: -10px; width: 8px; height: 12px; border-radius: 2px; animation: fall 2.4s ease-in forwards; }
@keyframes fall { to { transform: translateY(420px) rotate(540deg); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.planned { display: grid; gap: 4px; margin: -4px 0 14px; }
.planned a { text-decoration: none; }
.est.good { color: var(--good); }
.est.late { color: color-mix(in oklch, var(--warn) 75%, var(--text)); }
.est.muted { color: var(--muted); }
.pacechart { display: block; margin-bottom: 6px; }
.pacechart text { font: 500 10px var(--sans); fill: var(--muted); font-variant-numeric: lining-nums; }

/* ---------- printed page (Tzuras HaDaf) + Follow along ---------- */
.viewtabs { flex: none; }
.viewtabs button { padding: 5px 12px; font-size: .88rem; }
.readerbar { flex-wrap: nowrap; padding: 8px 10px 8px 18px; gap: 2px; }
.readerbar h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 1.1rem; }
.readerbar .iconbtn { width: 34px; }
.pdfview { position: relative; border: 1px solid var(--line); border-radius: 12px; background: #fff; overflow: hidden; }
.pdfscroll { overflow: auto; height: calc(100dvh - 215px - var(--player-h) - var(--nav-h) - env(safe-area-inset-bottom)); min-height: 260px; touch-action: pan-x pan-y; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.pdfpage { position: relative; width: 100%; color: #333; }
.pdfpage canvas { display: block; width: 100%; height: auto; }
.pdfmarks { position: absolute; inset: 0; pointer-events: none; }
.pdfmarks i { position: absolute; background: rgb(255 208 0 / .42); border-radius: 3px; mix-blend-mode: multiply; box-shadow: 0 0 0 1px rgb(214 160 0 / .35); }
.pdftools { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 4px; align-items: center; background: rgb(255 255 255 / .92); border: 1px solid #ddd; border-radius: 999px; padding: 2px 4px; color: #222; }
.pdftools .iconbtn { color: #222; font-size: 1.3rem; width: 36px; height: 36px; }
.pdftools .btn { background: #fff; color: #222; border-color: #ccc; }
.pdfcap { margin: 6px 0 0; }
.gemara .w { border-radius: 3px; }
.gemara .w.fl-past { background: color-mix(in oklch, var(--hl) 45%, transparent); }
.gemara .w.fl-now { background: var(--hl); box-shadow: 0 0 0 2px var(--hl); }
.backpill { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--player-h) + 14px + env(safe-area-inset-bottom)); z-index: 26; border: 0; border-radius: 999px; padding: 9px 16px; background: var(--primary); color: var(--primary-text); font-weight: 600; box-shadow: var(--shadow); cursor: pointer; }
