/* =========================================================================
   DET_ML Uncertainty — Manuscript Versions site
   Shared stylesheet for landing page and all sub-pages.
   Clean, scientific aesthetic. Print-friendly. Mobile-first responsive.
   ========================================================================= */

/* --- Design tokens ------------------------------------------------------- */
:root {
    --color-bg: #ffffff;
    --color-bg-alt: #f6f7f9;
    --color-bg-card: #fdfdfe;
    --color-text: #1a1a1a;
    --color-text-muted: #555;
    --color-text-light: #777;
    --color-border: #d9dce1;
    --color-border-light: #e8eaee;
    --color-accent: #1f4e79;       /* deep scientific blue */
    --color-accent-hover: #163a5c;
    --color-accent-soft: #eaf0f6;
    --color-link: #1f4e79;
    --color-link-visited: #5a3a8a;
    --color-code-bg: #f4f5f7;
    --color-code-text: #333;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", "PingFang SC", "Hiragino Sans GB",
                 "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas,
                 "Liberation Mono", monospace;
    --max-width: 960px;
    --max-width-wide: 1100px;
    --radius: 6px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* --- Reset / base -------------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- Layout primitives --------------------------------------------------- */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.25rem;
}

.container-wide {
    max-width: var(--max-width-wide);
    margin: 0 auto;
    padding: 0 1.25rem;
}

main {
    flex: 1 0 auto;
    padding: 2rem 0 3rem;
}

/* --- Site header (landing page) ----------------------------------------- */
.site-header {
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
    position: sticky;
    top: 0;
    z-index: 100;
}

.site-header__inner {
    max-width: var(--max-width-wide);
    margin: 0 auto;
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.site-header__brand {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-accent);
    text-decoration: none;
    white-space: nowrap;
}

.site-header__brand:hover {
    color: var(--color-accent-hover);
}

/* --- Language toggle ---------------------------------------------------- */
.lang-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.lang-toggle__btn {
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-text-muted);
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    line-height: 1.4;
}

.lang-toggle__btn:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.lang-toggle__btn.active {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #fff;
    font-weight: 600;
}

.lang-toggle__sep {
    color: var(--color-border);
    user-select: none;
}

/* --- Hero / project intro ------------------------------------------------ */
.hero {
    padding: 2.5rem 0 1.5rem;
}

.hero__title {
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 0.75rem;
    letter-spacing: -0.01em;
}

.hero__subtitle {
    font-size: 1rem;
    color: var(--color-text-muted);
    max-width: 70ch;
    line-height: 1.7;
}

/* --- Section headings ---------------------------------------------------- */
.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-text);
    margin: 2.5rem 0 1rem;
    padding-bottom: 0.4rem;
    border-bottom: 2px solid var(--color-border-light);
}

.section-title--first {
    margin-top: 0;
}

/* --- Card grid ----------------------------------------------------------- */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.25rem;
    margin: 1.5rem 0;
}

@media (min-width: 768px) {
    .card-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.15s, border-color 0.15s;
}

.card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--color-accent);
}

.card__version {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--color-accent);
    margin-bottom: 0.5rem;
}

.card__desc {
    font-size: 0.92rem;
    color: var(--color-text-muted);
    line-height: 1.6;
    margin-bottom: 1rem;
    flex-grow: 1;
}

.card__links {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.card__link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.88rem;
    color: var(--color-link);
    text-decoration: none;
    padding: 0.35rem 0.6rem;
    border-radius: 4px;
    border: 1px solid transparent;
    transition: background 0.15s, border-color 0.15s;
}

.card__link:hover {
    background: var(--color-accent-soft);
    border-color: var(--color-border);
    text-decoration: none;
}

.card__link:visited {
    color: var(--color-link-visited);
}

.card__link--whatsnew {
    color: var(--color-text-muted);
    font-style: italic;
    font-size: 0.85rem;
}

.card__link--whatsnew::before {
    content: "↳ ";
}

/* --- What's new list ----------------------------------------------------- */
.whatsnew-list {
    list-style: none;
    margin: 1rem 0;
    padding: 0;
}

.whatsnew-list li {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--color-border-light);
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem 1rem;
}

.whatsnew-list li:last-child {
    border-bottom: none;
}

.whatsnew-list__version {
    font-weight: 600;
    color: var(--color-accent);
    min-width: 5rem;
}

.whatsnew-list__links {
    display: inline-flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.whatsnew-list__links a {
    font-size: 0.88rem;
    color: var(--color-link);
    text-decoration: none;
}

.whatsnew-list__links a:hover {
    text-decoration: underline;
}

.whatsnew-list__links a:visited {
    color: var(--color-link-visited);
}

/* --- Site nav (sub-pages) ----------------------------------------------- */
.site-nav {
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    padding: 0.75rem 1.25rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.site-nav__inner {
    max-width: var(--max-width-wide);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.site-nav__home {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-accent);
    text-decoration: none;
    white-space: nowrap;
}

.site-nav__home:hover {
    color: var(--color-accent-hover);
}

.site-nav__links {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
}

.site-nav__links a {
    font-size: 0.88rem;
    color: var(--color-link);
    text-decoration: none;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    transition: background 0.15s;
}

.site-nav__links a:hover {
    background: var(--color-accent-soft);
}

.site-nav__links a:visited {
    color: var(--color-link-visited);
}

/* --- Article / manuscript body (sub-pages) ------------------------------- */
.article {
    max-width: 780px;
    margin: 0 auto;
    padding: 0 1rem;
}

.article h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin: 1.5rem 0 0.5rem;
    line-height: 1.3;
}

.article h2 {
    font-size: 1.3rem;
    font-weight: 600;
    margin: 2rem 0 0.75rem;
    color: var(--color-text);
}

.article h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 1.5rem 0 0.5rem;
    color: var(--color-text);
}

.article p {
    margin: 0.75rem 0;
    line-height: 1.75;
}

.article ul, .article ol {
    margin: 0.75rem 0;
    padding-left: 2rem;
}

.article li {
    margin: 0.3rem 0;
    line-height: 1.7;
}

/* --- Math / inline code -------------------------------------------------- */
.math, .math-inline {
    font-family: var(--font-mono);
    font-size: 0.95em;
}

code {
    font-family: var(--font-mono);
    font-size: 0.88em;
    background: var(--color-code-bg);
    color: var(--color-code-text);
    padding: 0.15em 0.35em;
    border-radius: 3px;
}

pre {
    font-family: var(--font-mono);
    background: var(--color-code-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius);
    padding: 1rem;
    overflow-x: auto;
    line-height: 1.5;
    font-size: 0.85rem;
}

pre code {
    background: none;
    padding: 0;
    border-radius: 0;
}

/* --- Tables (overflow-safe) --------------------------------------------- */
.table-wrap {
    max-width: 100%;
    overflow-x: auto;
    margin: 1rem 0;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius);
}

table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.9rem;
}

table thead {
    background: var(--color-bg-alt);
}

table th, table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border-light);
    white-space: nowrap;
}

table th {
    font-weight: 600;
    color: var(--color-text);
}

table td {
    color: var(--color-text-muted);
}

table tbody tr:hover {
    background: var(--color-accent-soft);
}

/* --- Figures ------------------------------------------------------------- */
.figure {
    margin: 1.5rem 0;
    text-align: center;
}

.figure img {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.figure figcaption {
    font-size: 0.85rem;
    color: var(--color-text-light);
    margin-top: 0.5rem;
    line-height: 1.5;
}

/* --- Site footer --------------------------------------------------------- */
.site-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-alt);
    padding: 1.5rem 1.25rem;
    text-align: center;
}

.site-footer__inner {
    max-width: var(--max-width-wide);
    margin: 0 auto;
    font-size: 0.82rem;
    color: var(--color-text-light);
    line-height: 1.6;
}

.site-footer__inner a {
    color: var(--color-link);
    text-decoration: none;
}

.site-footer__inner a:hover {
    text-decoration: underline;
}

/* --- Utility ------------------------------------------------------------- */
.lang-content {
    display: none;
}

.lang-content.active {
    display: block;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --- Mobile tuning ------------------------------------------------------- */
@media (max-width: 640px) {
    html { font-size: 15px; }

    .hero { padding: 1.5rem 0 1rem; }
    .hero__title { font-size: 1.4rem; }
    .hero__subtitle { font-size: 0.92rem; }

    .card-grid { grid-template-columns: 1fr; }

    .site-header__inner { flex-wrap: wrap; }
    .site-header__brand { font-size: 1rem; }

    .article h1 { font-size: 1.35rem; }
    .article h2 { font-size: 1.15rem; }

    .site-nav__inner { flex-direction: column; align-items: flex-start; }
    .site-nav__links { width: 100%; }
}

/* --- Print --------------------------------------------------------------- */
@media print {
    .site-header,
    .site-nav,
    .lang-toggle,
    .card__links,
    .whatsnew-list__links {
        display: none !important;
    }

    body {
        color: #000;
        background: #fff;
        font-size: 11pt;
        line-height: 1.5;
    }

    main { padding: 0; }

    .card {
        border: 1px solid #ccc;
        box-shadow: none;
        break-inside: avoid;
    }

    a {
        color: #000;
        text-decoration: underline;
    }

    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #555;
    }

    pre, .table-wrap, table {
        page-break-inside: avoid;
    }

    .figure img {
        border: none;
        box-shadow: none;
    }
}
