/* ---------- Fonts (self-hosted, Georgian + Latin subsets) ---------- */
@font-face { font-family: "Serif Ka"; font-weight: 700; font-display: swap; src: url(fonts/serifgeorgian-700-georgian.woff2) format("woff2"); unicode-range: U+10A0-10FF, U+1C90-1CBF, U+2D00-2D2F; }
@font-face { font-family: "Serif Ka"; font-weight: 700; font-display: swap; src: url(fonts/serifgeorgian-700-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: "Serif Ka"; font-weight: 900; font-display: swap; src: url(fonts/serifgeorgian-900-georgian.woff2) format("woff2"); unicode-range: U+10A0-10FF, U+1C90-1CBF, U+2D00-2D2F; }
@font-face { font-family: "Serif Ka"; font-weight: 900; font-display: swap; src: url(fonts/serifgeorgian-900-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: "Sans Ka"; font-weight: 400; font-display: swap; src: url(fonts/sansgeorgian-400-georgian.woff2) format("woff2"); unicode-range: U+10A0-10FF, U+1C90-1CBF, U+2D00-2D2F; }
@font-face { font-family: "Sans Ka"; font-weight: 400; font-display: swap; src: url(fonts/sansgeorgian-400-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: "Sans Ka"; font-weight: 500; font-display: swap; src: url(fonts/sansgeorgian-500-georgian.woff2) format("woff2"); unicode-range: U+10A0-10FF, U+1C90-1CBF, U+2D00-2D2F; }
@font-face { font-family: "Sans Ka"; font-weight: 500; font-display: swap; src: url(fonts/sansgeorgian-500-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: "Sans Ka"; font-weight: 700; font-display: swap; src: url(fonts/sansgeorgian-700-georgian.woff2) format("woff2"); unicode-range: U+10A0-10FF, U+1C90-1CBF, U+2D00-2D2F; }
@font-face { font-family: "Sans Ka"; font-weight: 700; font-display: swap; src: url(fonts/sansgeorgian-700-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }

/* ---------- Tokens ---------- */
:root {
  color-scheme: light dark;
  --paper: oklch(97.4% 0.009 70);
  --paper-2: oklch(94.5% 0.014 70);
  --ink: oklch(22% 0.02 35);
  --ink-2: oklch(46% 0.02 40);
  --ink-3: oklch(64% 0.018 45);
  --line: oklch(88% 0.012 65);
  --accent: oklch(60% 0.235 25);
  --accent-deep: oklch(50% 0.22 25);
  --accent-soft: oklch(94% 0.04 25);
  --on-accent: oklch(98% 0.01 70);
  --stage: oklch(17% 0.014 30);
  --stage-2: oklch(24% 0.016 30);
  --on-stage: oklch(95% 0.01 70);
  --on-stage-2: oklch(70% 0.015 60);
  --ok: oklch(62% 0.15 150);

  --font-display: "Serif Ka", "Noto Serif Georgian", Georgia, serif;
  --font-body: "Sans Ka", "Noto Sans Georgian", system-ui, sans-serif;

  --gutter: clamp(18px, 5vw, 28px);
  --tabs-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --radius: 14px;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: oklch(18% 0.012 40);
    --paper-2: oklch(23% 0.014 40);
    --ink: oklch(94% 0.01 70);
    --ink-2: oklch(72% 0.015 60);
    --ink-3: oklch(56% 0.015 50);
    --line: oklch(30% 0.012 45);
    --accent: oklch(66% 0.22 25);
    --accent-deep: oklch(58% 0.21 25);
    --accent-soft: oklch(28% 0.06 25);
    --on-accent: oklch(98% 0.01 70);
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
img { display: block; max-width: 100%; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

.view {
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: calc(var(--tabs-h) + var(--safe-b) + 24px);
  min-height: 100dvh;
}
.page { animation: rise .32s var(--ease-out) both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---------- Offline banner ---------- */
.offline {
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + var(--safe-t)) var(--gutter) 8px;
  background: var(--ink); color: var(--paper);
  font-size: .8125rem; font-weight: 500; line-height: 1.3;
  position: sticky; top: 0; z-index: 5;
}
.offline svg { width: 18px; height: 18px; flex: none; }

/* ---------- Top bar (sub pages) ---------- */
.topbar {
  display: flex; align-items: center; gap: 6px;
  padding: calc(10px + var(--safe-t)) calc(var(--gutter) - 10px) 6px;
  position: sticky; top: 0; z-index: 4;
  background: color-mix(in oklab, var(--paper) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.topbar .back {
  width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%;
}
.topbar .back:active { background: var(--paper-2); }
.topbar .back svg { width: 24px; height: 24px; }
.topbar .crumb {
  font-size: .8125rem; color: var(--ink-2); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.topbar.on-stage { position: static; background: var(--stage); color: var(--on-stage); backdrop-filter: none; -webkit-backdrop-filter: none; }
.topbar.on-stage .crumb { color: var(--on-stage-2); }
.topbar.on-stage .back:active { background: var(--stage-2); }

/* ---------- Home ---------- */
.masthead {
  padding: calc(28px + var(--safe-t)) var(--gutter) 10px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
}
.wordmark {
  font-family: var(--font-display); font-weight: 900;
  font-size: clamp(2.25rem, 10vw, 3rem); line-height: 1; letter-spacing: -.01em;
}
.wordmark::after { content: "."; color: var(--accent); }
.masthead .date { font-size: .8125rem; color: var(--ink-3); font-weight: 500; }

.section-label {
  padding: 0 var(--gutter);
  font-size: .75rem; font-weight: 700; letter-spacing: .08em; color: var(--ink-3);
}

.continue {
  margin: 22px var(--gutter) 0;
  display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center;
  padding: 12px; border-radius: var(--radius);
  background: var(--paper-2);
}
.continue .thumb { width: 64px; aspect-ratio: 3/4; border-radius: 8px; object-fit: cover; background: var(--stage); }
.continue .eyebrow { font-size: .75rem; color: var(--accent); font-weight: 700; letter-spacing: .06em; }
.continue .title { font-family: var(--font-display); font-weight: 700; font-size: 1.125rem; line-height: 1.2; margin-top: 2px; }
.continue .meta { font-size: .8125rem; color: var(--ink-2); margin-top: 3px; }
.continue .play { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; }
.continue .play svg { width: 20px; height: 20px; margin-left: 2px; }
.continue .bar { grid-column: 1 / -1; height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; }
.continue .bar i { display: block; height: 100%; background: var(--accent); }

.programs { margin-top: 26px; display: grid; gap: 22px; padding: 0 var(--gutter); }
.program-card {
  position: relative; display: block; border-radius: 20px; overflow: hidden;
  background: var(--stage); color: var(--on-stage);
  aspect-ratio: 4 / 4.6;
  animation: rise .5s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 70ms);
}
.program-card img { width: 100%; height: 100%; object-fit: cover; opacity: .9; }
.program-card::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to top, oklch(12% 0.02 30 / .92) 0%, oklch(12% 0.02 30 / .35) 45%, transparent 75%);
}
.program-card .text { position: absolute; inset: auto 0 0 0; padding: 22px 20px 20px; z-index: 1; }
.program-card .kicker { font-size: .75rem; letter-spacing: .08em; font-weight: 700; color: var(--accent); }
.program-card h2 { font-family: var(--font-display); font-weight: 900; font-size: clamp(1.75rem, 7.5vw, 2.25rem); line-height: 1.05; margin-top: 8px; }
.program-card .meta { margin-top: 10px; font-size: .875rem; color: var(--on-stage-2); }
.program-card .meta b { color: var(--on-stage); font-weight: 500; }

/* ---------- Program page ---------- */
.program-head { padding: 12px var(--gutter) 0; }
.program-head h1 { font-family: var(--font-display); font-weight: 900; font-size: clamp(2rem, 9vw, 2.75rem); line-height: 1.05; letter-spacing: -.01em; }
.program-head p { margin-top: 12px; color: var(--ink-2); font-size: .9375rem; max-width: 48ch; }
.program-head .stats { margin-top: 14px; font-size: .8125rem; color: var(--ink-3); font-weight: 500; }

.chapter { margin-top: 34px; }
.chapter-head {
  padding: 0 var(--gutter) 6px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  border-bottom: 1px solid var(--line); margin: 0 var(--gutter) 4px; padding-inline: 0;
}
.chapter-head h2 { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; line-height: 1.2; }
.chapter-head .count { font-size: .8125rem; color: var(--ink-3); font-weight: 500; white-space: nowrap; }
.chapter-empty { padding: 14px var(--gutter) 0; color: var(--ink-3); font-size: .875rem; display: flex; align-items: center; gap: 8px; }
.chapter-empty::before { content: ""; width: 8px; height: 8px; border-radius: 50%; border: 2px dashed var(--ink-3); }

/* ---------- Video rows (shared by program / saved / downloads) ---------- */
.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 14px; align-items: center;
  padding: 10px var(--gutter);
  transition: background .15s;
}
.row:active { background: var(--paper-2); }
.row .thumb {
  width: 56px; aspect-ratio: 3/4; border-radius: 8px; object-fit: cover; background: var(--stage-2);
  position: relative;
}
.row .thumb-wrap { position: relative; width: 56px; }
.row .thumb-wrap .bar { position: absolute; left: 4px; right: 4px; bottom: 4px; height: 3px; border-radius: 2px; background: oklch(100% 0 0 / .35); overflow: hidden; }
.row .thumb-wrap .bar i { display: block; height: 100%; background: var(--accent); }
.row .thumb-wrap .done { position: absolute; right: -4px; top: -4px; width: 18px; height: 18px; border-radius: 50%; background: var(--ok); color: #fff; display: grid; place-items: center; }
.row .thumb-wrap .done svg { width: 11px; height: 11px; }
.row .body { min-width: 0; }
.row .name { font-family: var(--font-display); font-weight: 700; font-size: 1.0625rem; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: .8125rem; color: var(--ink-2); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub .off { color: var(--ok); font-weight: 500; }
.row .sub .dot::before { content: "·"; margin: 0 5px; color: var(--ink-3); }
.row .marks { display: flex; gap: 6px; align-items: center; color: var(--ink-3); }
.row .marks svg { width: 18px; height: 18px; }
.row .marks .on { color: var(--accent); }
.row .marks .dl { color: var(--ok); }
.row.current { background: var(--accent-soft); }
.row.unavailable { opacity: .42; }
.row .icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: var(--ink-2);
}
.row .icon-btn:active { background: var(--paper-2); }
.row .icon-btn svg { width: 20px; height: 20px; }
.row .num {
  font-family: var(--font-display); font-weight: 900; font-size: 1.5rem; color: var(--ink-3); width: 56px; text-align: center; line-height: 1;
}

/* ---------- Video page ---------- */
.stage {
  background: var(--stage); color: var(--on-stage);
  position: relative;
}
.stage video {
  display: block; width: 100%; max-height: min(66dvh, 620px); object-fit: contain; background: var(--stage);
}
.stage .resume {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: color-mix(in oklab, var(--stage) 70%, transparent); color: var(--on-stage);
  border: 1px solid oklch(100% 0 0 / .18); backdrop-filter: blur(8px);
  padding: 8px 14px; border-radius: 999px; font-size: .8125rem; font-weight: 500;
  display: flex; align-items: center; gap: 8px;
}
.stage .resume svg { width: 14px; height: 14px; }

.video-body { padding: 20px var(--gutter) 0; }
.video-body h1 { font-family: var(--font-display); font-weight: 900; font-size: clamp(1.75rem, 8vw, 2.25rem); line-height: 1.1; letter-spacing: -.01em; }
.video-body .meta { margin-top: 8px; color: var(--ink-2); font-size: .9375rem; }
.video-body .meta .off { color: var(--ok); font-weight: 500; }
.video-body .meta .dot::before { content: "·"; margin: 0 6px; color: var(--ink-3); }

.actions { margin-top: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn {
  height: 52px; border-radius: 12px; display: flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 700; font-size: .9375rem; position: relative; overflow: hidden;
  transition: transform .12s var(--ease-out), background .15s, color .15s;
  border: 1.5px solid transparent;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn-ghost { border-color: var(--line); color: var(--ink); background: transparent; }
.btn-ghost.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.btn-solid { background: var(--accent); color: var(--on-accent); }
.btn-solid:active { background: var(--accent-deep); }
.btn-solid.done { background: var(--paper-2); color: var(--ink); }
.btn-solid.done svg { color: var(--ok); }
.btn.busy { background: var(--paper-2); color: var(--ink); }
.btn.busy .fill { position: absolute; inset: 0; width: 0%; background: var(--accent-soft); transition: width .3s linear; }
.btn.busy .label { position: relative; font-variant-numeric: tabular-nums; }
.btn.busy .x { position: relative; margin-left: 4px; color: var(--ink-3); }
.btn.busy .x svg { width: 16px; height: 16px; }

.dl-note { margin-top: 10px; font-size: .8125rem; color: var(--ink-3); display: flex; justify-content: space-between; align-items: center; }
.dl-note button { color: var(--ink-2); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }

.next-up { margin-top: 34px; }
.next-up .section-label { padding: 0; }
.next-up .row { padding-inline: 0; margin-top: 6px; border-radius: 12px; }
.next-up .row:active { background: transparent; }
.next-up .row .name { font-size: 1.125rem; }
.chapter-list { margin-top: 30px; }
.chapter-list .rows { margin: 8px calc(var(--gutter) * -1) 0; }

/* ---------- Saved / Downloads pages ---------- */
.page-head { padding: calc(28px + var(--safe-t)) var(--gutter) 6px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-family: var(--font-display); font-weight: 900; font-size: clamp(1.875rem, 8vw, 2.5rem); line-height: 1.05; min-width: 0; overflow-wrap: anywhere; }
.page-head .count { font-size: .8125rem; color: var(--ink-3); font-weight: 500; white-space: nowrap; }
.storage { padding: 4px var(--gutter) 16px; color: var(--ink-2); font-size: .9375rem; }
.storage b { font-family: var(--font-display); font-weight: 900; font-size: 1.5rem; color: var(--ink); margin-right: 2px; }
.list-group { margin-top: 12px; }
.list-group .group-label { padding: 14px var(--gutter) 4px; font-size: .75rem; font-weight: 700; letter-spacing: .08em; color: var(--ink-3); }
.footer-action { padding: 22px var(--gutter) 0; }
.btn-text { color: var(--ink-2); font-weight: 500; font-size: .9375rem; text-decoration: underline; text-underline-offset: 3px; }

.empty {
  padding: 40px var(--gutter) 0; max-width: 34ch;
}
.empty .glyph { width: 44px; height: 44px; color: var(--accent); margin-bottom: 18px; }
.empty h2 { font-family: var(--font-display); font-weight: 700; font-size: 1.375rem; line-height: 1.2; }
.empty p { margin-top: 10px; color: var(--ink-2); font-size: .9375rem; }
.empty a { color: var(--accent); font-weight: 700; }

.error { padding: 60px var(--gutter); color: var(--ink-2); text-align: center; }
.error button { color: var(--accent); font-weight: 700; margin-top: 12px; }

/* ---------- Tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  height: calc(var(--tabs-h) + var(--safe-b));
  padding: 0 0 var(--safe-b);
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: color-mix(in oklab, var(--paper) 90%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--ink-3); font-size: .6875rem; font-weight: 500;
  transition: color .15s;
}
.tabs a svg { width: 24px; height: 24px; }
.tabs a.active { color: var(--ink); }
.tabs a.active svg { color: var(--accent); }
.tabs a .badge { position: absolute; }
@media (min-width: 640px) {
  .tabs { max-width: 640px; margin: 0 auto; border-inline: 1px solid var(--line); }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + var(--safe-b) + 14px); transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 10px 16px; border-radius: 999px; font-size: .875rem; font-weight: 500;
  max-width: calc(100vw - 2 * var(--gutter)); text-align: center;
  z-index: 7; animation: toast-in .28s var(--ease-out);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
