:root {
  --ink: #0f1217;
  --ink-2: #151a21;
  --surface: #171d25;
  --surface-2: #1d242e;
  --border: rgba(255, 255, 255, 0.09);
  --border-soft: rgba(255, 255, 255, 0.055);

  --text: #eef1f5;
  --text-dim: #9aa4b2;       /* AA on --ink */
  --text-faint: #626c7a;

  --accent: #d3a44a;         /* single brand accent (gold) */
  --accent-soft: #e6c07e;
  --danger: #cf7554;

  /* muted, harmonious type hues — used sparingly, not as full fills */
  --t0: #9092c9;   /* برامج أكاديمية */
  --t1: #4fa595;   /* شهادات مهنية */
  --t2: #c39a52;   /* برامج تدريبية */
  --t3: #c67d5f;   /* فعاليات */
  --t4: #6fa0c9;   /* برامج تعلم ذاتي */
  --t5: #bd7f9e;   /* الكتب والمؤلفات */

  --font-ui: "Tajawal", system-ui, sans-serif;
  --font-display: "Tajawal", system-ui, sans-serif;

  --z-sticky: 100;
  --z-menu: 210;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { overflow-x: hidden; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-ui);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===================== Topbar ===================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: rgba(15, 18, 23, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
}

.toolbar {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 13px clamp(16px, 4vw, 32px);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand > i { font-size: 18px; color: var(--accent); flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.brand-title { font-weight: 700; font-size: 17px; color: var(--text); }
.brand-sub { font-size: 12px; color: var(--text-dim); }

.toolbar-actions { display: flex; align-items: center; gap: 10px; }

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  width: clamp(200px, 32vw, 320px);
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.18s;
}
.search-field:focus-within { border-color: var(--accent); }
.search-field > i { color: var(--text-faint); font-size: 13px; flex: none; }
.search-field input {
  flex: 1; min-width: 0;
  border: none; outline: none; background: transparent;
  color: var(--text); font-family: var(--font-ui); font-size: 14px;
}
.search-field input::placeholder { color: var(--text-faint); }
.search-clear {
  border: none; background: transparent; color: var(--text-faint);
  cursor: pointer; padding: 2px 4px; font-size: 13px; flex: none;
}
.search-clear:hover { color: var(--text); }

/* ===================== Filter bar ===================== */
.filterbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 clamp(16px, 4vw, 32px) 12px;
  flex-wrap: wrap;
}
.facets { display: flex; gap: 8px; flex-wrap: wrap; }

.facet { position: relative; }
.facet-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 13.5px;
  cursor: pointer;
  transition: border-color 0.16s, color 0.16s;
}
.facet-btn:hover { color: var(--text); border-color: var(--border); }
.facet-btn > i:first-child { font-size: 12px; color: var(--text-faint); }
.facet.open .facet-btn,
.facet.active .facet-btn { color: var(--text); border-color: var(--accent); }
.facet.active .facet-btn > i:first-child { color: var(--accent); }
.facet-caret { font-size: 9px; transition: transform 0.18s var(--ease); margin-inline-start: 2px; color: var(--text-faint); }
.facet.open .facet-caret { transform: rotate(180deg); }
.facet-badge {
  display: inline-grid; place-items: center;
  min-width: 17px; height: 17px; padding: 0 5px;
  border-radius: 999px;
  background: var(--accent); color: #17130a;
  font-size: 11px; font-weight: 700;
}

.facet-menu {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-start: 0;
  z-index: var(--z-menu);
  min-width: 220px;
  max-height: 320px;
  overflow-y: auto;
  padding: 5px;
  background: var(--ink-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 14px 36px -18px rgba(0, 0, 0, 0.8);
}
.facet-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 13.5px;
  text-align: start;
  cursor: pointer;
  transition: background 0.13s, color 0.13s;
}
.facet-opt:hover { background: var(--surface); color: var(--text); }
.opt-check {
  display: grid; place-items: center;
  width: 18px; height: 18px; flex: none;
  border: 1.5px solid var(--border);
  border-radius: 5px;
  color: transparent; font-size: 9px;
  transition: background 0.13s, border-color 0.13s, color 0.13s;
}
.facet-opt[aria-checked="true"] { color: var(--text); }
.facet-opt[aria-checked="true"] .opt-check {
  background: var(--accent); border-color: var(--accent); color: #17130a;
}
.opt-label { flex: 1; }
.opt-count { font-size: 11.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.facet-opt[aria-disabled="true"] { opacity: 0.38; pointer-events: none; }

.filters-clear {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 12px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-ui); font-size: 13px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.filters-clear:hover { color: var(--danger); border-color: var(--danger); }
.filters-clear i { font-size: 12px; }

/* ===================== Matrix ===================== */
#matrix-container {
  padding: clamp(22px, 4vw, 40px) clamp(16px, 4vw, 32px) 40px;
  overflow-x: auto;
}
.explore-head {
  max-width: 860px;
  margin: 0 auto 26px;
}
.matrix {
  --rowhead: clamp(180px, 22vw, 246px);
  --cell: minmax(94px, 1fr);
  display: grid;
  gap: 7px;
  min-width: 720px;
  margin-inline: auto;
  max-width: 1300px;
}
.matrix-head,
.mrow {
  display: grid;
  grid-template-columns: var(--rowhead) repeat(6, var(--cell));
  gap: 7px;
}

/* corner */
.corner {
  display: flex; flex-direction: column; justify-content: flex-end; gap: 3px;
  padding: 4px 6px 8px;
}
.corner .ax { font-weight: 700; font-size: 12px; }
.corner .ax-rows { color: var(--accent); }
.corner .ax-cols { color: var(--text-dim); }
.corner .ax-cols i { font-size: 9px; margin-inline-start: 3px; }

/* column headers = types */
.col-head {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px;
  text-align: center;
  padding: 13px 8px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-top: 2px solid color-mix(in oklab, var(--hue) 55%, transparent);
}
.col-head .ch-icon {
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border-radius: 10px;
  background: color-mix(in oklab, var(--hue) 14%, transparent);
  color: var(--hue);
  font-size: 14px;
}
.col-head .ch-name { font-weight: 700; font-size: 13px; color: var(--text); line-height: 1.35; }

/* row headers = domains */
.row-head {
  display: flex; align-items: center; gap: 11px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
}
.row-head .rh-icon {
  display: grid; place-items: center;
  width: 36px; height: 36px; flex: none;
  border-radius: 10px;
  background: color-mix(in oklab, var(--accent) 12%, transparent);
  color: var(--accent-soft);
  font-size: 15px;
}
.row-head .rh-body { min-width: 0; }
.row-head .rh-name { display: block; font-weight: 700; font-size: 13.5px; color: var(--text); line-height: 1.35; }
.row-head .rh-count { font-size: 12px; color: var(--text-dim); }

/* cells */
.cell {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 62px;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: var(--surface);
  font-family: var(--font-ui);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.cell .cell-type { display: none; }
.cell .cell-count {
  font-weight: 700; font-size: 20px; line-height: 1;
  color: var(--hue, var(--text));
}
.cell .cell-label { font-size: 10.5px; color: var(--text-faint); }

.cell.has { background: color-mix(in oklab, var(--hue) 6%, var(--surface)); }
.cell.has:hover,
.cell.has:focus-visible {
  border-color: var(--hue);
  background: color-mix(in oklab, var(--hue) 11%, var(--surface));
  outline: none;
}

.cell.empty {
  cursor: default;
  background: transparent;
  border-style: dashed;
}
.cell.empty .cell-count { color: var(--text-faint); font-size: 15px; font-weight: 500; }
.cell.empty .cell-label { display: none; }

/* selected cell */
.cell.active {
  border-color: var(--hue) !important;
  box-shadow: inset 0 0 0 1px var(--hue);
}

/* search / filter dimming */
.cell.dim, .row-head.dim, .col-head.dim { opacity: 0.32; }
.cell.dim { pointer-events: none; }

.no-results { text-align: center; color: var(--text-dim); font-size: 15px; padding: 40px 16px; }

/* ===================== Inline results ===================== */
.results-hint {
  max-width: 1300px;
  margin: 22px auto 0;
  text-align: center;
  color: var(--text-faint);
  font-size: 13.5px;
}
.results {
  max-width: 1300px;
  margin: 28px auto 0;
  scroll-margin-top: 132px;
  border-top: 1px solid var(--border-soft);
  padding-top: 22px;
}
.results-head {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.results-cross { display: flex; flex-wrap: wrap; gap: 8px; }
.results-title {
  margin: 0; margin-inline-end: auto;
  font-weight: 700; font-size: 17px; color: var(--text);
}
.results-close {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-dim);
  font-family: var(--font-ui); font-size: 13px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.results-close:hover { color: var(--text); border-color: var(--accent); }
.results-close i { font-size: 12px; }

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
  align-items: stretch;   /* equal-height cards per row */
}

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  border-radius: 7px;
  font-size: 12.5px; font-weight: 500;
}
.chip.domain { background: color-mix(in oklab, var(--accent) 13%, transparent); color: var(--accent-soft); }
.chip.type { background: color-mix(in oklab, var(--hue) 15%, transparent); color: var(--hue); }

/* opportunity card */
.op-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 16px 17px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  transition: border-color 0.16s;
}
.op-card:hover { border-color: var(--border); }
.op-kind {
  display: inline-block;
  font-size: 11.5px; font-weight: 700;
  color: var(--hue);
  background: color-mix(in oklab, var(--hue) 13%, transparent);
  padding: 3px 9px; border-radius: 5px;
  margin-bottom: 9px;
}
.op-title {
  margin: 0 0 3px;
  font-weight: 700; font-size: 15.5px; line-height: 1.45;
  color: var(--text); text-wrap: balance;
}
.op-title-en {
  margin: 0 0 10px;
  font-size: 12px; color: var(--text-faint);
  direction: ltr; text-align: right;
}
.op-provider {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--accent-soft);
  margin-bottom: 10px;
}
.op-provider i { font-size: 12px; color: var(--text-faint); }
.op-desc { margin: 0 0 12px; font-size: 13px; line-height: 1.7; color: var(--text-dim); }
.op-meta { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.op-meta li {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  padding: 4px 9px; border-radius: 6px;
}
.op-meta li i { font-size: 10.5px; color: var(--text-faint); }
.op-reqs { margin-bottom: 13px; }
.op-reqs summary {
  cursor: pointer; font-size: 12.5px; font-weight: 500; color: var(--text-dim);
  list-style: none; display: inline-flex; align-items: center; gap: 7px; padding: 6px 0;
}
.op-reqs summary::-webkit-details-marker { display: none; }
.op-reqs summary i { transition: transform 0.18s; font-size: 10px; }
.op-reqs[open] summary i { transform: rotate(-90deg); }
.op-reqs .reqs-body {
  font-size: 12.5px; line-height: 1.75; color: var(--text-dim);
  white-space: pre-line;
  padding: 10px 12px; margin-top: 6px;
  border-radius: 8px;
  background: var(--ink);
  border: 1px solid var(--border-soft);
  max-height: 260px; overflow-y: auto;
}
.op-cta {
  display: inline-flex; align-items: center; gap: 8px;
  align-self: flex-start;
  margin-top: auto;         /* pin CTA to the card's bottom edge */
  padding: 9px 17px;
  border-radius: 8px;
  background: var(--accent);
  color: #17130a;
  font-weight: 700; font-size: 13px;
  text-decoration: none;
  transition: background 0.15s;
}
.op-cta:hover { background: var(--accent-soft); }
.op-cta i { font-size: 11px; }

/* gentle, non-decorative entrance */
.op-card { opacity: 0; animation: fadeIn 0.28s var(--ease) forwards; animation-delay: calc(var(--i, 0) * 30ms); }
@keyframes fadeIn { to { opacity: 1; } }

/* ===================== Mode switch ===================== */
.mode-switch {
  display: flex;
  gap: 4px;
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 20px auto 0;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
}
.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 20px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.18s var(--ease), color 0.18s;
}
.mode-btn:hover { color: var(--text); }
.mode-btn[aria-selected="true"] {
  background: var(--accent);
  color: #17130a;
}
.mode-btn i { font-size: 13px; }

/* hide matrix-only tools while in quiz mode */
body[data-view="quiz"] .toolbar-actions,
body[data-view="quiz"] .filterbar { display: none; }

/* ===================== Quiz ===================== */
.quiz {
  max-width: 860px;
  margin: 0 auto;
  padding: clamp(22px, 4vw, 40px) clamp(16px, 4vw, 32px) 60px;
}

/* progress */
.quiz-progress { margin-bottom: 30px; }
.qp-top {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.qp-step { font-size: 13px; font-weight: 700; color: var(--accent-soft); }
.qp-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.qp-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  color: var(--text-dim);
  font-size: 11.5px;
}
.qp-chip i { font-size: 10px; color: var(--accent); }
.qp-bar {
  height: 5px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.qp-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.45s var(--ease);
}

/* steps */
.q-step { animation: stepIn 0.24s var(--ease); }
.q-step.leaving { animation: stepOut 0.18s var(--ease) forwards; }
@keyframes stepIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes stepOut { to { opacity: 0; transform: translateY(-10px); } }

.q-title {
  margin: 0 0 6px;
  font-size: clamp(21px, 3.4vw, 26px);
  font-weight: 800;
  color: var(--text);
  text-wrap: balance;
  outline: none;
}
.q-sub { margin: 0 0 24px; font-size: 14px; color: var(--text-dim); }

.q-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 10px;
}
.q-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 96px;
  padding: 16px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.16s, background 0.16s, transform 0.14s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.q-opt:hover { border-color: var(--accent); transform: translateY(-1px); }
.q-opt:active { transform: scale(0.98); }
.q-opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.q-opt[data-value="all"] { grid-column: 1 / -1; flex-direction: row; justify-content: center; }
.q-opt .qo-icon {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 10px;
  background: color-mix(in oklab, var(--accent) 10%, transparent);
  color: var(--accent-soft);
  font-size: 16px;
  transition: background 0.16s, color 0.16s;
}
.q-opt[aria-checked="true"] {
  border-color: var(--accent);
  background: color-mix(in oklab, var(--accent) 9%, var(--surface));
}
.q-opt[aria-checked="true"] .qo-icon {
  background: var(--accent);
  color: #17130a;
}

.q-nav { display: flex; align-items: center; gap: 12px; margin-top: 26px; }
.q-back {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.q-back:hover { color: var(--text); border-color: var(--accent); }
.q-back i { font-size: 11px; }

/* quiz results */
.qr-head { margin-bottom: 22px; }
.qr-count {
  margin: 0 0 12px;
  font-size: clamp(20px, 3.2vw, 25px);
  font-weight: 800;
  color: var(--text);
}
.qr-count strong { color: var(--accent); font-variant-numeric: tabular-nums; }
.qr-chips { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 14px; }
.qr-actions { display: flex; gap: 10px; }
.qr-edit {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.qr-edit:hover { color: var(--text); border-color: var(--accent); }
.qr-edit i { font-size: 11px; }

.match-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 10px;
  border: 1px solid var(--border-soft);
  background: var(--surface-2);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.match-badge.high {
  background: color-mix(in oklab, var(--accent) 15%, transparent);
  border-color: color-mix(in oklab, var(--accent) 40%, transparent);
  color: var(--accent-soft);
}
.match-badge.mid {
  background: color-mix(in oklab, var(--t1) 14%, transparent);
  border-color: color-mix(in oklab, var(--t1) 40%, transparent);
  color: var(--t1);
}

.qr-foot { margin-top: 28px; text-align: center; }
.qr-explore {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 11px 22px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.qr-explore:hover { border-color: var(--accent); background: var(--surface-2); }
.qr-explore i { font-size: 12px; color: var(--accent); }

/* ===================== Responsive ===================== */
@media (max-width: 720px) {
  .toolbar { padding: 11px 16px 8px; gap: 10px; flex-wrap: wrap; }
  .brand-sub { display: none; }
  .toolbar-actions { width: 100%; }
  .search-field { width: 100%; }

  .filterbar { padding: 0 16px 10px; gap: 8px; }
  .facet-btn { padding: 7px 11px; font-size: 12.5px; }
  .facet-menu { min-width: 200px; }

  #matrix-container { overflow-x: visible; padding: 16px; }
  .matrix { display: block; min-width: 0; }
  .matrix-head { display: none; }

  .mrow {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 22px;
  }
  .row-head { grid-column: 1 / -1; margin-bottom: 2px; }

  .cell { flex-direction: row; justify-content: flex-start; gap: 10px; min-height: 56px; text-align: start; padding: 10px 12px; }
  .cell .cell-type {
    display: flex; align-items: center; gap: 7px; flex: 1; min-width: 0;
    font-weight: 700; font-size: 12.5px; color: var(--text);
  }
  .cell .cell-type i { color: var(--hue); font-size: 13px; flex: none; }
  .cell .cell-count { font-size: 19px; }
  .cell .cell-label { display: none; }
  .cell.empty { display: none; }

  .results-grid { grid-template-columns: 1fr; }
  .results { scroll-margin-top: 12px; }
}

/* ===================== Reduced motion ===================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .op-card { opacity: 1; }
}
