/* ─────────────────────────────────────────────────────────────────────────────
   site.css — shared styles for base-reality.org

   Everything here was previously duplicated inline across the eight pages.
   Page-level <style> blocks still hold whatever is genuinely page-specific
   (article prose, the 500 particle field, the homepage departure board) and
   load after this file, so a page can still override any rule below.
   ───────────────────────────────────────────────────────────────────────────── */

/* ── Design tokens ────────────────────────────────────────────────────────── */

:root {
    --bg-color: #fcfcfc;
    --text-main: #111827;
    --text-muted: #4b5563;
    --accent: #7f1d1d;
    --border-color: #111827;
}

body.dark {
    --bg-color: #0f172a;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #f8fafc;
}

/* ── Dark mode overrides for the Tailwind utilities the pages use ─────────── */

body.dark { background-color: var(--bg-color); color: var(--text-main); }
body.dark header { background-color: var(--bg-color) !important; }
body.dark footer { background-color: var(--bg-color) !important; }
body.dark .bg-white { background-color: #1e293b !important; }
body.dark .bg-gray-900 { background-color: #0f172a !important; }
body.dark .text-gray-900 { color: #f8fafc !important; }
body.dark .text-gray-700 { color: #cbd5e1 !important; }
body.dark .text-gray-600 { color: #94a3b8 !important; }
/* These three previously mapped to #64748b / #475569, which land at 3.75:1 and
   2.36:1 against the dark background — below the WCAG AA 4.5:1 floor for body
   text. Raised to the muted and prose tones, which clear it at 6.96:1 and
   12.02:1. */
body.dark .text-gray-500 { color: #94a3b8 !important; }
body.dark .text-gray-400 { color: #94a3b8 !important; }
body.dark .text-gray-300 { color: #cbd5e1 !important; }
body.dark .text-white { color: #f8fafc !important; }
body.dark .border-gray-900 { border-color: #f8fafc !important; }
body.dark .border-gray-200 { border-color: #334155 !important; }
body.dark .nav-border { border-color: var(--border-color); }

/* ── Base ─────────────────────────────────────────────────────────────────── */

html {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4, h5, .editorial-text { font-family: 'Playfair Display', serif; }

.border-t-thick { border-top: 3px solid var(--border-color); }
.border-b-thick { border-bottom: 3px solid var(--border-color); }
.nav-border { border-bottom: 1px solid var(--border-color); }

/* ── Theme switch ─────────────────────────────────────────────────────────── */

.switch-container { display: flex; align-items: center; margin-left: 2rem; padding-bottom: 0.25rem; }

/* Below md the header stacks and the nav cluster spans the full width, so the
   desktop gutter would push the toggle off-screen. */
@media (max-width: 767px) {
    .switch-container { margin-left: 0; }
}

.switch { font-size: 10px; position: relative; display: inline-block; width: 1.2em; height: 3.3em; }
.switch .chk { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 5px; }
.slider:before { position: absolute; content: ""; height: .5em; width: 2.4em; border-radius: 5px; left: -0.6em; top: 0.2em; background-color: white; box-shadow: 0 6px 7px rgba(0,0,0,0.3); transition: .4s; }
.slider:before, .slider:after { content: ""; display: block; }
.slider:after { background: linear-gradient(transparent 50%, rgba(255, 255, 255, 0.15) 0) 0 50% / 50% 100%, repeating-linear-gradient(90deg,rgb(255, 255, 255) 0,rgb(255, 255, 255),rgb(255, 255, 255) 20%,rgb(255, 255, 255) 20%,rgb(255, 255, 255) 40%) 0 50% / 50% 100%, radial-gradient(circle at 50% 50%,rgb(255, 255, 255) 25%, transparent 26%); background-repeat: no-repeat; border: 0.25em solid transparent; border-left: 0.4em solid #ffffff; border-right: 0 solid transparent; transition: border-left-color 0.1s 0.3s ease-out, transform 0.3s ease-out; transform: translateX(-22.5%) rotate(90deg); transform-origin: 25% 50%; position: relative; top: 0.5em; left: 0.55em; width: 2em; height: 1em; box-sizing: border-box; }
.chk:checked + .slider { background-color: var(--accent); }
.chk:focus + .slider { box-shadow: 0 0 1px var(--accent); }
.chk:checked + .slider:before { transform: translateY(2.3em); }
.chk:checked + .slider:after { transform: rotateZ(90deg) rotateY(180deg) translateY(0.45em) translateX(-1.4em); }

/* ── Scroll progress ──────────────────────────────────────────────────────── */

#scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0;
    background: var(--accent);
    z-index: 60;
    transition: width 0.1s linear;
    pointer-events: none;
}

/* ── Back to top ──────────────────────────────────────────────────────────── */

#back-to-top {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 2.75rem;
    height: 2.75rem;
    background: var(--bg-color);
    border: 1.5px solid var(--border-color);
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transform: translateY(0.5rem);
    transition: opacity 0.25s ease, transform 0.25s ease, background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    z-index: 55;
}
#back-to-top.visible { opacity: 1; pointer-events: auto; transform: translateY(0); }
#back-to-top:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Contact ──────────────────────────────────────────────────────────────── */

#contact-fab {
    position: fixed;
    bottom: 1.5rem;
    left: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.9rem;
    background: var(--bg-color);
    border: 1.5px solid var(--border-color);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-decoration: none;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    z-index: 55;
}
#contact-fab:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
#contact-fab .contact-label { display: inline; }

@media (max-width: 640px) {
    #contact-fab { padding: 0.6rem; }
    #contact-fab .contact-label { display: none; }
}

/* ── Search ───────────────────────────────────────────────────────────────── */

#search-toggle {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    transition: color 0.2s;
}
#search-toggle:hover { color: var(--accent); }

#search-overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.55);
    z-index: 100;
    display: none;
    padding: 12vh 1rem 1rem;
    justify-content: center;
    align-items: flex-start;
}
#search-overlay.open { display: flex; }

#search-panel {
    width: 100%;
    max-width: 40rem;
    background: var(--bg-color);
    border: 1.5px solid var(--border-color);
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}

#search-input {
    width: 100%;
    padding: 1rem 1.25rem;
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    outline: none;
}
#search-input::placeholder { color: var(--text-muted); }

#search-results { overflow-y: auto; }
#search-results li { border-bottom: 1px solid rgba(128, 128, 128, 0.2); }
#search-results li:last-child { border-bottom: none; }
#search-results a {
    display: block;
    padding: 0.9rem 1.25rem;
    text-decoration: none;
    color: var(--text-main);
    transition: background 0.15s ease;
}
#search-results a:hover,
#search-results li.active a { background: rgba(127, 29, 29, 0.08); }
#search-results .result-title { font-family: 'Playfair Display', serif; font-size: 1rem; }
#search-results .result-kicker {
    display: block;
    font-size: 0.65rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}
#search-results .result-snippet { display: block; font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }
#search-empty { padding: 1.25rem; color: var(--text-muted); font-size: 0.85rem; }
#search-hint {
    padding: 0.6rem 1.25rem;
    border-top: 1px solid rgba(128, 128, 128, 0.2);
    font-size: 0.65rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* ── Storage consent notice ───────────────────────────────────────────────── */

#consent-banner {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    background: var(--bg-color);
    border-top: 3px solid var(--border-color);
    padding: 1.25rem 1.5rem;
    display: none;
    gap: 1.25rem;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.08);
}
#consent-banner.show { display: flex; }
#consent-text {
    font-size: 0.8rem;
    line-height: 1.6;
    color: var(--text-main);
    max-width: 62ch;
}
#consent-text a { color: var(--accent); text-decoration: underline; }
#consent-actions { display: flex; gap: 0.6rem; flex-shrink: 0; }
#consent-banner button {
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 0.65rem 1.1rem;
    border: 1.5px solid var(--border-color);
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
#consent-banner button:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
#consent-accept { background: var(--border-color); color: var(--bg-color); }

@media (max-width: 640px) {
    #consent-banner { padding: 1rem; }
    #consent-actions { width: 100%; }
    #consent-banner button { flex: 1; }
}

/* ── Loading skeletons ────────────────────────────────────────────────────── */

.skeleton {
    background: linear-gradient(90deg,
        rgba(128, 128, 128, 0.10) 25%,
        rgba(128, 128, 128, 0.20) 37%,
        rgba(128, 128, 128, 0.10) 63%);
    background-size: 400% 100%;
    animation: skeletonShimmer 1.4s ease-in-out infinite;
}
.skeleton-line { height: 0.9rem; margin-bottom: 0.75rem; }
.skeleton-line.short { width: 40%; }
.skeleton-line.medium { width: 70%; }
.skeleton-block { height: 12rem; }

@keyframes skeletonShimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

/* ── Collapsible sections (reference lists, FAQ) ──────────────────────────── */

.br-details { border-top: 1px solid var(--border-color); margin-top: 3rem; }
.br-details > summary {
    cursor: pointer;
    list-style: none;
    padding: 1rem 0;
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.br-details > summary::-webkit-details-marker { display: none; }
.br-details > summary::after { content: "+"; font-size: 1rem; }
.br-details[open] > summary::after { content: "−"; }
.br-details > summary:hover { color: var(--accent); }

/* ── Accessibility: honour reduced-motion ─────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
    .skeleton { animation: none; }
    #scroll-progress { transition: none; }
}

/* ── Print ────────────────────────────────────────────────────────────────── */

@media print {
    /* Chrome/Safari drop background colours by default; force the page to a
       clean light ground regardless of the reader's theme choice. */
    body,
    body.dark {
        background: #fff !important;
        color: #000 !important;
        font-size: 11pt;
    }
    body.dark * { color: #000 !important; background-color: transparent !important; }

    header,
    footer,
    nav,
    .switch-container,
    #scroll-progress,
    #back-to-top,
    #contact-fab,
    #search-toggle,
    #search-overlay,
    #glossary-tooltip,
    .series-banner,
    .no-print {
        display: none !important;
    }

    main, #main-content { max-width: 100% !important; padding: 0 !important; margin: 0 !important; }

    /* Long-form essays are the reason this stylesheet exists: keep headings
       with their text and never orphan a line of an argument. */
    h1, h2, h3, h4 { page-break-after: avoid; break-after: avoid; }
    p, li, blockquote { orphans: 3; widows: 3; }
    figure, table, .chart-container { page-break-inside: avoid; break-inside: avoid; }

    /* A printed page has no hyperlinks, so print the destination. */
    .article-body a[href^="http"]::after,
    .references-section a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 9pt;
        word-break: break-all;
    }

    /* Reference lists must print in full even when collapsed on screen. */
    .br-details { display: block !important; }
    .br-details > summary { display: none !important; }
    details:not([open]) > *:not(summary) { display: revert !important; }

    /* Glossary terms lose their tooltip, so surface the definition inline. */
    .glossary-term { border-bottom: none !important; }
    .glossary-term::after { content: " [" attr(data-def) "]"; font-size: 9pt; font-style: italic; }

    a { text-decoration: none !important; }
    img, canvas { max-width: 100% !important; page-break-inside: avoid; }
}
