/* ============================================================
   «کاشی» — پایهٔ مشترکِ بخش‌های «یادگیری» و «محتوا» در خودآموز تطبیقی
   قلم‌ها، رنگ‌ها، دکمه‌ها، سربرگ و کاشی‌های تسلط.
   امضای بصری: هر مفهوم یک کاشی است و رنگش تسلط را نشان می‌دهد؛
   از کم‌رنگ (شروع‌نشده) تا لاجوردی و فیروزه‌ای.
   ============================================================ */

@font-face { font-family: "Vazirmatn"; src: url("../fonts/Vazirmatn-Variable.f6d31671339d.woff2") format("woff2");
  font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Naskh"; src: url("../fonts/NotoNaskhArabic-Variable.b5523c994f90.woff2") format("woff2");
  font-weight: 400 700; font-display: swap; }
@font-face { font-family: "Lalezar"; src: url("../fonts/Lalezar-Regular.d29aca20adbd.woff2") format("woff2");
  font-weight: 400; font-display: swap; }

:root {
  --lapis: #1D3C78;
  --lapis-deep: #142B57;
  --lapis-soft: #E6ECF7;
  --turquoise: #178F86;
  --turquoise-soft: #E2F3F1;
  --saffron: #E2A23B;
  --saffron-soft: #FBF0DC;
  --pomegranate: #C2453B;
  --pomegranate-soft: #F9E6E3;

  --paper: #F2F4F8;
  --card: #FFFFFF;
  --ink: #172133;
  --ink-soft: #5A6478;
  --line: #DDE2EC;

  /* مقیاسِ ترتیبیِ تسلط — یک مسیر، نه پنج رنگِ بی‌ربط */
  --t-unknown: #DCE1EA;
  --t-weak: #AFC3E3;
  --t-learning: #6E93CF;
  --t-strong: #2F5BA8;
  --t-mastered: #178F86;

  /* رنگ‌های نشانِ برنامه — در هر دو حالتِ روشن و تیره یکسان */
  --brand-tile: #1D3C78;
  --brand-tile-edge: rgba(255, 255, 255, .06);

  --r-sm: 8px;
  --r: 14px;
  --r-lg: 22px;
  --lift: 0 1px 2px rgba(23, 33, 51, .05), 0 6px 20px rgba(29, 60, 120, .07);

  --ui: "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
  --read: "Naskh", "Vazirmatn", serif;
  --display: "Lalezar", "Vazirmatn", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --lapis: #8FB0EC;
    --lapis-deep: #B9CDF3;
    --lapis-soft: #1C2A4A;
    --turquoise: #3CC2B6;
    --turquoise-soft: #123733;
    --saffron: #EDB65A;
    --saffron-soft: #3A2E18;
    --pomegranate: #EB7B70;
    --pomegranate-soft: #3B1F1C;
    --paper: #0F1729;
    --card: #17213A;
    --ink: #E6EAF2;
    --ink-soft: #9DA8BD;
    --line: #27324D;
    --t-unknown: #26314B;
    --t-weak: #34507F;
    --t-learning: #4B72B5;
    --t-strong: #6E96DB;
    --t-mastered: #3CC2B6;
    --brand-tile: #21447F;
    --brand-tile-edge: rgba(143, 176, 236, .28);
    --lift: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 24px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  font-family: var(--ui); font-size: 16px; line-height: 1.8;
  background: var(--paper); color: var(--ink);
}
a { color: var(--lapis); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--saffron); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { line-height: 1.4; margin: 0; }
p { margin: 0; }
.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }

/* ── دکمه‌ها ───────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 700; font-size: .95rem; cursor: pointer;
  padding: 9px 20px; border-radius: 999px; border: 1.5px solid var(--lapis);
  background: var(--lapis); color: #fff; text-decoration: none;
}
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn-quiet { background: transparent; color: var(--lapis); }
.btn-quiet:hover { background: var(--lapis-soft); filter: none; }
.btn-sm { padding: 5px 14px; font-size: .85rem; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--ink-soft);
  cursor: pointer; }
.link-btn:hover { color: var(--pomegranate); text-decoration: underline; }
@media (prefers-color-scheme: dark) { .btn:not(.btn-quiet):not(.btn-ghost):not(.btn-danger) { color: #0F1729; } }

/* ── سربرگ ─────────────────────────────── */
.bar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px clamp(16px, 4vw, 40px);
  background: var(--card); border-bottom: 1px solid var(--line);
}
/* نشانِ برنامه: لوگوی «باش‌تاپ» روی یک کاشیِ لاجوردی (همان امضای کاشی‌ها)،
   سپس یک خطِ جداکننده و نامِ برنامه. کاشی در حالتِ تیره هم لاجوردیِ پررنگ می‌ماند. */
.bar-brand { display: flex; align-items: center; gap: 12px; font-weight: 800; color: var(--ink); }
.bar-brand:hover { text-decoration: none; }
.bar-brand:hover .brand-tile { filter: brightness(1.12); }
.brand-tile {
  display: inline-grid; place-items: center; flex: none;
  height: 40px; padding: 0 12px; border-radius: 11px;
  background: var(--brand-tile);
  box-shadow: inset 0 0 0 1px var(--brand-tile-edge), 0 1px 2px rgba(20, 43, 87, .22), 0 4px 12px rgba(29, 60, 120, .14);
  transition: filter .15s;
}
.brand-tile img { display: block; height: 26px; width: auto; }
.brand-tile-lg { height: auto; padding: 18px 26px; border-radius: var(--r-lg); }
.brand-tile-lg img { height: 76px; }
.brand-sep { width: 1.5px; height: 22px; border-radius: 2px; background: var(--line); flex: none; }
.brand-name { font-size: .98rem; white-space: nowrap; }
.bar-course {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 14px;
  border-radius: 999px; background: var(--lapis-soft); font-size: .88rem; max-width: 42ch;
}
.bar-course b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-course a { font-size: .8rem; font-weight: 700; white-space: nowrap;
  padding: 2px 10px; border-radius: 999px; background: var(--card); }
.bar-end { margin-inline-start: auto; display: flex; align-items: center; gap: 12px; }
.bar-user { font-weight: 700; }
.sub { font-size: .8rem; padding: 2px 10px; border-radius: 999px;
  background: var(--turquoise-soft); color: var(--turquoise); white-space: nowrap; }
.sub.warn { background: var(--saffron-soft); color: #8A5A0F; }
@media (prefers-color-scheme: dark) { .sub.warn { color: var(--saffron); } }
.bar form { margin: 0; }

/* جابه‌جایی میانِ سه بخشِ برنامه: یادگیری · محتوا · تنظیمات */
.mode { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px;
  background: var(--paper); border: 1px solid var(--line); }
.mode a { padding: 3px 14px; border-radius: 999px; font-size: .85rem; font-weight: 700;
  color: var(--ink-soft); white-space: nowrap; }
.mode a:hover { color: var(--ink); text-decoration: none; }
.mode a.on { background: var(--card); color: var(--lapis); box-shadow: var(--lift); }

/* پیامِ کوتاهِ پایینِ صفحه (ذخیرهٔ فایل و…) */

.flashes { max-width: 1120px; margin: 16px auto 0; padding: 0 clamp(16px, 4vw, 40px); }
.flash { padding: 10px 16px; border-radius: var(--r-sm); margin-bottom: 8px; font-size: .92rem;
  background: var(--lapis-soft); border-inline-start: 4px solid var(--lapis); }
.flash-error { background: var(--pomegranate-soft); border-color: var(--pomegranate); }
.flash-warning { background: var(--saffron-soft); border-color: var(--saffron); }

.page { max-width: 1120px; margin: 0 auto; padding: clamp(20px, 4vw, 40px) clamp(16px, 4vw, 40px) 60px; }
.page-narrow { max-width: 760px; }

/* ── کاشی‌ها — امضای بصری ─────────────── */
.tile { width: 100%; aspect-ratio: 1; border-radius: 5px; background: var(--t-unknown);
  position: relative; }
.tile.lv-weak { background: var(--t-weak); }
.tile.lv-learning { background: var(--t-learning); }
.tile.lv-strong { background: var(--t-strong); }
.tile.lv-mastered { background: var(--t-mastered); }
/* سررسیدِ مرور: نقطهٔ زعفرانی در گوشه */
.tile.due::after { content: ""; position: absolute; top: 3px; inset-inline-end: 3px;
  width: 7px; height: 7px; border-radius: 50%; background: var(--saffron);
  box-shadow: 0 0 0 2px var(--card); }
.mosaic { display: grid; gap: 5px; grid-template-columns: repeat(auto-fill, minmax(26px, 1fr)); }
.mosaic-sm { gap: 3px; grid-template-columns: repeat(auto-fill, minmax(14px, 1fr)); }
.mosaic-sm .tile { border-radius: 3px; }
.mosaic-sm .tile.due::after { width: 5px; height: 5px; top: 1px; inset-inline-end: 1px; box-shadow: none; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .78rem; color: var(--ink-soft); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .tile { width: 12px; height: 12px; aspect-ratio: auto; border-radius: 3px; }
.legend .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--saffron); }

.chip { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; font-weight: 700;
  padding: 2px 10px 2px 12px; border-radius: 999px; background: var(--lapis-soft); color: var(--ink); }
.chip .tile { width: 10px; height: 10px; aspect-ratio: auto; border-radius: 3px; }

/* ── متنِ غنی (Markdown + فرمول) — مشترکِ هر دو برنامه ── */
.rich { white-space: normal; }
.rich > :first-child { margin-top: 0; }
.rich > :last-child { margin-bottom: 0; }
.rich p { margin: 0 0 .8em; }
.rich h1, .rich h2, .rich h3, .rich h4 { font-family: var(--ui); font-size: 1.08em; font-weight: 800;
  margin: 1.1em 0 .4em; color: var(--lapis); line-height: 1.6; }
.rich ul, .rich ol { margin: 0 0 .8em; padding-inline-start: 1.4em; }
.rich li { margin: .15em 0; }
.rich blockquote { margin: 0 0 .8em; padding: .3em 1em; border-inline-start: 3px solid var(--saffron);
  background: var(--saffron-soft); border-radius: var(--r-sm); }
.rich img { max-width: 100%; height: auto; border-radius: var(--r-sm); display: block; margin: .6em auto; }
.rich a { text-decoration: underline; text-underline-offset: 3px; }
.rich code { font-family: ui-monospace, Consolas, monospace; font-size: .88em; direction: ltr;
  unicode-bidi: isolate; background: var(--lapis-soft); padding: 0 .35em; border-radius: 4px; }
.rich pre { direction: ltr; text-align: left; background: var(--lapis-soft); padding: .8em 1em;
  border-radius: var(--r-sm); overflow-x: auto; }
.rich pre code { background: none; padding: 0; }
/* جدول با قلمِ رابط و اندازهٔ ثابت (نه قلمِ درشتِ متنِ درس) تا جدول‌های داده در کادر جا شوند */
.rich table { border-collapse: collapse; margin: 0 0 .9em; font-family: var(--ui); font-size: .85rem;
  line-height: 1.6; }
.rich th, .rich td { border: 1px solid var(--line); padding: .3em .6em; }
/* جدولِ پهن درونِ کادر می‌ماند و اگر جا نشد، افقی پیمایش می‌شود */
.rich .table-wrap { max-width: 100%; overflow-x: auto; margin: 0 0 .9em; }
.rich .table-wrap > table { margin: 0; }
.rich .table-wrap[dir="ltr"] > table { margin-left: auto; }   /* هم‌ترازِ لبهٔ راستِ متن */
.rich th { background: var(--paper); }
.rich .math-display { display: block; text-align: center; margin: .6em 0; overflow-x: auto; overflow-y: hidden; }
.katex { direction: ltr; unicode-bidi: isolate; font-size: 1.05em; }
.rich .blank { display: inline-block; min-width: 5.5em; border-bottom: 2px solid var(--lapis);
  margin: 0 .25em; vertical-align: baseline; }

/* ── نمودارهای SVG (core/charts.py) — مشترکِ دو برنامه ── */
.chart { width: 100%; height: auto; display: block; direction: ltr; overflow: visible; }
.ch-grid { stroke: var(--line); stroke-width: 1; }
.ch-tick { fill: var(--ink-soft); font-size: 11px; font-family: var(--ui); }
.ch-line { fill: none; stroke: var(--lapis); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ch-area { fill: var(--lapis); opacity: .08; }
.ch-dot { fill: var(--lapis); stroke: var(--card); stroke-width: 2; }
.ch-val { fill: var(--ink); font-size: 12px; font-weight: 700; font-family: var(--ui); }
.ch-bar { fill: var(--t-strong); }
.ch-bar.met { fill: var(--turquoise); }
.ch-goal { stroke: var(--saffron); stroke-width: 1.5; stroke-dasharray: 5 4; }
.ch-goal-t { fill: var(--ink-soft); font-size: 11px; font-family: var(--ui); }
.ch-hit rect { fill: transparent; }
.ch-hit circle { fill: transparent; }
.ch-hit:hover circle { fill: var(--lapis); stroke: var(--card); stroke-width: 2; }
.ch-hit:hover rect { fill: var(--lapis-soft); opacity: .5; }

/* ── نقشهٔ حرارتی و منحنیِ تسلط (core/charts.py) ── */
.heatmap { width: auto; max-width: none; }
.hm-cell.hm-0 { fill: var(--paper); stroke: var(--line); stroke-width: 1; }
.hm-cell.hm-1 { fill: var(--t-weak); }
.hm-cell.hm-2 { fill: var(--t-strong); }
.hm-cell.hm-3 { fill: var(--turquoise); fill-opacity: .6; }
.hm-cell.hm-4 { fill: var(--turquoise); }
.hm-legend i.hm-0 { background: var(--paper); box-shadow: inset 0 0 0 1px var(--line); }
.hm-legend i.hm-1 { background: var(--t-weak); }
.hm-legend i.hm-2 { background: var(--t-strong); }
.hm-legend i.hm-3 { background: var(--turquoise); opacity: .6; }
.hm-legend i.hm-4 { background: var(--turquoise); }
.hm-cell:hover { stroke: var(--ink); stroke-width: 1.5; }
.hm-cell.hm-today { stroke: var(--saffron); stroke-width: 2.5; }
.hm-month { font-weight: 700; }
.mc-th-m { stroke: var(--turquoise); stroke-width: 1.5; stroke-dasharray: 6 5; }
.mc-th-r { stroke: var(--saffron); stroke-width: 1.5; stroke-dasharray: 6 5; }
.mc-pt { stroke: var(--card); stroke-width: 2; }
.mc-ok { fill: var(--turquoise); }
.mc-bad { fill: var(--pomegranate); }
.mc-teach { fill: var(--card); stroke: var(--lapis); stroke-width: 2; }
.mc-other { fill: var(--ink-soft); }
.mc-start { fill: var(--card); stroke: var(--ink-soft); stroke-width: 2; }
.mc-now { fill: var(--saffron); }
.mc-decay { fill: none; stroke: var(--saffron); stroke-width: 2; stroke-dasharray: 4 4; }

/* ── منوی حساب (نوارِ بالا) ── */
.user-menu { position: relative; }
.user-menu > summary { list-style: none; cursor: pointer; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary::after { content: " ▾"; font-size: .7em; opacity: .7; }
.user-menu-pop { position: absolute; inset-inline-end: 0; top: calc(100% + 6px); z-index: 50; min-width: 190px;
  display: flex; flex-direction: column; gap: 2px; padding: 8px; border-radius: var(--r-sm, 10px);
  background: var(--card); border: 1px solid var(--line); box-shadow: 0 8px 24px rgb(0 0 0 / .12); }
.user-menu-pop > span { padding: 2px 10px 6px; text-align: start; }
.user-menu-pop a, .user-menu-pop button { display: block; width: 100%; text-align: start; padding: 7px 10px;
  border-radius: 8px; font: inherit; font-size: .9rem; color: var(--ink); background: none; border: 0; cursor: pointer; }
.user-menu-pop a:hover, .user-menu-pop button:hover { background: var(--paper); text-decoration: none; }
.user-menu-pop form { margin: 0; }
.user-menu-pop button { color: var(--pomegranate); }
