/* ==========================================================================
   Lakhchen Faïçal — personal academic website
   Shared stylesheet for every page (home, course pages, award page).
   ========================================================================== */

:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-alt: #f0f3f7;
    --text: #1d2733;
    --text-muted: #5b6878;
    --border: #dde3ea;
    --primary: #1f4e79;
    --primary-hover: #163a5a;
    --primary-soft: #e6eef6;
    --accent: #b5832b;
    --success: #2e7d5b;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
    --radius: 10px;
    --maxw: 1080px;
    --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #11161d;
        --surface: #182029;
        --surface-alt: #1e2833;
        --text: #e4e9ef;
        --text-muted: #9aa8b8;
        --border: #2b3744;
        --primary: #7fb2e5;
        --primary-hover: #a5c9ee;
        --primary-soft: #1d3247;
        --accent: #e0b25c;
        --success: #5cc497;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    }
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.65;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

h1, h2, h3, h4 { font-family: var(--font-serif); line-height: 1.25; margin: 0 0 .5em; color: var(--text); }

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

/* ---------- Header / navigation ---------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(160%) blur(8px);
    border-bottom: 1px solid var(--border);
}

.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
    gap: 16px;
}

.brand { display: flex; flex-direction: column; line-height: 1.2; color: var(--text); }
.brand:hover { text-decoration: none; color: var(--text); }
.brand-name { font-family: var(--font-serif); font-weight: 700; font-size: 1.2rem; }
.brand-tag { font-size: .78rem; color: var(--text-muted); letter-spacing: .02em; }

.nav-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 1.1rem;
    color: var(--text);
    cursor: pointer;
}

.site-nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 4px; }
.site-nav a {
    display: block;
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: .95rem;
}
.site-nav a:hover, .site-nav a.active { background: var(--primary-soft); color: var(--primary); text-decoration: none; }

@media (max-width: 820px) {
    .nav-toggle { display: block; }
    .site-nav {
        display: none;
        position: absolute;
        top: 64px; left: 0; right: 0;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow);
    }
    .site-nav.open { display: block; }
    .site-nav ul { flex-direction: column; padding: 8px 16px 16px; }
}

/* ---------- Hero (home) ---------- */
.hero {
    background: linear-gradient(135deg, var(--primary-soft), var(--bg) 70%);
    border-bottom: 1px solid var(--border);
    padding: 56px 0 48px;
}
.hero .container { display: flex; align-items: center; gap: 40px; }
.hero-photo {
    width: 180px; height: 180px;
    flex-shrink: 0;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid var(--surface);
    box-shadow: var(--shadow);
}
.hero h1 { font-size: 2.4rem; margin-bottom: .15em; }
.hero .role { font-size: 1.1rem; color: var(--primary); font-weight: 600; margin: 0 0 .6em; }
.hero .lead { color: var(--text-muted); max-width: 640px; margin: 0 0 1.2em; }

@media (max-width: 720px) {
    .hero { padding: 36px 0 32px; }
    .hero .container { flex-direction: column; text-align: center; gap: 20px; }
    .hero-photo { width: 140px; height: 140px; }
    .hero h1 { font-size: 1.9rem; }
    .hero .lead { margin-left: auto; margin-right: auto; }
    .hero .btn-row { justify-content: center; }
}

/* ---------- Buttons ---------- */
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-weight: 500;
    font-size: .92rem;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { text-decoration: none; border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .btn-primary,
    :root:not([data-theme="light"]) .btn-primary:hover { color: #0d1620; }
}

/* Small resource buttons (slides, exercises, data, code...) */
.res {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: .82rem;
    font-weight: 600;
    background: var(--primary-soft);
    color: var(--primary);
    border: 1px solid transparent;
    white-space: nowrap;
}
.res:hover { text-decoration: none; border-color: var(--primary); }
.res.res-ex   { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.res.res-ex:hover { border-color: var(--success); }
.res.res-note { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.res.res-note:hover { border-color: var(--accent); }

/* Links whose href is still "#TODO" are shown as "coming soon" by main.js */
.is-pending, .is-pending:hover {
    background: var(--surface-alt) !important;
    color: var(--text-muted) !important;
    border-color: transparent !important;
    cursor: not-allowed;
    opacity: .75;
}

/* ---------- Sections ---------- */
main { padding: 48px 0 64px; }
.section { margin-bottom: 64px; }
.section:last-child { margin-bottom: 0; }
.section-title { font-size: 1.75rem; margin-bottom: .3em; }
.section-sub { color: var(--text-muted); margin: 0 0 24px; }
.section-title::after {
    content: "";
    display: block;
    width: 48px; height: 3px;
    margin-top: 10px;
    background: var(--accent);
    border-radius: 2px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

.prose p { margin: 0 0 1em; }
.prose p:last-child { margin-bottom: 0; }

.highlight {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    margin-top: 20px;
    padding: 16px 18px;
    border-left: 4px solid var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, var(--surface));
    border-radius: 0 var(--radius) var(--radius) 0;
}
.highlight-icon { font-size: 1.5rem; line-height: 1; }
.highlight p { margin: 0 0 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 0; padding: 0; list-style: none; }
.chips li {
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: .85rem;
    font-weight: 500;
}

/* ---------- Publications ---------- */
.pub-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.pub {
    display: grid;
    grid-template-columns: 64px 1fr auto;
    gap: 16px;
    align-items: start;
    padding: 18px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.pub-year { font-family: var(--font-serif); font-weight: 700; font-size: 1.15rem; color: var(--accent); }
.pub-title { font-weight: 600; margin: 0 0 4px; }
.pub-meta { color: var(--text-muted); font-size: .92rem; margin: 0; }
.pub-meta em { color: var(--text); }
.tag {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    background: var(--surface-alt);
    color: var(--text-muted);
    vertical-align: middle;
}
@media (max-width: 640px) {
    .pub { grid-template-columns: 1fr; gap: 6px; }
}

/* ---------- Teaching ---------- */
.subsection-title {
    font-size: 1.25rem;
    margin: 36px 0 6px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.subsection-title:first-of-type { margin-top: 0; }
.level-badge {
    font-family: var(--font-sans);
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .level-badge { color: #0d1620; }
}

.course-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.course-card {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    color: var(--text);
    transition: transform .15s, box-shadow .15s, border-color .15s;
}
.course-card:hover {
    text-decoration: none;
    color: var(--text);
    transform: translateY(-3px);
    border-color: var(--primary);
    box-shadow: var(--shadow);
}
.course-icon {
    width: 44px; height: 44px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--primary-soft);
    color: var(--primary);
    font-family: var(--font-serif);
    font-weight: 700;
    font-size: 1.15rem;
    margin-bottom: 14px;
}
.course-card h4 { font-size: 1.1rem; margin-bottom: 2px; }
.course-card .en { color: var(--text-muted); font-size: .85rem; margin: 0 0 10px; }
.course-card .desc { font-size: .9rem; color: var(--text-muted); margin: 0 0 14px; flex: 1; }
.course-card .meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: .82rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    padding-top: 10px;
}
.course-card .go { color: var(--primary); font-weight: 600; }

/* Master / advanced courses (collapsible) */
.course-acc { display: grid; gap: 12px; margin-top: 16px; }
.course-acc details {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.course-acc summary {
    cursor: pointer;
    list-style: none;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-weight: 600;
}
.course-acc summary::-webkit-details-marker { display: none; }
.course-acc summary::after { content: "+"; font-size: 1.3rem; color: var(--text-muted); line-height: 1; }
.course-acc details[open] summary::after { content: "–"; }
.course-acc summary small { color: var(--text-muted); font-weight: 400; margin-left: 8px; }
.course-acc .lessons { margin: 0; padding: 0 20px 16px; list-style: none; counter-reset: l; }
.course-acc .lessons li {
    counter-increment: l;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 0;
    border-top: 1px solid var(--border);
}
.course-acc .lessons li > span::before {
    content: counter(l) ".";
    display: inline-block;
    min-width: 28px;
    color: var(--text-muted);
    font-weight: 600;
}
.course-acc .lessons .btn-row { gap: 6px; }

/* ---------- Contact ---------- */
.contact-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.contact-item { display: flex; gap: 12px; align-items: flex-start; }
.contact-item .label { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin: 0; }
.contact-item p { margin: 0; overflow-wrap: anywhere; }

/* ---------- Course page ---------- */
.page-head {
    background: linear-gradient(135deg, var(--primary-soft), var(--bg) 75%);
    border-bottom: 1px solid var(--border);
    padding: 32px 0 36px;
}
.breadcrumb { font-size: .88rem; color: var(--text-muted); margin-bottom: 14px; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb span[aria-hidden] { margin: 0 6px; }
.page-head h1 { font-size: 2.1rem; margin-bottom: .2em; }
.page-head .subtitle { color: var(--text-muted); margin: 0 0 18px; max-width: 760px; }
.facts { display: flex; flex-wrap: wrap; gap: 10px 26px; margin: 0 0 20px; padding: 0; list-style: none; font-size: .92rem; }
.facts li strong { display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.toolbar h2 { margin: 0; font-size: 1.4rem; }
.search {
    padding: 9px 14px;
    min-width: 240px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: .92rem;
}
.search:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.chapters { width: 100%; border-collapse: collapse; font-size: .95rem; }
.chapters th, .chapters td { padding: 12px 16px; text-align: left; vertical-align: middle; }
.chapters thead th {
    background: var(--surface-alt);
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}
.chapters tbody tr { border-top: 1px solid var(--border); }
.chapters tbody tr:hover td { background: color-mix(in srgb, var(--primary-soft) 45%, transparent); }
.chapters .num { width: 56px; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.chapters .res-cell { width: 1%; white-space: nowrap; }
.chapters tr.part-row td {
    background: var(--surface-alt);
    font-family: var(--font-serif);
    font-weight: 700;
    color: var(--text);
    padding-top: 14px;
    padding-bottom: 10px;
}
.chapters tr.part-row td small { font-family: var(--font-sans); font-weight: 500; color: var(--text-muted); margin-left: 8px; }
.chapters tr.part-row:hover td { background: var(--surface-alt); }
.no-results { padding: 24px; text-align: center; color: var(--text-muted); display: none; }

@media (max-width: 720px) {
    .chapters thead { display: none; }
    .chapters, .chapters tbody, .chapters tr, .chapters td { display: block; width: 100%; }
    .chapters tbody tr:not(.part-row) {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        gap: 8px 6px;
        padding: 12px 14px;
    }
    .chapters td { padding: 0; }
    .chapters .num { width: 36px; flex: 0 0 36px; }
    .chapters .title { flex: 1 1 calc(100% - 50px); width: auto; }
    .chapters .res-cell { width: auto; }
    .chapters .res-cell:nth-child(3) { margin-left: 42px; }
    .chapters tr.part-row td { padding: 12px 14px 8px; }
}

.resources { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.resource {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
}
.resource h3 { font-size: 1.05rem; margin: 0; }
.resource p { margin: 0; color: var(--text-muted); font-size: .9rem; flex: 1; }
.resource .btn-row { margin-top: 6px; gap: 6px; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; font-size: .85rem; color: var(--text-muted); }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); padding: 28px 0; font-size: .9rem; color: var(--text-muted); }
.site-footer .container { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; }
.site-footer p { margin: 0; }
.site-footer a { color: var(--text-muted); }
.site-footer a:hover { color: var(--primary); }
.footer-links { display: flex; gap: 18px; flex-wrap: wrap; }

/* Back-to-top */
#toTop {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 44px; height: 44px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--primary);
    font-size: 1.2rem;
    box-shadow: var(--shadow);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
}
#toTop.show { opacity: 1; pointer-events: auto; }

/* Media coverage (award page) */
.press-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.press-list a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-weight: 500;
}
.press-list a::after { content: "↗"; color: var(--text-muted); }
.press-list a:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }

@media print {
    .site-header, #toTop, .search, .site-footer { display: none; }
    body { background: #fff; }
}

@media (max-width: 520px) {
    .search { min-width: 0; width: 100%; }
}

/* Award page */
.award-figure { margin: 0; }
.award-figure img {
    width: 100%;
    height: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.award-figure figcaption { margin-top: 10px; font-size: .9rem; color: var(--text-muted); text-align: center; }
.award-quote {
    margin: 0 0 1em;
    padding: 12px 18px;
    border-left: 4px solid var(--accent);
    background: var(--surface-alt);
    border-radius: 0 8px 8px 0;
    font-family: var(--font-serif);
    font-size: 1.08rem;
}
