/* ctos docs — narrow-viewport / mobile compliance.
 *
 * Stock mdBook 0.5.4 already ships:
 *   - <meta name="viewport" content="width=device-width, initial-scale=1">
 *   - sidebar hamburger (#mdbook-sidebar-toggle)
 *   - --sidebar-width: min(300px, 80vw)
 *   - .table-wrapper { overflow-x: auto }
 *   - .content img { max-width: 100% }
 *
 * This file closes the remaining gaps vs the architecture.artof.link bar:
 * wrap/scroll instead of page-wide overflow, readable type, 44px touch.
 * Desktop layout stays the mdBook default (750px content column).
 */

.content,
.content main {
    min-width: 0;
    max-width: min(var(--content-max-width), 100%);
}

.content pre,
.content pre > code {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-wrapper {
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

.content table td,
.content table th {
    overflow-wrap: break-word;
    word-break: normal;
}

.content table td code,
.content table th code {
    word-break: break-all;
}

.content img,
.content video {
    max-width: 100%;
    height: auto;
}

/* Wide identifier strings in headings (target triples, symbol names). */
.content h1,
.content h2,
.content h3 {
    overflow-wrap: break-word;
}

/*
 * 44×44px tap targets on mdBook 0.5.4 chrome (all viewports).
 * Stock chrome sets #mdbook-menu-bar .icon-button / .fa-svg to
 * padding:0 8px (0 5px under 420px) with no min-width — DSO measured
 * header icons under 44px at laptop width. Right-side print/GitHub
 * controls are <a> + .fa-svg, not .icon-button. Force box size with
 * enough specificity (and !important on min-*) to beat chrome.css.
 */
#mdbook-menu-bar .icon-button,
#mdbook-menu-bar label.icon-button,
#mdbook-menu-bar button.icon-button,
#mdbook-sidebar-toggle,
.menu-bar .icon-button,
#mdbook-menu-bar .right-buttons > a,
#mdbook-menu-bar .left-buttons > .icon-button {
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 0 10px !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    line-height: 1 !important;
}

/* Nested FA SVG must not become a second undersized hit target. */
#mdbook-menu-bar .icon-button .fa-svg,
#mdbook-menu-bar .right-buttons > a > .fa-svg {
    min-width: 0 !important;
    min-height: 0 !important;
    padding: 0 !important;
    line-height: 1 !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.mobile-nav-chapters {
    min-width: 44px !important;
    min-height: 44px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

@media (max-width: 768px) {
    :root {
        --page-padding: 12px;
        /* Stock is 50px; keep ≥44px on phones (safe-area padding is extra). */
        --menu-bar-height: 50px;
    }

    /* 1.6rem × 62.5% root = 16px. Do not shrink body type on phones. */
    body {
        font-size: 1.6rem;
    }

    .content table td,
    .content table th,
    .content table thead th,
    .content table thead td {
        padding: 0.45rem 0.65rem;
    }

    /* Scroll a wide table instead of crushing columns (ledger, FR/NFR). */
    .table-wrapper table {
        min-width: 28rem;
    }

    /* Sidebar chapter links + fold chevrons (mdBook fold UI). */
    .chapter li a,
    .chapter-fold-toggle {
        min-height: 44px !important;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        box-sizing: border-box;
    }

    .chapter-fold-toggle {
        justify-content: center;
        padding: 0 12px !important;
    }

    .chapter-link-wrapper {
        align-items: center;
        min-height: 44px;
    }

    .content pre > code {
        font-size: clamp(1.2rem, 3.6vw, 1.4rem);
    }

    #mdbook-menu-bar {
        min-height: var(--menu-bar-height);
        height: auto;
        padding-top: env(safe-area-inset-top, 0px);
        padding-left: env(safe-area-inset-left, 0px);
        padding-right: env(safe-area-inset-right, 0px);
    }

    .content {
        padding-bottom: calc(50px + env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 420px) {
    :root {
        --page-padding: 10px;
    }

    /* Beat stock chrome padding:0 5px under 420px without shrinking hits. */
    #mdbook-menu-bar .icon-button,
    #mdbook-menu-bar label.icon-button,
    #mdbook-menu-bar button.icon-button,
    #mdbook-sidebar-toggle,
    #mdbook-menu-bar .right-buttons > a {
        min-width: 44px !important;
        min-height: 44px !important;
        padding: 0 10px !important;
    }
}
