/* ==========================================================================
   Raytracer — documentation technique
   Feuille de style commune (design sobre, professionnel, responsive, clair)
   ========================================================================== */

:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #e2e6ec;
    --text: #1c2530;
    --text-muted: #5a6673;
    --primary: #2f6fed;
    --primary-dark: #1f52bd;
    --accent: #7c3aed;
    --code-bg: #f5f6f8;
    --sidebar-w: 260px;
    --topbar-h: 58px;
    --radius: 10px;
    --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 16px); }

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

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

/* -------------------------------------------------------------- Top bar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.25rem;
    background: rgba(255, 255, 255, .9);
    backdrop-filter: saturate(160%) blur(8px);
    border-bottom: 1px solid var(--border);
}
.topbar .brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-weight: 700;
    color: var(--text);
    font-size: 1.05rem;
    white-space: nowrap;
}
.topbar .brand .logo {
    width: 28px; height: 28px;
    display: grid; place-items: center;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff; font-size: 15px;
}
.topbar .brand small { color: var(--text-muted); font-weight: 500; }
.topbar nav { margin-left: auto; display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar nav a {
    color: var(--text-muted);
    padding: .4rem .7rem;
    border-radius: 8px;
    font-size: .92rem;
    font-weight: 500;
}
.topbar nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.topbar nav a.active { color: var(--primary); background: #eaf1fe; }

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

/* -------------------------------------------------------------- Layout */
.layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    align-items: start;
    max-width: 1400px;
    margin: 0 auto;
}

/* -------------------------------------------------------------- Sidebar */
.sidebar {
    position: sticky;
    top: var(--topbar-h);
    align-self: start;
    height: calc(100vh - var(--topbar-h));
    overflow-y: auto;
    padding: 1.4rem 1rem 3rem;
    border-right: 1px solid var(--border);
    background: var(--surface);
}
.sidebar h4 {
    margin: 1.3rem .6rem .4rem;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
}
.sidebar h4:first-child { margin-top: 0; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li a {
    display: block;
    padding: .4rem .6rem;
    border-radius: 8px;
    color: var(--text-muted);
    font-size: .92rem;
}
.sidebar li a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar li a.active {
    background: #eaf1fe;
    color: var(--primary-dark);
    font-weight: 600;
}

/* -------------------------------------------------------------- Content */
.content {
    min-width: 0;
    padding: 2.2rem clamp(1.2rem, 4vw, 3.5rem) 5rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
}
.content.has-toc { grid-template-columns: minmax(0, 1fr) 220px; gap: 2.5rem; }

.article { min-width: 0; max-width: 880px; }

.content h1 {
    font-size: clamp(1.8rem, 3.4vw, 2.4rem);
    line-height: 1.2;
    margin: 0 0 .4rem;
    letter-spacing: -.02em;
}
.content .lead {
    font-size: 1.12rem;
    color: var(--text-muted);
    margin: 0 0 2rem;
}
.content h2 {
    font-size: 1.5rem;
    margin: 2.6rem 0 .8rem;
    padding-top: .4rem;
    letter-spacing: -.01em;
    border-top: 1px solid var(--border);
    padding-top: 1.6rem;
}
.content h2:first-of-type { border-top: none; padding-top: 0; }
.content h3 { font-size: 1.18rem; margin: 1.8rem 0 .6rem; }
.content h4 { font-size: 1rem; margin: 1.4rem 0 .5rem; color: var(--text); }
.content p, .content li { color: #2a3542; }
.content ul, .content ol { padding-left: 1.3rem; }
.content li { margin: .3rem 0; }

/* Breadcrumb */
.crumbs { font-size: .85rem; color: var(--text-muted); margin-bottom: 1rem; }
.crumbs a { color: var(--text-muted); }

/* Inline code */
code {
    font-family: var(--mono);
    font-size: .88em;
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .12em .4em;
}
pre {
    margin: 1.1rem 0;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow-x: auto;
    background: #0f1729;
    box-shadow: var(--shadow);
}
pre code {
    display: block;
    background: none;
    border: none;
    padding: 1rem 1.15rem;
    font-size: .85rem;
    line-height: 1.6;
    color: #e6edf3;
}

/* Tables */
.table-wrap { overflow-x: auto; margin: 1.2rem 0; }
table {
    border-collapse: collapse;
    width: 100%;
    font-size: .92rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
th, td { text-align: left; padding: .65rem .85rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; color: var(--text); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td code { white-space: nowrap; }

/* Callouts */
.note, .warn, .tip {
    display: flex;
    gap: .7rem;
    padding: .9rem 1.1rem;
    border-radius: var(--radius);
    margin: 1.3rem 0;
    border: 1px solid var(--border);
    font-size: .95rem;
}
.note { background: #eef4ff; border-color: #cfe0ff; }
.warn { background: #fff6ed; border-color: #ffd9b0; }
.tip  { background: #edfaf1; border-color: #bfead0; }
.note::before { content: "ℹ️"; }
.warn::before { content: "⚠️"; }
.tip::before  { content: "✅"; }
.note p, .warn p, .tip p { margin: 0; }

/* Cards grid (home + feature) */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; margin: 1.6rem 0; }
.card {
    display: block;
    padding: 1.1rem 1.2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    color: inherit;
    transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
a.card:hover { transform: translateY(-2px); border-color: var(--primary); text-decoration: none; box-shadow: 0 6px 22px rgba(47,111,237,.14); }
.card .icon { font-size: 1.4rem; }
.card h3 { margin: .5rem 0 .3rem; font-size: 1.05rem; }
.card p { margin: 0; color: var(--text-muted); font-size: .9rem; }

/* Pills / badges */
.pill {
    display: inline-block;
    padding: .12rem .55rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
    background: #eaf1fe;
    color: var(--primary-dark);
    border: 1px solid #cfe0ff;
}
.pill.gray { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }
.pill.green { background: #e7f7ee; color: #157347; border-color: #bfead0; }

.badges { display: flex; flex-wrap: wrap; gap: .4rem; margin: 1rem 0 1.6rem; }

/* Hero */
.hero {
    background: linear-gradient(135deg, #101a33 0%, #1b2a55 55%, #2f2470 100%);
    color: #eaf0ff;
    border-radius: 16px;
    padding: 2.6rem 2rem;
    margin: 0 0 2rem;
    box-shadow: var(--shadow);
}
.hero h1 { margin: 0 0 .6rem; color: #fff; }
.hero p { color: #c4d0f0; font-size: 1.1rem; margin: 0 0 1.3rem; max-width: 640px; }
.hero .actions { display: flex; gap: .7rem; flex-wrap: wrap; }
.btn {
    display: inline-block;
    padding: .6rem 1.1rem;
    border-radius: 9px;
    font-weight: 600;
    font-size: .95rem;
    border: 1px solid transparent;
}
.btn.primary { background: #fff; color: #16233f; }
.btn.primary:hover { background: #eaf0ff; text-decoration: none; }
.btn.ghost { border-color: rgba(255,255,255,.4); color: #eaf0ff; }
.btn.ghost:hover { background: rgba(255,255,255,.1); text-decoration: none; }

/* In-page TOC */
.toc {
    position: sticky;
    top: calc(var(--topbar-h) + 1.5rem);
    align-self: start;
    font-size: .88rem;
    border-left: 1px solid var(--border);
    padding-left: 1.1rem;
    max-height: calc(100vh - var(--topbar-h) - 3rem);
    overflow-y: auto;
}
.toc strong { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin-bottom: .6rem; }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li a { display: block; padding: .22rem 0; color: var(--text-muted); }
.toc li a:hover { color: var(--primary); text-decoration: none; }
.toc li.sub a { padding-left: .9rem; font-size: .84rem; }

/* Definition list for reference */
dl.api { margin: 1rem 0; }
dl.api dt { font-family: var(--mono); font-size: .9rem; font-weight: 600; margin-top: 1rem; color: var(--primary-dark); }
dl.api dd { margin: .2rem 0 0; color: var(--text-muted); }

/* Footer */
.site-footer {
    border-top: 1px solid var(--border);
    padding: 1.6rem clamp(1.2rem, 4vw, 3.5rem);
    color: var(--text-muted);
    font-size: .88rem;
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

kbd {
    font-family: var(--mono);
    font-size: .8em;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 6px;
    padding: .05em .45em;
}

/* -------------------------------------------------------------- Responsive */
@media (max-width: 1080px) {
    .content.has-toc { grid-template-columns: minmax(0, 1fr); }
    .toc { display: none; }
}
@media (max-width: 860px) {
    .layout { grid-template-columns: 1fr; }
    .menu-toggle { display: inline-block; }
    .topbar nav { display: none; }
    .sidebar {
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        width: 82%;
        max-width: 320px;
        height: calc(100vh - var(--topbar-h));
        transform: translateX(-102%);
        transition: transform .22s ease;
        z-index: 45;
        box-shadow: var(--shadow);
    }
    body.nav-open .sidebar { transform: translateX(0); }
    body.nav-open::after {
        content: "";
        position: fixed; inset: var(--topbar-h) 0 0 0;
        background: rgba(10,15,25,.35); z-index: 44;
    }
}

/* Print */
@media print {
    .topbar, .sidebar, .toc, .menu-toggle { display: none; }
    .layout, .content { display: block; }
}

/* Dark mode: opt-in via the OS, light stays the default look */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0d1017;
        --surface: #151a23;
        --surface-2: #1c222d;
        --border: #262d3a;
        --text: #e6e9ef;
        --text-muted: #9aa6b6;
        --code-bg: #1a2130;
        --shadow: 0 1px 2px rgba(0,0,0,.4);
    }
    :root:not([data-theme="light"]) .topbar { background: rgba(21,26,35,.9); }
    :root:not([data-theme="light"]) .topbar nav a.active,
    :root:not([data-theme="light"]) .sidebar li a.active { background: #1b2b4d; color: #9cc0ff; }
    :root:not([data-theme="light"]) .note { background: #14213b; border-color: #1f3a68; }
    :root:not([data-theme="light"]) .warn { background: #33240f; border-color: #5c421c; }
    :root:not([data-theme="light"]) .tip  { background: #10281a; border-color: #1e4d33; }
    :root:not([data-theme="light"]) .btn.primary { background: #eaf0ff; }
}

/* ==========================================================================
   Recherche + sélecteur de langue (ajouts)
   ========================================================================== */

/* Barre de recherche dans le header */
.search {
    position: relative;
    margin-left: auto;
    display: flex;
    align-items: center;
}
.topbar nav + .search, .topbar .search { margin-left: .5rem; }
.search input {
    width: 200px;
    max-width: 40vw;
    padding: .42rem .7rem .42rem 2rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237a8698' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") .55rem center/15px no-repeat;
    font-size: .9rem;
    color: var(--text);
    outline: none;
    transition: width .15s ease, border-color .15s ease;
}
.search input:focus { border-color: var(--primary); width: 260px; background-color: var(--surface); }
.search-results {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: min(460px, 92vw);
    max-height: 60vh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 30px rgba(16,24,40,.18);
    z-index: 60;
    display: none;
    padding: .4rem;
}
.search-results.open { display: block; }
.search-results .sr-item { display: block; padding: .55rem .7rem; border-radius: 8px; color: var(--text); }
.search-results .sr-item:hover, .search-results .sr-item.active { background: var(--surface-2); text-decoration: none; }
.search-results .sr-title { font-weight: 600; font-size: .92rem; }
.search-results .sr-crumb { font-size: .74rem; color: var(--primary); text-transform: uppercase; letter-spacing: .04em; }
.search-results .sr-snippet { font-size: .82rem; color: var(--text-muted); margin-top: .15rem; }
.search-results .sr-empty { padding: .8rem .7rem; color: var(--text-muted); font-size: .9rem; }
.search-results mark { background: #fff2b8; color: inherit; border-radius: 3px; padding: 0 1px; }

/* Sélecteur de langue */
.lang-toggle {
    margin-left: .5rem;
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .38rem .6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-muted);
    font-size: .85rem;
    font-weight: 600;
    white-space: nowrap;
}
.lang-toggle:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }

/* Raccourci clavier "/" pour la recherche */
kbd.kbd-hint {
    position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
    pointer-events: none; opacity: .6; font-size: .68rem;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .search-results mark { background: #6b5d1e; color: #fff; }
}

@media (max-width: 860px) {
    .search input { width: 130px; }
    .search input:focus { width: 150px; }
    .lang-toggle { padding: .35rem .5rem; }
}
