:root {
  --page: #faf7f2;
  --card: #ffffff;
  --ink: #251f21;
  --ink-2: #6b5f55;
  --hairline: #e6ded4;
  --teal: #4f8f7f;
  --teal-dark: #3a6f62;
  --teal-soft: rgba(79, 143, 127, 0.12);
  --sand: #f3ece1;
  --radius: 16px;
  --shadow: 0 4px 18px rgba(37, 31, 33, 0.07);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, "Noto Kufi Arabic", "Noto Sans Arabic", Arial, sans-serif;
  line-height: 1.7;
}
.page { max-width: 960px; margin: 0 auto; padding: 0 20px 48px; min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--teal-dark); }

.nav { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 14px 0; border-bottom: 1px solid var(--hairline); position: sticky; top: 0; z-index: 50; background: var(--page); }
.brand { font-weight: 800; font-size: 18px; color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: 10px; }
.brand-logo { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; }
.nav-links { display: flex; flex-wrap: wrap; gap: 18px; }
.nav-links a { color: var(--ink-2); text-decoration: none; padding: 6px 0; }
.nav-links a.active, .nav-links a:hover { color: var(--ink); box-shadow: inset 0 -2px 0 var(--teal); }
@media (max-width: 600px) { .nav-links a { min-height: 40px; display: inline-flex; align-items: center; } }

main { flex: 1; padding: 28px 0; }
.foot { border-top: 1px solid var(--hairline); padding: 16px 0; color: var(--ink-2); font-size: 13px; text-align: center; }

.hero { text-align: center; margin: 8px 0 28px; }
.hero img { width: 100%; max-width: 640px; border-radius: 20px; box-shadow: var(--shadow); }
.hero h1 { font-size: 30px; margin: 20px 0 6px; }
.hero .tag { color: var(--teal-dark); font-weight: 600; }
.hero p.lead { max-width: 640px; margin: 10px auto 0; color: var(--ink-2); }

h2.section { font-size: 22px; margin: 36px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--hairline); }
.muted { color: var(--ink-2); }

.grid { display: grid; gap: 14px; }
@media (min-width: 720px) { .grid.cols-3 { grid-template-columns: repeat(3, 1fr); } .grid.cols-2 { grid-template-columns: repeat(2, 1fr); } }

.card {
  display: block; background: var(--card); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 18px 20px; text-decoration: none; color: var(--ink);
  transition: box-shadow .15s ease, border-color .15s ease;
}
a.card:hover { border-color: var(--teal); box-shadow: var(--shadow); }
.card h3 { margin: 0 0 6px; font-size: 17px; }
.card p { margin: 0; color: var(--ink-2); font-size: 14px; }
.card .cta { display: inline-block; margin-top: 10px; color: var(--teal-dark); font-weight: 600; font-size: 14px; }

.grade-card { display: flex; gap: 16px; align-items: flex-start; }
.badge {
  display: flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0;
  background: var(--teal-soft); color: var(--teal-dark); font-size: 22px; font-weight: 700;
}

.banner { display: flex; align-items: center; gap: 16px; background: var(--sand); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 14px; }
.banner img { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; }
.banner .t { font-weight: 600; }
.banner .s { color: var(--ink-2); font-size: 13px; }

.notice { background: var(--teal-soft); border: 1px solid var(--teal); border-radius: 12px; padding: 12px 16px; margin: 12px 0; font-size: 14px; }
.notice.warn { background: #fdf3e3; border-color: #d9a648; }
.notice.error { background: #fdecec; border-color: #d96a6a; color: #7a2c2c; }

form.panel { background: var(--card); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 22px; max-width: 460px; margin: 0 auto; }
label { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 4px; }
input[type=email], input[type=password], input[type=text], input[type=url], input[type=file], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--hairline); border-radius: 10px;
  font: inherit; background: var(--card); color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal-soft); border-color: var(--teal); }
textarea { min-height: 90px; resize: vertical; }

button, .btn {
  display: inline-block; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--teal); color: #fff; border: none; border-radius: 10px; padding: 10px 22px;
  text-decoration: none; text-align: center;
}
button:hover, .btn:hover { background: var(--teal-dark); }
button.ghost, .btn.ghost { background: transparent; color: var(--teal-dark); border: 1px solid var(--teal); }
button.ghost:hover, .btn.ghost:hover { background: var(--teal-soft); }
button.danger { background: #c05b4d; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

.video-wrap { position: relative; width: 100%; aspect-ratio: 16/9; background: #000; border-radius: var(--radius); overflow: hidden; margin: 12px 0; }
.video-wrap iframe, .video-wrap video { width: 100%; height: 100%; border: 0; }

.lecture { border: 1px solid var(--hairline); border-radius: var(--radius); background: var(--card); padding: 16px 18px; margin-bottom: 12px; }
.lecture h3 { margin: 0 0 4px; font-size: 16px; }
.lecture .meta { color: var(--ink-2); font-size: 13px; margin-bottom: 8px; }
.unit-title { font-size: 18px; font-weight: 700; margin: 26px 0 10px; }

.list-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--hairline); border-radius: 12px; padding: 12px 16px; margin-bottom: 10px; }
.list-row .grow { flex: 1; }
.list-row small { color: var(--ink-2); display: block; }

.center { text-align: center; }
.spin { color: var(--ink-2); padding: 24px; text-align: center; }

/* ---------- dark theme ---------- */
[data-theme="dark"] {
  --page: #1b1916;
  --card: #27231f;
  --ink: #efe8dd;
  --ink-2: #b0a491;
  --hairline: #3b362f;
  --teal: #6fae9d;
  --teal-dark: #93c6b6;
  --teal-soft: rgba(111, 174, 157, 0.18);
  --sand: #2d2924;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}
[data-theme="dark"] .notice.warn { background: #38301e; border-color: #a8833d; color: #e6c78c; }
[data-theme="dark"] .notice.error { background: #3c2421; border-color: #b06a5a; color: #eda795; }

/* ---------- theme toggle ---------- */
.theme-btn { background: transparent; color: var(--ink); border: 1px solid var(--hairline); border-radius: 10px; padding: 6px 10px; font-size: 16px; line-height: 1; }
.theme-btn:hover { background: var(--teal-soft); }

/* ---------- help chatbot ---------- */
#chat-fab {
  position: fixed; bottom: 20px; left: 20px; z-index: 90;
  width: 56px; height: 56px; border-radius: 50%; font-size: 24px; padding: 0;
  display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow);
}
#chat-panel {
  position: fixed; bottom: 88px; left: 20px; z-index: 91;
  width: 340px; max-width: calc(100vw - 32px); height: 440px; max-height: 72vh;
  background: var(--card); border: 1px solid var(--hairline); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden;
}
#chat-panel[hidden] { display: none; }
.chat-head { background: var(--teal); color: #fff; padding: 10px 14px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chat-head span { font-size: 13px; font-weight: 400; opacity: .9; }
.chat-head button { background: transparent; color: #fff; padding: 0 6px; font-size: 20px; }
.chat-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; font-size: 14px; line-height: 1.7; white-space: pre-wrap; }
.chat-msg.bot { background: var(--sand); color: var(--ink); align-self: flex-start; }
.chat-msg.me { background: var(--teal); color: #fff; align-self: flex-end; }
.chat-chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 6px 12px 2px; }
.chat-chips button { background: var(--teal-soft); color: var(--teal-dark); border: none; border-radius: 999px; padding: 4px 12px; font-size: 12px; font-weight: 600; }
.chat-input { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--hairline); }
.chat-input input { flex: 1; width: auto; }
.chat-input button { padding: 8px 16px; }

/* ---------- v4: search, continue, dashboard, badges, exam timer ---------- */
.search-form { display: flex; gap: 8px; max-width: 460px; margin: 18px auto 0; }
.search-form input { flex: 1; width: auto; }
.search-form button { padding: 10px 20px; }

.continue-card { display: flex; align-items: center; gap: 14px; border-color: var(--teal); margin-bottom: 14px; }
.continue-card .badge { border-radius: 12px; }

.new-badge { background: var(--teal); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 2px 10px; vertical-align: middle; }

.score-badge { font-weight: 700; border-radius: 999px; padding: 4px 14px; background: var(--sand); color: var(--ink); white-space: nowrap; }
.score-badge.pass { background: var(--teal-soft); color: var(--teal-dark); }
.score-badge.fail { background: #f6e3e0; color: #a44a3d; }
[data-theme="dark"] .score-badge.fail { background: #3c2421; color: #eda795; }

.quiz-timer {
  position: fixed; bottom: 20px; right: 20px; z-index: 80;
  background: var(--card); border: 2px solid var(--teal); color: var(--ink);
  font-size: 20px; font-weight: 700; border-radius: 999px; padding: 8px 20px; box-shadow: var(--shadow);
}
.quiz-timer.low { border-color: #c05b4d; color: #c05b4d; }
