/*
 * BlackOut: Can You Cope? — Website Stylesheet
 *
 * Design system: Card front as primary (per STYLE_GUIDE.md).
 * Night theme for dark mode. Time-of-day adaptive with user override.
 *
 * Palette from STYLE_GUIDE.md:
 *   Paper #fafaf8, Parchment #f0ede6, Linen #f5f0e8
 *   Ink #1a1a1a, Charcoal #3d352c, Ash #888, Dust #aaa
 *   Ember #c45a3c, Field Green #2d5f3e, Beeswax #d4a23a
 *   Dusk #3b4876, Wine #8B3A3A
 */

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

/* ===== THEME CUSTOM PROPERTIES ===== */

/* Light theme (daytime) — Card front aesthetic */
:root,
[data-theme="light"] {
    --bg-page: #fafaf8;
    --bg-surface: #f0ede6;
    --bg-elevated: #ffffff;
    --bg-nav: #1a1a1a;
    --bg-footer: #1a1a1a;
    --bg-parchment: #f0ede6;
    --bg-code: #f5f0e8;

    --text-primary: #1a1a1a;
    --text-body: #3d352c;
    --text-secondary: #888888;
    --text-muted: #aaaaaa;
    --text-nav: #e8e0d4;
    --text-on-dark: #f0ede6;

    --border-light: #e0dbd2;
    --border-medium: #c8c0b4;
    --border-accent: #8B3A3A;

    --accent-warm: #c45a3c;
    --accent-green: #2d5f3e;
    --accent-gold: #d4a23a;
    --accent-dusk: #3b4876;
    --accent-wine: #8B3A3A;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.10);

    --theme-transition: background-color 0.5s ease, color 0.4s ease, border-color 0.4s ease;
}

/* Dark theme (nighttime) — Night theme from style guide */
[data-theme="dark"] {
    --bg-page: #141210;
    --bg-surface: #1e1c18;
    --bg-elevated: #252320;
    --bg-nav: #0e0d0b;
    --bg-footer: #0e0d0b;
    --bg-parchment: #2a2620;
    --bg-code: #1e1c18;

    --text-primary: #e8e0d4;
    --text-body: #c8bfb0;
    --text-secondary: #9a9080;
    --text-muted: #706858;
    --text-nav: #e8e0d4;
    --text-on-dark: #f0ede6;

    --border-light: #2e2a24;
    --border-medium: #3d3830;
    --border-accent: #8B3A3A;

    --accent-warm: #d46a4c;
    --accent-green: #3d7f5e;
    --accent-gold: #d4a23a;
    --accent-dusk: #5b78a6;
    --accent-wine: #a04a4a;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.20);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.30);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.40);
}

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

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-page);
    color: var(--text-body);
    line-height: 1.7;
    transition: var(--theme-transition);
}

/* ===== TYPOGRAPHY ===== */
h1, h2, h3, h4 {
    font-family: 'Libre Baskerville', 'Georgia', serif;
    color: var(--text-primary);
    line-height: 1.3;
}

h1 { font-size: 2.2rem; margin-bottom: 1rem; }
h2 { font-size: 1.6rem; margin-top: 2.5rem; margin-bottom: 0.75rem; }
h3 { font-size: 1.25rem; margin-top: 1.8rem; margin-bottom: 0.5rem; }
h4 { font-size: 1.1rem; margin-top: 1.4rem; margin-bottom: 0.4rem; }

p { margin-bottom: 1rem; }

a {
    color: var(--accent-warm);
    text-decoration: none;
    transition: color 0.2s;
}
a:hover { color: var(--accent-wine); text-decoration: underline; }

strong { color: var(--text-primary); }

/* ===== LAYOUT ===== */
.site-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.content-wrap {
    flex: 1;
    width: 100%;
    max-width: 52rem;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* ===== NAVIGATION ===== */
.site-nav {
    background-color: var(--bg-nav);
    border-bottom: 3px solid var(--accent-wine);
    position: sticky;
    top: 0;
    z-index: 100;
    transition: var(--theme-transition);
}

.nav-inner {
    max-width: 68rem;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 3.5rem;
}

.nav-brand {
    font-family: 'Lora', 'Libre Baskerville', serif;
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--text-nav);
    text-decoration: none;
    letter-spacing: 0.02em;
}
.nav-brand:hover { color: var(--accent-gold); text-decoration: none; }

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    list-style: none;
}

.nav-links a {
    font-family: 'DM Sans', sans-serif;
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-nav);
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    opacity: 0.8;
    transition: opacity 0.2s;
}
.nav-links a:hover { opacity: 1; text-decoration: none; }
.nav-links a.active { opacity: 1; border-bottom: 2px solid var(--accent-gold); }

/* Theme toggle button */
.theme-toggle {
    background: none;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 6px;
    color: var(--text-nav);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.3rem 0.5rem;
    line-height: 1;
    transition: border-color 0.2s;
}
.theme-toggle:hover { border-color: var(--accent-gold); }

/* ===== FOOTER ===== */
.site-footer {
    background-color: var(--bg-footer);
    border-top: 3px solid var(--accent-wine);
    color: var(--text-muted);
    padding: 1.5rem;
    text-align: center;
    font-size: 0.85rem;
    transition: var(--theme-transition);
}

.site-footer a {
    color: var(--accent-gold);
}

/* ===== WIKI CONTENT ===== */

/* Cluster header */
.cluster-header {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-light);
}

.cluster-header h1 {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.cluster-icon {
    font-size: 1.8rem;
}

.cluster-cards-covered {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 0.3rem;
}

/* Card section within a cluster */
.card-section {
    scroll-margin-top: 5rem;
    padding: 2rem 0;
    border-bottom: 1px solid var(--border-light);
}

.card-section:last-child {
    border-bottom: none;
}

/* Card ID badge */
.card-badge {
    display: inline-block;
    font-family: 'DM Sans', sans-serif;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    padding: 0.2rem 0.7rem;
    border-radius: 100px;
    color: #fff;
    margin-right: 0.5rem;
    vertical-align: middle;
}

/* Category colours */
.card-badge--F { background-color: #c43c3c; }
.card-badge--E { background-color: #6a6258; }
.card-badge--S { background-color: #2d5f3e; }
.card-badge--J-relief { background-color: #3b6b8b; }
.card-badge--J-escalation { background-color: #1a1a1a; }
.card-badge--J-wildcard { background-color: #7b4d8a; }

/* Parchment instruction blocks */
.parchment-block,
.wiki-content blockquote {
    background-color: var(--bg-parchment);
    border-left: 3px solid var(--accent-gold);
    border-radius: 4px;
    padding: 1rem 1.25rem;
    margin: 1rem 0;
    transition: var(--theme-transition);
}

/* Safety notes */
.safety-note {
    background-color: var(--bg-parchment);
    border-left: 3px solid var(--accent-wine);
    border-radius: 4px;
    padding: 1rem 1.25rem;
    margin: 1rem 0;
}

.safety-note::before {
    content: 'Safety';
    display: block;
    font-family: 'DM Sans', sans-serif;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--accent-wine);
    margin-bottom: 0.4rem;
}

/* Historical notes */
.historical-note {
    font-family: 'Libre Baskerville', serif;
    font-style: italic;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-light);
    padding-top: 1rem;
    margin-top: 1.5rem;
}

/* Wiki content rendered from Markdown */
.wiki-content h2 {
    font-size: 1.5rem;
    padding-top: 1rem;
}

.wiki-content h3 {
    font-family: 'DM Sans', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.wiki-content ol,
.wiki-content ul {
    padding-left: 1.5rem;
    margin-bottom: 1rem;
}

.wiki-content li {
    margin-bottom: 0.4rem;
}

.wiki-content hr {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 2rem 0;
}

.wiki-content code {
    font-family: 'DM Mono', monospace;
    font-size: 0.9em;
    background-color: var(--bg-code);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
}

.wiki-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.95rem;
}

.wiki-content th,
.wiki-content td {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-light);
}

.wiki-content th {
    font-weight: 700;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-medium);
}

/* ===== LANDING PAGE ===== */
.hero {
    text-align: center;
    padding: 4rem 1rem 3rem;
}

.hero-title {
    font-family: 'Lora', 'Libre Baskerville', serif;
    font-size: 3rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.hero-subtitle {
    font-family: 'DM Sans', sans-serif;
    font-weight: 600;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.22em;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.hero-intro {
    font-family: 'Libre Baskerville', serif;
    font-size: 1.15rem;
    color: var(--text-body);
    max-width: 38rem;
    margin: 0 auto;
    line-height: 1.8;
}

.hero-rule {
    width: 40px;
    height: 2px;
    background-color: var(--accent-wine);
    border: none;
    margin: 2rem auto;
}

/* Feature pillars */
.pillars {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: 1.5rem;
    margin: 2rem 0 3rem;
}

.pillar {
    background-color: var(--bg-surface);
    border-radius: 6px;
    padding: 1.5rem;
    transition: var(--theme-transition);
    border: 1px solid var(--border-light);
}

.pillar-icon {
    font-size: 1.6rem;
    margin-bottom: 0.6rem;
}

.pillar h3 {
    font-family: 'Libre Baskerville', serif;
    font-size: 1rem;
    margin-top: 0;
    margin-bottom: 0.4rem;
}

.pillar p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0;
}

/* Cluster index cards */
.cluster-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
    gap: 1rem;
    margin: 2rem 0;
}

.cluster-card {
    display: block;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 1.25rem;
    text-decoration: none;
    transition: box-shadow 0.2s, border-color 0.2s;
}

.cluster-card:hover {
    border-color: var(--accent-gold);
    box-shadow: var(--shadow-md);
    text-decoration: none;
}

.cluster-card-icon {
    font-size: 1.6rem;
    margin-bottom: 0.4rem;
}

.cluster-card-title {
    font-family: 'Libre Baskerville', serif;
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 0.3rem;
}

.cluster-card-count {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===== WIKI SIDEBAR / TOC ===== */
.wiki-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    max-width: 68rem;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

@media (min-width: 64rem) {
    .wiki-layout {
        grid-template-columns: 14rem 1fr;
    }
}

.wiki-toc {
    position: sticky;
    top: 5rem;
    align-self: start;
    max-height: calc(100vh - 6rem);
    overflow-y: auto;
}

.wiki-toc-title {
    font-family: 'DM Sans', sans-serif;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.wiki-toc a {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 0.25rem 0;
    border-left: 2px solid transparent;
    padding-left: 0.75rem;
    transition: color 0.2s, border-color 0.2s;
}

.wiki-toc a:hover,
.wiki-toc a.active {
    color: var(--text-primary);
    border-left-color: var(--accent-gold);
    text-decoration: none;
}

/* ===== HIGHLIGHT ANCHOR TARGET ===== */
.card-section:target {
    animation: highlight-fade 2s ease-out;
}

@keyframes highlight-fade {
    0% { background-color: rgba(212, 162, 58, 0.15); }
    100% { background-color: transparent; }
}

/* ===== MOBILE NAV ===== */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-nav);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.3rem;
}

@media (max-width: 48rem) {
    .nav-toggle { display: block; }

    .nav-links {
        display: none;
        position: absolute;
        top: 3.5rem;
        left: 0;
        right: 0;
        background-color: var(--bg-nav);
        flex-direction: column;
        padding: 1rem 1.5rem;
        gap: 0.75rem;
        border-bottom: 3px solid var(--accent-wine);
    }

    .nav-links.open { display: flex; }

    .hero-title { font-size: 2.2rem; }
    .pillars { grid-template-columns: 1fr; }
}

/* ===== UTILITY ===== */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.mt-2 { margin-top: 2rem; }
.mb-2 { margin-bottom: 2rem; }
