/* =====================================================
   DV HANDBOOK — BOOK / DOCUMENTATION UI
   Dedicated stylesheet for the Topics page (topics.html)
   Applied only when <body class="handbook-mode"> is set.
   ===================================================== */

.handbook-mode {
    --hb-brand-1: #6366f1;
    --hb-brand-2: #06b6d4;
    --hb-brand-soft: rgba(99, 102, 241, 0.12);
    --hb-ink-900: #e8eaf1;
    --hb-ink-700: #b5bac8;
    --hb-ink-500: #7a8098;
    --hb-ink-400: #5c627a;
    --hb-surface-0: #0b0d14;
    --hb-surface-1: #11141d;
    --hb-surface-2: #171b26;
    --hb-surface-3: #1d2231;
    --hb-border: rgba(255, 255, 255, 0.07);
    --hb-border-strong: rgba(255, 255, 255, 0.12);
    --hb-note-blue: rgba(56, 189, 248, 0.10);
    --hb-note-blue-border: rgba(56, 189, 248, 0.28);
    --hb-note-amber: rgba(245, 158, 11, 0.10);
    --hb-note-amber-border: rgba(245, 158, 11, 0.28);
    --hb-note-rose: rgba(244, 63, 94, 0.10);
    --hb-note-rose-border: rgba(244, 63, 94, 0.28);
    --hb-note-green: rgba(34, 197, 94, 0.10);
    --hb-note-green-border: rgba(34, 197, 94, 0.28);

    background: var(--hb-surface-0);
    color: var(--hb-ink-900);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Hide the original animated background; the handbook has its own canvas */
.handbook-mode .bg-circuit,
.handbook-mode .grid-overlay { display: none !important; }

/* ===== Reading-progress bar (top, under navbar) ===== */
.hb-progress {
    position: fixed;
    top: 64px;
    left: 0; right: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.04);
    z-index: 50;
}
.hb-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--hb-brand-1), var(--hb-brand-2));
    transition: width 0.1s linear;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}

/* ===== Shell (3-column layout) ===== */
.book-shell {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 300px;
    gap: 2.5rem;
    max-width: 1480px;
    margin: 0 auto;
    padding: 5.5rem 2rem 4rem;
    align-items: start;
}

@media (max-width: 1200px) {
    .book-shell { grid-template-columns: 260px minmax(0, 1fr); }
    .hb-utility { display: none; }
}
@media (max-width: 900px) {
    .book-shell { grid-template-columns: 1fr; padding: 5.5rem 1rem 3rem; }
    .hb-toc { display: none; }
}

/* ===== Left: Table of Contents sidebar ===== */
.hb-toc {
    position: sticky;
    top: 90px;
    max-height: calc(100vh - 110px);
    overflow-y: auto;
    padding-right: 0.5rem;
    scrollbar-width: thin;
}
.hb-toc::-webkit-scrollbar { width: 6px; }
.hb-toc::-webkit-scrollbar-thumb { background: #2a2f40; border-radius: 3px; }

.hb-toc-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--hb-ink-500);
    margin-bottom: 0.85rem;
    padding-left: 0.5rem;
}

.hb-search {
    position: relative;
    margin-bottom: 1.25rem;
}
.hb-search input {
    width: 100%;
    padding: 0.6rem 0.85rem 0.6rem 2.25rem;
    background: var(--hb-surface-1);
    border: 1px solid var(--hb-border);
    border-radius: 10px;
    color: var(--hb-ink-900);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.15s, background 0.15s;
}
.hb-search input::placeholder { color: var(--hb-ink-500); }
.hb-search input:focus {
    outline: none;
    border-color: rgba(99, 102, 241, 0.5);
    background: var(--hb-surface-2);
}
.hb-search::before {
    content: "🔍";
    position: absolute;
    left: 0.7rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.85rem;
    opacity: 0.5;
}

.hb-toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.hb-toc-item {
    position: relative;
}
.hb-toc-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 0.85rem;
    border-radius: 8px;
    color: var(--hb-ink-700);
    text-decoration: none;
    font-size: 0.91rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s, transform 0.15s;
    border-left: 2px solid transparent;
}
.hb-toc-link:hover {
    background: var(--hb-surface-1);
    color: var(--hb-ink-900);
}
.hb-toc-link .hb-toc-num {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    color: var(--hb-ink-400);
    min-width: 24px;
    font-weight: 600;
}
.hb-toc-link .hb-toc-icon {
    font-size: 1rem;
    line-height: 1;
}
.hb-toc-link.active {
    background: var(--hb-brand-soft);
    color: var(--hb-ink-900);
    border-left-color: var(--hb-brand-1);
}
.hb-toc-link.active .hb-toc-num { color: var(--hb-brand-1); }
.hb-toc-item.hidden { display: none; }

.hb-toc-footer {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--hb-border);
    font-size: 0.78rem;
    color: var(--hb-ink-500);
    padding-left: 0.5rem;
}
.hb-toc-footer strong { color: var(--hb-ink-900); }

/* ===== Center: Chapter reading area ===== */
.hb-content {
    min-width: 0;
    max-width: 780px;
    margin: 0 auto;
}

.hb-pagebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    letter-spacing: 0.15em;
    color: var(--hb-ink-500);
    text-transform: uppercase;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--hb-border);
    margin-bottom: 2rem;
}
.hb-pagebar .hb-breadcrumb { display: flex; gap: 0.5rem; align-items: center; }
.hb-pagebar .hb-breadcrumb .sep { opacity: 0.4; }

.chapter-page {
    display: none;
    animation: fadeInUp 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.chapter-page.active { display: block; }

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

.chapter-hero {
    padding-bottom: 1.75rem;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--hb-border);
}
.chapter-kicker {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--hb-brand-1);
    font-weight: 600;
    margin-bottom: 0.9rem;
}
.chapter-kicker .dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--hb-brand-1);
    box-shadow: 0 0 8px var(--hb-brand-1);
}
.chapter-title {
    font-size: clamp(2rem, 4vw, 2.6rem);
    font-weight: 800;
    letter-spacing: -0.025em;
    line-height: 1.12;
    margin: 0 0 0.75rem;
    color: var(--hb-ink-900);
    display: flex;
    align-items: center;
    gap: 0.8rem;
}
.chapter-title .title-icon {
    font-size: 0.85em;
}
.chapter-subtitle {
    color: var(--hb-ink-700);
    font-size: 1.05rem;
    line-height: 1.6;
    margin: 0 0 1.25rem;
    max-width: 680px;
}
.chapter-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}
.chapter-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.75rem;
    background: var(--hb-surface-1);
    border: 1px solid var(--hb-border);
    border-radius: 999px;
    font-size: 0.78rem;
    color: var(--hb-ink-700);
    font-weight: 500;
}
.chapter-pill .pill-icon { font-size: 0.85rem; }
.chapter-pill.bookmark {
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}
.chapter-pill.bookmark:hover {
    background: var(--hb-surface-2);
    border-color: rgba(99, 102, 241, 0.35);
    color: var(--hb-ink-900);
}
.chapter-pill.bookmark.active {
    background: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.35);
    color: #f59e0b;
}

/* ===== Chapter section blocks ===== */
.chapter-block {
    margin-bottom: 2.25rem;
}
.chapter-block > h3 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--hb-ink-900);
    margin: 0 0 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.55rem;
}
.chapter-block > h3::before {
    content: "";
    display: inline-block;
    width: 3px;
    height: 1.1em;
    background: linear-gradient(180deg, var(--hb-brand-1), var(--hb-brand-2));
    border-radius: 2px;
}

.chapter-block p {
    color: var(--hb-ink-700);
    line-height: 1.72;
    font-size: 1rem;
    margin: 0 0 1rem;
}
.chapter-block p strong, .chapter-block li strong { color: var(--hb-ink-900); }

/* Concept list — clean bulleted rows */
.concept-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.concept-list li {
    position: relative;
    padding: 0.75rem 0.95rem 0.75rem 2.25rem;
    background: var(--hb-surface-1);
    border: 1px solid var(--hb-border);
    border-radius: 10px;
    color: var(--hb-ink-700);
    font-size: 0.95rem;
    line-height: 1.55;
    transition: background 0.15s, border-color 0.15s;
}
.concept-list li::before {
    content: "▸";
    position: absolute;
    left: 0.9rem;
    top: 0.75rem;
    color: var(--hb-brand-1);
    font-size: 0.85rem;
    line-height: 1.55;
}
.concept-list li:hover {
    background: var(--hb-surface-2);
    border-color: var(--hb-border-strong);
}

/* Resource cards */
.resource-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.6rem;
}
.resource-card {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.8rem 1rem;
    background: var(--hb-surface-1);
    border: 1px solid var(--hb-border);
    border-radius: 10px;
    color: var(--hb-ink-900);
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.resource-card:hover {
    background: var(--hb-surface-2);
    border-color: rgba(99, 102, 241, 0.35);
    transform: translateX(2px);
}
.resource-card .res-icon {
    width: 36px; height: 36px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.18), rgba(6, 182, 212, 0.12));
    border: 1px solid rgba(99, 102, 241, 0.22);
    border-radius: 9px;
    font-size: 1rem;
    flex-shrink: 0;
}
.resource-card .res-body {
    flex: 1;
    min-width: 0;
}
.resource-card .res-title {
    display: block;
    font-weight: 600;
    font-size: 0.93rem;
    color: var(--hb-ink-900);
    line-height: 1.35;
}
.resource-card .res-meta {
    display: block;
    font-size: 0.77rem;
    color: var(--hb-ink-500);
    margin-top: 0.2rem;
}
.resource-card .res-arrow {
    color: var(--hb-ink-500);
    flex-shrink: 0;
    transition: transform 0.2s, color 0.2s;
}
.resource-card:hover .res-arrow {
    color: var(--hb-brand-1);
    transform: translateX(3px);
}

.resource-card.text-only {
    cursor: default;
}
.resource-card.text-only:hover {
    transform: none;
    border-color: var(--hb-border);
}

/* Note / callout boxes */
.note-box {
    position: relative;
    padding: 1rem 1.15rem 1rem 3rem;
    border-radius: 12px;
    border: 1px solid;
    margin: 1.25rem 0;
    font-size: 0.93rem;
    line-height: 1.6;
    color: var(--hb-ink-700);
}
.note-box::before {
    position: absolute;
    top: 0.95rem;
    left: 1rem;
    font-size: 1.1rem;
    line-height: 1;
}
.note-box .note-title {
    display: block;
    font-weight: 700;
    color: var(--hb-ink-900);
    margin-bottom: 0.2rem;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.note-box.tip {
    background: var(--hb-note-blue);
    border-color: var(--hb-note-blue-border);
}
.note-box.tip::before { content: "💡"; }
.note-box.tip .note-title { color: #38bdf8; }

.note-box.focus {
    background: var(--hb-note-green);
    border-color: var(--hb-note-green-border);
}
.note-box.focus::before { content: "🎯"; }
.note-box.focus .note-title { color: #4ade80; }

.note-box.warning {
    background: var(--hb-note-amber);
    border-color: var(--hb-note-amber-border);
}
.note-box.warning::before { content: "⚠️"; }
.note-box.warning .note-title { color: #f59e0b; }

.note-box.mistake {
    background: var(--hb-note-rose);
    border-color: var(--hb-note-rose-border);
}
.note-box.mistake::before { content: "🚫"; }
.note-box.mistake .note-title { color: #fb7185; }

.note-box a {
    color: var(--hb-brand-1);
    font-weight: 600;
    text-decoration: none;
    border-bottom: 1px dashed rgba(99, 102, 241, 0.4);
}
.note-box a:hover { color: var(--hb-brand-2); }

/* ===== Chapter nav (prev / next) ===== */
.chapter-nav {
    margin-top: 3rem;
    padding-top: 1.75rem;
    border-top: 1px solid var(--hb-border);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
.chapter-nav-btn {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 1rem 1.15rem;
    background: var(--hb-surface-1);
    border: 1px solid var(--hb-border);
    border-radius: 12px;
    color: var(--hb-ink-900);
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, transform 0.15s;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}
.chapter-nav-btn:hover:not(:disabled) {
    background: var(--hb-surface-2);
    border-color: rgba(99, 102, 241, 0.35);
}
.chapter-nav-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.chapter-nav-btn .dir {
    font-size: 0.7rem;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 0.12em;
    color: var(--hb-ink-500);
    text-transform: uppercase;
}
.chapter-nav-btn .title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--hb-ink-900);
}
.chapter-nav-btn.next { text-align: right; align-items: flex-end; }

@media (max-width: 560px) {
    .chapter-nav { grid-template-columns: 1fr; }
}

/* ===== Right: Utility panel ===== */
.hb-utility {
    position: sticky;
    top: 90px;
    max-height: calc(100vh - 110px);
    overflow-y: auto;
    scrollbar-width: thin;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.hb-utility::-webkit-scrollbar { width: 6px; }
.hb-utility::-webkit-scrollbar-thumb { background: #2a2f40; border-radius: 3px; }

.util-card {
    background: var(--hb-surface-1);
    border: 1px solid var(--hb-border);
    border-radius: 12px;
    padding: 1.1rem 1.15rem;
}
.util-card-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--hb-ink-500);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.util-stat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0;
    font-size: 0.88rem;
}
.util-stat + .util-stat { border-top: 1px solid var(--hb-border); }
.util-stat .label { color: var(--hb-ink-500); }
.util-stat .value {
    color: var(--hb-ink-900);
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
}

.util-difficulty {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}
.util-difficulty .bar {
    width: 6px; height: 14px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 1px;
}
.util-difficulty .bar.on { background: linear-gradient(180deg, var(--hb-brand-1), var(--hb-brand-2)); }

/* Quick jump list (H2 anchors inside chapter) */
.quick-jump {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.quick-jump a {
    display: block;
    padding: 0.4rem 0.6rem;
    color: var(--hb-ink-500);
    text-decoration: none;
    font-size: 0.85rem;
    border-left: 2px solid var(--hb-border);
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.quick-jump a:hover {
    color: var(--hb-ink-900);
    border-left-color: var(--hb-brand-1);
}
.quick-jump a.active {
    color: var(--hb-ink-900);
    border-left-color: var(--hb-brand-1);
    background: var(--hb-brand-soft);
}

.hb-overall-progress {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.hb-overall-progress .ring {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: conic-gradient(var(--hb-brand-1) calc(var(--pct, 0) * 1%), rgba(255,255,255,0.08) 0);
    display: grid;
    place-items: center;
    position: relative;
    flex-shrink: 0;
}
.hb-overall-progress .ring::before {
    content: "";
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    background: var(--hb-surface-1);
}
.hb-overall-progress .ring-value {
    position: relative;
    z-index: 1;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--hb-ink-900);
}
.hb-overall-progress .label-small {
    font-size: 0.78rem;
    color: var(--hb-ink-500);
}
.hb-overall-progress .label-small strong {
    display: block;
    color: var(--hb-ink-900);
    font-size: 0.9rem;
    font-weight: 600;
}

/* Bookmarks list */
.bookmarks-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.bookmarks-list li a {
    display: block;
    padding: 0.4rem 0.55rem;
    font-size: 0.85rem;
    color: var(--hb-ink-700);
    text-decoration: none;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}
.bookmarks-list li a:hover {
    background: var(--hb-surface-2);
    color: var(--hb-ink-900);
}
.bookmarks-list .empty {
    color: var(--hb-ink-500);
    font-size: 0.82rem;
    padding: 0.25rem 0.1rem;
    font-style: italic;
}

/* ===== Mobile TOC drawer ===== */
.hb-mobile-toc-btn {
    display: none;
    position: fixed;
    bottom: 1.25rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 80;
    padding: 0.7rem 1.15rem;
    background: linear-gradient(135deg, var(--hb-brand-1), var(--hb-brand-2));
    color: #fff;
    border: none;
    border-radius: 999px;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 10px 30px -10px rgba(99, 102, 241, 0.8);
}
.hb-mobile-toc-btn:hover { filter: brightness(1.08); }

@media (max-width: 900px) {
    .hb-mobile-toc-btn { display: inline-flex; align-items: center; gap: 0.4rem; }

    .hb-toc {
        display: block;
        position: fixed;
        top: 0; left: 0;
        bottom: 0;
        width: min(85vw, 320px);
        background: var(--hb-surface-0);
        border-right: 1px solid var(--hb-border);
        padding: 5rem 1rem 2rem 1.25rem;
        z-index: 90;
        transform: translateX(-102%);
        transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
        max-height: none;
    }
    .hb-toc.open { transform: translateX(0); }

    .hb-toc-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.55);
        z-index: 85;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s;
    }
    .hb-toc-backdrop.show { opacity: 1; pointer-events: auto; }
}

/* ===== Typography & misc ===== */
.handbook-mode .footer {
    background: transparent;
    border-top: 1px solid var(--hb-border);
}
