/* ====================================================================
 * blackCurrant demo site — base styles
 * Self-contained, no external fonts, no external images.
 * ==================================================================== */

:root {
    --bg:        #0a0e1a;
    --panel:     #131a2c;
    --panel-2:   #1a2238;
    --text:      #e6e9ef;
    --muted:     #8892a8;
    --accent:    #d946ef;
    --accent-2:  #06b6d4;
    --good:      #34d399;
    --bad:       #f87171;
    --border:    #1f2937;
    --max-w:     980px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html {
    height: 100%;
    /* Stop iOS Safari inflating text after orientation change. */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: radial-gradient(ellipse at top, rgba(217, 70, 239, 0.06), transparent 50%), var(--bg);
    color: var(--text);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    /* Use dynamic viewport height so mobile browser chrome doesn't clip. */
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    /* Long unbroken tokens (URLs, hashes) must never force a horizontal
       scrollbar on the whole page. */
    overflow-wrap: break-word;
}

/* Media never overflows its column on small screens. */
img, svg, video, canvas, iframe { max-width: 100%; height: auto; }

.container {
    width: 100%;
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 0 1.5rem;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
    background: var(--panel);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-size: 0.88em;
    color: var(--accent);
    font-family: "SF Mono", Menlo, Consolas, monospace;
}
pre code { background: none; padding: 0; color: var(--text); }
strong { color: var(--text); }

/* ── Header ──────────────────────────────────────────────────────────── */
.site-header, .admin-header {
    background: rgba(19, 26, 44, 0.8);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 10;
}
.admin-header { background: rgba(45, 26, 60, 0.85); border-bottom-color: var(--accent); }

.site-header .container, .admin-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}
.logo { font-weight: 800; font-size: 1.25rem; color: var(--text);  align-items: baseline; gap: 0.35rem; }
.logo:hover { text-decoration: none; }
.logo span { color: var(--accent); }
.logo .logo-suffix {
    color: var(--muted);
    font-weight: 600;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: var(--panel-2);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    border: 1px solid var(--border);
}

.nav { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.nav a {
    color: var(--muted);
    font-weight: 500;
    font-size: 0.95rem;
    padding: 0.25rem 0;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}
.nav a:hover, .nav a.is-active {
    color: var(--text);
    border-bottom-color: var(--accent);
    text-decoration: none;
}

/* ── Hamburger button (hidden on desktop, shown < 768px) ─────────────── */
.nav-burger {
    display: none;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid var(--border);
    background: var(--panel);
    border-radius: 8px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}
.nav-burger:hover { border-color: var(--accent); }
.nav-burger-bars,
.nav-burger-bars::before,
.nav-burger-bars::after {
    content: "";
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}
.nav-burger-bars { position: relative; }
.nav-burger-bars::before { position: absolute; left: 0; top: -6px; }
.nav-burger-bars::after  { position: absolute; left: 0; top: 6px; }
/* Open → morph the three bars into an X. */
.nav-open .nav-burger-bars { background: transparent; }
.nav-open .nav-burger-bars::before { transform: translateY(6px) rotate(45deg); }
.nav-open .nav-burger-bars::after  { transform: translateY(-6px) rotate(-45deg); }

/* ── Layout ──────────────────────────────────────────────────────────── */
.main {
    flex: 1;
    padding: 3rem 0 4rem;
}
.main > .container > section { margin-bottom: 3rem; }
.main > .container > section:last-child { margin-bottom: 0; }

/* ── Typography ──────────────────────────────────────────────────────── */
h1 { font-size: 2.5rem; margin-bottom: 1rem; font-weight: 800; letter-spacing: -0.02em; }
h1 strong { color: var(--accent); }
h2 { font-size: 1.5rem; margin: 2rem 0 1rem; font-weight: 700; }
p  { margin-bottom: 1rem; color: var(--muted); }
.lead { font-size: 1.125rem; color: var(--text); max-width: 65ch; }
.note { font-size: 0.92rem; opacity: 0.9; }

.badge {
    display: inline-block;
    background: rgba(6, 182, 212, 0.15);
    color: var(--accent-2);
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    margin-bottom: 1rem;
    letter-spacing: 0.04em;
}

/* ── Hero ────────────────────────────────────────────────────────────── */
.hero { padding: 1rem 0 1.5rem; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 0.65rem 1.4rem;
    background: var(--accent);
    color: #fff;
    border-radius: 6px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background 0.15s, transform 0.05s;
    text-decoration: none;
}
.btn:hover  { background: #b91dd0; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--panel); }
.btn + .btn { margin-left: 0.5rem; }

/* ── Feature list ────────────────────────────────────────────────────── */
.feature-list {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 0.75rem;
}
.feature-list li {
    background: var(--panel);
    padding: 1rem;
    border-radius: 8px;
    border-left: 3px solid var(--accent-2);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.feature-label { color: var(--text); font-weight: 500; }
.feature-source { font-size: 0.78rem; color: var(--muted); background: transparent; padding: 0; }

/* ── Anatomy grid ────────────────────────────────────────────────────── */
.anatomy-grid {
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 0.5rem;
    margin: 1.25rem 0;
}
.block {
    padding: 1rem 1.25rem;
    border-radius: 8px;
    border: 1px dashed var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.block-header { background: rgba(217, 70, 239, 0.08); }
.block-body   { background: rgba(6, 182, 212, 0.08);  padding: 2.5rem 1.25rem; }
.block-footer { background: rgba(136, 146, 168, 0.05); }
.block-tag {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--muted);
}
.block-header .block-tag { color: var(--accent); }
.block-body   .block-tag { color: var(--accent-2); }

/* ── Flow / cascade lists ────────────────────────────────────────────── */
.flow, .cascade { padding-left: 1.5rem; color: var(--muted); }
.flow li, .cascade li { margin-bottom: 0.4rem; }

/* ── Debug dashboard ─────────────────────────────────────────────────── */
.debug-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.debug-card-wide { grid-column: 1 / -1; }
.debug-dl { display: grid; grid-template-columns: 8.5rem 1fr; gap: 0.35rem 0.75rem; margin: 0; font-size: 0.88rem; }
.debug-dl dt { color: var(--muted); font-weight: 500; }
.debug-dl dd { margin: 0; color: var(--text); word-break: break-word; }
.debug-dl code, .debug-list code { font-size: 0.82rem; }
.debug-list { margin: 0; padding-left: 1.2rem; font-size: 0.88rem; }
.debug-list li { margin-bottom: 0.4rem; }
.debug-list strong + small { display: block; color: var(--muted); font-size: 0.78rem; }
.debug-headers th { white-space: nowrap; color: var(--muted); font-weight: 500; text-transform: none; letter-spacing: 0; }
.debug-headers td { word-break: break-all; }

/* ── Nav core-mode toggle ────────────────────────────────────────────── */
.nav-sep { color: var(--border); margin: 0 .15rem; }
.nav-toggle {
    margin-left: auto;
    padding: 0.15rem 0.55rem;
    border: 1px dashed var(--border);
    border-radius: 999px;
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted) !important;
    text-decoration: none;
}
.nav-toggle:hover { color: var(--accent) !important; border-color: var(--accent); }

/* ── File map ────────────────────────────────────────────────────────── */
.filemap pre {
    background: var(--panel);
    padding: 1rem 1.25rem;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.85rem;
    line-height: 1.55;
    color: var(--text);
    border: 1px solid var(--border);
}
.filemap-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    margin-bottom: 1.5rem;
}
.filemap-table th,
.filemap-table td {
    padding: 0.55rem 0.85rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.filemap-table th {
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    background: var(--panel);
}
.filemap-table tbody tr:hover { background: var(--panel-2); }
.filemap-table code { font-size: 0.82rem; }

/* ── Forms ───────────────────────────────────────────────────────────── */
.form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    max-width: 480px;
    margin-top: 1rem;
}
.form label {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    color: var(--text);
    font-weight: 500;
}
.form label span { font-size: 0.95rem; }
.form input, .form textarea {
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.65rem 0.8rem;
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form input:focus, .form textarea:focus {
    outline: none;
    border-color: var(--accent-2);
    box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.18);
}
.error { color: var(--bad); font-size: 0.85rem; font-weight: 400; }

.alert {
    padding: 0.85rem 1rem;
    border-radius: 6px;
    margin-bottom: 1.25rem;
    font-size: 0.95rem;
}
.alert-error { background: rgba(248, 113, 113, 0.12); color: var(--bad); border: 1px solid rgba(248, 113, 113, 0.3); }

/* ── Admin ───────────────────────────────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-top: 1.25rem;
}
.stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
    text-align: left;
}
.stat-value { font-size: 2rem; font-weight: 800; color: var(--accent); margin-bottom: 0.25rem; }
.stat-label { color: var(--muted); font-size: 0.9rem; }

/* ── Footer ──────────────────────────────────────────────────────────── */
.site-footer {
    background: var(--panel);
    border-top: 1px solid var(--border);
    padding: 1.5rem 0;
    color: var(--muted);
    font-size: 0.9rem;
}
.site-footer .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.site-footer .meta { color: var(--muted); margin: 0; }

/* ════════════════════════════════════════════════════════════════════
 * Responsive — mobile-first hardening.
 * Base styles above target desktop; these progressively adapt downward.
 * Breakpoints: 768 (tablet / large phone landscape), 600 (phone), 480 (small).
 * ════════════════════════════════════════════════════════════════════ */

/* ── Header: burger button left, logo centered, nav as dropdown ──────── */
@media (max-width: 768px) {
    .site-header { padding: 0.6rem 0; }

    /* 1fr | auto | 1fr → burger pinned left, logo dead-centre, right column
       balances. Nav drops to a full-width second row. */
    .site-header .container {
        display: grid;
        grid-template-columns: 1fr auto 1fr;
        align-items: center;
        gap: 0.5rem;
    }
    .nav-burger { display: inline-flex; grid-area: 1 / 1 / 2 / 2; justify-self: start; }
    .logo       { grid-area: 1 / 2 / 2 / 3; justify-self: center; }

    /* Collapsed by default; .nav-open on the header reveals it. */
    .nav {
        grid-area: 2 / 1 / 3 / 4;
        display: none;
        flex-direction: column;
        gap: 0;
        margin: 0.5rem -1.5rem 0;
        border-top: 1px solid var(--border);
        max-height: 70vh;
        overflow-y: auto;
    }
    .site-header.nav-open .nav { display: flex; }
    .nav a {
        font-size: 1rem;
        padding: 0.9rem 1.5rem;
        border-bottom: 1px solid var(--border);
        border-left: 3px solid transparent;   /* active indicator slot */
    }
    .nav a:hover,
    .nav a.is-active {
        color: var(--text);
        background: var(--panel);
        border-bottom-color: var(--border);
        border-left-color: var(--accent);
    }
    .nav-sep { display: none; }
    /* core-mode pill becomes a normal full-width row item */
    .nav-toggle { margin: 0.6rem 1.5rem; align-self: flex-start; }
}

/* ── Footer: stack the two lines, left-aligned ───────────────────────── */
@media (max-width: 600px) {
    .site-footer { padding: 1.25rem 0; }
    .site-footer .container {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.4rem;
    }

    h1 { font-size: 1.85rem; }
    h2 { font-size: 1.3rem; }
    .main { padding: 2rem 0 3rem; }
    .lead { font-size: 1.05rem; }

    /* Button rows: drop the sibling margin (it breaks on wrap) and let the
       buttons sit comfortably with their own spacing. */
    .btn { padding: 0.6rem 1.1rem; }
    .btn + .btn { margin-left: 0; }
    /* Any <p> holding multiple buttons becomes a wrapping flex row. */
    .hero p:has(.btn + .btn),
    p:has(.btn + .btn) { display: flex; flex-wrap: wrap; gap: 0.5rem; }

    /* Fixed-column definition lists (debug) stack label over value. */
    .debug-dl { grid-template-columns: 1fr; gap: 0.1rem 0; }
    .debug-dl dt { margin-top: 0.5rem; }
    .debug-dl dt:first-child { margin-top: 0; }
}

@media (max-width: 480px) {
    .container { padding: 0 1rem; }
    .ref-toc { padding-left: 1rem; padding-right: 1rem; margin-left: -1rem; margin-right: -1rem; }
    .nav { margin: 0 -1rem; padding-left: 1rem; padding-right: 1rem; }
    h1 { font-size: 1.6rem; }
}

/* ── Responsive tables (used on /features, /components, /debug, /about) ──
   Tables with code in cells overflow a phone viewport. Let each scroll
   horizontally inside its own box instead of blowing out the page. */
@media (max-width: 700px) {
    .ref-cheat table,
    .filemap-table,
    .cmp-table,
    .debug-headers {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        width: 100%;
    }
    /* Keep cell text wrapping where it must, but allow the table to scroll. */
    .ref-cheat td, .filemap-table td { white-space: normal; min-width: 14rem; }
}

/* ── Reference page (/features, /components) ────────────────────────── */

/* When a reference TOC is present on the page, let the site header scroll
   away normally so the TOC can rise into its spot and lock to the very top.
   :has() means we don't need a per-route body class. */
body:has(.ref-toc) .site-header { position: static; }

.ref-toc {
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 0.65rem 1.5rem;
    margin: 0 -1.5rem 2rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    align-items: center;
    font-size: 0.9rem;
    /* Pinned to the very top once the user scrolls past it. The site header
       above has been demoted to position:static (see :has rule above) so
       the dropdown is the single sticky strip. */
    position: sticky;
    top: 0;
    z-index: 10;
}
.ref-toc label { color: var(--muted); }
.ref-toc strong { color: var(--text); }
.ref-toc-select {
    flex: 1 1 220px;
    max-width: 24rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.45rem 0.7rem;
    font: inherit;
    font-size: 0.92rem;
    line-height: 1.3;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--muted) 50%),
        linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position:
        calc(100% - 18px) 50%,
        calc(100% - 12px) 50%;
    background-size: 6px 6px;
    background-repeat: no-repeat;
    padding-right: 2rem;
}
.ref-toc-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(217, 70, 239, 0.18);
}
.ref-toc-select:hover { border-color: var(--accent-2); }

.ref { margin-bottom: 2.5rem; scroll-margin-top: 6rem; }
.ref h2 {
    color: var(--accent);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}
.ref pre {
    background: #0e1424;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    overflow-x: auto;
    font-size: 0.85rem;
    line-height: 1.6;
    color: #d8dde8;
    margin-bottom: 1rem;
}
.ref pre code { background: none; padding: 0; color: inherit; font-size: inherit; }
.ref-note {
    background: rgba(6, 182, 212, 0.06);
    border-left: 3px solid var(--accent-2);
    padding: 0.6rem 0.9rem;
    border-radius: 4px;
    font-size: 0.9rem;
    color: var(--text);
}
.ref-cheat table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}
.ref-cheat th, .ref-cheat td {
    text-align: left;
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    font-size: 0.92rem;
}
.ref-cheat th { color: var(--muted); font-weight: 600; }
.ref-cheat code { font-size: 0.82rem; }
