/* PersonalLearning — RTL, mobile-first, light/dark */
:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1d2130;
  --muted: #6b7080;
  --border: #e4e2da;
  --accent: #3d4fb8;
  --accent-ink: #ffffff;
  --accent-soft: #e8ebfa;
  --ok: #1f7a4d;   --ok-soft: #e3f3ea;
  --warn: #8a5a00; --warn-soft: #fdf1dc;
  --bad: #b3261e;  --bad-soft: #fbe7e5;
  --info: #25639b; --info-soft: #e3eef8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 22, 30, .05), 0 4px 16px rgba(20, 22, 30, .04);
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans Hebrew", "Arial Hebrew", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #13151c; --surface: #1b1e28; --surface-2: #20242f; --ink: #e8e9ee; --muted: #9aa0b0;
    --border: #2c3040; --accent: #8e9dff; --accent-ink: #11131a; --accent-soft: #262c4d;
    --ok: #6fd3a0; --ok-soft: #173327; --warn: #f0bd5e; --warn-soft: #3a2c12;
    --bad: #ff8a80; --bad-soft: #3d1c1a; --info: #86bdf0; --info-soft: #182c40;
    --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
code, pre { font-family: var(--mono); }
img { max-width: 100%; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; justify-content: center; }
.error { color: var(--bad); }
.warn-text { color: var(--warn); }

/* ── Top bar & navigation ─────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: .6rem max(1rem, env(safe-area-inset-right)) .6rem max(1rem, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--ink); }
.brand img { border-radius: 7px; }
.topnav { display: none; gap: .25rem; margin-inline-start: 1rem; }
.topnav a { padding: .4rem .7rem; border-radius: 9px; color: var(--muted); }
.topnav a.active, .topnav a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.jobs-indicator { margin-inline-start: auto; }
.lang-toggle { margin: 0; }
.lang-toggle .btn { padding: .25rem .55rem; font-size: .8rem; }
label.checkbox { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
label.checkbox input { width: auto; }
[dir="ltr"] .prose pre, [dir="ltr"] .code-input { text-align: left; }
.job-pill { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; padding: .25rem .6rem;
  border-radius: 999px; background: var(--info-soft); color: var(--info); white-space: nowrap; }
.job-pill.warn { background: var(--warn-soft); color: var(--warn); }
.badge { display: inline-block; min-width: 1.3rem; padding: 0 .35rem; border-radius: 999px; background: var(--accent);
  color: var(--accent-ink); font-size: .75rem; text-align: center; }
.bottomnav {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a { position: relative; display: flex; flex-direction: column; align-items: center; padding: .45rem 0 .5rem;
  font-size: .72rem; color: var(--muted); }
.bottomnav a.active { color: var(--accent); }
.bottomnav .ico { font-size: 1.2rem; line-height: 1.2; }
.bottomnav .dot { position: absolute; top: .45rem; inset-inline-end: calc(50% - 1rem); width: .5rem; height: .5rem;
  border-radius: 50%; background: var(--bad); }

.page { max-width: 1180px; margin: 0 auto; padding: 1rem 1rem 6rem; }
@media (min-width: 760px) {
  .topnav { display: flex; }
  .bottomnav { display: none; }
  .page { padding: 1.5rem 1.5rem 3rem; }
}

/* ── Building blocks ──────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; margin: 0 0 1rem; box-shadow: var(--shadow); }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary h2 { display: inline; }
details.card > summary::after { content: "▾"; float: inline-end; color: var(--muted); }
details[open].card > summary::after { content: "▴"; }
.narrow { max-width: 760px; margin-inline: auto; }
.flash { background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: .6rem .9rem; margin-bottom: 1rem; }
.warn-box { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: .6rem .9rem; }
.error-box { border-color: var(--bad); background: var(--bad-soft); }
.empty { text-align: center; padding: 3rem 1rem; }
.empty p { max-width: 560px; margin: .5rem auto 1.5rem; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: .55rem 1rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--ink); border-color: var(--border); }
.btn-small { padding: .3rem .65rem; font-size: .85rem; }
.btn-danger { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.danger > summary h2 { color: var(--bad); }
.btn-block { width: 100%; }
.row-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .6rem; }
.row-actions form, .lesson-actions form, .module-actions form { margin: 0; }

.chip { display: inline-block; padding: .08rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.chip-ok, .chip-done { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip-bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.chip-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.level { display: inline-flex; align-items: center; gap: 2px; }
.level i { width: 7px; height: 12px; border-radius: 2px; background: var(--border); }
.level i.on { background: var(--accent); }
.level small { margin-inline-start: .35rem; color: var(--muted); font-size: .75rem; }
.bar { height: 7px; border-radius: 999px; background: var(--border); overflow: hidden; margin: .4rem 0; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

.spinner { display: inline-block; width: .9em; height: .9em; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -.1em; }
@keyframes spin { to { transform: rotate(360deg); } }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-flex; align-items: center; gap: .4rem; }
.waiting { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; color: var(--info); background: var(--info-soft); border-color: transparent; }

/* ── Forms ────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: .8rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .9rem; }
input, select, textarea { font: inherit; font-weight: 400; color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr; gap: .8rem; }
@media (min-width: 560px) { .form-row { grid-template-columns: 1fr 1fr; } }
.copy-row { display: flex; gap: .5rem; align-items: center; margin: .4rem 0; flex-wrap: wrap; }
.copy-row input { flex: 1 1 260px; font-size: .8rem; }
.copy-row label { flex-basis: 100%; }

/* ── Dashboard ────────────────────────────────────────── */
.hero { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.hero-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.coach-note { border-inline-start: 4px solid var(--accent); background: var(--accent-soft); border-radius: 10px;
  padding: .7rem 1rem; margin-bottom: 1rem; }
.coach-label { font-size: .75rem; font-weight: 700; color: var(--accent); margin-bottom: .2rem; }
.coach-note p { margin: 0; }
.suggestions { list-style: none; margin: 0; padding: 0; }
.suggestions li { padding: .6rem 0; border-top: 1px solid var(--border); }
.suggestions li:first-child { border-top: 0; }
.topic-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.topic-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem;
  display: flex; flex-direction: column; gap: .6rem; box-shadow: var(--shadow); }
.topic-card header { display: flex; justify-content: space-between; align-items: start; gap: .5rem; }
.topic-card h2 { margin: 0; }
.topic-card h2 a { color: var(--ink); }
.progress-line small { color: var(--muted); }
.next-lesson { display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  background: var(--surface-2); border-radius: 10px; padding: .5rem .7rem; }
.next-lesson .btn { margin-top: auto; }

/* ── Topic & roadmap ──────────────────────────────────── */
.topic-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.topic-head > div:first-child { flex: 1 1 380px; }
.head-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: start; }
.head-actions form { margin: 0; }
.crumb, .crumbs { font-size: .85rem; color: var(--muted); }
.crumbs a { color: var(--muted); }
.meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin: .3rem 0; }
.approve-row { margin: .8rem 0; }
.proposal { border-color: var(--accent); }
.ops { padding-inline-start: 1.2rem; }
.ops li { margin: .3rem 0; }
.roadmap > h2 { margin-top: 1.5rem; }
.module { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .8rem;
  box-shadow: var(--shadow); overflow: hidden; }
.module.depth-1 { margin-inline-start: 1.2rem; border-inline-start: 3px solid var(--accent-soft); }
.module.depth-2 { margin-inline-start: 2.4rem; border-inline-start: 3px solid var(--accent-soft); }
.module.depth-3 { margin-inline-start: 3.6rem; }
.module-skipped, .module-done { opacity: .75; }
.module > header { display: flex; justify-content: space-between; gap: .5rem; padding: .8rem 1rem .4rem; }
.module > header p { margin: .1rem 0 0; font-size: .9rem; }
.module-tags { display: flex; gap: .3rem; align-items: start; flex-wrap: wrap; }
.lessons { list-style: none; margin: 0; padding: 0; counter-reset: lesson; }
.lesson-row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .55rem 1rem;
  border-top: 1px solid var(--border); counter-increment: lesson; }
.lesson-row .lesson-main::before { content: counter(lesson) "."; color: var(--muted); margin-inline-end: .4rem; font-size: .85rem; }
.lesson-main { flex: 1; min-width: 0; }
.lesson-meta { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin-top: .15rem; }
.lesson-actions { display: flex; gap: .2rem; flex-shrink: 0; }
.status-done .lesson-main > a, .status-done .lesson-main > span { color: var(--muted); }
.status-skipped .lesson-main > span, .status-skipped .lesson-main > a { text-decoration: line-through; color: var(--muted); }
.module-actions { display: flex; flex-wrap: wrap; gap: .4rem; padding: .5rem 1rem .7rem; border-top: 1px solid var(--border); }
.concepts { list-style: none; padding: 0; margin: .5rem 0 0; display: grid; gap: .5rem; }
.concepts li { display: grid; grid-template-columns: minmax(120px, 1fr) 2fr auto; gap: .6rem; align-items: center; }
.history { list-style: none; padding: 0; }
.history li { display: flex; justify-content: space-between; gap: .5rem; padding: .5rem 0; border-top: 1px solid var(--border); }
.history li small { display: block; }

/* ── Lesson ───────────────────────────────────────────── */
.lesson-layout { display: grid; gap: 1.2rem; }
@media (min-width: 1000px) {
  .lesson-layout { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
  .side { position: sticky; top: 4.5rem; max-height: calc(100vh - 5.5rem); overflow: auto; }
}
.lesson { min-width: 0; }
.lesson-head { margin: .3rem 0 1rem; }
.validation { border-radius: 10px; padding: .6rem .9rem; margin-bottom: 1rem; font-size: .92rem; }
.validation.ok { background: var(--ok-soft); color: var(--ok); }
.validation.ok summary { cursor: pointer; font-weight: 600; }
.validation.ok p, .validation.ok li { color: var(--ink); }
.minor-issues { margin: .2rem 0 .5rem; font-size: .88rem; }
.validation.warn { background: var(--warn-soft); color: var(--warn); }
.validation.warn li { color: var(--ink); margin: .3rem 0; }
.audio-card { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .9rem; margin-bottom: 1rem; }
.audio-card audio { flex: 1 1 260px; width: 100%; }
.objectives { background: var(--surface-2); border-radius: 10px; padding: .6rem 1rem; margin-bottom: 1rem; }
.objectives ul { margin: .3rem 0 0; }

.prose { font-size: 1.06rem; line-height: 1.85; overflow-wrap: anywhere; }
.lesson .prose { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.2rem 1.4rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.prose h2 { font-size: 1.3rem; margin: 1.8rem 0 .6rem; padding-top: .4rem; border-top: 1px solid var(--border); }
.prose h2:first-child { margin-top: 0; border-top: 0; padding-top: 0; }
.prose h3 { font-size: 1.1rem; margin: 1.3rem 0 .4rem; }
.prose p { margin: 0 0 .9rem; }
.prose ul, .prose ol { padding-inline-start: 1.4rem; margin: 0 0 .9rem; }
.prose li { margin: .25rem 0; }
.prose blockquote { margin: 0 0 1rem; padding: .3rem 1rem; border-inline-start: 3px solid var(--accent); background: var(--surface-2); border-radius: 6px; }
.prose code { font-size: .88em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: .05em .3em; unicode-bidi: isolate; direction: ltr; }
.prose pre { direction: ltr; text-align: left; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: .8rem 1rem; overflow-x: auto; font-size: .88rem; line-height: 1.55; }
.prose pre code { background: none; border: 0; padding: 0; font-size: inherit; }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; margin-bottom: 1rem; }
.prose th, .prose td { border: 1px solid var(--border); padding: .35rem .6rem; }
.math.display { direction: ltr; overflow-x: auto; overflow-y: hidden; margin: .8rem 0 1rem; text-align: center; }
.math.inline { unicode-bidi: isolate; }
.prose-inline p { display: inline; margin: 0; }

.glossary { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: .6rem 0 0; }
.glossary dt { font-weight: 600; font-family: var(--mono); font-size: .9rem; }
.glossary dd { margin: 0; }
.videos { display: grid; gap: 1rem; }
@media (min-width: 700px) { .videos { grid-template-columns: 1fr 1fr; } }
.video { margin: 0; }
.video-frame { position: relative; aspect-ratio: 16 / 9; max-width: 100%; border-radius: 10px; overflow: hidden; background: #000; }
.video-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video figcaption { margin-top: .35rem; font-size: .9rem; }
.sources { padding-inline-start: 1.2rem; margin: 0; }
.sources li { margin: .35rem 0; }
.finish p { margin-top: 0; }

.chat h2 { margin-bottom: .6rem; }
.chat-log { display: flex; flex-direction: column; gap: .6rem; max-height: 55vh; overflow-y: auto; margin-bottom: .6rem; }
.msg { border-radius: 12px; padding: .5rem .75rem; }
.msg .prose { font-size: .95rem; line-height: 1.65; }
.msg .prose p:last-child { margin-bottom: 0; }
.msg-user { background: var(--accent-soft); align-self: flex-start; max-width: 92%; }
.msg-assistant { background: var(--surface-2); border: 1px solid var(--border); }
.msg-error { background: var(--warn-soft); color: var(--warn); }
.correction { margin-top: .4rem; font-size: .88rem; background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: .35rem .55rem; }
.chat-form { display: flex; flex-direction: column; gap: .4rem; }
.remark { border-top: 1px solid var(--border); padding-top: .5rem; margin-top: .6rem; }
.remark p { margin: .3rem 0; }
.response { background: var(--surface-2); border-radius: 8px; padding: .4rem .6rem; font-size: .92rem; }
.lesson-nav { display: flex; justify-content: space-between; gap: .5rem; font-size: .9rem; }

/* ── Quiz ─────────────────────────────────────────────── */
.quiz { max-width: 820px; margin: 0 auto; }
.question legend, .graded-head { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; font-weight: 600; }
fieldset.question { border: 1px solid var(--border); }
.qnum { display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: .85rem; }
.question .prose { margin: .6rem 0; }
.choices { display: grid; gap: .45rem; }
.choice { flex-direction: row; align-items: center; gap: .6rem; font-weight: 400; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: .55rem .75rem; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { width: auto; }
.code-input { font-family: var(--mono); font-size: .9rem; direction: ltr; text-align: left; }
.result { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; }
.score { font-size: 2.6rem; font-weight: 800; min-width: 6rem; text-align: center; }
.score.good { color: var(--ok); } .score.mid { color: var(--warn); } .score.low { color: var(--bad); }
.band { font-weight: 600; font-size: 1.05rem; margin: 0 0 .3rem; }
.graded.right { border-inline-start: 4px solid var(--ok); }
.graded.partial { border-inline-start: 4px solid var(--warn); }
.graded.wrong { border-inline-start: 4px solid var(--bad); }
.item-score { margin-inline-start: auto; font-weight: 700; }
.choices-result { list-style: none; padding: 0; display: grid; gap: .3rem; }
.choices-result li { border: 1px solid var(--border); border-radius: 8px; padding: .35rem .6rem; }
.choices-result li p { margin: 0; }
.choices-result li.correct { border-color: var(--ok); background: var(--ok-soft); }
.choices-result li.chosen:not(.correct) { border-color: var(--bad); background: var(--bad-soft); }
.answer-block { background: var(--surface-2); border-radius: 8px; padding: .4rem .7rem; margin: .4rem 0; }
.feedback { background: var(--info-soft); border-radius: 8px; padding: .45rem .7rem; margin: .5rem 0; font-size: .95rem; }
details summary { cursor: pointer; }

/* ── Reviews, notes, profile, system ──────────────────── */
.flashcard .answer { border-top: 1px dashed var(--border); margin-top: .6rem; padding-top: .6rem; }
.flashcard details > summary { list-style: none; margin-top: .6rem; }
.grade-buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; margin-top: .6rem; }
.grade-0 { color: var(--bad); } .grade-3 { color: var(--warn); } .grade-4 { color: var(--info); } .grade-5 { color: var(--ok); }
.done-card { color: var(--ok); }
.remark-card header { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-bottom: .3rem; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; margin-bottom: 1rem; }
@media (min-width: 560px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stats div { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .7rem; text-align: center; }
.stats strong { display: block; font-size: 1.5rem; }
.stats small { color: var(--muted); }
.kv { list-style: none; padding: 0; margin: 0; }
.kv li { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.kv li:first-child { border-top: 0; }
.kv li span:last-child { overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: start; padding: .35rem .5rem; border-bottom: 1px solid var(--border); }

/* ── Login ────────────────────────────────────────────── */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 2rem 1.5rem; text-align: center; box-shadow: var(--shadow); }
.login-card img { border-radius: 14px; }
.login-card form { display: flex; flex-direction: column; gap: .7rem; text-align: start; margin-top: 1rem; }
