:root {
    --primary: #1a2a3a;
    --accent: #007aff;
    --text: #333;
    --subtitle-bg: #eef2f7;
    --bg-color: #ffffff;
    --title-font: 'Sofia Sans Extra Condensed', sans-serif;
    --body-font: 'Merriweather', serif;
    --header-height: 73px;
}

body {
    background-color: var(--bg-color);
    font-family: var(--body-font);
    font-size: 18px;
    font-weight: 400;
    line-height: 1.8;
    margin: 0;
    padding: 0;
    color: var(--text);
}

/* Global Menu */
.global-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: transparent;
    color: black;
    padding: 18px 24px;
    display: flex;
    justify-content: space-between;
    z-index: 1000;
    height: auto;
    pointer-events: none;
}

.global-header>* {
    pointer-events: auto;
}

.global-header a {
    color: black;
    text-decoration: none;
    font-weight: 400;
    font-size: 1.2rem;
    font-family: var(--body-font);
}

/* Hamburger Menu - hidden on desktop */
.hamburger-menu {
    display: none;
}

/* Search Container */
.search-container {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input {
    padding: 8px 40px 8px 12px;
    border: 2px solid #ddd;
    border-radius: 20px;
    font-size: 0.9rem;
    font-family: var(--body-font);
    width: 200px;
    transition: all 0.3s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
    width: 250px;
}

.search-button {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 0;
    width: 28px;
    height: 28px;
    cursor: pointer;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.search-button:hover {
    color: var(--accent);
    background: rgba(0, 122, 255, 0.1);
}

.search-button:active {
    transform: translateY(-50%) scale(0.95);
}

.search-results {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: 400px;
    overflow-y: auto;
    min-width: 300px;
    max-width: 500px;
    display: none;
    z-index: 1001;
}

.search-result-item {
    display: block;
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    text-decoration: none !important;
    color: var(--text);
    transition: background-color 0.2s;
    font-weight: normal !important;
    text-transform: none !important;
    letter-spacing: normal !important;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background-color: #f5f5f5;
}

.search-result-title {
    font-family: var(--title-font) !important;
    font-size: 1rem !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    color: var(--primary) !important;
    margin-bottom: 4px;
    letter-spacing: 1px !important;
    line-height: 1.1 !important;
}

.search-result-context {
    font-size: 0.85rem !important;
    line-height: 1.4 !important;
    color: #666 !important;
    font-family: 'Merriweather Sans', sans-serif !important;
    font-weight: 400 !important;
    text-transform: none !important;
    letter-spacing: normal !important;
}

.search-loading,
.search-no-results {
    padding: 16px;
    text-align: center;
    color: #999;
    font-size: 0.9rem;
    font-family: var(--body-font);
}

/* Tables */
.content-table {
    width: 100%;
    border-collapse: collapse;
    margin: 2rem 0;
    font-family: 'Merriweather Sans', sans-serif;
    font-size: 0.98rem;
    line-height: 1.55;
}

.content-table th,
.content-table td {
    border: none;
    border-bottom: 1px solid #e5e7eb;
    padding: 10px 12px 10px 0;
    text-align: left;
    vertical-align: top;
}

.content-table th:last-child,
.content-table td:last-child {
    padding-right: 0;
}

.content-table th {
    background-color: transparent;
    border-bottom: 2px solid #cbd5e1;
    font-weight: 700;
    font-size: 0.88rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #475569;
}

.content-table td[colspan="2"] {
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.06em;
    color: var(--primary);
    padding-top: 22px;
    padding-bottom: 8px;
}

.content-table td[colspan="2"]:empty {
    padding: 6px 0;
    border-bottom: none;
}

.content-table p {
    margin: 0 0 0.35rem;
}

.content-table p:last-child {
    margin-bottom: 0;
}

.content-table ul {
    margin: 0.2rem 0;
    padding-left: 1.2rem;
}

.content-table li {
    margin: 0.2rem 0;
}

/* Colored boxes - independent styling with strong overrides */
.colored-box {
    padding: 25px !important;
    margin: 1.5rem 0 !important;
    border-radius: 5px !important;
    font-family: 'Merriweather Sans', sans-serif !important;
    font-style: italic !important;
    font-weight: 400 !important;
    font-size: 1.1rem;
    /* Background color comes from inline style */
}

.colored-box ul {
    padding-left: 1.5rem !important;
    margin: 0.5rem 0 !important;
}

.colored-box li {
    margin: 0.25rem 0 !important;
}

/* Colored boxes inside tables */
.colored-box-table {
    padding: 10px;
    margin: 0.5rem 0;
    border-radius: 3px;
    font-family: 'Merriweather Sans', sans-serif;
    font-style: italic;
    font-weight: 400;
    display: block;
}

/* Strong overrides for colored boxes in tables */
.content-table th .colored-box-table,
.content-table td .colored-box-table,
.content-table th .colored-box-table *,
.content-table td .colored-box-table *,
.colored-box-table,
.colored-box-table * {
    font-family: 'Merriweather Sans', sans-serif !important;
    font-style: italic !important;
    font-weight: 400 !important;
    text-align: left !important;
    border: none !important;
    background: none !important;
    padding: 0 !important;
    margin: 0.25rem 0 !important;
}

.colored-box-table ul {
    padding-left: 1rem !important;
    margin: 0.25rem 0 !important;
}

.colored-box-content {
    font-family: 'Merriweather Sans', sans-serif;
    font-style: italic;
    font-weight: 400;
}

/* Lists */
ul {
    margin: 1rem 0;
    padding-left: 2rem;
}

li {
    margin: 0.5rem 0;
}

/* Nested lists */
ul ul {
    margin: 0.25rem 0;
    padding-left: 1.5rem;
}

ul ul li {
    list-style-type: circle;
}

ul ul ul li {
    list-style-type: square;
}

/* Blockquotes */
blockquote {
    margin: 1.5rem 0;
    padding-left: 2rem;
    padding-right: 1rem;
    border-left: 3px solid #ddd;
    font-style: italic;
    color: #555;
}

blockquote p {
    margin: 0.5rem 0;
}

/* Image captions */
.image-caption {
    font-size: 0.85rem;
    color: #666;
    text-align: center;
    margin: 0.5rem 0 1.5rem 0;
    font-style: italic;
}

.image-caption a {
    color: var(--accent);
    text-decoration: none;
}

.image-caption a:hover {
    text-decoration: underline;
}

/* Logic for hiding header title on index */
.is-index .header-title {
    opacity: 0;
    transition: opacity 0.3s;
}

.is-index .scrolled .header-title {
    opacity: 1;
}

main {
    max-width: 750px;
    margin: 0 auto;
    padding: 40px 24px;
}

h1 {
    font-family: var(--title-font);
    font-weight: 800;
    font-size: 4.5rem;
    text-transform: uppercase;
    color: var(--primary);
    margin-bottom: 0.5em;
    border-bottom: 2px solid #eee;
    padding-bottom: 10px;
    line-height: 0.9;
}

/* Page Title Hierarchy */
.heading-prefix {
    font-weight: 400;
    font-size: 1.8rem;
    color: var(--primary);
    opacity: 0.7;
    margin-bottom: 10px;
}

.heading-main {
    font-weight: 800;
}

/* General Light Font Style */
.light-prefix {
    font-weight: 400;
    opacity: 0.7;
    margin-right: 5px;
}

/* Role labels (small caps with letter spacing) */
.role-label {
    font-variant: small-caps;
    letter-spacing: 0.1em;
    font-weight: 700;
}

/* Index Page Titles */
.index-title {
    font-family: var(--body-font);
    font-weight: 300;
    font-size: 6rem;
    color: var(--primary);
    margin-bottom: 0;
    line-height: 1.0;
}

.index-subtitle {
    font-family: var(--body-font);
    font-weight: 400;
    font-family: 'Merriweather Sans', sans-serif;
    font-size: 24px;
    color: var(--text);
    margin-top: 5px;
    margin-bottom: 3em;
    color: rgb(155, 155, 155);
}

/* Index page blockquotes */
.index-blockquote {
    font-family: 'Merriweather', serif;
    font-style: italic;
    font-weight: 400;
    font-size: 22px;
    color: var(--text);
    margin: 1.5rem 0;
    padding: 0;
    border: none;
    max-width: 75%;
    line-height: 1.6;
}

.index-blockquote-text {
    font-family: 'Merriweather', serif;
    font-style: italic;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.index-blockquote-attribution {
    font-family: 'Merriweather Sans', sans-serif;
    font-style: normal;
    font-weight: 400;
    font-size: 16px;
    text-align: right;
}

/* Index background image */
.index-bg-image {
    position: absolute;
    right: 0;
    top: 40px;
    right: 200px;
    max-width: 350px;
    height: auto;
    z-index: -1;
    opacity: 0.9;
}

/* Low-level subtitles styling */
.body-subtitle {
    font-family: var(--title-font);
    font-size: 2.5rem;
    color: var(--primary);
    padding: 0;
    margin-top: 3rem;
    margin-bottom: 1rem;
    display: block;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Navigation styling */
.nav-container {
    display: flex;
    width: 100vw;
    position: relative;
    left: 50%;
    right: 50%;
    margin-left: -50vw;
    margin-right: -50vw;
    gap: 0;
}

.nav-box {
    flex: 1;
    display: flex;
    flex-direction: row;
    align-items: center;
    min-height: var(--header-height);
    padding: 15px 24px;
    border: 1px solid #eee;
    text-decoration: none;
    color: inherit;
    transition: background-color 0.2s;
    box-sizing: border-box;
    gap: 20px;
}

.nav-box:hover {
    background-color: rgba(0, 122, 255, 0.05);
}

.nav-box.empty {
    border: none;
}

.arrow-icon {
    width: 12px;
    height: 12px;
    border-top: 2px solid var(--accent);
    border-left: 2px solid var(--accent);
    flex-shrink: 0;
}

.arrow-left {
    transform: rotate(-45deg);
}

.arrow-right {
    transform: rotate(135deg);
}

.nav-title {
    font-family: var(--title-font);
    font-size: 1.2rem;
    font-weight: 800;
    text-transform: uppercase;
    line-height: 1.1;
    color: var(--primary);
    word-wrap: break-word;
}

.nav-prev {
    text-align: left;
    justify-content: flex-start;
}

.nav-next {
    text-align: right;
    justify-content: flex-end;
}

.top-nav {
    margin-top: var(--header-height);
}

.bottom-nav {
    margin-top: 60px;
}

/* TOC links */
.toc-container {
    padding: 20px 0;
}

.toc-subsection {
    color: #666;
    text-decoration: none;
    font-family: var(--title-font);
    font-weight: 700;
    display: block;
    margin-top: 12px;
    text-decoration: none;
    font-size: 1.4rem;
    text-transform: uppercase;
}

.toc-part-link {
    font-family: var(--title-font);
    font-weight: 800;
    font-size: 2rem;
    text-transform: uppercase;
    margin-top: 2.5rem;
    display: block;
    color: var(--accent);
    text-decoration: none;
    border-bottom: 3px dotted #e0e0e0;
    padding-bottom: 5px;
}

.toc-part-link:hover {
    text-decoration: underline;
}

.toc-chap-link {
    font-family: var(--title-font);
    font-weight: 700;
    display: block;
    margin-top: 12px;
    color: var(--accent);
    text-decoration: none;
    font-size: 1.4rem;
    text-transform: uppercase;
}

.toc-chap-link:hover {
    text-decoration: underline;
}

main a,
main a u {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 3px;
}

main a:hover,
main a:hover u {
    color: var(--accent);
}

footer {
    text-align: center;
    font-size: 0.85rem;
    color: #888;
    margin-top: 20px;
    padding-bottom: 10px;
}

footer a {
    color: #888;
    text-decoration: underline;
}

footer a:hover {
    color: var(--accent);
}

/* Full-width images (image_1 and image_2) */
.document-image-fullwidth {
    width: 100vw;
    max-width: 100vw;
    height: auto;
    display: block;
    margin: 20px 0;
    position: relative;
    left: 50%;
    right: 50%;
    margin-left: -50vw;
    margin-right: -50vw;
    object-fit: contain;
    cursor: pointer;
}

/* Constrained images (all others) */
.document-image-constrained {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 20px auto;
    cursor: pointer;
}

/* Link styling for images */
a:has(.document-image-fullwidth),
a:has(.document-image-constrained) {
    text-decoration: none;
    display: block;
    border: none;
    outline: none;
}

/* Hover effects */
.document-image-fullwidth:hover,
.document-image-constrained:hover {
    opacity: 0.9;
    transition: opacity 0.3s ease;
}

/* Mobile Styles */
@media (max-width: 768px) {
    body {
        font-size: 16px;
    }

    h1 {
        font-size: 2.5rem;
    }

    .heading-prefix {
        font-size: 1.2rem;
    }

    .index-title {
        font-size: 3rem;
    }

    .index-subtitle {
        font-size: 16px;
        margin-bottom: 9em;
    }

    .body-subtitle {
        font-size: 1.8rem;
        line-height: 2rem;
    }

    .global-header {
        transition: transform 0.25s ease, background-color 0.2s ease;
    }

    .global-header.scrolled {
        background: rgba(255, 255, 255, 0.96);
    }

    .global-header.header-hidden {
        transform: translateY(-100%);
    }

    .global-header a {
        font-size: 0.9rem;
        padding-top: 5px;
    }

    .content-table {
        font-size: 0.88rem;
    }

    .colored-box {
        font-size: 0.95rem;
        padding: 15px !important;
    }

    .nav-title {
        font-size: 1rem;
    }

    .toc-subsection {
        font-size: 1.1rem;
    }

    .toc-part-link {
        font-size: 1.5rem;
    }

    .toc-chap-link {
        font-size: 1.1rem;
    }

    footer {
        font-size: 0.8rem;
    }

    .image-caption {
        font-size: 0.8rem;
    }

    .index-bg-image {
        max-width: 200px;
        top: 135px;
        right: 0px !important;
    }

    main {
        padding: 30px 16px;
    }

    .global-header {
        padding: 10px 16px;
        flex-direction: row;
        gap: 12px;
        align-items: center;
    }

    .header-title {
        display: none;
        /* Hide the text title on mobile */
    }

    .search-container {
        flex: 1;
    }

    .search-input {
        width: 100%;
        font-size: 16px;
        /* Prevents zoom on iOS Safari */
        padding: 8px 40px 8px 12px;
        border-radius: 20px;
    }

    .search-input:focus {
        width: 100%;
    }

    .search-results {
        left: 0;
        right: 0;
        min-width: 100%;
        max-width: 100%;
        margin-top: 4px;
    }

    .hamburger-menu {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        padding: 8px;
        color: var(--primary);
        flex-shrink: 0;
    }

    .hamburger-menu svg {
        width: 24px;
        height: 24px;
    }
}

/* Search Results View */
.search-results-page {
    max-width: 900px;
    margin: 0 auto;
    padding: 40px 20px;
}

.search-results-header {
    margin-bottom: 30px;
}

.search-results-query {
    font-family: var(--title-font);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 10px;
}

.search-results-count {
    font-family: 'Merriweather Sans', sans-serif;
    font-size: 1rem;
    color: #666;
}

.search-result-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    transition: box-shadow 0.2s, border-color 0.2s;
    text-decoration: none;
    display: block;
    color: inherit;
}

.search-result-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-color: var(--accent);
}

.search-result-card-title {
    font-family: var(--title-font);
    font-size: 1.3rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 10px;
    letter-spacing: 1px;
    text-align: left;
}

.search-result-card-context {
    font-family: 'Merriweather Sans', sans-serif;
    font-size: 0.95rem;
    line-height: 1.6;
    color: #555;
    text-align: left;
}

.search-results-loading,
.search-results-empty {
    text-align: center;
    font-family: 'Merriweather Sans', sans-serif;
    font-size: 1.1rem;
    color: #666;
    padding: 30px 0;
}

/* Image Lightbox */
#appMain img:not(.index-bg-image) {
    cursor: zoom-in;
}

.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 35, 0.92);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: none;
    flex-direction: column;
    user-select: none;
    -webkit-user-select: none;
}

.lightbox-overlay.is-open {
    display: flex;
}

.lightbox-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    color: #f1f5f9;
    font-family: 'Merriweather Sans', sans-serif;
    font-size: 0.9rem;
    background: rgba(0, 0, 0, 0.35);
    z-index: 2002;
}

.lightbox-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.lightbox-btn {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.9rem;
    font-family: 'Merriweather Sans', sans-serif;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    transition: background 0.15s;
}

.lightbox-btn:hover {
    background: rgba(255, 255, 255, 0.24);
}

.lightbox-zoom-label {
    min-width: 52px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    color: #cbd5e1;
}

.lightbox-stage {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
}

.lightbox-img {
    max-width: 92vw;
    max-height: 82vh;
    object-fit: contain;
    transform-origin: center center;
    transition: transform 0.12s ease-out;
    cursor: zoom-in;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    border-radius: 4px;
}

.lightbox-img.is-zoomed {
    cursor: grab;
}

.lightbox-img.is-dragging {
    cursor: grabbing;
    transition: none;
}

.lightbox-hint {
    text-align: center;
    padding: 8px 16px;
    font-family: 'Merriweather Sans', sans-serif;
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.6);
    background: rgba(0, 0, 0, 0.25);
}

/* Live-text Pyramid Chart */
.pyramid-chart {
    display: grid;
    grid-template-columns: minmax(220px, 360px) 1fr;
    grid-template-rows: repeat(4, 1fr);
    align-items: center;
    column-gap: 24px;
    margin: 2rem 0;
    font-family: 'Merriweather Sans', sans-serif;
}

.pyramid-svg {
    grid-column: 1;
    grid-row: 1 / 5;
    width: 100%;
    height: auto;
    display: block;
}

.pyramid-label {
    grid-column: 2;
    font-size: 1rem;
    font-weight: 500;
    color: var(--primary);
    line-height: 1.35;
}

.pyramid-label:nth-child(2) {
    margin-left: -136px;
}

.pyramid-label:nth-child(3) {
    margin-left: -90px;
}

.pyramid-label:nth-child(4) {
    margin-left: -44px;
}

.pyramid-label:nth-child(5) {
    margin-left: 0;
}

@media (max-width: 600px) {
    .lightbox-toolbar {
        padding: 10px 12px;
        gap: 6px;
    }

    .lightbox-controls {
        gap: 6px;
    }

    .lightbox-btn {
        padding: 6px 10px;
        font-size: 0.82rem;
    }

    .lightbox-btn-text {
        display: none;
    }

    .lightbox-zoom-label {
        min-width: 44px;
        font-size: 0.82rem;
    }

    .pyramid-chart {
        grid-template-columns: 170px 1fr;
        column-gap: 14px;
    }

    .pyramid-label {
        font-size: 0.85rem;
    }

    .pyramid-label:nth-child(2) {
        margin-left: -64px;
    }

    .pyramid-label:nth-child(3) {
        margin-left: -42px;
    }

    .pyramid-label:nth-child(4) {
        margin-left: -20px;
    }

    .pyramid-label:nth-child(5) {
        margin-left: 0;
    }
}