/* ---------- tokens ---------- */
:root {
  --bg: #12151a;
  --surface: #191d24;
  --surface-2: #20252e;
  --border: #2b313b;
  --text: #e6e9ee;
  --text-dim: #9aa3b0;
  --accent: #5aa9e6;
  --accent-soft: rgba(90, 169, 230, 0.14);
  --ok: #5cbf8a;
  --ok-soft: rgba(92, 191, 138, 0.13);
  --warn: #d9a441;
  --warn-soft: rgba(217, 164, 65, 0.13);
  --danger: #e06a6a;
  --danger-soft: rgba(224, 106, 106, 0.13);
  --radius: 10px;
  --maxw: 1100px;

  --t-learn-fg: #7cb9f0;    --t-learn-bg: rgba(124, 185, 240, 0.13);
  --t-practice-fg: #6fc79b; --t-practice-bg: rgba(111, 199, 155, 0.13);
  --t-build-fg: #c39ae8;    --t-build-bg: rgba(195, 154, 232, 0.13);
  --t-setup-fg: #9aa3b0;    --t-setup-bg: rgba(154, 163, 176, 0.13);
  --t-review-fg: #d9a441;   --t-review-bg: rgba(217, 164, 65, 0.13);
}

html[data-theme="light"] {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1b1f26;
  --text-dim: #616b7a;
  --accent: #1f6fb2;
  --accent-soft: rgba(31, 111, 178, 0.10);
  --ok: #2f8b5f;
  --ok-soft: rgba(47, 139, 95, 0.10);
  --warn: #9a6b12;
  --warn-soft: rgba(154, 107, 18, 0.10);
  --danger: #b4302f;
  --danger-soft: rgba(180, 48, 47, 0.08);

  --t-learn-fg: #1f6fb2;    --t-learn-bg: rgba(31, 111, 178, 0.10);
  --t-practice-fg: #2f8b5f; --t-practice-bg: rgba(47, 139, 95, 0.10);
  --t-build-fg: #7a45b5;    --t-build-bg: rgba(122, 69, 181, 0.10);
  --t-setup-fg: #5b6573;    --t-setup-bg: rgba(91, 101, 115, 0.10);
  --t-review-fg: #9a6b12;   --t-review-bg: rgba(154, 107, 18, 0.10);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 0 env(safe-area-inset-bottom, 0px);
  background: var(--bg);
  color: var(--text);
  font-family: Cairo, Tajawal, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.35; margin: 0; font-weight: 700; }
ul { margin: 0; padding: 0; list-style: none; }
hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; max-width: 100%; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--text-dim); }
.small { font-size: 13px; }
.strong { font-weight: 700; }
.center { text-align: center; }
.pre-wrap { white-space: pre-wrap; }
.mt-s { margin-top: 8px; }
.mt-m { margin-top: 16px; }
.mb-m { margin-bottom: 16px; }
.pad-xs { padding: 4px 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0px);
}
.app-header__inner {
  max-width: var(--maxw); margin: 0 auto;
  padding: 10px 16px;
  display: flex; align-items: center; gap: 10px;
}
.brand { display: flex; flex-direction: column; min-width: 0; margin-inline-end: auto; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand__title { font-weight: 700; font-size: 15px; direction: ltr; }
.brand__meta { font-size: 12px; color: var(--text-dim); direction: ltr; }

.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius); width: 34px; height: 34px; font-size: 15px; cursor: pointer; flex: none;
}
.icon-btn:hover { border-color: var(--accent); }

/* ---------- shell ---------- */
.shell { max-width: var(--maxw); margin: 0 auto; display: flex; gap: 20px; align-items: flex-start; }

.sidenav {
  position: sticky; top: 64px;
  width: 170px; flex: none;
  padding: 20px 8px 20px 0;
  display: flex; flex-direction: column; gap: 2px;
}
.sidenav a { padding: 7px 12px; border-radius: var(--radius); color: var(--text-dim); font-size: 14px; }
.sidenav a:hover { background: var(--surface-2); text-decoration: none; }
.sidenav a.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

.view { flex: 1; min-width: 0; padding: 20px 16px 48px; }
.view:focus { outline: none; }
.tabbar { display: none; }

.page-head { margin-bottom: 18px; }
.page-head h1 { font-size: 20px; }
.page-head p { margin: 4px 0 0; color: var(--text-dim); font-size: 14px; }

.banner {
  background: var(--warn-soft); color: var(--warn);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px; font-size: 13px; text-align: center;
}

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
  display: block; color: var(--text);
}
.card--link:hover { border-color: var(--accent); text-decoration: none; }
.card--next { border-inline-start: 3px solid var(--accent); }
.card--warn { background: var(--warn-soft); border-color: var(--warn); }
.card--danger { border-color: var(--danger); }
.card--evidence { border-inline-start: 3px solid var(--ok); }
.card--card { min-height: 140px; }
.card__title { font-size: 15px; }
.card__label { font-size: 12px; color: var(--text-dim); font-weight: 700; }
.stat { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; direction: ltr; }
.sep { margin: 14px 0; }
.q { font-size: 17px; font-weight: 700; margin-top: 6px; }
.evidence { border-inline-start: 2px solid var(--ok); padding-inline-start: 10px; }

.row { display: flex; align-items: center; gap: 10px; }
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.gap-s { gap: 8px; }
.grid-2, .grid-3 { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }

.pace { display: flex; align-items: flex-start; gap: 10px; }
.pace__dot { width: 9px; height: 9px; border-radius: 50%; flex: none; margin-top: 8px; }
.pace__dot--ok { background: var(--ok); }
.pace__dot--warn { background: var(--warn); }
.pace__body { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }

/* ---------- controls ---------- */
.btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius); padding: 7px 14px; font-size: 13.5px;
  font-family: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
html[data-theme="light"] .btn--primary { color: #fff; }
.btn--quiet { background: transparent; }
.btn--sm { padding: 4px 10px; font-size: 12.5px; }
.btn--icon { padding: 2px 9px; font-size: 15px; line-height: 1.4; }
.btn--danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn--ok { color: var(--ok); border-color: var(--ok); background: transparent; }
.btn--teach { border-style: dashed; direction: ltr; }
.btn.is-on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }

.input {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius); padding: 8px 12px; font-size: 14px;
  font-family: inherit; width: 100%; max-width: 100%;
}
.input:focus { border-color: var(--accent); }
.input--sm { width: auto; padding: 5px 10px; font-size: 13px; }
.input--tiny { width: 90px; padding: 5px 10px; font-size: 13px; }
.input--area { resize: vertical; line-height: 1.7; }
.input--title { font-size: 18px; font-weight: 700; }
.field { display: block; }

.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-dim); }

.check {
  flex: none; width: 24px; height: 24px; border-radius: 6px;
  border: 1.5px solid var(--border); background: var(--surface-2);
  color: transparent; cursor: pointer; font-size: 14px; line-height: 1; padding: 0;
}
.check:hover { border-color: var(--accent); }
.check.is-on { background: var(--accent); border-color: var(--accent); color: #fff; }
.check--void { display: grid; place-items: center; color: var(--text-dim); cursor: default; }
.pick { width: 16px; height: 16px; flex: none; accent-color: var(--accent); }

.toast {
  position: fixed; inset-inline: 0; bottom: 84px; margin: 0 auto; width: max-content; max-width: 90vw;
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 999px;
  font-size: 13px; z-index: 60; opacity: 0; pointer-events: none; transition: opacity 0.18s ease;
}
.toast.is-on { opacity: 1; }

.sticky-bar {
  position: sticky; top: 56px; z-index: 10;
  background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 12px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
}
.bulk {
  position: sticky; top: 56px; z-index: 10;
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 8px 12px; margin-bottom: 8px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}

/* ---------- progress ---------- */
.bar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar__fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.2s ease; }

.overall { margin-bottom: 20px; }
.overall__row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; font-size: 13px; color: var(--text-dim); gap: 10px; }

.ring { flex: none; transform: rotate(-90deg); }
.ring__bg { fill: none; stroke: var(--surface-2); stroke-width: 3; }
.ring__fg { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; }

/* ---------- month / week rows ---------- */
.month { margin-bottom: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.month > summary { cursor: pointer; list-style: none; padding: 12px 16px; display: flex; align-items: center; gap: 10px; }
.month > summary::-webkit-details-marker { display: none; }
.month > summary::after { content: "▾"; color: var(--text-dim); font-size: 12px; transition: transform 0.15s ease; }
.month[open] > summary::after { transform: rotate(180deg); }
.month > summary:hover { background: var(--surface-2); }
.month__head { flex: 1; min-width: 0; }
.month__num { flex: none; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 7px; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 700; }
.month__title { font-weight: 700; font-size: 15px; }
.month__meta { font-size: 12px; color: var(--text-dim); }
.month__pct { font-size: 13px; color: var(--text-dim); font-weight: 700; }
.month__body { padding: 0 16px 14px; border-top: 1px solid var(--border); }
.month__goal { color: var(--text-dim); font-size: 13.5px; margin: 10px 0 12px; }

.weeks { display: flex; flex-direction: column; gap: 6px; }
.week-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text);
}
.week-row:hover { border-color: var(--accent); text-decoration: none; }
.week-row__num { flex: none; min-width: 26px; text-align: center; font-weight: 700; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.week-row__main { min-width: 0; flex: 1; }
.week-row__title { font-size: 14px; }
.week-row__meta { font-size: 12px; color: var(--text-dim); }
.week-row.is-current { border-color: var(--accent); background: var(--accent-soft); }
.week-row.is-done .week-row__title { color: var(--text-dim); }

.pill { flex: none; font-size: 11.5px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-dim); background: var(--surface); }
.pill--current { border-color: var(--accent); color: var(--accent); background: transparent; }
.pill--done { border-color: var(--ok); color: var(--ok); background: transparent; }

/* ---------- badges / chips ---------- */
.badge { font-size: 11.5px; padding: 1px 8px; border-radius: 999px; white-space: nowrap; direction: ltr; flex: none; }
.badge--learn { color: var(--t-learn-fg); background: var(--t-learn-bg); }
.badge--practice { color: var(--t-practice-fg); background: var(--t-practice-bg); }
.badge--build { color: var(--t-build-fg); background: var(--t-build-bg); }
.badge--setup { color: var(--t-setup-fg); background: var(--t-setup-bg); }
.badge--review { color: var(--t-review-fg); background: var(--t-review-bg); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 12px; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim); direction: ltr;
  display: inline-block;
}
.chip--link { color: var(--accent); }
.chip--link:hover { text-decoration: none; border-color: var(--accent); }
.chip--tag { color: var(--accent); }
.chip--warn, .chip--optional { color: var(--warn); border-color: var(--warn); }
.chip--danger, .chip--skip { color: var(--danger); border-color: var(--danger); }
.chip--ok, .chip--active { color: var(--ok); border-color: var(--ok); }
.chip--replaced, .chip--paused { opacity: 0.8; }

/* ---------- tasks / rows ---------- */
.section-title { font-size: 13px; color: var(--text-dim); margin: 22px 0 8px; font-weight: 700; }

.task {
  display: flex; align-items: flex-start; gap: 10px; padding: 11px 14px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 6px;
}
.task__text { flex: 1; min-width: 0; font-size: 14px; }
.task__hours { flex: none; font-size: 12.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.task.is-done .task__text { color: var(--text-dim); text-decoration: line-through; text-decoration-thickness: 1px; }

.res {
  display: flex; align-items: center; gap: 8px; padding: 9px 14px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 6px;
}
.res--block { align-items: flex-start; }
.res__title { flex: 1; min-width: 0; }

/* course sections */
.srow {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 6px;
}
.srow__num { flex: none; min-width: 22px; text-align: center; color: var(--text-dim); font-weight: 700; }
.srow__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.srow__title { font-size: 14px; }
.srow__meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.srow__reason { color: var(--danger); }
.srow.is-skipped { opacity: 0.75; background: var(--danger-soft); }
.srow.is-skipped .srow__title { text-decoration: line-through; text-decoration-thickness: 1.5px; }
.srow.is-done .srow__title { color: var(--text-dim); }
.verdicts { display: flex; gap: 4px; flex: none; }

/* ---------- skills ---------- */
.skills { display: grid; gap: 6px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.skill { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 5px 0; }
.skill__name { font-size: 13.5px; min-width: 0; }
.levels { display: flex; gap: 3px; flex: none; }
.lvl {
  width: 26px; height: 26px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-dim);
  font-size: 12px; font-family: inherit; padding: 0;
}
.lvl:hover { border-color: var(--accent); }
.lvl.is-on { color: #fff; font-weight: 700; }
.lvl--0.is-on { background: var(--text-dim); border-color: var(--text-dim); }
.lvl--1.is-on { background: var(--warn); border-color: var(--warn); }
.lvl--2.is-on { background: var(--accent); border-color: var(--accent); }
.lvl--3.is-on { background: var(--ok); border-color: var(--ok); }

/* ---------- chart ---------- */
.chart-wrap { width: 100%; overflow-x: auto; }
.chart { width: 100%; min-width: 260px; height: auto; display: block; }
.chart__bar { fill: var(--accent); opacity: 0.75; }
.chart__bar.is-on { opacity: 1; fill: var(--ok); }
.chart__target { stroke: var(--warn); stroke-width: 1; stroke-dasharray: 3 3; }
.chart__label { fill: var(--text-dim); font-size: 9px; }

/* ---------- markdown ---------- */
.md { font-size: 14.5px; }
.md h2, .md h3, .md h4, .md h5 { margin: 16px 0 6px; font-size: 15px; }
.md p { margin: 8px 0; }
.md .md-list { padding-inline-start: 20px; margin: 8px 0; }
.md .md-list li { list-style: disc; }
.md ol.md-list li { list-style: decimal; }
.md blockquote { border-inline-start: 3px solid var(--border); margin: 8px 0; padding-inline-start: 12px; color: var(--text-dim); }
.md code, code[dir="ltr"] {
  font-family: Consolas, "SF Mono", Menlo, Monaco, "Courier New", monospace;
  font-size: 0.9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px;
  direction: ltr; unicode-bidi: isolate;
}
.code, .md pre.code {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; overflow-x: auto; direction: ltr; text-align: left; margin: 10px 0;
}
.code code { background: none; padding: 0; font-size: 13px; line-height: 1.6; white-space: pre; }

.reader__note { margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.print-only { display: none; }

/* ---------- empty / error ---------- */
.notice { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 22px 18px; text-align: center; color: var(--text-dim); }
.notice h2 { font-size: 16px; color: var(--text); margin-bottom: 6px; }

.pager { display: flex; justify-content: space-between; gap: 10px; margin-top: 26px; padding-top: 14px; border-top: 1px solid var(--border); }
.pager a { padding: 8px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: 13.5px; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager__spacer { flex: 1; }

/* ---------- mobile ---------- */
@media (max-width: 800px) {
  .sidenav { display: none; }
  .view { padding-bottom: 84px; }
  .sticky-bar, .bulk { top: 52px; }

  .tabbar {
    display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    gap: 4px; overflow-x: auto; scrollbar-width: none;
  }
  .tabbar::-webkit-scrollbar { display: none; }
  .tabbar a { flex: none; padding: 7px 12px; border-radius: var(--radius); color: var(--text-dim); font-size: 13px; white-space: nowrap; }
  .tabbar a.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
  .tabbar a:hover { text-decoration: none; }

  .srow { flex-wrap: wrap; }
  .verdicts { width: 100%; justify-content: flex-end; }
  .skills { grid-template-columns: 1fr; }
}

/* ---------- print ---------- */
@media print {
  .no-print, .tabbar, .sidenav, .app-header, .btn, .toast, .banner { display: none !important; }
  body { background: #fff; color: #000; font-size: 12pt; }
  .shell, .view { display: block; max-width: none; padding: 0; margin: 0; }
  .card, .notice { border: none; padding: 0; background: none; }
  .print-only { display: block; }
  .reader__note { page-break-inside: avoid; border-bottom: 1px solid #ccc; }
  .code { border: 1px solid #ccc; background: #f6f6f6; }
  a { color: #000; text-decoration: underline; }
}
