/* ============================================================
   Mohamed Bayan Kmainasi — Academic Portfolio
   ============================================================ */

:root {
  --bg: #ffffff;
  --bg-alt: #f6f8fb;
  --surface: #ffffff;
  --border: #e6eaf0;
  --text: #1a2230;
  --text-muted: #5c6b80;
  --accent: #2f5bea;
  --accent-soft: #eaf0ff;
  --accent-strong: #1d44c4;
  --badge-top: #0b8a5b;
  --badge-top-bg: #e3f7ee;
  --badge-bg: #eef1f6;
  --badge-text: #46546b;
  --shadow: 0 1px 2px rgba(16, 30, 60, .05), 0 8px 24px rgba(16, 30, 60, .06);
  --radius: 14px;
  --maxw: 1080px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --bg-alt: #11161f;
  --surface: #161c27;
  --border: #232c3a;
  --text: #e7ecf3;
  --text-muted: #98a4b6;
  --accent: #6b8cff;
  --accent-soft: #1a2540;
  --accent-strong: #8aa4ff;
  --badge-top: #3ad79a;
  --badge-top-bg: #0e2a20;
  --badge-bg: #1c2533;
  --badge-text: #aab6c8;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; scroll-padding-top: 80px; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background .3s ease, color .3s ease;
}

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }

a { color: var(--accent); text-decoration: none; transition: color .15s ease; }
a:hover { color: var(--accent-strong); text-decoration: underline; }

h1, h2, h3 { line-height: 1.2; letter-spacing: -0.02em; }

/* ---------- Navigation ---------- */
.nav {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav__inner { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.nav__brand {
  font-weight: 800; font-size: 1.15rem; letter-spacing: .04em;
  color: var(--text); text-decoration: none;
  border: 2px solid var(--accent); padding: 2px 8px; border-radius: 8px;
}
.nav__brand:hover { text-decoration: none; background: var(--accent-soft); }
.nav__links { display: flex; gap: 28px; }
.nav__links a {
  color: var(--text-muted); font-weight: 500; font-size: .95rem;
  text-decoration: none; position: relative;
}
.nav__links a:hover { color: var(--text); }
.nav__links a::after {
  content: ""; position: absolute; left: 0; bottom: -6px; width: 0; height: 2px;
  background: var(--accent); transition: width .2s ease;
}
.nav__links a:hover::after { width: 100%; }
.nav__actions { display: flex; align-items: center; gap: 10px; }

.theme-toggle {
  display: grid; place-items: center; width: 38px; height: 38px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  color: var(--text); cursor: pointer; transition: background .15s, border-color .15s;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

.lang-select {
  height: 38px; padding: 0 8px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); cursor: pointer;
  font: inherit; font-size: .88rem; font-weight: 600; max-width: 130px;
  transition: border-color .15s, color .15s;
}
.lang-select:hover { border-color: var(--accent); color: var(--accent); }
.lang-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.nav__burger { display: none; flex-direction: column; gap: 5px; background: none; border: none; cursor: pointer; padding: 8px; }
.nav__burger span { width: 22px; height: 2px; background: var(--text); border-radius: 2px; transition: .2s; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 22px; border-radius: 10px; font-weight: 600; font-size: .95rem;
  text-decoration: none; cursor: pointer; transition: transform .12s ease, box-shadow .15s, background .15s;
  border: 1px solid transparent;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn--primary { background: var(--accent); color: #fff; box-shadow: var(--shadow); }
.btn--primary:hover { background: var(--accent-strong); color: #fff; }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn--ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Hero ---------- */
.hero { padding: 72px 0 56px; }
.hero__inner { display: grid; grid-template-columns: 260px 1fr; gap: 48px; align-items: center; }
.hero__photo { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.hero__photo img {
  width: 240px; height: 240px; object-fit: cover; border-radius: 24px;
  box-shadow: var(--shadow); border: 4px solid var(--surface);
}
.eyebrow {
  text-transform: uppercase; letter-spacing: .12em; font-size: .78rem; font-weight: 700;
  color: var(--accent); margin-bottom: 12px;
}
.hero__text h1 { font-size: clamp(2.1rem, 5vw, 3.1rem); margin-bottom: 6px; }
.hero__name-alt { font-size: 1.25rem; font-weight: 600; color: var(--text-muted); margin-bottom: 18px; }
[dir="rtl"] .hero__name-alt { display: none; }
.lead { font-size: 1.08rem; color: var(--text); max-width: 64ch; margin-bottom: 14px; }
.lead--muted { color: var(--text-muted); font-size: 1rem; }
.hero__actions { display: flex; gap: 14px; flex-wrap: wrap; margin: 26px 0 18px; }
.hero__links { list-style: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; }
.hero__links a { font-weight: 600; font-size: .92rem; }

/* ---------- Stats ---------- */
.stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
  margin-top: 48px; padding-top: 36px; border-top: 1px solid var(--border);
}
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat__num { font-size: 1.5rem; font-weight: 800; color: var(--accent); letter-spacing: -.02em; line-height: 1.1; }
.stat__label { font-size: .85rem; color: var(--text-muted); }

/* ---------- Sections ---------- */
.section { padding: 72px 0; }
.section--alt { background: var(--bg-alt); }
.section__title {
  font-size: clamp(1.6rem, 3vw, 2.1rem); margin-bottom: 12px;
  position: relative; display: inline-block;
}
.section__title::after {
  content: ""; display: block; width: 52px; height: 4px; border-radius: 4px;
  background: var(--accent); margin-top: 10px;
}
.section__intro { color: var(--text-muted); max-width: 70ch; margin-bottom: 40px; font-size: 1.02rem; }
.section__title--sub { font-size: 1.35rem; margin-top: 56px; margin-bottom: 24px; }
.section__title--sub::after { height: 3px; width: 40px; }

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.cards--projects { grid-template-columns: repeat(3, 1fr); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 26px; transition: transform .15s ease, box-shadow .15s ease, border-color .15s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.card__icon { font-size: 1.8rem; margin-bottom: 10px; }
.card h3 { font-size: 1.15rem; margin-bottom: 8px; }
.card p { color: var(--text-muted); font-size: .96rem; }
.card--project { display: flex; flex-direction: column; }
.card__tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 12px; }
.card__tags span {
  font-size: .74rem; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-strong);
}
.card--project .pub__links { margin-top: auto; }

/* ---------- News ---------- */
.news { list-style: none; display: flex; flex-direction: column; }
.news__item {
  display: grid; grid-template-columns: 110px 1fr; gap: 20px; align-items: baseline;
  padding: 16px 4px; border-bottom: 1px solid var(--border);
}
.news__item:last-child { border-bottom: none; }
.news__date { font-weight: 700; color: var(--accent); font-size: .9rem; }
.news__text { color: var(--text); }

/* ---------- Publications ---------- */
.pub-group { margin-bottom: 30px; }
.pub-group__year {
  font-size: 1.05rem; font-weight: 800; color: var(--text-muted);
  letter-spacing: .04em; margin-bottom: 14px; padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}
.pubs { list-style: none; display: flex; flex-direction: column; gap: 16px; }
.pub {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 24px; transition: border-color .15s, box-shadow .15s;
}
.pub:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); box-shadow: var(--shadow); }
.pub__title { font-size: 1.08rem; margin-bottom: 6px; }
.pub__authors { color: var(--text-muted); font-size: .92rem; margin-bottom: 8px; }
.pub__venue { font-size: .92rem; color: var(--text); margin-bottom: 10px; }
.badge {
  display: inline-block; font-size: .74rem; font-weight: 700; letter-spacing: .02em;
  padding: 3px 10px; border-radius: 6px; margin-right: 8px;
  background: var(--badge-bg); color: var(--badge-text);
}
.badge--top { background: var(--badge-top-bg); color: var(--badge-top); }
.pub__links { display: flex; flex-wrap: wrap; gap: 8px; }
.pub__links a {
  font-size: .85rem; font-weight: 600; padding: 5px 12px;
  border: 1px solid var(--border); border-radius: 8px; color: var(--text);
}
.pub__links a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.cite-btn {
  font-family: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
  padding: 5px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: transparent; color: var(--text); transition: border-color .15s, color .15s;
}
.cite-btn:hover { border-color: var(--accent); color: var(--accent); }
.bibtex {
  display: none; margin-top: 12px; padding: 14px 16px; border-radius: 10px;
  background: var(--bg-alt); border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .8rem; line-height: 1.55; color: var(--text); white-space: pre;
  overflow-x: auto; direction: ltr; text-align: left;
}
.bibtex.open { display: block; }

/* ---------- Experience / Education timeline ---------- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 48px; }
.timeline { list-style: none; position: relative; margin-bottom: 36px; }
.timeline__item {
  position: relative; padding-left: 22px; padding-bottom: 22px;
  border-left: 2px solid var(--border);
}
.timeline__item:last-child { padding-bottom: 0; }
.timeline__item::before {
  content: ""; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--accent); border: 3px solid var(--bg-alt);
}
.timeline__top { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: baseline; }
.timeline__role { font-weight: 700; font-size: 1.02rem; }
.timeline__date { font-size: .85rem; color: var(--text-muted); white-space: nowrap; }
.timeline__org { color: var(--accent); font-size: .92rem; font-weight: 600; margin: 2px 0 6px; }
.timeline__desc { color: var(--text-muted); font-size: .94rem; }
.awards { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.awards li {
  padding-left: 22px; position: relative; color: var(--text-muted); font-size: .96rem;
}
.awards li::before { content: "🏆"; position: absolute; left: 0; top: 0; font-size: .9rem; }
.awards li b { color: var(--text); }

/* ---------- Contact ---------- */
.contact { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.contact__card {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; color: var(--text); text-decoration: none; transition: transform .15s, border-color .15s, box-shadow .15s;
}
.contact__card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: var(--shadow); text-decoration: none; }
.contact__label { font-size: .78rem; text-transform: uppercase; letter-spacing: .1em; color: var(--text-muted); font-weight: 700; }
.contact__value { font-weight: 600; word-break: break-word; }
.contact__location { margin-top: 28px; color: var(--text-muted); font-size: .98rem; }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--border); padding: 28px 0; background: var(--bg); }
.footer__inner { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.footer p { color: var(--text-muted); font-size: .9rem; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .hero__inner { grid-template-columns: 1fr; gap: 28px; text-align: center; }
  .hero__photo { justify-self: center; }
  .lead, .section__intro { margin-left: auto; margin-right: auto; }
  .hero__actions { justify-content: center; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .cards, .cards--projects, .contact { grid-template-columns: 1fr 1fr; }
  .two-col { grid-template-columns: 1fr; gap: 24px; }
}

/* ---------- RTL (Arabic) ---------- */
[dir="rtl"] body { line-height: 1.85; }
[dir="rtl"] .section__title::after { margin-left: auto; }
[dir="rtl"] .nav__brand { letter-spacing: 0; }
[dir="rtl"] .timeline__item { border-left: none; border-right: 2px solid var(--border); padding-left: 0; padding-right: 22px; }
[dir="rtl"] .timeline__item::before { left: auto; right: -7px; }
[dir="rtl"] .awards li { padding-left: 0; padding-right: 22px; }
[dir="rtl"] .awards li::before { left: auto; right: 0; }
/* Keep Latin tokens (venues, links, BibTeX) rendering left-to-right inside RTL flow,
   but anchor them to the right edge so they line up with the Arabic text around them */
[dir="rtl"] .badge, [dir="rtl"] .pub__authors, [dir="rtl"] .pub__links,
[dir="rtl"] .contact__value, [dir="rtl"] .stat__num { direction: ltr; }
[dir="rtl"] .pub__authors, [dir="rtl"] .pub__links,
[dir="rtl"] .stat__num, [dir="rtl"] .contact__value { text-align: right; }
[dir="rtl"] .stat { text-align: right; }

@media (max-width: 640px) {
  .nav__links {
    position: fixed; top: 64px; right: 0; left: 0;
    flex-direction: column; gap: 0; background: var(--surface);
    border-bottom: 1px solid var(--border); padding: 0;
    max-height: 0; overflow: hidden; transition: max-height .25s ease;
  }
  .nav__links.open { max-height: 320px; }
  .nav__links a { padding: 14px 24px; border-top: 1px solid var(--border); }
  .nav__links a::after { display: none; }
  .nav__burger { display: flex; }
  .hero { padding: 48px 0 40px; }
  .cards, .cards--projects, .contact { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; gap: 18px; }
  .news__item { grid-template-columns: 1fr; gap: 4px; padding: 14px 4px; }
  .footer__inner { flex-direction: column; text-align: center; }
}
[dir="rtl"] .nav__links a { text-align: right; }
