/* =========================================================
   STRUCTURE OF THIS FILE
   -------------------------------------------------------
   1. Tokens + resets            (shared)
   2. Base layer                 = the PHONE layout
   3. @media (min-width: 769px)  = the DESKTOP layout

   The old file did the opposite: desktop was the base and the
   phone had to undo it. Rules like `.card--post { min-width:
   1000px }` lived in the base layer, so if the phone's media
   query didn't match for any reason, the page rendered a
   1000px-wide column on a 390px screen. That is what "zoomed
   in" was — a 1000px layout crammed into a phone viewport,
   which also triggers Chrome's font-boosting on Android and
   blows the text up further.

   Now the phone layout is the default and nothing has to be
   undone. Desktop is unchanged: every desktop declaration
   below is the original one, moved verbatim into the
   min-width block.
   ========================================================= */


/* ---------- 1. Tokens + resets ---------------------------- */

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

:root{
    --bg: #fbf6ee;
    --surface: #fffaf2;
    --text: #3a3229;
    --text-muted: #7d7264;
    --accent: #c1613f;
    --border: #e8ddc8;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1c1917;
        --surface: #212521;
        --text: #f0e9df;
        --text-muted: #b3a99c;
        --accent: #e08762;
        --border: #3d272f;
    }
}

html {
    -webkit-text-size-adjust: 100%;   /* stops Android Chrome inflating body text */
    text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: "Baloo 2", sans-serif;
    background-color: var(--bg);
    color: var(--text);
}


/* ---------- 2. Base layer = phone ------------------------- */

main {
    display: block;                   /* one column; no flex row to fight */
    padding: 0.5rem;
    padding-left: max(0.5rem, env(safe-area-inset-left));
    padding-right: max(0.5rem, env(safe-area-inset-right));
}

.posts-feed {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    min-width: 0;   /* without this a flex item won't shrink below its widest unbroken content */
    flex: 1;
}

.card {
    position: relative;
    width: 100%;
    max-width: 100%;
    padding: 1rem;
    margin-bottom: 0.6rem;
    background: var(--surface);
    border: 0;
    border-radius: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    overflow-wrap: anywhere;   /* long URLs and hashes can't widen the card */
}

/* --- type scale: ~45 characters per line, which is the readable range --- */

.card h1 {
    margin: 0 0 0.5rem;
    font-size: 1.35rem;
    line-height: 1.25;
}

.card h2 {
    margin: 1.4rem 0 0.4rem;
    font-size: 1.1rem;
    line-height: 1.3;
}

.card h3 {
    margin: 1.1rem 0 0.35rem;
    font-size: 1rem;
    line-height: 1.35;
}

.card p {
    margin: 0 0 0.85rem;
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text);
}

.card ul,
.card ol {
    padding-left: 1.2rem;
    font-size: 0.95rem;
    line-height: 1.6;
}

.card li { margin-bottom: 0.35rem; }

/* --- post header --- */

.card-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding-right: 4.75rem;   /* reserved lane so the title never runs under Share */
}

.card-header h2 {
    margin: 0;
    font-size: 1.05rem;
}

.card-header-text {
    display: flex;
    flex-direction: column;
}

.profile-image {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;   /* stops the avatar squashing when the title wraps */
    border-radius: 50%;
    object-fit: cover;
}

.post-date {
    display: block;
    margin-top: 0.9rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* --- share button: a real 40px tap target --- */

.share-btn {
    position: absolute;
    top: 0.8rem;
    right: 0.8rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    min-width: 62px;
    padding: 0 0.85rem;
    background: var(--border);
    color: var(--text);
    border: none;
    border-radius: 999px;
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.12s ease;
}

.share-btn:active {
    background: var(--accent);
    color: var(--surface);
    transform: scale(0.96);
}

@media (hover: hover) {
    .share-btn:hover {
        background: var(--accent);
        color: var(--surface);
    }
}

/* --- code: full-bleed to the card edges so more of each line fits --- */

.card pre {
    margin: 0.9rem -1rem;
    padding: 0.85rem 1rem;
    background: var(--bg);
    border-radius: 0;
    overflow-x: auto;              /* scrolls sideways instead of breaking out of the card */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;   /* sideways scroll in code won't drag the page */
    font-family: "Courier New", monospace;
    font-size: 0.78rem;
    line-height: 1.45;
}

.card p code {
    background: var(--border);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-family: "Courier New", monospace;
    font-size: 0.85em;
}

/* --- markdown extras that only appear once a post renders --- */

.post-content img,
.post-content video {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
}

.post-content table {
    display: block;
    width: 100%;
    margin: 1rem 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-collapse: collapse;
    font-size: 0.82rem;
    white-space: nowrap;
}

.post-content th,
.post-content td {
    padding: 0.45rem 0.65rem;
    border: 1px solid var(--border);
}

.post-content blockquote {
    margin: 1rem 0;
    padding: 0.25rem 0 0.25rem 0.9rem;
    border-left: 3px solid var(--accent);
    color: var(--text-muted);
}

.card a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: var(--border);
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

.card a:hover {
    color: var(--text);
    text-decoration-color: var(--accent);
}

.footer {
    text-align: center;
    margin: 1.5rem 0;
    padding-bottom: env(safe-area-inset-bottom);
    font-size: 0.85rem;
    color: var(--text-muted);
}

@media (prefers-reduced-motion: reduce) {
    .share-btn { transition: none; }
    .share-btn:active { transform: none; }
}


/* =========================================================
   3. DESKTOP  (≥769px) — unchanged from the original file
   ========================================================= */

@media (min-width: 769px) {

    body {
        margin: 8px;   /* the browser default the original file relied on */
    }

    main {
        display: flex;
        align-items: flex-start;   /* important — without this, sticky won't have room to "stick" */
        justify-content: center;
        gap: 1.5rem;
        flex-wrap: wrap;
        padding: 2rem;
        min-height: 100vh;
    }

    .posts-feed {
        gap: 1.5rem;
    }

    .card {
        width: auto;
        max-width: 320px;
        padding: 2rem 2.5rem;
        margin-bottom: 0;
        border: 5px solid var(--surface);
        border-radius: 24px;
        box-shadow: 0px 4px 16px rgba(0, 0, 0, 0.08);
        overflow-wrap: normal;
    }

    .card--main {
        position: sticky;
        top: 2rem;   /* stays 2rem from the top of the browser window while you scroll */
        min-width: 0;
    }

    .card--post {
        min-width: 1000px;
    }

    .card h1 {
        margin-top: 0;
        margin-bottom: 0.67em;
        font-size: 2em;
        line-height: normal;
    }

    .card h2 {
        margin: 0.83em 0;
        font-size: 1.5em;
        line-height: normal;
    }

    .card h3 {
        margin: 1em 0;
        font-size: 1.17em;
        line-height: normal;
    }

    .card p {
        margin: 1em 0;
        font-size: 1rem;
        line-height: 1.6;
    }

    .card ul,
    .card ol {
        padding-left: 40px;
        font-size: 1rem;
        line-height: normal;
    }

    .card li { margin-bottom: 0; }

    .card-header {
        gap: 1rem;
        padding-right: 0;
    }

    .card-header h2 {
        margin: 0.83em 0;
        font-size: 1.5em;
    }

    .profile-image {
        width: 48px;
        height: 48px;
        flex: 0 0 auto;
    }

    .post-date {
        display: inline;
        margin-top: 0;
        font-size: 0.8rem;
    }

    .share-btn {
        top: 1rem;
        right: 1rem;
        display: inline-block;
        min-height: 0;
        min-width: 0;
        padding: 0.4rem 0.8rem;
        border-radius: 8px;
        font-size: 0.8rem;
        transition: none;
    }

    .card pre {
        margin: 1rem 0;
        padding: 1rem;
        border-radius: 8px;
        font-size: 0.9rem;
        line-height: 1.5;
    }

    .card p code {
        font-size: 0.9em;
    }

    .post-content table {
        display: table;
        white-space: normal;
        font-size: 1rem;
    }

    .card a {
        text-decoration-thickness: auto;
        text-underline-offset: auto;
    }

    .footer {
        margin-bottom: 2rem;
        margin-top: 0;
        font-size: 0.9rem;
    }
}


/* =========================================================
   4. SPLIT-SITE ADDITIONS
   -------------------------------------------------------
   Added when the single-page feed was split into one page
   per post. Everything above this line is untouched; these
   rules only style the two shapes that did not exist before:

     - the PREVIEW card on the index (title, date, excerpt,
       link) instead of a full post body
     - the POST page, where the article is the whole page and
       the title is its <h1> rather than a header <h2>

   Phone-first, same as the rest of the file.
   ========================================================= */

/* --- post page: the title sits where Share does, so it needs
       the same reserved lane .card-header already gets --- */

.card--post > h1 {
    padding-right: 4.75rem;
}

.post-author {
    font-size: 0.9rem;
}

/* .post-date's own margin-top assumes it follows a post body.
   Inside the byline it sits directly under the name instead. */
.card-header-text .post-date {
    margin-top: 0.1rem;
}

.post-nav {
    margin: 1.5rem 0 0;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
}

/* --- index: preview cards --- */

.card-header h2 a {
    color: inherit;
    text-decoration: none;
}

.card-header h2 a:hover {
    color: var(--accent);
    text-decoration: underline;
}

.post-excerpt {
    margin: 0.9rem 0 0;
    color: var(--text-muted);
}

.post-more {
    margin: 0.6rem 0 0;
    font-size: 0.9rem;
}

@media (min-width: 769px) {

    .card--post > h1 {
        padding-right: 0;
    }

    /* .card--post is min-width: 1000px so a full article has room to
       breathe. A preview is four short lines, and at 1000px it reads as a
       letterbox slot with a sentence stranded in it -- so previews opt out
       of that floor and take a comfortable measure instead. */
    .card--preview {
        min-width: 0;
        max-width: 620px;
    }
}


/* =========================================================
   5. SYNTAX HIGHLIGHTING
   -------------------------------------------------------
   highlight.js ships themes, but every one of them brings its
   own background and its own idea of a palette, which fights
   the warm cream/ink look of the rest of the site. So we load
   only highlight.js's JavaScript (it just wraps tokens in
   .hljs-* classes) and colour those classes ourselves, from
   the same tokens everything else here uses.

   That means dark mode keeps working for free, and there is
   no second stylesheet to fetch.
   ========================================================= */

:root {
    --code-keyword: #a8452f;
    --code-string:  #567036;   /* 5.2:1 on the code background */
    --code-number:  #8a5a2b;
    --code-comment: #746a5c;   /* 4.9:1 -- comments still recede, but readably */
}

@media (prefers-color-scheme: dark) {
    :root {
        --code-keyword: #e08762;
        --code-string:  #a9c286;
        --code-number:  #d7a45f;
        --code-comment: #8b8176;
    }
}

/* highlight.js sets a background on .hljs; we want the card's own */
.hljs {
    background: transparent;
    color: var(--text);
}

.hljs-comment,
.hljs-quote {
    color: var(--code-comment);
    font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-section,
.hljs-doctag,
.hljs-type,
.hljs-name {
    color: var(--code-keyword);
}

.hljs-string,
.hljs-regexp,
.hljs-addition,
.hljs-attribute {
    color: var(--code-string);
}

.hljs-number,
.hljs-symbol,
.hljs-bullet,
.hljs-link,
.hljs-selector-attr,
.hljs-selector-pseudo {
    color: var(--code-number);
}

.hljs-title,
.hljs-title.function_,
.hljs-title.class_,
.hljs-built_in {
    color: var(--text);
    font-weight: 600;
}

.hljs-meta {
    color: var(--code-comment);
}

.hljs-emphasis { font-style: italic; }
.hljs-strong   { font-weight: 700; }


/* =========================================================
   6. RESULTS BLOCK  ({{results}} in a post)
   -------------------------------------------------------
   A run's pass/fail CSVs, rendered as a headline pair plus a
   per-category breakdown. No chart library and no <canvas> --
   the bars are ten little <span>s, so they inherit the theme,
   print, and cost nothing to load.

   The generic `.post-content table` rules give every cell a
   box border, which turns this into a spreadsheet. The
   overrides below undo that for this table only.
   ========================================================= */

:root {
    --leak: #b03a2e;
    --safe: #4a7c43;
}

@media (prefers-color-scheme: dark) {
    :root {
        --leak: #e8705d;
        --safe: #8fbd83;
    }
}

.results {
    margin: 1.6rem 0;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.results figcaption {
    margin-bottom: 0.9rem;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* --- the two headline numbers --- */

.results-headline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.9rem;
    padding-bottom: 1rem;
    margin-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
}

.results-stat {
    flex: 1;
    text-align: center;
}

.results-pct {
    display: block;
    font-size: 2.1rem;
    font-weight: 700;
    line-height: 1.1;
}

.results-pct--bad  { color: var(--leak); }
.results-pct--good { color: var(--safe); }

.results-meta {
    display: block;
    margin-top: 0.2rem;
    font-size: 0.75rem;
    line-height: 1.35;
    color: var(--text-muted);
}

.results-meta strong {
    display: block;
    color: var(--text);
    font-weight: 600;
}

.results-arrow {
    flex: 0 0 auto;
    font-size: 1.3rem;
    color: var(--text-muted);
}

/* --- the per-category table --- */

.post-content .results-table {
    display: table;          /* not the scrolling block the generic rule sets */
    width: 100%;
    margin: 0;
    white-space: normal;
    font-size: 0.8rem;
}

.post-content .results-table th,
.post-content .results-table td {
    padding: 0.5rem 0.2rem;
    border: 0;                          /* kill the spreadsheet grid */
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.post-content .results-table thead th {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.post-content .results-table tbody th {
    font-weight: 400;
    font-family: "Courier New", monospace;
    font-size: 0.78rem;
}

.post-content .results-table tfoot th,
.post-content .results-table tfoot td {
    border-bottom: 0;
    padding-top: 0.7rem;
    font-weight: 700;
}

/* --- the ten-segment bar --- */

.meter {
    display: inline-flex;
    gap: 2px;
    width: 88px;
    vertical-align: middle;
}

.seg {
    flex: 1;
    height: 11px;
    border-radius: 2px;
    background: var(--border);
}

.seg--on { background: var(--leak); }

.meter-num {
    margin-left: 0.5rem;
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
    vertical-align: middle;
}

.meter-den { color: var(--text-muted); }

@media (min-width: 769px) {

    .results {
        padding: 1.5rem;
    }

    .results-headline {
        gap: 2rem;
        padding-bottom: 1.4rem;
    }

    .results-pct { font-size: 2.8rem; }
    .results-meta { font-size: 0.85rem; }
    .results-arrow { font-size: 1.6rem; }

    .post-content .results-table {
        font-size: 0.9rem;
    }

    .post-content .results-table th,
    .post-content .results-table td {
        padding: 0.6rem 0.4rem;
    }

    .meter { width: 132px; }
    .seg { height: 13px; }
    .meter-num { font-size: 0.85rem; }
}


/* =========================================================
   7. SIDEBAR + CONTACT CARD
   -------------------------------------------------------
   The About card used to be a direct child of <main>, which
   on desktop is a flex ROW -- so a second card dropped in
   beside it would have become a third column, not a card
   underneath it. Both cards now live in .sidebar, a column
   that is itself one flex item.

   The sticky behaviour moves up with them: .card--main was
   the thing that stuck, but now the whole column should, or
   only the About card would follow you down the page.
   ========================================================= */

.contact-email {
    margin: 0.6rem 0 0;
    overflow-wrap: anywhere;   /* the address is long and the card is narrow */
    font-size: 0.9rem;
}

.contact-email a {
    font-weight: 600;
}

@media (min-width: 769px) {

    .sidebar {
        position: sticky;
        top: 2rem;
        display: flex;
        flex-direction: column;
        gap: 1.5rem;
        max-width: 320px;
        min-width: 0;
    }

    /* the column sticks now, not the single card inside it */
    .card--main {
        position: static;
    }
}
