:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #e2e6ec;
  --text: #1c2430;
  --text-muted: #626c7a;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-bg: #eaf1ff;
  --good: #16a34a;
  --good-bg: #e9f9ef;
  --bad-bg: #fdecec;
  --bad: #dc2626;
  --chip-mech: #7c3aed;
  --chip-mech-bg: #f1e9ff;
  --chip-aid: #dc2626;
  --chip-aid-bg: #fdecec;
  --chip-sign: #2563eb;
  --chip-sign-bg: #eaf1ff;
  --chip-eth: #ca8a04;
  --chip-eth-bg: #fef7e0;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 30, 50, 0.08), 0 8px 24px rgba(20, 30, 50, 0.05);
}

:root[data-theme="dark"] {
  --bg: #12161f;
  --panel: #1a2030;
  --border: #2a3245;
  --text: #eef1f6;
  --text-muted: #99a3b5;
  --brand: #5b8cff;
  --brand-dark: #7ea2ff;
  --brand-bg: #1c2a4d;
  --good: #34d399;
  --good-bg: #113325;
  --bad-bg: #3a1a1c;
  --bad: #f87171;
  --chip-mech: #b794ff;
  --chip-mech-bg: #2a1f47;
  --chip-aid: #f87171;
  --chip-aid-bg: #3a1a1c;
  --chip-sign: #7ea2ff;
  --chip-sign-bg: #1c2a4d;
  --chip-eth: #fbbf24;
  --chip-eth-bg: #3a2f0d;
  --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.3);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161f;
    --panel: #1a2030;
    --border: #2a3245;
    --text: #eef1f6;
    --text-muted: #99a3b5;
    --brand: #5b8cff;
    --brand-dark: #7ea2ff;
    --brand-bg: #1c2a4d;
    --good: #34d399;
    --good-bg: #113325;
    --bad-bg: #3a1a1c;
    --bad: #f87171;
    --chip-mech: #b794ff;
    --chip-mech-bg: #2a1f47;
    --chip-aid: #f87171;
    --chip-aid-bg: #3a1a1c;
    --chip-sign: #7ea2ff;
    --chip-sign-bg: #1c2a4d;
    --chip-eth: #fbbf24;
    --chip-eth-bg: #3a2f0d;
    --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
  direction: rtl;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

header.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

header.top h1 {
  font-size: 1.5rem;
  margin: 0;
}

header.top .sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.theme-toggle {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
}

.stats-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
  box-shadow: var(--shadow);
}

.stat b {
  color: var(--text);
  font-size: 1.05rem;
  display: block;
}

.controls {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

#searchInput {
  flex: 1;
  min-width: 200px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

#searchInput:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.filter-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.chip-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.chip-btn.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.group-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  align-self: center;
  margin-left: 4px;
}

#emptyState {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
  display: none;
}

.qlist {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.qcard {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.qcard-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.qmeta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 8px;
}

.badge {
  font-size: 0.72rem;
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.exam {
  background: var(--brand-bg);
  color: var(--brand-dark);
}

.badge.cat-mech { background: var(--chip-mech-bg); color: var(--chip-mech); }
.badge.cat-aid { background: var(--chip-aid-bg); color: var(--chip-aid); }
.badge.cat-sign { background: var(--chip-sign-bg); color: var(--chip-sign); }
.badge.cat-eth { background: var(--chip-eth-bg); color: var(--chip-eth); }

.qnum {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.qtext {
  font-size: 1.05rem;
  line-height: 1.6;
  font-weight: 600;
  margin: 6px 0 12px;
  white-space: pre-line;
}

.qimg {
  max-width: 320px;
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
  display: block;
}

.choices {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.choice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 0.92rem;
  line-height: 1.5;
}

.choice .letter {
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

.choice.correct {
  background: var(--good-bg);
  border-color: var(--good);
}

.choice.correct .letter {
  color: var(--good);
}

.choice.correct::after {
  content: "✓";
  margin-right: auto;
  color: var(--good);
  font-weight: 700;
}

.explain-toggle {
  background: var(--brand-bg);
  color: var(--brand-dark);
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
}

.explain-box {
  display: none;
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 10px;
  border: 1px dashed var(--border);
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text);
}

.explain-box.show { display: block; }

.explain-box .label {
  color: var(--brand);
  font-weight: 700;
  font-size: 0.78rem;
  margin-bottom: 4px;
  display: block;
}

.mark-known {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}

.qcard.known {
  opacity: 0.55;
}

.mark-known.active {
  background: var(--good-bg);
  border-color: var(--good);
  color: var(--good);
}

.qcard-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

footer.page-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 40px;
}

@media (max-width: 560px) {
  .qtext { font-size: 0.98rem; }
  .qimg { max-width: 100%; }
}

/* ---- back link (used on questions.html / study.html) ---- */
.back-link {
  display: inline-block;
  color: var(--brand);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 8px;
}
.back-link:hover { text-decoration: underline; }

/* ---- landing page (index.html) ---- */
.landing {
  max-width: 920px;
  margin: 0 auto;
  padding: 40px 20px 60px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.landing-hero {
  text-align: center;
  margin: 30px 0 44px;
}

.landing-hero .badge-src {
  display: inline-block;
  background: var(--brand-bg);
  color: var(--brand-dark);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 999px;
  margin-bottom: 16px;
}

.landing-hero h1 {
  font-size: 2rem;
  margin: 0 0 10px;
}

.landing-hero p {
  color: var(--text-muted);
  font-size: 1rem;
  max-width: 560px;
  margin: 0 auto;
  line-height: 1.7;
}

.landing-hero-img {
  max-width: 420px;
  width: 100%;
  height: auto;
  margin: 0 auto 20px;
  display: block;
}

.landing-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 30px;
}

@media (max-width: 700px) {
  .landing-cards { grid-template-columns: 1fr; }
}

.landing-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px 26px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.landing-card:hover {
  transform: translateY(-3px);
  border-color: var(--brand);
}

.landing-card .icon {
  font-size: 2.2rem;
  line-height: 1;
}

.landing-card h2 {
  font-size: 1.25rem;
  margin: 0;
}

.landing-card p {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.7;
  margin: 0;
  flex: 1;
}

.landing-card .cta {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--brand);
  display: flex;
  align-items: center;
  gap: 6px;
}

.landing-card.study .cta { color: var(--good); }
.landing-card.study:hover { border-color: var(--good); }

.landing-tip {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 14px 18px;
}

.landing-footer {
  margin-top: auto;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.78rem;
  padding-top: 40px;
}

/* ---- study page ---- */
.study-toc {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.study-toc a {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.85rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.study-toc a:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.study-chapter {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 28px;
  box-shadow: var(--shadow);
  margin-bottom: 22px;
  scroll-margin-top: 16px;
}

.study-chapter-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.study-chapter-head .icon {
  font-size: 1.6rem;
}

.study-chapter-head h2 {
  margin: 0;
  font-size: 1.3rem;
}

.chapter-banner {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 16px;
  padding: 10px;
}

.study-body .icon-inline {
  float: right;
  width: 84px;
  height: 84px;
  object-fit: contain;
  background: #fff;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 6px;
  margin: 0 0 8px 14px;
}

.study-chapter .chapter-desc {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin: 0 0 18px;
}

.study-body h3 {
  font-size: 1.08rem;
  color: var(--brand-dark);
  margin: 24px 0 10px;
  border-bottom: 2px solid var(--brand-bg);
  padding-bottom: 6px;
}

.study-body h3:first-child { margin-top: 0; }

.study-body h4 {
  font-size: 0.98rem;
  margin: 16px 0 8px;
  color: var(--text);
}

.study-body p {
  line-height: 1.85;
  font-size: 0.95rem;
  margin: 0 0 12px;
  color: var(--text);
}

.study-body ul, .study-body ol {
  margin: 0 0 14px;
  padding-right: 22px;
  line-height: 1.85;
  font-size: 0.95rem;
}

.study-body li { margin-bottom: 6px; }

.study-body strong { color: var(--brand-dark); }

.study-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 18px;
  font-size: 0.9rem;
  overflow-x: auto;
  display: block;
}

.study-body table thead { background: var(--brand-bg); }

.study-body th, .study-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: right;
}

.study-body th { color: var(--brand-dark); }

.study-cta-row {
  margin-top: 26px;
  text-align: center;
}

.study-cta {
  display: inline-block;
  background: var(--brand);
  color: #fff;
  text-decoration: none;
  padding: 12px 26px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.92rem;
}

/* ---- study visuals: image gallery, figures, callouts, stat strip ---- */
.study-body .img-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 14px;
  margin: 6px 0 20px;
}

.study-body figure {
  margin: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}

.study-body figure img {
  width: 100%;
  height: 90px;
  object-fit: contain;
  border-radius: 6px;
  background: #fff;
}

.study-body figure figcaption {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.4;
}

.study-body .callout {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border-radius: 12px;
  padding: 14px 16px;
  margin: 4px 0 18px;
  font-size: 0.92rem;
  line-height: 1.75;
}

.study-body .callout .emoji {
  font-size: 1.3rem;
  flex-shrink: 0;
}

.study-body .callout-tip {
  background: var(--good-bg);
  border: 1px solid var(--good);
}

.study-body .callout-warn {
  background: var(--bad-bg);
  border: 1px solid var(--bad);
}

.study-body .callout-info {
  background: var(--brand-bg);
  border: 1px solid var(--brand);
}

.study-body .stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin: 6px 0 20px;
}

.study-body .stat-strip .stat-item {
  background: var(--brand-bg);
  border-radius: 12px;
  padding: 14px 10px;
  text-align: center;
}

.study-body .stat-strip .stat-item .num {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--brand-dark);
  display: block;
  line-height: 1.2;
}

.study-body .stat-strip .stat-item .lbl {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
  display: block;
}

.study-body .callout-inline {
  display: inline-block;
  background: var(--bad-bg);
  color: var(--bad);
  border-radius: 6px;
  padding: 1px 8px;
  font-weight: 700;
  font-size: 0.88rem;
  margin-right: 4px;
}

.chapter-progress {
  height: 5px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
  margin-bottom: 16px;
}

.chapter-progress .bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--brand), var(--good));
  transition: width 0.2s ease;
}
