/* Neon Dark Theme for C Compiler Book */
:root {
    --bg: #0f0f17;
    --bg-secondary: #16161f;
    --text: #e0e0ff;
    --text-muted: #8a8aa0;
    --accent: #00f0ff;
    --accent2: #ff00aa;
    --border: #2a2a3a;
    --card: #1a1a24;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] {
    --bg: #f8f9fc;
    --bg-secondary: #ffffff;
    --text: #1a1a2e;
    --text-muted: #5a5a70;
    --accent: #0066ff;
    --accent2: #cc0088;
    --border: #d0d0e0;
    --card: #ffffff;
    --shadow: 0 20px 60px rgba(28, 34, 58, 0.18);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.75;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0;
    background: linear-gradient(to right, var(--accent), var(--accent2));
    z-index: 1000;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-weight: 700;
}
.brand-mark {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    box-shadow: 0 0 20px var(--accent);
}
.top-actions { display: flex; align-items: center; gap: 10px; }
.theme-btn {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 14px;
    border-radius: 999px;
    cursor: pointer;
}
.theme-btn:hover { border-color: var(--accent); }

.main {
    max-width: 900px;
    margin: 40px auto 80px;
    padding: 0 24px;
}
.chapter-page .main { max-width: 860px; }
.article h1 { font-size: clamp(1.8rem, 3vw, 2.6rem); border-bottom: 2px solid var(--accent); padding-bottom: 8px; line-height: 1.25; }
.article h2, .article h3 { margin-top: 2.2em; line-height: 1.35; }
.article img { max-width: 100%; height: auto; }

.chapter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}
.chapter-card {
    display: grid;
    gap: 8px;
    min-height: 120px;
    padding: 18px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text);
}
.chapter-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.chapter-card span { color: var(--text-muted); font-size: 0.92rem; }

.note {
    background: var(--card);
    border-left: 4px solid var(--accent);
    padding: 16px 20px;
    margin: 2em 0;
    border-radius: 0 8px 8px 0;
}

/* Floating controls: TOC on the left, back-to-top on the right. */
.drawer-toggle {
    position: fixed;
    left: 24px;
    right: auto;
    bottom: 24px;
    z-index: 220;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    background: var(--accent);
    color: #000;
    border: none;
    padding: 12px 18px;
    border-radius: 999px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: var(--shadow);
}
.drawer-toggle span,
.drawer-toggle span::before,
.drawer-toggle span::after {
    display: block;
    width: 14px;
    height: 2px;
    background: #000;
    border-radius: 2px;
    content: "";
}
.drawer-toggle span { position: relative; }
.drawer-toggle span::before { position: absolute; top: -5px; left: 0; }
.drawer-toggle span::after { position: absolute; top: 5px; left: 0; }

.backtop {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 220;
    width: 44px;
    height: 44px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    font-size: 1.2rem;
    box-shadow: var(--shadow);
}
.backtop:hover { border-color: var(--accent); text-decoration: none; }

.drawer-scrim {
    position: fixed;
    inset: 0;
    z-index: 250;
    background: rgba(0, 0, 0, 0.45);
}
.drawer-scrim[hidden] { display: none; }

.toc-drawer {
    position: fixed;
    top: 0;
    left: min(-380px, -88vw);
    right: auto;
    width: min(360px, 88vw);
    height: 100vh;
    z-index: 300;
    background: var(--bg);
    border-right: 1px solid var(--border);
    border-left: none;
    box-shadow: var(--shadow);
    transition: left 0.25s ease;
    padding: 22px;
    overflow-y: auto;
}
.toc-drawer.open { left: 0; }
.toc-head {
    position: sticky;
    top: -22px;
    z-index: 2;
    background: var(--bg);
    padding: 6px 0 14px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
}
.toc-kicker { color: var(--accent); font-size: 0.8rem; letter-spacing: 0.12em; text-transform: uppercase; }
.toc-head h2 { margin: 6px 44px 4px 0; }
.toc-head p { margin: 0; color: var(--text-muted); font-size: 0.9rem; }
.drawer-close {
    position: absolute;
    top: 8px;
    right: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
}
.toc-list { display: grid; gap: 2px; padding-bottom: 64px; }
.toc-link {
    display: block;
    padding: 8px 10px;
    color: var(--text);
    border-radius: 8px;
    line-height: 1.35;
}
.toc-link:hover { background: var(--card); text-decoration: none; }
.toc-link.level-2 { padding-left: 24px; color: color-mix(in srgb, var(--text) 88%, var(--text-muted)); font-size: 0.94rem; }
.toc-link.level-3 { padding-left: 38px; color: var(--text-muted); font-size: 0.9rem; }
.toc-link.is-current-page { border-left: 3px solid var(--accent); background: var(--card); }

/* Code blocks */
pre {
    position: relative;
    margin: 1.6em 0;
    padding: 46px 16px 16px;
    overflow-x: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    white-space: pre;
    line-height: 1.55;
}
pre code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 0.92rem;
    tab-size: 4;
}
.sourceCode { background: var(--bg-secondary); }
pre.sourceCode.c::before { content: "C"; }
pre.sourceCode.asm::before { content: "ASM"; }

pre.sourceCode.bash::before { content: "BASH"; }
pre.sourceCode.makefile::before { content: "MAKEFILE"; }
pre.sourceCode.grammar::before { content: "GRAMMAR"; }
pre.shell::before { content: "SHELL"; }
pre::before {
    position: absolute;
    left: 14px;
    top: 12px;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.12em;
}
.copy-code-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 0.78rem;
    cursor: pointer;
}
.copy-code-btn:hover { border-color: var(--accent); }
.copy-code-btn.copied { color: var(--accent); }

.pager {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-top: 60px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}
.pager a {
    padding: 10px 18px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
}
.pager a:hover { border-color: var(--accent); text-decoration: none; }

@media (max-width: 720px) {
    .topbar { padding: 10px 14px; }
    .brand span:last-child { max-width: 58vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .main { margin-top: 28px; padding: 0 16px 80px; }
    .drawer-toggle { left: 14px; bottom: 14px; padding: 11px 15px; }
    .backtop { right: 14px; bottom: 14px; }
    pre { margin-left: -2px; margin-right: -2px; padding-left: 12px; padding-right: 12px; }
    .pager { flex-direction: column; }
}

/* UI layout corrections: homepage, bottom-left TOC, bottom-right back-to-top. */
:root {
    --floating-bottom: calc(22px + env(safe-area-inset-bottom, 0px));
    --floating-left: calc(22px + env(safe-area-inset-left, 0px));
    --floating-right: calc(22px + env(safe-area-inset-right, 0px));
}

body {
    min-height: 100vh;
    padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
}

.chapter-intro {
    margin-bottom: 28px;
}
.chapter-intro h1 {
    margin: 0;
    font-size: clamp(2rem, 4vw, 3rem);
    line-height: 1.18;
}
.subtitle,
.breadcrumb {
    color: var(--text-muted);
}
.breadcrumb {
    margin-bottom: 10px;
    font-size: 0.92rem;
}
.breadcrumb a {
    color: var(--accent);
}

.home-page .main {
    max-width: 1120px;
    margin-top: 32px;
}
.home-main {
    display: grid;
    gap: 26px;
}
.home-hero,
.home-section {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: linear-gradient(135deg, color-mix(in srgb, var(--card) 94%, var(--accent) 6%), var(--card));
    box-shadow: var(--shadow);
}
.home-hero {
    padding: clamp(32px, 7vw, 76px);
}
.home-hero::after {
    content: "";
    position: absolute;
    inset: auto -90px -130px auto;
    width: 320px;
    height: 320px;
    border-radius: 50%;
    background: radial-gradient(circle, color-mix(in srgb, var(--accent) 50%, transparent), transparent 68%);
    opacity: 0.55;
    pointer-events: none;
}
.home-eyebrow,
.section-head span {
    color: var(--accent);
    font-size: 0.82rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}
.home-hero h1 {
    max-width: 780px;
    margin: 10px 0 14px;
    font-size: clamp(2.5rem, 7vw, 5.4rem);
    line-height: 1.05;
    letter-spacing: -0.04em;
}
.home-subtitle {
    max-width: 720px;
    margin: 0;
    color: var(--text-muted);
    font-size: clamp(1rem, 2vw, 1.25rem);
}
.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 28px;
}
.hero-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 18px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    background: var(--bg-secondary);
    font-weight: 700;
}
.hero-link.primary {
    color: #000;
    border-color: transparent;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
}
.hero-link:hover {
    text-decoration: none;
    transform: translateY(-1px);
}
.home-meta {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    max-width: 660px;
    margin-top: 34px;
}
.home-meta div {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: color-mix(in srgb, var(--bg-secondary) 84%, transparent);
}
.home-meta strong {
    display: block;
    font-size: 1.3rem;
    line-height: 1.1;
}
.home-meta span {
    color: var(--text-muted);
    font-size: 0.9rem;
}
.home-section {
    padding: clamp(22px, 4vw, 36px);
}
.section-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 14px;
}
.section-head h2 {
    margin: 0;
    font-size: clamp(1.4rem, 3vw, 2rem);
}
.intro-card p {
    max-width: 820px;
}
.status-line {
    margin-top: 18px;
    padding: 14px 16px;
    border-left: 4px solid var(--accent);
    border-radius: 0 10px 10px 0;
    background: var(--bg-secondary);
}
.chapters-section .chapter-grid {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.drawer-toggle {
    left: var(--floating-left) !important;
    right: auto !important;
    bottom: var(--floating-bottom) !important;
    z-index: 230;
    min-width: 96px;
    justify-content: center;
}
.backtop {
    left: auto !important;
    right: var(--floating-right) !important;
    bottom: var(--floating-bottom) !important;
    z-index: 230;
}
.drawer-toggle,
.backtop {
    -webkit-tap-highlight-color: transparent;
}
.drawer-toggle:focus-visible,
.backtop:focus-visible,
.theme-btn:focus-visible,
.drawer-close:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 70%, transparent);
    outline-offset: 3px;
}
.drawer-toggle[aria-expanded="true"] {
    transform: translateY(-1px);
}
.toc-drawer {
    left: calc(-1 * min(380px, 88vw));
    max-width: 100vw;
}
.toc-drawer.open {
    left: 0;
}

@media (max-width: 720px) {
    :root {
        --floating-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
        --floating-left: calc(14px + env(safe-area-inset-left, 0px));
        --floating-right: calc(14px + env(safe-area-inset-right, 0px));
    }
    .home-page .main {
        margin-top: 20px;
    }
    .home-hero,
    .home-section {
        border-radius: 18px;
    }
    .home-meta {
        grid-template-columns: 1fr;
    }
    .section-head {
        display: block;
    }
    .drawer-toggle {
        min-width: 86px;
        padding: 11px 14px;
    }
    .backtop {
        width: 44px;
        height: 44px;
    }
}

