/* محاضرتي — clinical and calm: deep navy ink on cool paper, a teal accent for "learned", amber only for what is due */
:root {
  --bg: #F2F4F8; --surface: #FFFFFF; --surface2: #E9EDF3; --line: #DAE0E9;
  --ink: #152033; --muted: #5A6578; --primary: #1B3A5F; --primary2: #2C6AA0; --on-primary: #FFFFFF;
  --tint: #E5EDF6; --accent: #0F7C78; --accent-bg: #E0F2F0;
  --amber: #B45309; --amber-bg: #FCEFD9; --good: #13744A; --good-bg: #DFF3E8; --bad: #B42318; --bad-bg: #FBE6E4;
  --radius: 14px; --shadow: 0 1px 2px rgba(16,28,48,.05), 0 3px 12px rgba(16,28,48,.06);
  --font: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B111B; --surface: #121A27; --surface2: #1A2436; --line: #253249;
    --ink: #E5EAF2; --muted: #95A1B5; --primary: #86B8EC; --primary2: #A6CBF2; --on-primary: #0B1A2C;
    --tint: #16263D; --accent: #4FD1C5; --accent-bg: #10302E;
    --amber: #F2A541; --amber-bg: #2E2416; --good: #4ADE80; --good-bg: #13291E; --bad: #F87171; --bad-bg: #2F1B1B;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0B111B; --surface: #121A27; --surface2: #1A2436; --line: #253249;
  --ink: #E5EAF2; --muted: #95A1B5; --primary: #86B8EC; --primary2: #A6CBF2; --on-primary: #0B1A2C;
  --tint: #16263D; --accent: #4FD1C5; --accent-bg: #10302E;
  --amber: #F2A541; --amber-bg: #2E2416; --good: #4ADE80; --good-bg: #13291E; --bad: #F87171; --bad-bg: #2F1B1B;
  --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.6; }
body { min-height: 100vh; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.35; margin: 0 0 .4em; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); } .small { font-size: .86rem; } .center { text-align: center; }
b, strong { font-weight: 700; }

/* top bar */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); font-size: 1.05rem; }
.logo { width: 26px; height: 26px; border-radius: 8px; background: #1B3A5F; position: relative; flex: none; }
.logo::after { content: ''; position: absolute; inset: 7px 6px; border: 2px solid #fff; border-top-width: 5px; border-radius: 2px; }
.top-title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top.sub .brand { display: none; }
.icon-btn { position: relative; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 1.1rem; flex: none; }
.dot { position: absolute; top: 6px; left: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--bad); }

/* bottom nav */
.bottom { position: fixed; bottom: 0; inset-inline: 0; z-index: 20; display: flex; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottom a { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 0 7px; color: var(--muted); font-size: .76rem; font-weight: 500; }
.bottom a span { font-size: 1.2rem; line-height: 1.2; }
.bottom a.on { color: var(--primary); }
.badge { position: absolute; top: 4px; left: calc(50% - 26px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--amber); color: #fff; font-size: .7rem; font-style: normal; line-height: 18px; text-align: center; }

.app { max-width: 720px; margin: 0 auto; padding: 16px; }
.loading { padding: 60px 0; text-align: center; color: var(--muted); }

/* cards, lists */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card, .stack > * + * { margin-top: 12px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 22px 2px 10px; }
.section-title h2 { margin: 0; }
.list { display: grid; gap: 10px; }
.row { display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; color: var(--ink); box-shadow: var(--shadow); }
a.row:active, .row.tap:active { transform: scale(.99); }
.row .ic { width: 44px; height: 44px; flex: none; border-radius: 12px; display: grid; place-items: center; font-size: 1.35rem; background: var(--tint); }
.row .body { flex: 1; min-width: 0; }
.row .t { display: block; font-weight: 600; }
.row .s { display: block; color: var(--muted); font-size: .85rem; }
.row .end { flex: none; text-align: left; font-size: .85rem; color: var(--muted); }
.chev::after { content: '‹'; font-size: 1.4rem; color: var(--muted); }
.num { width: 34px; height: 34px; flex: none; border-radius: 10px; display: grid; place-items: center; font-weight: 700; background: var(--surface2); color: var(--muted); font-size: .9rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface2); color: var(--muted); white-space: nowrap; }
.chip.free { background: var(--accent-bg); color: var(--accent); }
.chip.own { background: var(--tint); color: var(--primary); }
.chip.lock { background: var(--surface2); }
.chip.due { background: var(--amber-bg); color: var(--amber); }
.chip.warn { background: var(--bad-bg); color: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.bar { height: 6px; border-radius: 3px; background: var(--surface2); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }

/* buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 18px; border-radius: 12px; border: 1px solid transparent;
  background: var(--primary); color: var(--on-primary); font-weight: 600; cursor: pointer; text-align: center; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.block { display: flex; width: 100%; }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.soft { background: var(--tint); color: var(--primary); }
.btn.danger { background: var(--bad-bg); color: var(--bad); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .88rem; border-radius: 10px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btns > .btn { flex: 1; }
label.f { display: block; margin-top: 12px; font-weight: 600; font-size: .92rem; }
label.f > span.h { display: block; font-weight: 400; color: var(--muted); font-size: .82rem; }
input:not([type]), input[type=text], input[type=tel], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; margin-top: 6px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary2) 22%, transparent); }
textarea { min-height: 110px; resize: vertical; }
input, select { min-width: 0; }
input[type=file] { display: block; width: 100%; margin-top: 6px; padding: 10px; border: 1px dashed var(--line); border-radius: 12px; background: var(--surface); font-size: .85rem; }
input[type=file]::file-selector-button { margin-inline-end: 10px; padding: 6px 12px; border: 0; border-radius: 8px; background: var(--tint); color: var(--primary); font: inherit; font-weight: 600; cursor: pointer; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
textarea.code { min-height: 320px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .8rem; direction: ltr; text-align: left; white-space: pre; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }
.err { margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: var(--bad-bg); color: var(--bad); white-space: pre-line; font-size: .9rem; }
.ok { margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: var(--good-bg); color: var(--good); font-size: .9rem; }
.note { padding: 12px 14px; border-radius: 12px; background: var(--tint); color: var(--ink); font-size: .9rem; }
.note.amber { background: var(--amber-bg); }

/* hero & stats */
.hero { padding: 24px 18px; border-radius: 18px; color: #fff; position: relative; overflow: hidden;
  background: linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px) 0 0 / 22px 22px, linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px) 0 0 / 22px 22px, linear-gradient(160deg, #1B3A5F, #12263F); }
.hero h1 { font-size: 1.5rem; margin-bottom: 6px; }
.hero p { margin: 0; opacity: .88; }
.hero::after { content: ''; position: absolute; inset-inline-end: 0; bottom: 0; width: 100%; height: 3px; background: linear-gradient(90deg, transparent, #4FD1C5, transparent); opacity: .7; }
.hero .btn { background: #fff; color: #1B3A5F; }
.hero .btn.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.hero .eyebrow { display: inline-block; font-size: .78rem; letter-spacing: .02em; padding: 2px 10px; border-radius: 999px; background: rgba(255,255,255,.12); margin-bottom: 10px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 8px; text-align: center; }
.stat b { display: block; font-size: 1.3rem; }
.stat span { color: var(--muted); font-size: .78rem; }
.stat.hot b { color: var(--amber); }
.due-cta { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 14px; border-radius: 16px; background: var(--amber-bg); color: var(--ink); }
.due-cta .big { font-size: 1.6rem; font-weight: 700; color: var(--amber); min-width: 44px; text-align: center; }

/* tabs */
.tabs { display: flex; gap: 6px; padding: 4px; background: var(--surface2); border-radius: 14px; margin: 14px 0; overflow-x: auto; }
.tabs button { flex: 1; min-width: max-content; border: 0; background: transparent; padding: 9px 12px; border-radius: 10px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* lecture: reading view */
.toc { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; margin-bottom: 6px; scrollbar-width: none; }
.toc a { flex: none; padding: 5px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--ink); font-size: .82rem; white-space: nowrap; }
.sec { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 16px 10px; box-shadow: var(--shadow); scroll-margin-top: 76px; }
.sec + .sec { margin-top: 12px; }
.sec h3 { display: flex; align-items: flex-start; gap: 10px; color: var(--primary); font-size: 1.05rem; margin: 0 0 10px; }
.sec h3 .n { flex: none; min-width: 26px; height: 26px; border-radius: 8px; background: var(--tint); color: var(--primary); display: grid; place-items: center; font-size: .8rem; margin-top: 1px; }
.sec ul { margin: 0 0 8px; padding-inline-start: 20px; }
.sec li { margin: 7px 0; line-height: 1.75; }
.sec li::marker { color: var(--primary2); }
.tbl { overflow-x: auto; margin: 10px 0 12px; border: 1px solid var(--line); border-radius: 12px; }
.tbl table { width: 100%; border-collapse: collapse; font-size: .88rem; min-width: 100%; }
.tbl th { background: var(--tint); color: var(--primary); font-weight: 600; text-align: start; padding: 9px 10px; white-space: nowrap; }
.tbl td { padding: 9px 10px; border-top: 1px solid var(--line); vertical-align: top; line-height: 1.6; }
.tbl td:first-child { font-weight: 600; min-width: 7em; }
.tbl td, .tbl th { min-width: 5.5em; }
.tbl td:only-child { min-width: 0; }
.tbl tr:nth-child(even) td { background: color-mix(in srgb, var(--surface2) 45%, transparent); }
.callout { margin: 10px 0 12px; padding: 10px 12px; border-radius: 12px; background: var(--amber-bg); border-inline-start: 4px solid var(--amber); line-height: 1.7; }
.formula { margin: 10px 0 12px; padding: 12px; border-radius: 12px; background: var(--surface2); direction: ltr; text-align: center; font-family: 'Cambria Math', 'STIX Two Math', Georgia, serif; font-size: 1.02rem; overflow-x: auto; }
/* lecture */
.lec-head .crumbs { color: var(--muted); font-size: .84rem; }
.rich { overflow-wrap: anywhere; }

/* flashcards */
.study-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: .88rem; color: var(--muted); }
.flash { perspective: 1400px; margin-top: 10px; cursor: pointer; user-select: none; }
.flash-in { position: relative; min-height: 300px; transition: transform .45s cubic-bezier(.3,.7,.3,1); transform-style: preserve-3d; }
.flash.flipped .flash-in { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 10px; padding: 26px 20px; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); backface-visibility: hidden; -webkit-backface-visibility: hidden; font-size: 1.15rem; overflow-y: auto; }
.face.back { transform: rotateY(180deg); background: var(--surface); border-color: var(--primary2); box-shadow: inset 0 4px 0 var(--primary2), var(--shadow); }
.face .tag { position: absolute; top: 12px; inset-inline-start: 14px; }
.face .hint { position: absolute; bottom: 12px; font-size: .8rem; color: var(--muted); }
.face .from { position: absolute; top: 12px; inset-inline-end: 14px; font-size: .76rem; color: var(--muted); max-width: 60%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rate { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.rate button { min-height: 54px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer; }
.rate .r0 { color: var(--bad); } .rate .r1 { color: var(--amber); } .rate .r2 { color: var(--good); }
.rate small { display: block; font-weight: 400; font-size: .72rem; color: var(--muted); }
.done-box { text-align: center; padding: 28px 16px; }
.done-box .big { font-size: 2.6rem; }

/* quiz */
.q-text { font-size: 1.08rem; font-weight: 600; }
.opts { display: grid; gap: 8px; margin-top: 14px; }
.opt { display: flex; gap: 10px; align-items: flex-start; width: 100%; padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); cursor: pointer; text-align: start; }
.opt .k { flex: none; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--surface2); font-weight: 700; font-size: .85rem; }
.opt.right { border-color: var(--good); background: var(--good-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt:disabled { cursor: default; color: inherit; opacity: 1; }
.explain { margin-top: 12px; }
.score { font-size: 2.4rem; font-weight: 700; color: var(--primary); }

/* paywall */
.paywall { text-align: center; padding: 26px 18px; }
.paywall .big { font-size: 2.2rem; }
.price { font-size: 1.5rem; font-weight: 700; }

/* checkout */
.steps { counter-reset: s; }
.step { position: relative; padding-inline-start: 40px; }
.step::before { counter-increment: s; content: counter(s); position: absolute; inset-inline-start: 0; top: 0; width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-weight: 700; font-size: .9rem; }
.copy { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; margin-top: 8px; border-radius: 12px; background: var(--surface2); }
.copy code { font-family: inherit; font-weight: 700; direction: ltr; }
.qr { display: block; max-width: 200px; margin: 10px auto 0; border-radius: 12px; background: #fff; padding: 8px; }
.sticky-buy { position: sticky; bottom: calc(72px + env(safe-area-inset-bottom)); margin-top: 14px; padding: 12px; border-radius: 16px; background: var(--primary); color: var(--on-primary); display: flex; align-items: center; gap: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.sticky-buy .btn { background: var(--on-primary); color: var(--primary); }
.pick { width: 26px; height: 26px; flex: none; border-radius: 8px; border: 2px solid var(--line); display: grid; place-items: center; font-weight: 700; color: var(--on-primary); }
.pick.on { background: var(--primary); border-color: var(--primary); }

/* messages */
.thread { display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 85%; padding: 9px 12px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-start; background: var(--primary); color: var(--on-primary); border-end-start-radius: 4px; }
.msg.them { align-self: flex-end; background: var(--surface); border: 1px solid var(--line); border-end-end-radius: 4px; }
.msg time { display: block; font-size: .7rem; opacity: .7; margin-top: 2px; }

/* admin */
.admin-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.admin-tabs a { flex: none; padding: 8px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); color: var(--ink); font-size: .88rem; font-weight: 600; position: relative; }
.admin-tabs a.on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.admin-tabs a i { font-style: normal; margin-inline-start: 4px; padding: 0 6px; border-radius: 8px; background: var(--bad); color: #fff; font-size: .72rem; }
.tree details { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); margin-top: 8px; }
.tree details details { margin: 8px; }
.tree summary { padding: 10px 12px; cursor: pointer; font-weight: 600; display: flex; align-items: center; gap: 8px; list-style: none; }
.tree summary::-webkit-details-marker { display: none; }
.tree summary::before { content: '›'; color: var(--muted); transition: transform .2s; display: inline-block; }
.tree details[open] > summary::before { transform: rotate(-90deg); }
.tree summary .sp { flex: 1; }
.tree .lec { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); font-size: .92rem; }
.tree .lec .sp { flex: 1; min-width: 0; }
.tree .add { padding: 8px 12px; border-top: 1px dashed var(--line); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.kpi b { display: block; font-size: 1.35rem; }
.kpi span { color: var(--muted); font-size: .8rem; }
table.t { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.t td, table.t th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
.pay { border-inline-start: 4px solid var(--amber); }
.pay .amt { font-size: 1.15rem; font-weight: 700; }

/* toast & modal */
.toast { position: fixed; bottom: calc(86px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 60; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); font-size: .9rem; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; background: var(--bg); border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet .x { float: left; }
@media (min-width: 700px) { .modal { align-items: center; } .sheet { border-radius: 22px; } }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty .big { font-size: 2.2rem; }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { .flash-in { transition: none; } }
