/* ═══════════════════════════════════════════════════════════════════════
   Bitcoin Internals — Book-Style Premium Stylesheet
   A clean, readable, chapter-based layout for deep technical content
   ═══════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&family=Merriweather:wght@400;700&display=swap');

/* ── Design Tokens ───────────────────────────────────────────────────── */
:root {
    --btc:            #f7931a;
    --btc-dark:       #e07f0e;
    --btc-light:      #fff8ee;
    --btc-glow:       rgba(247, 147, 26, 0.12);

    --ink:            #1a1a2e;
    --ink-soft:       #2d3748;
    --ink-muted:      #718096;
    --ink-faint:      #a0aec0;

    --paper:          #fafbfd;
    --paper-warm:     #ffffff;
    --paper-code:     #1e1e2e;

    --accent-blue:    #3182ce;
    --accent-green:   #38a169;
    --accent-red:     #e53e3e;
    --accent-purple:  #805ad5;

    --shadow-sm:      0 1px 3px rgba(0,0,0,0.06);
    --shadow-md:      0 4px 16px rgba(0,0,0,0.08);
    --shadow-lg:      0 8px 30px rgba(0,0,0,0.12);
    --shadow-glow:    0 4px 20px rgba(247, 147, 26, 0.15);

    --radius:         12px;
    --radius-sm:      8px;
    --radius-xs:      4px;

    --max-width:      860px;
    --sidebar-width:  260px;
}

/* ── Reset & Base ────────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; font-size: 16px; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    line-height: 1.75;
    color: var(--ink-soft);
    background: var(--paper);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--btc); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--btc-dark); }

img { max-width: 100%; height: auto; }

/* ── Typography ──────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5 {
    font-family: 'Inter', sans-serif;
    color: var(--ink);
    line-height: 1.3;
    font-weight: 700;
}

/* ══════════════════════════════════════════════════════════════════════
   HOME PAGE / TABLE OF CONTENTS
   ══════════════════════════════════════════════════════════════════════ */

.book-cover {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Hero ─────────────────────────────────────────────────────────── */
.hero {
    background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 40%, #1e2a45 100%);
    color: #fff;
    padding: 5rem 2rem 4rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: '';
    position: absolute;
    top: -120px; right: -80px;
    width: 500px; height: 500px;
    background: radial-gradient(circle, rgba(247,147,26,0.18) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
}

.hero::after {
    content: '';
    position: absolute;
    bottom: -100px; left: -60px;
    width: 350px; height: 350px;
    background: radial-gradient(circle, rgba(49,130,206,0.10) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
}

.hero .bitcoin-icon {
    font-size: 3.5rem;
    margin-bottom: 1rem;
    display: block;
    opacity: 0.9;
}

.hero h1 {
    font-size: clamp(2rem, 5vw, 3.2rem);
    font-weight: 800;
    color: #fff;
    margin-bottom: 0.75rem;
    position: relative;
}

.hero h1 .accent { color: var(--btc); }

.hero .subtitle {
    font-size: clamp(1rem, 2.5vw, 1.25rem);
    color: rgba(255,255,255,0.75);
    max-width: 600px;
    margin: 0 auto 2rem;
    font-weight: 400;
}

.hero .badge {
    display: inline-block;
    background: rgba(247,147,26,0.15);
    border: 1px solid rgba(247,147,26,0.3);
    color: var(--btc);
    padding: 0.4rem 1.2rem;
    border-radius: 100px;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* ── Table of Contents ─────────────────────────────────────────────── */
.toc-container {
    max-width: 900px;
    margin: -2rem auto 0;
    padding: 0 1.5rem 4rem;
    position: relative;
    z-index: 2;
}

.toc-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.toc-header h2 {
    font-size: 1.5rem;
    color: var(--ink);
    margin-bottom: 0.5rem;
}

.toc-header p {
    color: var(--ink-muted);
    font-size: 0.95rem;
}

/* Part headers */
.part-group {
    margin-bottom: 2.5rem;
}

.part-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--btc);
}

.part-label .part-num {
    background: var(--btc);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    letter-spacing: 1px;
    text-transform: uppercase;
    white-space: nowrap;
}

.part-label .part-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--ink);
}

/* Chapter cards */
.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chapter-card {
    display: grid;
    grid-template-columns: 56px 1fr auto;
    align-items: center;
    gap: 1.25rem;
    background: var(--paper-warm);
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius);
    border: 1px solid rgba(0,0,0,0.06);
    box-shadow: var(--shadow-sm);
    transition: all 0.25s ease;
    text-decoration: none;
    color: inherit;
}

.chapter-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
    border-color: rgba(247,147,26,0.25);
    color: inherit;
}

.chapter-num {
    width: 56px; height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--btc-light);
    color: var(--btc);
    font-weight: 800;
    font-size: 1.1rem;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.chapter-card:hover .chapter-num {
    background: var(--btc);
    color: #fff;
}

.chapter-info h3 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 0.25rem;
}

.chapter-info p {
    font-size: 0.88rem;
    color: var(--ink-muted);
    line-height: 1.5;
}

.chapter-arrow {
    color: var(--ink-faint);
    font-size: 1.2rem;
    transition: transform 0.2s;
}

.chapter-card:hover .chapter-arrow {
    transform: translateX(4px);
    color: var(--btc);
}

/* ══════════════════════════════════════════════════════════════════════
   CHAPTER PAGE LAYOUT
   ══════════════════════════════════════════════════════════════════════ */

/* ── Chapter Header ──────────────────────────────────────────────── */
.chapter-header {
    background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 60%, #1e2a45 100%);
    color: #fff;
    padding: 3rem 2rem 2.5rem;
    position: relative;
    overflow: hidden;
}

.chapter-header::before {
    content: '';
    position: absolute;
    top: -80px; right: -40px;
    width: 350px; height: 350px;
    background: radial-gradient(circle, rgba(247,147,26,0.12) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
}

.chapter-header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    position: relative;
}

.chapter-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: rgba(255,255,255,0.5);
    margin-bottom: 1rem;
}

.chapter-breadcrumb a {
    color: rgba(255,255,255,0.6);
    transition: color 0.2s;
}

.chapter-breadcrumb a:hover { color: var(--btc); }

.chapter-label {
    display: inline-block;
    background: rgba(247,147,26,0.2);
    border: 1px solid rgba(247,147,26,0.35);
    color: var(--btc);
    padding: 0.3rem 0.9rem;
    border-radius: 100px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 0.75rem;
}

.chapter-header h1 {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 800;
    color: #fff;
    margin-bottom: 0.5rem;
}

.chapter-header .lead {
    font-size: 1.1rem;
    color: rgba(255,255,255,0.7);
    max-width: 650px;
    line-height: 1.6;
}

/* ── Chapter Body ────────────────────────────────────────────────── */
.chapter-body {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    gap: 2.5rem;
    max-width: calc(var(--max-width) + var(--sidebar-width) + 2.5rem);
    margin: 0 auto;
    padding: 2.5rem 1.5rem 4rem;
}

/* ── Sidebar / Mini-TOC ──────────────────────────────────────────── */
.chapter-sidebar {
    position: sticky;
    top: 1.5rem;
    align-self: start;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
}

.mini-toc {
    background: var(--paper-warm);
    border-radius: var(--radius);
    border: 1px solid rgba(0,0,0,0.06);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
}

.mini-toc h4 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--ink-muted);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(0,0,0,0.06);
}

.mini-toc ul {
    list-style: none;
}

.mini-toc li {
    margin-bottom: 0.15rem;
}

.mini-toc a {
    display: block;
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    color: var(--ink-muted);
    border-radius: var(--radius-xs);
    transition: all 0.2s;
    border-left: 2px solid transparent;
}

.mini-toc a:hover {
    background: var(--btc-light);
    color: var(--btc-dark);
    border-left-color: var(--btc);
}

.mini-toc a.active {
    background: var(--btc-light);
    color: var(--btc);
    font-weight: 600;
    border-left-color: var(--btc);
}

.mini-toc .deep-dive {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(0,0,0,0.06);
}

.mini-toc .deep-dive h4 {
    font-size: 0.7rem;
    color: var(--ink-faint);
}

.mini-toc .deep-dive a {
    font-size: 0.8rem;
    color: var(--ink-faint);
}

.mini-toc .deep-dive a:hover {
    color: var(--accent-blue);
}

/* ── Chapter Content ─────────────────────────────────────────────── */
.chapter-content {
    min-width: 0; /* prevent overflow */
}

.chapter-content h2 {
    font-size: 1.6rem;
    margin-top: 3rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--btc);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chapter-content h2:first-child { margin-top: 0; }

.chapter-content h3 {
    font-size: 1.2rem;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
    color: var(--ink);
}

.chapter-content h4 {
    font-size: 1rem;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--ink-soft);
    font-weight: 600;
}

.chapter-content p {
    margin-bottom: 1rem;
    font-size: 0.98rem;
}

.chapter-content ul, .chapter-content ol {
    margin: 0.75rem 0 1.25rem 1.75rem;
}

.chapter-content li {
    margin-bottom: 0.4rem;
    font-size: 0.95rem;
}

.chapter-content li::marker {
    color: var(--btc);
}

/* ── Code Blocks ─────────────────────────────────────────────────── */
code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.87em;
    background: rgba(247,147,26,0.08);
    color: var(--btc-dark);
    padding: 0.15rem 0.45rem;
    border-radius: var(--radius-xs);
}

pre {
    background: var(--paper-code);
    color: #e2e8f0;
    padding: 1.5rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.88rem;
    line-height: 1.65;
    margin: 1.25rem 0;
    border: 1px solid rgba(255,255,255,0.06);
    position: relative;
}

pre code {
    background: none;
    color: inherit;
    padding: 0;
    font-size: inherit;
}

pre .comment { color: #6a737d; font-style: italic; }
pre .keyword { color: #ff79c6; }
pre .string  { color: #f1fa8c; }
pre .type    { color: #8be9fd; }
pre .func    { color: #50fa7b; }

/* ── Callout Boxes ───────────────────────────────────────────────── */
.callout {
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-sm);
    margin: 1.5rem 0;
    border-left: 4px solid;
    font-size: 0.93rem;
}

.callout-title {
    font-weight: 700;
    font-size: 0.88rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.callout.info {
    background: #ebf8ff;
    border-color: var(--accent-blue);
}
.callout.info .callout-title { color: var(--accent-blue); }

.callout.tip {
    background: #f0fff4;
    border-color: var(--accent-green);
}
.callout.tip .callout-title { color: var(--accent-green); }

.callout.warning {
    background: var(--btc-light);
    border-color: var(--btc);
}
.callout.warning .callout-title { color: var(--btc-dark); }

.callout.important {
    background: #fff5f5;
    border-color: var(--accent-red);
}
.callout.important .callout-title { color: var(--accent-red); }

/* ── Key Concept Cards ───────────────────────────────────────────── */
.concept-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}

.concept-card {
    background: var(--paper-warm);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: var(--radius-sm);
    padding: 1.25rem;
    transition: all 0.2s;
}

.concept-card:hover {
    box-shadow: var(--shadow-md);
    border-color: rgba(247,147,26,0.2);
}

.concept-card .icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.concept-card h4 {
    font-size: 0.95rem;
    margin-top: 0;
    margin-bottom: 0.4rem;
    color: var(--ink);
}

.concept-card p {
    font-size: 0.85rem;
    color: var(--ink-muted);
    margin: 0;
    line-height: 1.5;
}

/* ── Data Structure / Diagram Boxes ──────────────────────────────── */
.struct-box {
    background: linear-gradient(135deg, #fafafa 0%, #f0f0f0 100%);
    border: 2px solid #e2e8f0;
    border-radius: var(--radius);
    padding: 1.5rem;
    margin: 1.5rem 0;
    position: relative;
}

.struct-box::before {
    content: attr(data-label);
    position: absolute;
    top: -0.6rem;
    left: 1rem;
    background: var(--paper);
    padding: 0 0.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--btc);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.struct-fields {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.88rem;
}

.struct-field {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: white;
    border-radius: var(--radius-xs);
    border-left: 3px solid var(--btc);
}

.struct-field .type { color: var(--accent-blue); font-weight: 500; }
.struct-field .name { color: var(--ink); font-weight: 600; }
.struct-field .desc {
    color: var(--ink-muted);
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    margin-left: auto;
}

/* ── Flow Diagrams ───────────────────────────────────────────────── */
.flow {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    margin: 1.5rem 0;
}

.flow-step {
    background: var(--paper-warm);
    border: 2px solid #e2e8f0;
    border-radius: var(--radius-sm);
    padding: 1rem 1.5rem;
    width: 100%;
    max-width: 500px;
    text-align: center;
    transition: all 0.2s;
}

.flow-step:hover {
    border-color: var(--btc);
    box-shadow: var(--shadow-glow);
}

.flow-step strong {
    display: block;
    font-size: 0.95rem;
    color: var(--ink);
}

.flow-step span {
    font-size: 0.82rem;
    color: var(--ink-muted);
}

.flow-arrow {
    color: var(--btc);
    font-size: 1.5rem;
    line-height: 1;
    padding: 0.25rem 0;
}

/* ── Chapter Navigation (prev/next) ──────────────────────────────── */
.chapter-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 2px solid rgba(0,0,0,0.06);
}

.chapter-nav a {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1.25rem;
    background: var(--paper-warm);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: var(--radius);
    transition: all 0.25s;
    color: inherit;
    text-decoration: none;
}

.chapter-nav a:hover {
    border-color: rgba(247,147,26,0.3);
    box-shadow: var(--shadow-glow);
    color: inherit;
}

.chapter-nav .label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--ink-muted);
    font-weight: 600;
}

.chapter-nav .title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
}

.chapter-nav .prev { text-align: left; }
.chapter-nav .next { text-align: right; }

/* ── Footer ──────────────────────────────────────────────────────── */
.book-footer {
    background: var(--ink);
    color: rgba(255,255,255,0.5);
    text-align: center;
    padding: 2rem;
    font-size: 0.85rem;
    margin-top: 3rem;
}

.book-footer a { color: var(--btc); }

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .chapter-body {
        grid-template-columns: 1fr;
        padding: 1.5rem 1rem 3rem;
    }
    .chapter-sidebar {
        position: static;
        max-height: none;
    }
    .mini-toc {
        display: flex;
        flex-wrap: wrap;
        gap: 0.25rem;
        padding: 1rem;
    }
    .mini-toc h4 {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    .mini-toc ul { display: flex; flex-wrap: wrap; gap: 0.25rem; }
    .mini-toc li { margin: 0; }
    .mini-toc .deep-dive { width: 100%; }
    .mini-toc .deep-dive ul { display: flex; flex-wrap: wrap; }
    .chapter-card { grid-template-columns: 44px 1fr auto; gap: 1rem; padding: 1rem; }
    .chapter-num { width: 44px; height: 44px; font-size: 0.95rem; }
    .chapter-nav { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .hero { padding: 3rem 1.5rem 2.5rem; }
    .chapter-header { padding: 2rem 1.5rem; }
    .concept-grid { grid-template-columns: 1fr; }
}

/* ── Utility ─────────────────────────────────────────────────────── */
.text-muted { color: var(--ink-muted); }
.text-btc   { color: var(--btc); }
.font-mono  { font-family: 'JetBrains Mono', monospace; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ═══════════════════════════════════════════════════════════════════════
   Interactive Animations
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Shared Controls ──────────────────────────────────────────── */
.anim-controls {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    padding: 1rem 0 0.5rem;
}
.anim-btn {
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.5rem 1.2rem;
    border: 2px solid var(--ink-faint);
    border-radius: 8px;
    background: var(--paper-warm);
    color: var(--ink-soft);
    cursor: pointer;
    transition: all 0.2s;
}
.anim-btn:hover:not(:disabled) {
    border-color: var(--btc);
    color: var(--btc);
    background: var(--btc-light);
}
.anim-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.anim-btn-primary {
    background: var(--btc);
    color: #fff;
    border-color: var(--btc);
}
.anim-btn-primary:hover:not(:disabled) {
    background: var(--btc-dark);
    color: #fff;
    border-color: var(--btc-dark);
}
.anim-btn-primary.playing {
    background: var(--ink-soft);
    border-color: var(--ink-soft);
}

/* ── Progress Bar ─────────────────────────────────────────────── */
.anim-progress {
    height: 4px;
    background: rgba(0,0,0,0.06);
    border-radius: 4px;
    margin: 0.5rem 0;
    overflow: hidden;
}
.anim-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--btc), var(--btc-dark));
    border-radius: 4px;
    transition: width 0.4s ease;
    width: 0%;
}

/* ── Dots ─────────────────────────────────────────────────────── */
.anim-dots {
    display: flex;
    gap: 6px;
    justify-content: center;
    padding: 0.5rem 0;
}
.anim-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all 0.3s;
}
.anim-dot.done { background: var(--accent-green); }
.anim-dot.active {
    background: var(--btc);
    transform: scale(1.3);
    box-shadow: 0 0 8px var(--btc-glow);
}

/* ── Stack Animation Widget ───────────────────────────────────── */
.anim-stack-widget {
    background: var(--paper-warm);
    border: 2px solid rgba(0,0,0,0.08);
    border-radius: 12px;
    padding: 1.5rem;
    margin: 2rem 0;
    box-shadow: var(--shadow-md);
}
.anim-layout {
    display: grid;
    grid-template-columns: 1fr 240px;
    gap: 1.5rem;
    min-height: 240px;
}
@media (max-width: 700px) {
    .anim-layout { grid-template-columns: 1fr; }
}
.anim-desc-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.anim-step-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 600;
    color: var(--btc);
    margin-bottom: 0.5rem;
}
.anim-step-desc {
    font-size: 0.95rem;
    color: var(--ink-soft);
    line-height: 1.6;
}
.anim-step-desc code {
    background: rgba(0,0,0,0.06);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
}

/* ── Stack Visualization ──────────────────────────────────────── */
.anim-stack-panel {
    display: flex;
    flex-direction: column;
}
.anim-stack-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-muted);
    margin-bottom: 0.5rem;
    text-align: center;
}
.anim-stack-viz {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 4px;
    background: var(--paper-code);
    border-radius: 8px;
    padding: 0.75rem;
    min-height: 200px;
}
.anim-stack-empty {
    color: rgba(255,255,255,0.25);
    font-style: italic;
    text-align: center;
    font-size: 0.85rem;
    margin: auto 0;
}
.anim-stack-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.1);
    animation: stackSlideIn 0.35s ease-out;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
}
.anim-stack-item.anim-stack-new {
    animation: stackPop 0.45s ease-out;
    background: rgba(247, 147, 26, 0.15);
    border-color: rgba(247, 147, 26, 0.3);
}
.anim-stack-item.anim-stack-highlight {
    background: rgba(49, 130, 206, 0.2);
    border-color: rgba(49, 130, 206, 0.4);
}
.anim-stack-item.anim-stack-success {
    background: rgba(56, 161, 105, 0.25);
    border-color: rgba(56, 161, 105, 0.5);
}
.anim-stack-item.anim-stack-fail {
    background: rgba(229, 62, 62, 0.25);
    border-color: rgba(229, 62, 62, 0.5);
}
.anim-stack-label {
    color: var(--ink-faint);
    font-size: 0.7rem;
    min-width: 3rem;
}
.anim-stack-value {
    color: #e2e8f0;
    flex: 1;
    word-break: break-all;
}
.anim-stack-top-marker {
    color: var(--btc);
    font-size: 0.65rem;
    opacity: 0.7;
    white-space: nowrap;
}

@keyframes stackSlideIn {
    from { opacity: 0; transform: translateX(-10px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes stackPop {
    0%   { opacity: 0; transform: scale(0.8) translateY(8px); }
    60%  { transform: scale(1.05) translateY(-2px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Lifecycle Animation Widget ───────────────────────────────── */
.anim-lifecycle-widget {
    background: var(--paper-warm);
    border: 2px solid rgba(0,0,0,0.08);
    border-radius: 12px;
    padding: 1.5rem;
    margin: 2rem 0;
    box-shadow: var(--shadow-md);
}
.anim-pipeline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 1rem 0;
    flex-wrap: wrap;
}
.anim-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    padding: 0.75rem 0.5rem;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    min-width: 70px;
}
.anim-stage:hover { background: var(--btc-light); }
.anim-stage.active {
    background: var(--btc-light);
    box-shadow: 0 0 0 2px var(--btc);
}
.anim-stage.done .anim-stage-icon {
    position: relative;
}
.anim-stage.done .anim-stage-icon::after {
    content: '✓';
    position: absolute;
    bottom: -2px;
    right: -6px;
    font-size: 0.65rem;
    color: var(--accent-green);
    font-weight: bold;
}
.anim-stage-icon {
    font-size: 1.6rem;
    position: relative;
}
.anim-stage-name {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--ink-soft);
    text-align: center;
    line-height: 1.2;
}
.anim-stage-arrow {
    font-size: 1.2rem;
    color: var(--ink-faint);
    padding: 0 0.15rem;
}
.anim-detail {
    background: var(--paper);
    border-radius: 8px;
    padding: 1.25rem;
    margin-top: 0.75rem;
    min-height: 100px;
    border: 1px solid rgba(0,0,0,0.05);
    transition: all 0.3s;
}
.anim-detail-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 0.5rem;
}
.anim-detail-body {
    font-size: 0.9rem;
    color: var(--ink-soft);
    line-height: 1.65;
}
.anim-detail-body code {
    background: rgba(0,0,0,0.06);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
}
.anim-detail-body ul {
    margin: 0.5rem 0;
    padding-left: 1.2rem;
}
.anim-detail-body li {
    margin: 0.25rem 0;
}

/* ── TX Anatomy Animation Widget ──────────────────────────────── */
.anim-tx-widget {
    background: var(--paper-warm);
    border: 2px solid rgba(0,0,0,0.08);
    border-radius: 12px;
    padding: 1.5rem;
    margin: 2rem 0;
    box-shadow: var(--shadow-md);
}
.anim-tx-title {
    text-align: center;
    font-size: 0.9rem;
    color: var(--ink-muted);
    margin-bottom: 1rem;
}
.anim-tx-diagram {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    justify-content: center;
    margin-bottom: 1rem;
}
.anim-tx-part {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    border: 2px solid transparent;
    min-width: 70px;
}
.anim-tx-part:nth-child(odd)  { background: rgba(49, 130, 206, 0.08); }
.anim-tx-part:nth-child(even) { background: rgba(128, 90, 213, 0.08); }
.anim-tx-part:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-sm);
}
.anim-tx-part.selected {
    border-color: var(--btc);
    background: var(--btc-light);
    box-shadow: 0 0 12px var(--btc-glow);
}
.anim-tx-part-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ink-soft);
}
.anim-tx-part-bytes {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    color: var(--ink-muted);
    margin-top: 2px;
}
.anim-tx-detail {
    background: var(--paper);
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid rgba(0,0,0,0.05);
    min-height: 80px;
}
.anim-tx-detail-inner {
    font-size: 0.9rem;
    color: var(--ink-soft);
    line-height: 1.6;
}
.anim-tx-detail-inner h4 {
    font-family: 'JetBrains Mono', monospace;
    color: var(--ink);
    margin: 0 0 0.5rem;
    font-size: 1rem;
}
.anim-tx-detail-inner code {
    background: rgba(0,0,0,0.06);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
}
