/* ==========================================================================
   Driftless Science — Field Guide design system
   Translated from the design comps (Direction C). Sage + clay on warm paper.
   ========================================================================== */

:root {
    --sage: #5b7553;
    --sage-soft: #eef2e8;
    --clay: #b5623c;
    --clay-soft: #f6ece4;
    --paper: #faf7f0;
    --ink: #23281f;
    --body: #2a2f29;
    --muted: #5c6157;
    --faint: #9a958a;
    --border: #e3ddd0;
    --border-soft: #eee6d8;
    --dark: #23281f;

    /* Surfaces (overridden in dark mode) */
    --surface: #fff;
    --surface-bar: #f7f3ea;
    --stage-bg: #fbf9f3;
    --stage-dot-rgb: 91, 117, 83;
    --header-bg: rgba(250, 247, 240, 0.88);
    --lab-no: #bcae8f;
    --dots: #d5cdba;

    --serif: 'Newsreader', Georgia, 'Times New Roman', serif;
    --sans: 'Public Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;

    --wrap: 1180px;
}

/* Dark theme — applied on explicit opt-in or by system preference (unless the
   user has explicitly chosen light). Surfaces + ink/border tokens are remapped;
   the warm dark band/footer keep --dark. */
:root[data-theme="dark"] {
    --sage: #8aa67f;
    --sage-soft: #2b3326;
    --clay: #d68a63;
    --clay-soft: #3a2c23;
    --paper: #15170f;
    --ink: #f1efe6;
    --body: #d9dccf;
    --muted: #aab0a1;
    --faint: #898f7f;
    --border: #34392c;
    --border-soft: #2a2f23;
    --dark: #101208;

    --surface: #1d2018;
    --surface-bar: #242820;
    --stage-bg: #1a1d15;
    --stage-dot-rgb: 138, 166, 127;
    --header-bg: rgba(21, 23, 15, 0.85);
    --lab-no: #6f7563;
    --dots: #3c4233;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --sage: #8aa67f;
        --sage-soft: #2b3326;
        --clay: #d68a63;
        --clay-soft: #3a2c23;
        --paper: #15170f;
        --ink: #f1efe6;
        --body: #d9dccf;
        --muted: #aab0a1;
        --faint: #898f7f;
        --border: #34392c;
        --border-soft: #2a2f23;
        --dark: #101208;

        --surface: #1d2018;
        --surface-bar: #242820;
        --stage-bg: #1a1d15;
        --stage-dot-rgb: 138, 166, 127;
        --header-bg: rgba(21, 23, 15, 0.85);
        --lab-no: #6f7563;
        --dots: #3c4233;
    }
}

/* Accent helpers — set per subject via .accent-sage / .accent-clay */
.accent-sage { --accent: var(--sage); --accent-soft: var(--sage-soft); }
.accent-clay { --accent: var(--clay); --accent-soft: var(--clay-soft); }
.accent-sage-text { color: var(--sage); }
.accent-clay-text { color: var(--clay); }

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--body);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a { color: inherit; }

.main-content { flex: 1 0 auto; }

em { font-style: italic; }

/* ---------- Header ---------------------------------------------------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--header-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}

.site-header-inner {
    max-width: var(--wrap);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 40px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 9px;
    background: var(--sage);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 17px;
    flex-shrink: 0;
}

.brand-mark-sm { width: 34px; height: 34px; border-radius: 8px; font-size: 15px; }

.brand-name {
    font-family: var(--serif);
    font-size: 21px;
    color: var(--ink);
}

.site-nav {
    display: flex;
    gap: 28px;
    font-size: 14px;
    font-weight: 600;
}

.site-nav a {
    color: var(--muted);
    text-decoration: none;
}

.site-nav a:hover { color: var(--ink); }

.header-right {
    display: flex;
    align-items: center;
    gap: 24px;
}

.theme-toggle {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    width: 36px;
    height: 36px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.theme-toggle:hover { color: var(--ink); border-color: var(--faint); }

/* Show the right icon for the active theme (sun in dark, moon in light). */
.theme-toggle .fa-sun { display: none; }
.theme-toggle .fa-moon { display: inline-block; }
:root[data-theme="dark"] .theme-toggle .fa-sun { display: inline-block; }
:root[data-theme="dark"] .theme-toggle .fa-moon { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .fa-sun { display: inline-block; }
    :root:not([data-theme="light"]) .theme-toggle .fa-moon { display: none; }
}

/* ---------- Hero ------------------------------------------------------ */
.hero {
    max-width: var(--wrap);
    margin: 0 auto;
    padding: 64px 40px 50px;
    display: grid;
    grid-template-columns: 1.45fr 1fr;
    gap: 48px;
    align-items: center;
}

.eyebrow {
    letter-spacing: 0.16em;
    text-transform: uppercase;
    font-size: 12px;
    color: var(--sage);
    font-weight: 700;
    margin: 0 0 18px;
}

.hero-title {
    font-family: var(--serif);
    font-weight: 400;
    font-size: 52px;
    line-height: 1.1;
    color: var(--ink);
    margin: 0;
}

.hero-title em { color: var(--clay); }

.hero-lead {
    font-size: 16px;
    line-height: 1.6;
    color: var(--muted);
    margin: 22px 0 0;
    max-width: 520px;
}

.hero-stats {
    display: flex;
    gap: 28px;
    margin-top: 30px;
}

.stat-divider { border-left: 1px solid var(--border); padding-left: 28px; }
.stat-num { font-family: var(--serif); font-size: 28px; color: var(--ink); }
.stat-label {
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--faint);
    font-weight: 600;
}

.hero-grid {
    background: var(--sage-soft);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 30px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
}

.hero-chip {
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 24px;
}

.hero-chip-filled { background: var(--accent); color: #fff; }

/* ---------- Section headers ------------------------------------------- */
.catalog {
    max-width: var(--wrap);
    margin: 0 auto;
    padding: 18px 40px 0;
    scroll-margin-top: 80px;
}

.catalog + .catalog { padding-top: 40px; }

.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    padding-bottom: 14px;
    margin-bottom: 28px;
}

.section-head-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.section-head-title i { font-size: 17px; }

.section-head-title h2 {
    font-family: var(--serif);
    font-weight: 400;
    font-size: 28px;
    color: var(--ink);
    margin: 0;
}

.section-head-no {
    font-size: 12px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--faint);
    font-weight: 600;
}

/* ---------- Lab cards ------------------------------------------------- */
.lab-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
}

.lab-card {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 8px;
    padding: 22px;
    display: flex;
    flex-direction: column;
    height: 100%;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.18s ease, transform 0.18s ease, border-color 0.18s ease;
}

.lab-card:hover {
    box-shadow: 0 12px 26px rgba(50, 60, 40, 0.1);
    transform: translateY(-3px);
    border-color: var(--accent);
}

.lab-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 18px;
}

.lab-icon {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--accent-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 23px;
    flex-shrink: 0;
}

.lab-no {
    font-family: var(--serif);
    font-style: italic;
    font-size: 15px;
    color: var(--lab-no);
}

.lab-card-title {
    font-family: var(--serif);
    font-weight: 500;
    font-size: 21px;
    color: var(--ink);
    margin: 0 0 8px;
}

.lab-card-blurb {
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--muted);
    margin: 0 0 18px;
    flex: 1;
}

.lab-card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid var(--border-soft);
    padding-top: 14px;
}

.lab-type {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--faint);
}

.lab-open { font-weight: 700; font-size: 13px; color: var(--clay); }

/* ---------- About band ------------------------------------------------ */
.about {
    max-width: var(--wrap);
    margin: 56px auto 0;
    padding: 0 40px;
    scroll-margin-top: 80px;
}

.about-band {
    background: var(--dark);
    border-radius: 12px;
    padding: 44px 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 40px;
    flex-wrap: wrap;
}

.about-copy { max-width: 560px; }

.about-copy h2 {
    font-family: var(--serif);
    font-weight: 400;
    font-size: 30px;
    color: #f4f0e6;
    margin: 0 0 12px;
}

.about-copy h2 em { color: #d99a6c; }

.about-copy p {
    font-size: 15px;
    line-height: 1.6;
    color: #b6bcaf;
    margin: 0;
}

.btn-clay {
    flex-shrink: 0;
    background: var(--clay);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    padding: 14px 26px;
    border-radius: 8px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 9px;
}

.btn-clay:hover { background: #a2562f; }

/* ---------- Footer ---------------------------------------------------- */
.site-footer {
    background: var(--dark);
    margin-top: 56px;
    flex-shrink: 0;
}

.site-footer-top {
    max-width: var(--wrap);
    margin: 0 auto;
    padding: 42px 40px 30px;
    display: flex;
    justify-content: space-between;
    gap: 40px;
    flex-wrap: wrap;
}

.footer-brand { max-width: 300px; }

.footer-brand-row {
    display: flex;
    align-items: center;
    gap: 11px;
    margin-bottom: 12px;
}

.footer-brand-name {
    font-family: var(--serif);
    font-size: 19px;
    color: #f4f0e6;
}

.footer-tagline {
    font-size: 13px;
    line-height: 1.6;
    color: #9aa090;
    margin: 0;
}

.footer-cols { display: flex; gap: 64px; flex-wrap: wrap; }

.footer-col-title {
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #6f7568;
    font-weight: 700;
    margin-bottom: 14px;
}

.footer-col a,
.footer-col .footer-muted {
    display: block;
    font-size: 14px;
    text-decoration: none;
    margin-bottom: 9px;
}

.footer-col a { color: #c9cdc0; }
.footer-col a:hover { color: #fff; }
.footer-col .footer-muted { color: #9aa090; }

.site-footer-bottom { border-top: 1px solid #343a2e; }

.site-footer-bottom-inner {
    max-width: var(--wrap);
    margin: 0 auto;
    padding: 16px 40px;
    font-size: 12px;
    color: #787e70;
}

/* ==========================================================================
   Lab Viewer
   ========================================================================== */
.lv-wrap {
    max-width: var(--wrap);
    margin: 0 auto;
    padding: 0 40px;
}

.lv-breadcrumb { padding: 28px 0 0; }

.lv-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
}

.lv-back:hover { color: var(--ink); }

.lv-crumb { font-size: 13px; color: var(--faint); margin-top: 14px; }
.lv-crumb-subject { color: var(--muted); }
.lv-crumb-no { font-family: var(--serif); font-style: italic; color: var(--lab-no); }

.lv-title-block {
    padding: 18px 0 8px;
    display: flex;
    align-items: flex-start;
    gap: 22px;
}

.lv-title-icon {
    flex-shrink: 0;
    width: 66px;
    height: 66px;
    border-radius: 50%;
    background: var(--accent-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 28px;
}

.lv-tags {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.lv-tag-subject {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #fff;
    background: var(--accent);
    padding: 4px 10px;
    border-radius: 5px;
}

.lv-tag-type {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--faint);
    border: 1px solid var(--border);
    padding: 3px 9px;
    border-radius: 5px;
}

.lv-title {
    font-family: var(--serif);
    font-weight: 400;
    font-size: 42px;
    line-height: 1.08;
    color: var(--ink);
    margin: 0;
}

.lv-lead {
    font-size: 16px;
    line-height: 1.55;
    color: var(--muted);
    margin: 12px 0 0;
    max-width: 640px;
}

.lv-body {
    padding: 28px 0 0;
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 32px;
    align-items: start;
}

/* Stage */
.lv-stage {
    position: relative;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
}

.lv-stage-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border-soft);
    background: var(--surface-bar);
}

.lv-dots { display: flex; align-items: center; gap: 7px; }
.lv-dots span { width: 11px; height: 11px; border-radius: 50%; background: var(--dots); }

.lv-stage-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--faint);
    letter-spacing: 0.04em;
}

.lv-expand {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    color: #bcb6a8;
    padding: 0;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.lv-expand:hover { color: var(--muted); }

.lv-expand-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.lv-fs-hint {
    position: absolute;
    top: 46px;
    right: 14px;
    background: rgba(0, 0, 0, 0.76);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    font-family: var(--sans);
    padding: 6px 11px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s;
    z-index: 10;
}

.lv-fs-hint::before {
    content: '';
    position: absolute;
    top: -5px;
    right: 10px;
    border-width: 0 5px 5px;
    border-style: solid;
    border-color: transparent transparent rgba(0, 0, 0, 0.76);
}

.lv-fs-hint.is-visible { opacity: 1; }

.lv-stage-area {
    aspect-ratio: 16 / 10;
    background-color: var(--stage-bg);
    background-image: radial-gradient(rgba(var(--stage-dot-rgb), 0.07) 1px, transparent 1px);
    background-size: 22px 22px;
}

.lv-stage-area.is-live {
    aspect-ratio: 16 / 10;
    background: var(--surface);
}

.lv-placeholder {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 18px;
    padding: 20px;
}

.lv-placeholder-icon {
    width: 84px;
    height: 84px;
    border-radius: 50%;
    background: var(--accent-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 36px;
}

.lv-placeholder-title { font-family: var(--serif); font-size: 20px; color: var(--ink); margin: 0 0 6px; }
.lv-placeholder-note { font-size: 13px; color: var(--faint); margin: 0; }

.lv-version-group {
    display: flex;
    gap: 8px;
}

.lv-version {
    background: var(--surface);
    color: var(--muted);
    border: 1.5px solid var(--border);
    font-family: var(--sans);
    font-weight: 600;
    font-size: 13px;
    padding: 7px 16px;
    border-radius: 20px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.lv-version:hover { border-color: var(--accent); color: var(--accent); }

.lv-version.is-active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

.lv-launch-group {
    margin-top: 4px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.lv-launch {
    background: var(--accent);
    color: #fff;
    border: none;
    font-family: var(--sans);
    font-weight: 700;
    font-size: 14px;
    padding: 12px 26px;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 9px;
}

.lv-launch:hover { filter: brightness(0.94); }


.lv-frame { width: 100%; height: 100%; border: 0; display: block; }

.lv-stage:fullscreen,
.lv-stage:-webkit-full-screen { background: var(--surface); display: flex; flex-direction: column; }
.lv-stage:fullscreen .lv-stage-area,
.lv-stage:-webkit-full-screen .lv-stage-area { flex: 1 1 auto; aspect-ratio: auto; min-height: 0; }
.lv-stage:fullscreen .lv-frame,
.lv-stage:-webkit-full-screen .lv-frame { height: 100%; }

/* CSS pseudo-fullscreen fallback (iOS Safari has no element Fullscreen API). */
.lv-stage.is-pseudo-full {
    position: fixed;
    inset: 0;
    z-index: 1000;
    width: 100%;
    height: 100%;
    height: 100dvh;
    max-width: none;
    border: 0;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    background: var(--surface);
}

.lv-stage.is-pseudo-full .lv-stage-area {
    flex: 1 1 auto;
    aspect-ratio: auto;
    min-height: 0;
}

.lv-stage.is-pseudo-full .lv-frame { height: 100%; }

body.lv-noscroll { overflow: hidden; }

/* Sidebar */
.lv-aside { display: flex; flex-direction: column; gap: 18px; }

.lv-panel {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 12px;
    padding: 22px;
}

.lv-panel h2 {
    font-family: var(--serif);
    font-weight: 500;
    font-size: 18px;
    color: var(--ink);
    margin: 0 0 10px;
}

.lv-panel p { font-size: 13.5px; line-height: 1.6; color: var(--muted); margin: 0; }

.lv-row {
    display: flex;
    justify-content: space-between;
    font-size: 13.5px;
    padding: 7px 0;
    border-bottom: 1px solid var(--border-soft);
}

.lv-row-last { border-bottom: none; }
.lv-row span:first-child { color: var(--faint); }
.lv-row span:last-child { color: var(--body); font-weight: 600; }

/* Related */
.lv-related { margin: 48px 0 0; }
.lv-related .section-head-title h2 {
    font-family: var(--serif);
    font-weight: 400;
    font-size: 24px;
    color: var(--ink);
    margin: 0;
}
.lv-viewall { font-size: 13px; font-weight: 700; color: var(--clay); text-decoration: none; }

.lv-related-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
}

.lv-related-card {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 8px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.18s ease, transform 0.18s ease;
}

.lv-related-card:hover {
    box-shadow: 0 10px 22px rgba(50, 60, 40, 0.1);
    transform: translateY(-2px);
}

.lv-related-card .lab-icon { width: 48px; height: 48px; font-size: 20px; }

.lv-related-card h3 {
    font-family: var(--serif);
    font-weight: 500;
    font-size: 17px;
    color: var(--ink);
    margin: 0 0 2px;
}

.lv-related-meta { font-size: 12px; color: var(--faint); }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 900px) {
    .hero { grid-template-columns: 1fr; }
    .lab-grid,
    .lv-related-grid { grid-template-columns: 1fr 1fr; }
    .lv-body { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
    .site-nav { display: none; }
}

@media (max-width: 640px) {
    .site-header-inner,
    .hero,
    .catalog,
    .about,
    .lv-wrap { padding-left: 22px; padding-right: 22px; }
    .lab-grid,
    .lv-related-grid { grid-template-columns: 1fr; }
    .hero-stats { flex-wrap: wrap; }
    .hero-title { font-size: 40px; }
    .lv-title { font-size: 32px; }
    .lv-title-block { flex-direction: column; gap: 14px; }
    .about-band { flex-direction: column; align-items: flex-start; }
}
