/* reader pages: blog posts (blog/blog-post.php) and book chapters (blog/book/vagabond.php)
   loaded after /style.css; these pages no longer load style-blog.css.
   sizes are fluid (clamp/min/max with vw) so nothing jumps when the window width changes. */

/* ---------- root and page ---------- */

/* undo /style.css's 250% / 180% / 130% root steps on these pages only: 1rem = the reader's own text size */
html.reader {
    font-size: 100%;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    background-color: #000;
    color-scheme: dark;
}

html.reader *,
html.reader *::before,
html.reader *::after {
    box-sizing: border-box;
}

html.reader body {
    background-color: #000;
    color: #fff;
    padding: 0;
    /* side margin: 16px on phones, 20px from 480px, 24px from 600px (see the media queries below) */
    --side: 1rem;
    /* body text size before the pinch scale; also used to size the header and nav to the text column */
    --body-size: clamp(1rem, 0.93rem + 0.45vw, 1.25rem);
}

@media (min-width: 30em) {
    html.reader body { --side: 1.25rem; }
}

@media (min-width: 37.5em) {
    html.reader body { --side: 1.5rem; }
}

/* /style.css sizes p, ul, a, h1, h2 and h4 in rem for its own big root; reset them here */
html.reader p,
html.reader ul,
html.reader ol,
html.reader a,
html.reader h1,
html.reader h2,
html.reader h3,
html.reader h4,
html.reader h5,
html.reader h6 {
    font-size: inherit;
    line-height: inherit;
    margin: 0;
}

/* ---------- cursors (moved from style-blog.css) ---------- */

#blog-post-page, #blog-post-page * {
    cursor: url("/images/cursors/cursor-black.cur"), auto;
}

/* text cursor on readable text */
#blog-post-page p, #blog-post-page span, #blog-post-page h1, #blog-post-page h2, #blog-post-page h3, #blog-post-page h4, #blog-post-page h5, #blog-post-page h6,
#blog-post-page li, #blog-post-page label, #blog-post-page blockquote, #blog-post-page td, #blog-post-page th, #blog-post-page dd, #blog-post-page dt,
#blog-post-page input[type="text"], #blog-post-page input[type="email"], #blog-post-page input[type="search"], #blog-post-page input[type="password"],
#blog-post-page textarea, #blog-post-page [contenteditable] {
    cursor: url("/images/cursors/cursor-black-text.cur"), text;
}

/* link cursor on links and buttons; after the text rules so it wins on nested text */
#blog-post-page a, #blog-post-page a *, #blog-post-page button, #blog-post-page button *,
#blog-post-page [type="button"], #blog-post-page [type="submit"], #blog-post-page [role="button"] {
    cursor: url("/images/cursors/cursor-black-link.cur"), pointer;
}

/* ---------- site header: site name and ornament ---------- */
/* sizes pass through today's values at 375, ~890 and 1920 px wide */

.site-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 0.75rem var(--side) 0;
}

html.reader .site-name {
    font-family: 'Roboto', sans-serif;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #fff;
    font-size: clamp(1.5rem, min(1.312rem + 2.136vw, 1.636rem + 1.553vw), 3.5rem);
    line-height: 1.2;
    margin: 0;
}

html.reader .ornament {
    font-family: 'Roboto', sans-serif;
    font-weight: 600;
    letter-spacing: 0.2px;
    color: #fff;
    font-size: clamp(1.125rem, min(0.948rem + 1.553vw, 1.218rem + 1.068vw), 2.5rem);
    line-height: 1.3;
    margin: 0.25em 0 0;
}

/* ---------- page column ---------- */

.post-container {
    padding: 0 var(--side) 2.5rem;
    margin: 0 auto;
}

/* the header, chapter navs and bottom links line up with the text column */
.post-header,
.chapter-nav,
.navigation,
.reader-controls {
    max-width: calc(var(--body-size) * 40.8); /* 68 Roboto Mono letters (0.6em each) */
    margin-left: auto;
    margin-right: auto;
}

/* ---------- reader controls: rss link and case toggle ---------- */

.reader-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.5rem 1.25rem;
    margin-top: 0;
    margin-bottom: 0.75rem;
}

html.reader .rss-link {
    color: rgba(255, 255, 255, 0.8);
    font-family: 'Roboto Mono', sans-serif;
    font-weight: 300;
    font-size: 0.75rem;
    text-decoration: none;
    text-transform: none;
}

html.reader .rss-link:hover {
    color: #fff;
    text-decoration: underline;
}

.case-toggle {
    background: #000;
    border: 1px solid #fff;
    color: #fff;
    padding: 8px 16px;
    font-family: 'Roboto Mono', sans-serif;
    font-size: 0.75rem;
    text-transform: none;
    transition: background 0.3s ease;
}

.case-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* from 768px the controls sit on one line at the bottom of the header, inside the text column:
   rss link at the left edge, case toggle at the right edge. nothing on these pages is position: fixed. */
@media (min-width: 48em) {
    .reader-controls {
        justify-content: space-between;
        margin-top: 0.75rem;
        margin-bottom: 0;
    }

    /* posts have no rss link, so the toggle still goes to the right edge */
    .case-toggle {
        margin-left: auto;
    }
}

/* ---------- post or chapter header ---------- */

.post-header {
    text-align: center;
    margin-top: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

html.reader .post-title {
    font-family: 'Roboto', sans-serif;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: #fff;
    font-size: clamp(1.125rem, max(1.1135rem + 0.5825vw, 0.951rem + 0.8738vw), 2rem);
    line-height: 1.25;
    margin: 0 0 0.3em;
}

html.reader .post-meta,
html.reader .post-tags {
    font-family: 'Roboto Mono', sans-serif;
    font-weight: 300;
    font-size: clamp(0.8125rem, max(0.803rem + 0.1748vw, 0.5976rem + 0.5437vw), 1.25rem);
    line-height: 1.5;
}

html.reader .post-meta {
    color: rgba(255, 255, 255, 0.8);
}

html.reader .post-tags {
    color: rgba(255, 255, 255, 0.7);
    font-style: italic;
    margin-top: 0.2em;
}

/* phones and small tablets: the controls row sits centered above the title */
@media (max-width: 47.99em) {
    .post-header {
        display: flex;
        flex-direction: column;
    }

    .reader-controls {
        order: -1;
        column-gap: 0.75rem; /* lets the rss link and toggle share one row from 360px wide */
    }
}

/* "continue at chapter N" link (book chapter 1, added by reader.js) */
html.reader .continue-link {
    margin-top: 0.4em;
    font-family: 'Roboto Mono', sans-serif;
    font-weight: 300;
    font-size: clamp(0.8125rem, max(0.803rem + 0.1748vw, 0.5976rem + 0.5437vw), 1.25rem);
    line-height: 1.5;
}

html.reader .continue-link a {
    color: #fff;
    text-decoration: underline;
}

@media (min-width: 48em) {
    .post-header {
        margin-top: 1.25rem;
        margin-bottom: 1.5rem;
        padding-bottom: 1.25rem;
    }
}

/* ---------- chapter nav (book) ---------- */

.chapter-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 1rem;
    margin-bottom: 1rem;
}

html.reader .chapter-nav-btn,
.chapter-select {
    background: #000;
    border: 1px solid #fff;
    color: #fff;
    padding: 8px 10px;
    font-family: 'Roboto Mono', sans-serif;
    font-weight: 300;
    font-size: 0.75rem;
    line-height: 1.5;
    text-decoration: none;
    transition: background 0.3s ease;
}

@media (min-width: 48em) {
    .chapter-nav { gap: 12px; }

    html.reader .chapter-nav-btn,
    .chapter-select { padding: 8px 16px; }
}

html.reader .chapter-nav-btn:hover,
.chapter-select:hover {
    background: rgba(255, 255, 255, 0.1);
}

html.reader .chapter-nav-btn.disabled {
    opacity: 0.3;
    pointer-events: none;
}

/* the open dropdown list gets its own dark background so the options stay readable */
.chapter-select option {
    background: #000;
    color: #fff;
}

/* ---------- body text ---------- */

#postContent {
    font-family: 'Roboto Mono', monospace !important;
    font-weight: 350 !important;
    font-size: calc(var(--body-size) * var(--reader-scale, 1));
    line-height: 1.65;
    color: rgba(255, 255, 255, 0.88);
    max-width: 68ch;
    margin: 0 auto 1.5rem;
    text-align: left;
    overflow-wrap: break-word;
    /* the reader's own pinch-to-resize (reader.js) replaces the browser's pinch-zoom here */
    touch-action: pan-y;
}

/* lowercase by default; the case toggle adds .case-on to <html> for the original case */
html:not(.case-on) #postContent {
    text-transform: lowercase;
}

/* everything inside the text takes the body size; headings get their own sizes below */
#postContent * {
    font-size: inherit;
    line-height: inherit;
}

#postContent p {
    font-family: 'Roboto Mono', monospace !important;
    font-weight: 350 !important;
    margin: 0 0 1em;
}

/* choice 1a: left-aligned on phones and small tablets, justified and hyphenated from 768px */
@media (min-width: 48em) {
    #postContent {
        text-align: justify;
        -webkit-hyphens: auto;
        hyphens: auto;
    }
}

#postContent a {
    color: inherit;
    text-decoration: underline;
    overflow-wrap: anywhere;
}

#postContent h1, #postContent h2, #postContent h3,
#postContent h4, #postContent h5, #postContent h6 {
    font-family: 'Roboto Mono', monospace;
    font-weight: 600;
    color: #fff;
    text-align: left;
    -webkit-hyphens: manual;
    hyphens: manual;
    line-height: 1.35;
    margin: 1.5em 0 0.6em;
}

#postContent h1 { font-size: 1.3em; }
#postContent h2 { font-size: 1.22em; }
#postContent h3 { font-size: 1.15em; }
#postContent h4 { font-size: 1.05em; }
#postContent h5 { font-size: 1em; letter-spacing: 0.04em; }
#postContent h6 { font-size: 0.95em; letter-spacing: 0.06em; }

#postContent ul,
#postContent ol {
    margin: 0 0 1em;
    padding-left: 1.25em;
}

#postContent li + li {
    margin-top: 0.25em;
}

#postContent li > ul,
#postContent li > ol {
    margin: 0.25em 0 0;
}

#postContent blockquote {
    margin: 0 0 1em;
    padding-left: 1em;
    border-left: 2px solid rgba(255, 255, 255, 0.3);
}

/* the book's scene breaks: short and centered */
.book-content hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    width: 30%;
    margin: 1.75em auto;
}

/* defensive: no post uses these yet, but the editor allows them */
#postContent img,
#postContent video,
#postContent iframe {
    max-width: 100%;
    height: auto;
}

#postContent table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
}

#postContent pre {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* ---------- bottom links ---------- */

.navigation {
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

html.reader .navigation a {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-family: 'Roboto Mono', sans-serif;
    font-weight: 300;
    font-size: clamp(0.8125rem, max(0.803rem + 0.1748vw, 0.5976rem + 0.5437vw), 1.25rem);
    line-height: 1.5;
    display: inline-block;
    margin: 0 15px;
    transition: color 0.3s ease;
}

html.reader .navigation a:hover {
    color: #fff;
}

@media (max-width: 47.99em) {
    html.reader .navigation a {
        display: block;
        margin: 10px 0;
    }
}

/* ---------- touch screens: every control at least 44 x 44 ---------- */

@media (pointer: coarse) {
    html.reader .rss-link,
    .case-toggle,
    html.reader .continue-link a,
    html.reader .chapter-nav-btn,
    html.reader .navigation a {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 44px;
        min-width: 44px;
    }

    html.reader .rss-link {
        padding: 0 8px;
    }

    .chapter-select {
        min-height: 44px;
        font-size: max(16px, 1rem); /* 16px or more stops iPhone Safari zooming in on tap */
    }

    html.reader .navigation a {
        margin: 0 8px;
        padding: 0 8px;
    }
}

@media (pointer: coarse) and (max-width: 47.99em) {
    html.reader .rss-link {
        padding: 0 4px;
    }

    html.reader .navigation a {
        display: flex;
        width: max-content;
        max-width: 100%;
        margin: 0 auto;
    }
}

/* ---------- keyboard focus ---------- */

#blog-post-page a:focus-visible,
#blog-post-page button:focus-visible,
#blog-post-page select:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* ---------- not-found pages ---------- */

.not-found {
    text-align: center;
    margin-top: 1.5rem;
}

html.reader .not-found p {
    font-family: 'Roboto Mono', sans-serif;
    font-weight: 300;
    font-size: var(--body-size);
    line-height: 1.6;
    margin-top: 0.75em;
}

/* ---------- print ---------- */

@media print {
    html.reader,
    html.reader body {
        background: #fff !important;
        color: #000 !important;
    }

    html.reader * {
        text-shadow: none !important;
    }

    .reader-controls,
    .continue-link,
    .chapter-nav,
    .navigation,
    .ornament,
    .rss-link,
    .case-toggle {
        display: none !important;
    }

    .site-header,
    .post-container {
        padding: 0;
    }

    html.reader .site-name {
        font-size: 10pt;
        color: #000;
        text-align: left;
    }

    .site-header {
        align-items: flex-start;
    }

    .post-header {
        max-width: none;
        border-bottom-color: #999;
        text-align: left;
        margin: 6pt 0 12pt;
        padding-bottom: 6pt;
    }

    html.reader .post-title {
        font-size: 16pt;
        color: #000;
    }

    html.reader .post-meta,
    html.reader .post-tags {
        font-size: 9pt;
        color: #333;
    }

    #postContent {
        font-size: 11pt;
        max-width: none;
        color: #000;
        text-align: left;
        -webkit-hyphens: manual;
        hyphens: manual;
    }

    #postContent h1, #postContent h2, #postContent h3,
    #postContent h4, #postContent h5, #postContent h6,
    #postContent a {
        color: #000;
    }

    #postContent blockquote {
        border-left-color: #999;
    }

    .book-content hr {
        border-top-color: #999;
    }

    #postContent h1, #postContent h2, #postContent h3,
    #postContent h4, #postContent h5, #postContent h6 {
        break-after: avoid;
    }

    #postContent p {
        orphans: 2;
        widows: 2;
    }
}
