body {
    background-color: #fbf9f4;
    color: #1b1c19;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.nav-item-active {
    background-color: #eae8e3;
    color: #181c1f;
    font-weight: 700;
}

.nav-item-inactive {
    color: #45464d;
}

.mobile-bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-nav-item {
    min-width: 0;
    flex: 1 1 0;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.05rem;
    border-radius: 0.6rem;
    padding: 0.35rem 0.15rem;
    font-family: "Hanken Grotesk", sans-serif;
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1.1;
    white-space: nowrap;
}

.mobile-nav-item .material-symbols-outlined {
    font-size: 1.15rem;
}

.mobile-nav-item span:last-child {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hairline-border {
    border-color: #c4c7ca;
}

.book-cover {
    aspect-ratio: 1 / 1.5;
    border: 1px solid #e0e3e5;
}

.text-balance {
    text-wrap: balance;
}

.book-section-summary {
    list-style: none;
}

.book-section-summary::-webkit-details-marker {
    display: none;
}

.book-section-chevron {
    transition: transform 180ms ease;
}

.book-section[open] .book-section-chevron {
    transform: rotate(180deg);
}

.summary-feature-card {
    border: 1px solid #c4c7ca;
    border-radius: 1rem;
    background:
        linear-gradient(135deg, rgba(239, 224, 208, 0.55), rgba(255, 255, 255, 0) 42%),
        #ffffff;
    padding: clamp(1.5rem, 4vw, 3rem);
    box-shadow: 0 18px 50px rgba(27, 28, 25, 0.06);
}

.summary-note-card {
    border: 1px solid #e4e2dd;
    border-radius: 0.75rem;
    background: #ffffff;
    padding: clamp(1.25rem, 3vw, 2rem);
}

.part-overview-text {
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.summary-note-card.is-open .part-overview-text {
    display: block;
    overflow: visible;
    white-space: pre-line;
}

.part-overview-toggle {
    transition: color 160ms ease;
    color: inherit;
    line-height: 1;
}

.part-overview-chevron {
    transition: transform 180ms ease;
}

.part-overview-toggle[aria-expanded="true"] .part-overview-chevron {
    transform: rotate(180deg);
}

.distilled-text {
    display: -webkit-box;
    -webkit-line-clamp: 6;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

#distilled-content.is-open .distilled-text {
    display: block;
    overflow: visible;
    white-space: pre-line;
}

.summary-prose {
    max-width: 78ch;
}

.summary-prose-wide {
    max-width: none;
}

.summary-prose p + p {
    margin-top: 1rem;
}

.chapter-card-summary {
    list-style: none;
    position: relative;
}

.chapter-card-summary::-webkit-details-marker {
    display: none;
}

.chapter-card-action {
    transition: color 160ms ease;
}

.chapter-summary-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    transition: color 180ms ease;
}

.chapter-summary-card.is-open .chapter-summary-text {
    display: block;
    overflow: visible;
    color: #1b1c19;
}

.chapter-card-action-close {
    display: none;
}

.chapter-card-action[aria-expanded="true"] .chapter-card-action-open {
    display: none;
}

.chapter-card-action[aria-expanded="true"] .chapter-card-action-close {
    display: inline;
}

.chapter-card-action[aria-expanded="true"] {
    color: #675d50;
}

.chapter-card-chevron {
    transition: transform 180ms ease;
}

.chapter-card-action[aria-expanded="true"] .chapter-card-chevron {
    transform: rotate(180deg);
}

.material-symbols-outlined {
    font-variation-settings: "FILL" 0, "wght" 300, "GRAD" 0, "opsz" 24;
}

.icon-fill {
    font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 0, "opsz" 24;
}

.knowledge-graph-canvas {
    width: 100%;
    height: 680px;
    position: relative;
    background:
        radial-gradient(circle at 1px 1px, rgba(116, 119, 122, 0.16) 1px, transparent 0),
        #fbf9f4;
    background-size: 24px 24px;
}

.summary-tree-canvas {
    width: 100%;
    height: 720px;
    position: relative;
    overflow: hidden;
    background: #fbf9f4;
}

.summary-tree-canvas canvas {
    display: block;
    cursor: grab;
    touch-action: none;
}

.summary-tree-canvas canvas:active {
    cursor: grabbing;
}

.summary-tree-tooltip {
    position: absolute;
    display: none;
    pointer-events: none;
    background: rgba(27, 28, 25, 0.94);
    color: #fbf9f4;
    padding: 8px 10px;
    border-radius: 6px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
    font-family: "Hanken Grotesk", sans-serif;
    font-size: 12px;
    line-height: 1.35;
    max-width: 280px;
    z-index: 5;
}

.summary-tree-tooltip .tooltip-level {
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(251, 249, 244, 0.6);
    margin-bottom: 2px;
}

.summary-tree-tooltip .tooltip-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.summary-tree-tooltip .tooltip-meta {
    font-size: 11px;
    color: rgba(251, 249, 244, 0.7);
}

.graph-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.graph-toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.graph-toggle-track {
    display: inline-block;
    width: 32px;
    height: 18px;
    border-radius: 999px;
    background: #c4c7ca;
    position: relative;
    flex-shrink: 0;
    transition: background 0.18s ease;
}

.graph-toggle-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.18s ease;
}

.graph-toggle input:checked + .graph-toggle-track {
    background: #476f95;
}

.graph-toggle input:checked + .graph-toggle-track::after {
    transform: translateX(14px);
}

.graph-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid #c4c7ca;
    border-radius: 999px;
    padding: 0.25rem 0.55rem;
    color: #44474a;
    font-size: 0.875rem;
    line-height: 1.2;
}

.graph-legend-item span {
    display: inline-block;
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 999px;
}

.graph-detail-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    border-top: 1px solid #e4e2dd;
    padding: 0.65rem 0;
}

.graph-detail-row span {
    color: #44474a;
}

.graph-detail-row strong {
    color: #1b1c19;
    font-weight: 600;
    text-align: right;
}

.chat-scroll {
    scrollbar-width: thin;
    scrollbar-color: #c4c7ca transparent;
}

.chat-message-user {
    background-color: #f0eee9;
    color: #1b1c19;
    border: 1px solid #e4e2dd;
    border-radius: 1rem 0.25rem 1rem 1rem;
    padding: 1rem 1.25rem;
    line-height: 1.55;
}

.chat-message-assistant {
    background-color: #ffffff;
    color: #1b1c19;
    border: 1px solid #c4c7ca;
    border-radius: 0.25rem 1rem 1rem 1rem;
    padding: 1.25rem;
    line-height: 1.65;
    box-shadow: 0 1px 2px rgba(27, 28, 25, 0.04);
}

.chat-message-assistant p + p {
    margin-top: 1rem;
}

.chat-message-assistant h1,
.chat-message-assistant h2,
.chat-message-assistant h3 {
    font-family: "Newsreader", serif;
    font-weight: 500;
    color: #181c1f;
    margin-top: 1.5rem;
    margin-bottom: 0.4rem;
    line-height: 1.3;
}

.chat-message-assistant h1 { font-size: 1.35rem; }
.chat-message-assistant h2 { font-size: 1.15rem; }
.chat-message-assistant h3 { font-size: 1rem; font-weight: 600; }

.chat-message-assistant ul,
.chat-message-assistant ol {
    padding-left: 1.4rem;
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
}

.chat-message-assistant ul { list-style: disc; }
.chat-message-assistant ol { list-style: decimal; }

.chat-message-assistant li + li {
    margin-top: 0.35rem;
}

.chat-message-assistant li > ul,
.chat-message-assistant li > ol {
    margin-top: 0.25rem;
    margin-bottom: 0.25rem;
}

.chat-message-assistant strong { font-weight: 600; color: #181c1f; }
.chat-message-assistant em { font-style: italic; }

.chat-message-assistant code {
    font-family: ui-monospace, monospace;
    font-size: 0.85em;
    background-color: #f0eee9;
    border: 1px solid #e4e2dd;
    border-radius: 0.2rem;
    padding: 0.1em 0.35em;
}

.chat-message-assistant pre {
    background-color: #f0eee9;
    border: 1px solid #e4e2dd;
    border-radius: 0.5rem;
    padding: 1rem 1.25rem;
    margin-top: 0.75rem;
    overflow-x: auto;
}

.chat-message-assistant pre code {
    background: none;
    border: none;
    padding: 0;
    font-size: 0.875rem;
}

.chat-message-assistant blockquote {
    border-left: 3px solid #c4c7ca;
    margin: 1rem 0;
    padding: 0.4rem 0 0.4rem 1rem;
    color: #44474a;
    font-style: italic;
}

.chat-message-assistant hr {
    border: none;
    border-top: 1px solid #e4e2dd;
    margin: 1.25rem 0;
}

.citation-badge {
    display: inline-flex;
    align-items: center;
    border: 1px solid #c4c7ca;
    border-radius: 999px;
    background-color: #f5f3ee;
    color: #181c1f;
    font-size: 0.75rem;
    line-height: 1;
    padding: 0.2rem 0.45rem;
    margin: 0 0.1rem;
    white-space: nowrap;
}

button.citation-badge {
    cursor: pointer;
    font-family: inherit;
    vertical-align: baseline;
    transition: background-color 120ms ease, border-color 120ms ease;
}

button.citation-badge:hover {
    background-color: #ede9e0;
    border-color: #a8a09a;
}

/* Sources dropdown -------------------------------------------------- */

.sources-dropdown {
    border-top: 1px solid #e4e2dd;
}

.sources-summary {
    list-style: none;
    padding-top: 0.6rem;
}

.sources-summary::-webkit-details-marker {
    display: none;
}

.sources-chevron {
    transition: transform 160ms ease;
}

.sources-dropdown[open] .sources-chevron {
    transform: rotate(180deg);
}

.source-card {
    border: 1px solid #e4e2dd;
    border-radius: 0.625rem;
    background: #faf9f6;
    transition: background-color 400ms ease, border-color 400ms ease;
}

.source-card--highlight {
    animation: source-card-flash 1.4s ease forwards;
}

@keyframes source-card-flash {
    0%   { background-color: #f0e6cc; border-color: #c9b896; }
    60%  { background-color: #f0e6cc; border-color: #c9b896; }
    100% { background-color: #faf9f6; border-color: #e4e2dd; }
}

.source-card .citation-badge {
    font-size: 0.7rem;
}

.source-quote {
    margin: 0;
    padding-left: 0.7rem;
    border-left: 3px solid #c9b896;
    font-style: italic;
    color: #2c3033;
}

/* ------------------------------------------------------------------- */

.chat-detail-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    border-top: 1px solid #e4e2dd;
    padding: 0.55rem 0;
}

.chat-detail-row span {
    color: #44474a;
}

.chat-detail-row strong {
    color: #1b1c19;
    font-weight: 600;
    text-align: right;
}

.chat-pulse {
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 999px;
    background-color: #181c1f;
    animation: chatPulse 1s ease-in-out infinite;
}

@keyframes chatPulse {
    0%, 100% {
        opacity: 0.25;
        transform: scale(0.85);
    }
    50% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.6s ease-out forwards;
}

.delay-100 {
    animation-delay: 100ms;
}

.delay-200 {
    animation-delay: 200ms;
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #fbf9f4;
}

::-webkit-scrollbar-thumb {
    background: #e4e2dd;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #c4c7ca;
}

/* ── Book Opening Animation ──────────────────────────────────────────────── */

/*
 * Two panels meeting at the CENTER (the spine).
 * Only the RIGHT cover swings open: its free (right) edge lifts toward the
 * viewer (+Z), sweeps through center, and lands face-down on the LEFT half.
 *
 * Right panel: transform-origin left center, rotateY 0° → −180°
 *   free edge at x_local = +50vw → z' = −50vw·sin(θ)
 *   sin(θ) < 0 for θ∈(−180°,0°) → z' > 0 (toward viewer) ✓
 *   At −180° the panel covers the LEFT half (x: 0→50vw), back face showing.
 *
 * The cover is two-sided: the FRONT is the dark book cover, the BACK is the
 * left half of the website (a live clone of the sidebar). During the first
 * 90° the front lifts to reveal the right half of the real app; during the
 * second 90° the cover folds onto the left half, unveiling the site's left
 * half on its interior. The whole thing then fades out — a seamless swap to
 * the real app, since both halves already match what's underneath.
 *
 * The LEFT panel stays dark behind the cover until it is folded over.
 */
#book-opening-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    perspective: 1500px;
    perspective-origin: 55% 50%;
    pointer-events: none;
}

#book-page-left,
#book-page-right {
    width: 50%;
    height: 100%;
    position: relative;
}

#book-page-left {
    overflow: hidden;
    background: linear-gradient(135deg, #2e2318 0%, #1e1b14 55%, #131008 100%);
    will-change: opacity;
}

/* The right cover is a two-sided 3D panel hinged at the spine (its left edge).
   NOTE: keep will-change to `transform` only — adding a grouping property like
   `opacity` here forces transform-style back to `flat` and kills the 3D faces. */
#book-page-right {
    transform-origin: left center;
    transform-style: preserve-3d;
    will-change: transform;
}

/* Both faces fill the cover; only the forward-facing one is ever shown. */
#book-cover-front,
#book-cover-back {
    position: absolute;
    inset: 0;
    overflow: hidden;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* FRONT face: the dark book cover (faces the viewer while closed) */
#book-cover-front {
    background: linear-gradient(225deg, #2e2318 0%, #1e1b14 55%, #131008 100%);
}

/* BACK face: the left half of the website, "printed" on the cover interior.
   Rotated 180° so it reads correctly once the cover folds onto the left half. */
#book-cover-back {
    background: #fbf9f4;
    transform: rotateY(180deg);
}

/* A soft inner shadow near the spine adds depth to the open interior */
#book-cover-back::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    width: 80px;
    height: 100%;
    background: linear-gradient(to right, transparent, rgba(0, 0, 0, 0.06));
    pointer-events: none;
    z-index: 5;
}

/* linen weave texture on the dark surfaces */
#book-page-left::before,
#book-cover-front::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(255, 255, 255, 0.02) 3px, rgba(255, 255, 255, 0.02) 4px),
        repeating-linear-gradient(90deg, transparent, transparent 3px, rgba(255, 255, 255, 0.011) 3px, rgba(255, 255, 255, 0.011) 4px);
    pointer-events: none;
}

/* spine shadow along the center join */
#book-page-left::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    width: 60px;
    height: 100%;
    background: linear-gradient(to right, transparent, rgba(0, 0, 0, 0.5));
}

#book-cover-front::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 60px;
    height: 100%;
    background: linear-gradient(to left, transparent, rgba(0, 0, 0, 0.5));
}

/* cover title / logo — floats above the closed cover, centered on screen,
   fades out first (before the sweep reveals much) */
#book-cover-title {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    text-align: center;
    color: rgba(255, 255, 255, 0.88);
    pointer-events: none;
    white-space: nowrap;
}

#book-cover-title .bct-icon {
    font-size: 44px;
    display: block;
    margin: 0 auto 14px;
    opacity: 0.8;
    font-variation-settings: 'FILL' 0, 'wght' 200;
}

#book-cover-title .bct-rule {
    display: block;
    width: 44px;
    height: 1px;
    background: rgba(255, 255, 255, 0.28);
    margin: 10px auto;
}

#book-cover-title h2 {
    font-family: 'Newsreader', Georgia, serif;
    font-size: 30px;
    font-weight: 500;
    letter-spacing: 0.01em;
    line-height: 1.2;
    margin: 0;
}

#book-cover-title p {
    font-family: 'Hanken Grotesk', sans-serif;
    font-size: 11px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    opacity: 0.45;
    margin: 0;
}

/* ── Animation state ── */

/* Right cover: sweeps the full 180° — from right half, through center,
   landing face-down on the left half. Left panel stays dark throughout. */
.book-opening-animate #book-page-right {
    animation: coverOpenRight 1.6s cubic-bezier(0.4, 0, 0.45, 1) 0.1s both;
}

/* After the sweep, the whole overlay fades out to reveal the full app */
.book-opening-animate {
    animation: overlayFadeOut 0.4s ease 1.8s forwards;
}

.book-opening-animate #book-cover-title {
    animation: bookTitleFade 0.35s ease 0.1s forwards;
}

/* Right edge lifts toward viewer (+Z) then sweeps left, landing on left half */
@keyframes coverOpenRight {
    from { transform: rotateY(0deg); }
    to   { transform: rotateY(-180deg); }
}

@keyframes overlayFadeOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

@keyframes bookTitleFade {
    from { opacity: 1; }
    to   { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .book-opening-animate #book-page-left,
    .book-opening-animate #book-page-right,
    .book-opening-animate #book-cover-title {
        animation: none;
        opacity: 0;
    }
    .book-opening-animate {
        animation: none;
        opacity: 0;
    }
}

/* Suppress all hover effects while the book-opening animation is playing. */
body.book-animating #library-root,
body.book-animating .book-cover {
    pointer-events: none;
}

