/* Layout: a quiet temple chamber – deep plum night, copper ginger fire, rose-sand skin.
   Mobile-first single column; lesson view splits into stage + path on wide screens. */
:root {
  --bg: #f6ede6;          /* rose-sand */
  --surface: #fffaf6;
  --surface-2: #efe2d8;
  --fg: #2a1620;          /* deep plum ink */
  --muted: #7a6068;
  --line: #e2d0c4;
  --accent: #b2502a;      /* ginger copper */
  --accent-fg: #fffaf6;
  --accent-soft: #f3d9c9;
  --plum: #5a2843;
  --gold: #b88a3e;
  --ok: #3f7a52;
  --warn: #a65d12;
  --danger: #a3313b;
  --shadow: 0 10px 30px -18px rgba(60, 20, 35, .45);

  --font-display: "Bellefair", "Frank Ruhl Libre", "David Libre", Georgia, serif;
  --font-body: "Assistant", "Heebo", "Segoe UI", Arial, sans-serif;

  --r: 14px;
  --r-lg: 22px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #170d13; --surface: #21141c; --surface-2: #2c1c26; --fg: #f4e7df; --muted: #b59ea6;
    --line: #3a2731; --accent: #e3895a; --accent-fg: #1b0f15; --accent-soft: #3d2420; --plum: #c98aa8;
    --gold: #d8b06a; --ok: #7fbf8f; --warn: #e3a35a; --danger: #ef7d86;
    --shadow: 0 14px 34px -20px rgba(0,0,0,.8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #170d13; --surface: #21141c; --surface-2: #2c1c26; --fg: #f4e7df; --muted: #b59ea6;
  --line: #3a2731; --accent: #e3895a; --accent-fg: #1b0f15; --accent-soft: #3d2420; --plum: #c98aa8;
  --gold: #d8b06a; --ok: #7fbf8f; --warn: #e3a35a; --danger: #ef7d86;
  --shadow: 0 14px 34px -20px rgba(0,0,0,.8);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--font-body); font-size: 17px; line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
img { max-width: 100%; display: block; }
h1, h2, h3, .display { font-family: var(--font-display); font-weight: 400; line-height: 1.2; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(2rem, 5vw, 3rem); }
h2 { font-size: clamp(1.5rem, 3.4vw, 2rem); }
h3 { font-size: 1.3rem; }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

.wrap {
  width: 100%; max-width: 1120px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.stack { display: flex; flex-direction: column; gap: var(--gap, 16px); }
.row { display: flex; gap: var(--gap, 12px); align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.eyebrow { font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .wrap { display: flex; align-items: center; gap: 14px; min-height: 62px; }
.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; color: var(--fg); }
.brand b { font-family: var(--font-display); font-weight: 400; font-size: 1.45rem; letter-spacing: .02em; }
.brand span { font-size: .78rem; color: var(--muted); letter-spacing: .12em; }
.brand img { height: 36px; width: auto; }
.nav { display: flex; gap: 4px; margin-inline-start: auto; flex-wrap: wrap; }
.nav a {
  text-decoration: none; color: var(--fg); padding: 6px 12px; border-radius: 999px; font-size: .95rem;
}
.nav a.on { background: var(--surface-2); }
.nav a:hover { background: var(--surface-2); }
.brand b { white-space: nowrap; }
@media (max-width: 640px) {
  .topbar .wrap { flex-wrap: wrap; gap: 0; padding-block: 8px 4px; }
  .brand span { display: none; }
  .nav { width: 100%; margin: 4px 0 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .nav a { padding: 6px 10px; font-size: .92rem; white-space: nowrap; }
}

main { padding-block: 28px 80px; }

/* ---------- buttons & inputs ---------- */
.btn {
  appearance: none; border: 1px solid transparent; cursor: pointer; font: inherit; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 22px; border-radius: 999px; text-decoration: none; line-height: 1.2;
  background: var(--accent); color: var(--accent-fg); transition: transform .15s ease, filter .15s ease;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--fg); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.soft { background: var(--accent-soft); color: var(--fg); }
.btn.sm { padding: 6px 14px; font-size: .88rem; }
.btn.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: .92rem; font-weight: 600; }
label.field small { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=tel], textarea, select {
  width: 100%; font: inherit; font-weight: 400; color: var(--fg); background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px;
}
textarea { min-height: 110px; resize: vertical; line-height: 1.7; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }

/* ---------- surfaces ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 24px; }
.notice {
  border-radius: var(--r); padding: 12px 16px; background: var(--accent-soft); color: var(--fg); font-size: .94rem;
}
.notice.demo { background: var(--surface-2); border: 1px dashed var(--line); }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.ok { color: var(--ok); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- login ---------- */
.login { min-height: calc(100dvh - 140px); display: grid; place-items: center; padding-block: 24px; }
.login .card { width: 100%; max-width: 440px; }
.login .sigil { width: 64px; height: 64px; margin: 0 auto 6px; color: var(--accent); }
.tabs { display: flex; background: var(--surface-2); border-radius: 999px; padding: 4px; gap: 4px; }
.tabs button { flex: 1; border: 0; background: transparent; font: inherit; padding: 8px; border-radius: 999px; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--surface); color: var(--fg); font-weight: 600; box-shadow: var(--shadow); }

/* ---------- home ---------- */
.hello { display: flex; flex-direction: column; gap: 6px; margin-bottom: 26px; }
.continue {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px; align-items: center;
  background: var(--plum); color: #fff4ee; border-radius: var(--r-lg); padding: 22px 26px; text-decoration: none;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
:root[data-theme="dark"] .continue { color: var(--bg); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .continue { color: var(--bg); } }
.continue .eyebrow { color: inherit; opacity: .75; }
.continue h3 { font-size: 1.5rem; }
.continue .go { width: 54px; height: 54px; border-radius: 50%; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; }
.continue::after {
  content: ""; position: absolute; inset-inline-start: -40px; bottom: -60px; width: 200px; height: 200px; border-radius: 50%;
  border: 1px solid currentColor; opacity: .15;
}

.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.course-card {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); overflow: hidden; text-decoration: none; color: var(--fg);
  transition: transform .2s ease, box-shadow .2s ease;
}
.course-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.cover {
  aspect-ratio: 16 / 9; max-width: 100%; background: var(--surface-2) center / cover no-repeat; position: relative;
}
.cover.blank { background-image: radial-gradient(circle at 70% 30%, var(--accent-soft), transparent 60%), radial-gradient(circle at 20% 80%, color-mix(in srgb, var(--plum) 30%, transparent), transparent 55%); }
.course-card .body { padding: 18px 20px 20px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.course-card h3 { font-size: 1.4rem; }
.meter { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--accent)); border-radius: inherit; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 38px 0 16px; }
.discover .course-card { opacity: .92; }

/* ---------- course page ---------- */
.course-hero { display: grid; gap: 26px; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); align-items: center; margin-bottom: 30px; }
.course-hero .cover { border-radius: var(--r-lg); }
@media (max-width: 820px) { .course-hero { grid-template-columns: minmax(0, 1fr); } .course-hero .cover { order: -1; } }
.ring { --p: 0; width: 86px; height: 86px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-2) 0); }
.ring span { width: 70px; height: 70px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; font-weight: 700; font-variant-numeric: tabular-nums; }

.chapter { border-top: 1px solid var(--line); }
.chapter > button {
  width: 100%; display: flex; gap: 14px; align-items: center; background: none; border: 0; font: inherit; color: inherit;
  padding: 18px 4px; cursor: pointer; text-align: start;
}
.chapter .idx { font-family: var(--font-display); font-size: 1.6rem; color: var(--accent); width: 2ch; text-align: center; flex: none; }
.chapter .ttl { flex: 1; min-width: 0; }
.chapter .ttl b { font-size: 1.12rem; display: block; }
.chapter .chev { transition: transform .2s; flex: none; }
.chapter.open .chev { transform: rotate(180deg); }
.lessons { display: none; padding: 0 0 14px; }
.chapter.open .lessons { display: flex; flex-direction: column; gap: 2px; }
.lesson-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; text-decoration: none; color: var(--fg);
}
.lesson-row:hover { background: var(--surface-2); }
.lesson-row.current { background: var(--accent-soft); }
.lesson-row .t { flex: 1; min-width: 0; }
.lesson-row .d { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.dot { width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--line); flex: none; display: grid; place-items: center; font-size: 12px; }
.dot.done { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }

/* ---------- lesson page ---------- */
.lesson-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 30px; align-items: start; }
@media (max-width: 960px) { .lesson-layout { grid-template-columns: minmax(0, 1fr); } }
.stage { display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.player { position: relative; aspect-ratio: 16 / 9; max-width: 100%; border-radius: var(--r-lg); overflow: hidden; background: #0e070b; box-shadow: var(--shadow); }
.player iframe, .player > div { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player .poster { display: grid; place-items: center; text-align: center; color: #f4e7df; padding: 20px;
  background: radial-gradient(circle at 50% 40%, rgba(178,80,42,.35), transparent 60%), #160b11; }
.player .poster a { color: #f4e7df; }
.crumb { font-size: .9rem; color: var(--muted); }
.crumb a { color: var(--muted); }
.lesson-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.notes { white-space: pre-wrap; }
.notes, .letter { max-width: 68ch; }
.files { display: flex; flex-direction: column; gap: 8px; }
.file { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-decoration: none; color: var(--fg); cursor: pointer; font: inherit; text-align: start; }
.file:hover { border-color: var(--accent); }
.journal-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.journal-box .prompt { font-family: var(--font-display); font-size: 1.35rem; line-height: 1.4; }
.journal-box textarea { min-height: 150px; background: var(--bg); }
.saved { font-size: .82rem; color: var(--muted); min-height: 1.3em; }
.path { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 80px); max-height: calc(100dvh - 110px); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 10px 14px; }
@media (max-width: 960px) { .path { position: static; max-height: none; } }
.path .chapter > button { padding: 12px 2px; }
.path .chapter .idx { font-size: 1.2rem; }

/* ---------- ceremony ---------- */
.ceremony { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 22px; padding-block: 20px; }
.ceremony .letter { text-align: start; white-space: pre-wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 28px; font-size: 1.08rem; }
.flame { width: 90px; height: 90px; color: var(--accent); animation: breathe 4s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.06); opacity: .85; } }
canvas.cert { width: 100%; max-width: 760px; height: auto; border-radius: 10px; box-shadow: var(--shadow); }

/* ---------- journal page ---------- */
.entry { border-inline-start: 2px solid var(--accent); padding: 4px 18px 6px; display: flex; flex-direction: column; gap: 6px; }
.entry .q { font-family: var(--font-display); font-size: 1.15rem; color: var(--muted); }
.entry .a { white-space: pre-wrap; }

/* ---------- admin ---------- */
.admin-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 22px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .8rem; letter-spacing: .06em; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.tree { display: flex; flex-direction: column; gap: 14px; }
.tree .ch { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.tree .ch-head { display: flex; gap: 8px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tree .ch-head b { flex: 1; min-width: 140px; }
.tree .ls { display: flex; gap: 8px; align-items: center; padding: 9px 14px; border-bottom: 1px dashed var(--line); flex-wrap: wrap; }
.tree .ls:last-child { border-bottom: 0; }
.tree .ls span { flex: 1; min-width: 140px; }
.iconbtn { border: 1px solid var(--line); background: var(--surface); color: var(--fg); width: 32px; height: 32px; border-radius: 9px; cursor: pointer; font: inherit; display: inline-grid; place-items: center; }
.iconbtn:hover { border-color: var(--accent); }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }
.stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.stat b { display: block; font-family: var(--font-display); font-size: 2rem; font-variant-numeric: tabular-nums; }

/* ---------- modal & toast ---------- */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(23, 10, 18, .55); display: grid; place-items: center; padding: 20px max(16px, env(safe-area-inset-right, 0px)) 20px max(16px, env(safe-area-inset-left, 0px)); overflow: auto; }
.modal { width: 100%; max-width: 620px; background: var(--surface); border-radius: var(--r-lg); padding: 26px; box-shadow: 0 30px 80px -30px rgba(0,0,0,.6); display: flex; flex-direction: column; gap: 16px; max-height: calc(100dvh - 40px); overflow: auto; }
.toast { position: fixed; z-index: 60; inset-inline: 0; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); display: flex; justify-content: center; pointer-events: none; padding-inline: 16px; }
.toast div { background: var(--fg); color: var(--bg); padding: 11px 20px; border-radius: 999px; box-shadow: var(--shadow); font-size: .95rem; animation: rise .25s ease; }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--accent); animation: spin 1s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.demo-bar { background: var(--plum); color: #fff4ee; font-size: .85rem; }
:root[data-theme="dark"] .demo-bar { color: var(--bg); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .demo-bar { color: var(--bg); } }
.demo-bar .wrap { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding-block: 8px; }
.demo-bar button { background: transparent; color: inherit; border: 1px solid currentColor; border-radius: 999px; padding: 3px 12px; font: inherit; cursor: pointer; }

/* ---------- קריאה בתוך הקורס, טקסט מלא וסאונד ---------- */
.reader { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px; }
.reader-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.reader-toc { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; position: sticky; top: 0; z-index: 2;
  background: var(--surface); padding: 8px 0; border-bottom: 1px solid var(--line); }
.chip { border: 1px solid var(--line); background: var(--surface-2); color: var(--fg); border-radius: 999px;
  padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.reader-pages { display: grid; gap: 14px; max-height: 80vh; overflow-y: auto; padding: 4px; }
.reader-pages:empty { display: none; }
.pdf-page { width: 100%; background: #fff; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,.08); overflow: hidden; scroll-margin-top: 60px; }
.pdf-page canvas { display: block; width: 100%; height: auto; }
.rich { line-height: 1.85; font-size: 1.05rem; overflow-wrap: anywhere; }
.rich h1, .rich h2, .rich h3, .rich h4 { margin: 1.2em 0 .4em; }
.rich blockquote { border-inline-start: 3px solid var(--accent); margin: 1em 0; padding: 4px 14px; color: var(--muted); }
.audio-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px 18px; }
.audio-box audio { width: 100%; margin-top: 8px; }

/* תכונת hidden תמיד מסתירה, גם על שדות שמוגדרים כ-flex */
[hidden] { display: none !important; }

/* מעקב צפייה */
.meter { display: inline-block; flex: 0 0 auto; width: 92px; height: 7px; border-radius: 99px; background: var(--line); overflow: hidden; vertical-align: middle; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.tr-lessons { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.tr-lessons li { display: flex; align-items: center; gap: 10px; font-size: .92rem; padding: 3px 0; color: var(--muted, inherit); }
.tr-lessons li.done, .tr-lessons li.open { color: var(--fg); }
.tr-dot { width: 12px; height: 12px; flex: 0 0 12px; border-radius: 50%; border: 2px solid var(--line); }
.tr-lessons li.open .tr-dot { border-color: var(--accent); }
.tr-lessons li.done .tr-dot { background: var(--accent); border-color: var(--accent); }
details.panel > summary { list-style: none; }
details.panel > summary::-webkit-details-marker { display: none; }
