/* App Footer Navigation - Always Visible */
:root {
    --ui-scale: 1.25; /* Desktop default */
    --mobile-button-min-size: 3rem; /* Minimum touch target size for mobile */
}

/* Reading Progress Bar */
.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 4px;
    height: 0%;
    background: linear-gradient(180deg, var(--bulma-scheme-main-ter, #667eea), var(--bulma-link, #485fc7));
    box-shadow: 2px 0 8px rgba(102, 126, 234, 0.4);
    z-index: 1002;
    transition: height 0.1s ease-out;
}

/* Sticky Display Navbar */
.display-navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: color-mix(in srgb, var(--bulma-scheme-main) 85%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--bulma-border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease, opacity 0.3s ease;
    padding: 0.5rem 1rem;
}

.display-navbar.hidden {
    transform: translateY(-100%);
    opacity: 0;
}

.display-navbar .breadcrumb {
    margin-bottom: 0;
    font-size: 0.9rem;
}

.display-navbar .breadcrumb ul {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.display-navbar .breadcrumb li {
    display: flex;
    align-items: center;
}

.display-navbar .breadcrumb li:not(:last-child)::after {
    content: '/';
    margin-left: 0.5rem;
    color: var(--bulma-text-weak, #7a7a7a);
}

.display-navbar .breadcrumb a {
    color: var(--bulma-link, #667eea);
    text-decoration: none;
    transition: color 0.2s;
}

.display-navbar .breadcrumb a:hover {
    color: var(--bulma-link-hover, #485fc7);
    text-decoration: underline;
}

.display-navbar .breadcrumb .is-active a {
    color: var(--bulma-text, #4a4a4a);
    cursor: default;
    pointer-events: none;
}

[data-theme="dark"] .display-navbar .breadcrumb .is-active a {
    color: var(--bulma-text, #dbdbdb);
}

.display-navbar .navbar-item {
    padding: 0;
}

.display-navbar .button {
    min-height: 2.5rem;
}

.app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bulma-scheme-main, #ffffff);
    border-top: 1px solid var(--bulma-border, #dbdbdb);
    padding: 0.75rem 1rem;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 999;
}

.app-footer .buttons {
    margin-bottom: 0;
}

.app-footer .button {
    min-width: calc(var(--mobile-button-min-size) * var(--ui-scale));
    min-height: calc(var(--mobile-button-min-size) * var(--ui-scale));
    font-size: calc(0.85rem * var(--ui-scale));
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-footer .nav-button .nav-title {
    margin-left: 0.5rem;
    margin-right: 0.5rem;
    white-space: nowrap;
}

.app-footer .nav-button:first-child .nav-title {
    margin-left: 0.5rem;
}

.app-footer .nav-button:last-child .nav-title {
    margin-right: 0.5rem;
}

/* Floating Scroll to Top Button */
#scrollToTop {
    position: fixed;
    bottom: 5.5rem;
    right: 1.5rem;
    z-index: 998;
    border-radius: 50%;
    width: calc(3rem * var(--ui-scale));
    height: calc(3rem * var(--ui-scale));
    padding: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
}

#scrollToTop:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.footer-left,
.footer-center,
.footer-right {
    display: flex;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
}

.footer-left {
    justify-content: flex-start;
}

.footer-center {
    justify-content: center;
}

.footer-right {
    justify-content: flex-end;
}

/* Mobile Menu */
.mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-menu-overlay.is-active {
    display: flex;
    opacity: 1;
    align-items: center;
    justify-content: center;
}

.mobile-menu {
    background: var(--bulma-scheme-main, #ffffff);
    border-radius: 0.5rem;
    padding: 2rem;
    max-width: 90%;
    width: 400px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.mobile-menu-overlay.is-active .mobile-menu {
    transform: scale(1);
}

.mobile-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.mobile-menu-header .title {
    margin-bottom: 0;
}

.mobile-menu-content .button {
    font-size: 1.25rem;
}

/* Responsive visibility helpers */
.mobile-only {
    display: none !important;
}

.desktop-only {
    display: flex !important;
}

@media screen and (max-width: 768px) {
    .mobile-only {
        display: flex !important;
    }

    .desktop-only {
        display: none !important;
    }

    .app-footer {
        padding: 0.5rem;
    }

    .app-footer .button {
        min-width: calc(var(--mobile-button-min-size) * var(--ui-scale));
        min-height: calc(var(--mobile-button-min-size) * var(--ui-scale));
        font-size: calc(1rem * var(--ui-scale));
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0.5rem;
    }

    .app-footer .button .icon {
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0;
    }

    .footer-left,
    .footer-center,
    .footer-right {
        min-width: 0;
    }

    .footer-left,
    .footer-right {
        flex: 0 0 auto;
    }

    .footer-center {
        flex: 1 1 auto;
    }

    #scrollToTop {
        bottom: 4.5rem;
        right: 1rem;
        width: calc(var(--mobile-button-min-size) * var(--ui-scale));
        height: calc(var(--mobile-button-min-size) * var(--ui-scale));
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .display-navbar {
        padding: 0.5rem;
    }

    .display-navbar .breadcrumb {
        font-size: 0.8rem;
        max-width: calc(100vw - 80px);
        overflow: hidden;
    }

    .display-navbar .breadcrumb ul {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .display-navbar .button {
        min-height: 2rem;
        font-size: 0.9rem;
    }

    .display-navbar .navbar-end {
        display: none;
    }
}

@media print {
    #content {
        max-width: 100%;
    }

    a::after {
        content: " (" attr(href) ")";
        font-size: 90%;
    }

    pre {
        white-space: pre-wrap;
        page-break-inside: avoid;
    }

    h1, h2, h3 {
        page-break-after: avoid;
    }

    .app-footer,
    #scrollToTop,
    .reading-progress,
    .display-navbar {
        display: none;
    }
}

/* Page Layout */
body {
    padding-bottom: 6rem;
}

/* Reader Column */
#content {
    max-width: 70ch; /* Optimal line length: 45-75 characters */
    margin: 0 auto;
    padding: 0 1rem;
}

@media screen and (max-width: 768px) {
    #content {
        max-width: 100%;
        padding: 0 1rem;
    }
}

/* Content Typography */
#content h1,
#content h2,
#content h3,
#content h4,
#content h5,
#content h6 {
    font-weight: 600;
    line-height: 1.3;
    margin-top: 1.6em;
    margin-bottom: 0.5em;
}

#content {
    font-size: calc(1rem * var(--ui-scale));
}

#content h1 {
    font-size: 2.1em;
    margin-top: 0;
}

#content h2 {
    font-size: 1.6em;
}

#content h3 {
    font-size: 1.3em;
}

#content p {
    margin: 0 0 0.9em 0;
}

#content ul,
#content ol {
    padding-left: 1.4em;
    margin-bottom: 1em;
}

#content li {
    margin-bottom: 0.3em;
}

/* Inline Code */
#content code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
    background: var(--bulma-code-background, #f5f5f5);
    color: var(--bulma-code, #da1039);
    padding: 2px 5px;
    border-radius: 4px;
}

/* Code Blocks */
#content pre {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
    background: var(--bulma-pre-background, #f5f5f5);
    color: var(--bulma-pre, #363636);
    padding: 14px 16px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 1.2em 0;
}

#content pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

/* Blockquotes */
#content blockquote {
    border-left: 3px solid var(--bulma-border, #dbdbdb);
    padding-left: 12px;
    margin: 1em 0;
    color: var(--bulma-text-weak, #7a7a7a);
    font-style: italic;
}

/* Images */
#content img {
    max-width: 100%;
    margin: 1.5em auto;
    display: block;
    border-radius: 6px;
}

/* Tables */
#content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
    margin: 1.5em 0;
}

#content th,
#content td {
    border: 1px solid var(--bulma-border, #dbdbdb);
    padding: 6px 8px;
}

#content th {
    background: var(--bulma-table-cell-heading-background-color, #f5f5f5);
    font-weight: 600;
}

/* Horizontal Rule */
#content hr {
    border: none;
    height: 1px;
    background: var(--bulma-border, #dbdbdb);
    margin: 2em 0;
}

/* Book Style Variant */
body.book {
    font-size: 15px;
    line-height: 1.45;
}

body.book #content {
    max-width: 600px;
}

body.book p {
    margin-bottom: 0.75em;
}

body.book h1 {
    font-size: 1.9rem;
}

body.book h2 {
    font-size: 1.45rem;
}

body.book h3 {
    font-size: 1.2rem;
}

body.book ul,
body.book ol {
    margin-bottom: 0.8em;
}

/* TOC Sidebar */
#toc {
    position: fixed;
    top: 100px;
    right: 32px;
    width: 240px;
    max-height: 70vh;
    overflow-y: auto;
    font-size: 0.9em;
    padding-left: 16px;
    border-left: 2px solid var(--bulma-border, #dbdbdb);
}

#toc h2 {
    font-size: 1em;
    margin-bottom: 0.5em;
    color: var(--bulma-text-weak, #7a7a7a);
}

#toc a {
    display: block;
    color: var(--bulma-text-weak, #7a7a7a);
    text-decoration: none;
    margin: 4px 0;
}

#toc a:hover {
    color: var(--bulma-link, #485fc7);
}

#toc .h2 { margin-left: 10px; }
#toc .h3 { margin-left: 20px; }

/* Hide TOC on medium screens */
@media (max-width: 1200px) {
    #toc {
        display: none;
    }
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    body {
        font-size: 18px;
        line-height: 1.6;
        padding-top: 70px;
        padding-bottom: 2rem;
    }

    #content {
        max-width: 100%;
        padding: 0 0.75rem;
    }

    #content h1 {
        font-size: 1.8rem;
    }

    #content h2 {
        font-size: 1.5rem;
    }

    #content h3 {
        font-size: 1.25rem;
    }
}

/* Extra Small Screens */
@media (max-width: 480px) {
    body {
        font-size: 17px;
        padding-top: 65px;
    }
}
