/* Tape — a quiet, text-first theme for a trading journal
   1. Tokens   2. Base   3. Header   4. Ledger   5. Post
   6. Content  7. Koenig cards   8. Footer   9. Small screens */

/* 1. Tokens ------------------------------------------------------------ */

:root {
    --bg: #ffffff;
    --ink: #151a1d;
    --muted: #667177;
    --rule: #dde2e4;
    --wash: #f1f3f4;
    --up: #1c7a58;
    --down: #b24a3c;
    --accent: var(--ghost-accent-color, #1f5f8b);

    --serif: var(--gh-font-body, "Newsreader", "Iowan Old Style", Georgia, serif);
    --display: var(--gh-font-heading, "Newsreader", "Iowan Old Style", Georgia, serif);
    --sans: "Instrument Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

    --measure: 48.3rem;
    --gutter: 1.5rem;
    color-scheme: light;
}

html.scheme-dark {
    --bg: #0f1315;
    --ink: #e4e8e9;
    --muted: #8b969b;
    --rule: #242b2f;
    --wash: #171d20;
    --up: #5cc49b;
    --down: #e48b7d;
    --accent: color-mix(in srgb, var(--ghost-accent-color, #1f5f8b) 55%, #fff);
    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    html.scheme-auto {
        --bg: #0f1315;
        --ink: #e4e8e9;
        --muted: #8b969b;
        --rule: #242b2f;
        --wash: #171d20;
        --up: #5cc49b;
        --down: #e48b7d;
        --accent: color-mix(in srgb, var(--ghost-accent-color, #1f5f8b) 55%, #fff);
        color-scheme: dark;
    }
}

/* 2. Base -------------------------------------------------------------- */

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

html {
    font-size: 100%;
    -webkit-text-size-adjust: 100%;
    background: var(--bg);
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--serif);
    font-size: 1.1875rem;
    line-height: 1.65;
    font-optical-sizing: auto;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

img, video, iframe { max-width: 100%; }
img, video { height: auto; display: block; }

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { color: var(--accent); }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 2px;
}

.wrap {
    width: 100%;
    max-width: calc(var(--measure) + var(--gutter) * 2);
    margin-inline: auto;
    padding-inline: var(--gutter);
}

.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.skip-link {
    position: absolute;
    left: var(--gutter);
    top: -4rem;
    padding: 0.5rem 0.75rem;
    background: var(--ink);
    color: var(--bg);
    font-family: var(--sans);
    font-size: 0.875rem;
    text-decoration: none;
    z-index: 10;
}
.skip-link:focus { top: 0.75rem; color: var(--bg); }

/* 3. Header ------------------------------------------------------------ */

.site-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem 2rem;
    padding-block: 2.5rem 0;
    font-family: var(--sans);
    font-size: 0.9375rem;
}

.site-title {
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-decoration: none;
    color: var(--ink);
}
.site-title img { max-height: 1.75rem; width: auto; }

.site-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 1.25rem;
    color: var(--muted);
}

.site-nav .nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1.25rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

.site-nav a { text-decoration: none; }
.site-nav .nav-current a { color: var(--ink); }

.nav-button {
    appearance: none;
    border: 0;
    padding: 0;
    background: none;
    font: inherit;
    color: inherit;
    cursor: pointer;
}
.nav-button:hover { color: var(--accent); }

.nav-action { color: var(--ink); font-weight: 500; }

.site-main { padding-block: 4.5rem 5rem; min-height: 60vh; }

/* 4. Ledger (home, tag and author lists) ------------------------------- */

.intro { margin-bottom: 3.5rem; }

.intro-text {
    margin: 0;
    max-width: 30ch;
    font-family: var(--display);
    font-size: clamp(1.625rem, 4.6vw, 2.25rem);
    line-height: 1.22;
    letter-spacing: -0.012em;
    text-wrap: balance;
}

.archive-title {
    margin: 0;
    font-family: var(--display);
    font-size: clamp(1.75rem, 5vw, 2.5rem);
    font-weight: 500;
    line-height: 1.15;
    letter-spacing: -0.012em;
}

.archive-description { margin: 0.75rem 0 0; color: var(--muted); max-width: 52ch; }

.ledger {
    list-style: none;
    margin: 0;
    padding: 0;
    border-bottom: 1px solid var(--rule);
}

.entry { border-top: 1px solid var(--rule); }

.entry-link {
    display: grid;
    grid-template-columns: 7.25rem 1fr 1.25rem;
    align-items: baseline;
    column-gap: 1rem;
    padding-block: 0.95rem;
    text-decoration: none;
    color: var(--ink);
}

.entry-date {
    font-family: var(--sans);
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    white-space: nowrap;
}

.entry-title {
    display: block;
    font-size: 1.1875rem;
    line-height: 1.35;
    text-wrap: pretty;
}

.entry-link:hover .entry-title { color: var(--accent); }

.entry-excerpt {
    display: block;
    margin-top: 0.3rem;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--muted);
}

.entry-mark { text-align: right; }

.mark { font-size: 0.6875rem; line-height: 1; }
.mark-up { color: var(--up); }
.mark-down { color: var(--down); }
.mark-flat { color: var(--muted); }

.empty { color: var(--muted); }

.pagination {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: baseline;
    gap: 1rem;
    margin-top: 2rem;
    font-family: var(--sans);
    font-size: 0.875rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}
.pagination a { color: var(--ink); }
.pagination-older { text-align: right; }

/* 5. Post -------------------------------------------------------------- */

.post-header { margin-bottom: 2.75rem; }

.post-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 1rem;
    margin: 0 0 1rem;
    font-family: var(--sans);
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

.post-title {
    margin: 0;
    font-family: var(--display);
    font-size: clamp(2rem, 6.2vw, 2.875rem);
    font-weight: 500;
    line-height: 1.1;
    letter-spacing: -0.018em;
    text-wrap: balance;
}

.post-lede {
    margin: 1.25rem 0 0;
    font-size: 1.3125rem;
    line-height: 1.5;
    color: var(--muted);
    text-wrap: pretty;
}

.post-feature { margin: 0 0 2.75rem; }
.post-feature img { width: 100%; border-radius: 3px; }

.post-footer { margin-top: 3rem; }

.post-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    list-style: none;
    margin: 0;
    padding: 0;
    font-family: var(--sans);
    font-size: 0.8125rem;
}
.post-tags a {
    display: block;
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--rule);
    border-radius: 999px;
    text-decoration: none;
    color: var(--muted);
}
.post-tags a:hover { color: var(--accent); border-color: currentColor; }

/* Email signup */
.signup { max-width: 27rem; }
.intro .signup { margin-top: 2rem; }
.intro .signup:first-child { margin-top: 0; }

.signup-boxed {
    max-width: none;
    margin-top: 3.5rem;
    padding: 1.5rem;
    background: var(--wash);
    border-radius: 6px;
}
.signup-heading {
    margin: 0 0 0.9rem;
    font-family: var(--display);
    font-size: 1.375rem;
    font-weight: 500;
    line-height: 1.25;
    letter-spacing: -0.01em;
}

.signup-form { margin: 0; }
.signup-fields { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.signup-boxed .signup-fields { max-width: 27rem; }

.signup-input {
    flex: 1 1 12rem;
    min-width: 0;
    padding: 0.65rem 0.9rem;
    border: 1px solid color-mix(in srgb, var(--muted) 55%, var(--bg));
    border-radius: 6px;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 1rem;
    line-height: 1.4;
}
.signup-input::placeholder { color: var(--muted); opacity: 1; }
.signup-input:focus-visible { outline-offset: 0; border-color: var(--accent); }

.signup-button {
    flex: 0 0 auto;
    padding: 0.65rem 1.2rem;
    border: 1px solid var(--ink);
    border-radius: 6px;
    background: var(--ink);
    color: var(--bg);
    font-family: var(--sans);
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.4;
    cursor: pointer;
}
.signup-button:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

.signup-note,
.signup-message {
    margin: 0.65rem 0 0;
    font-family: var(--sans);
    font-size: 0.8125rem;
    line-height: 1.45;
    color: var(--muted);
}
.signup-message { display: none; font-size: 0.9375rem; color: var(--ink); }
.signup-form.loading .signup-button { opacity: 0.6; cursor: progress; }
.signup-form.success .signup-fields { display: none; }
.signup-form.success .signup-success { display: block; margin-top: 0; }
.signup-form.error .signup-error { display: block; color: var(--down); }

.post-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-top: 3.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--rule);
}
.post-nav:empty { display: none; }
.post-nav-link { text-decoration: none; }
.post-nav-next { grid-column: 2; text-align: right; }
.post-nav-label {
    display: block;
    font-family: var(--sans);
    font-size: 0.8125rem;
    color: var(--muted);
}
.post-nav-title { display: block; margin-top: 0.2rem; font-size: 1.0625rem; line-height: 1.35; }

.post-comments { margin-top: 3.5rem; }

.error { padding-block: 3rem; }
.error-code {
    margin: 0 0 0.75rem;
    font-family: var(--sans);
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}
.error-text { margin-top: 1.5rem; }

/* 6. Content ----------------------------------------------------------- */

.gh-content > * { margin-block: 0; }
.gh-content > * + * { margin-top: 1.5rem; }

.gh-content h2,
.gh-content h3,
.gh-content h4 {
    font-family: var(--display);
    font-weight: 500;
    letter-spacing: -0.01em;
    text-wrap: balance;
}
.gh-content h2 { font-size: 1.75rem; line-height: 1.2; }
.gh-content h3 { font-size: 1.375rem; line-height: 1.28; }
.gh-content h4 { font-size: 1.1875rem; line-height: 1.35; font-weight: 600; }

.gh-content > * + h2 { margin-top: 3.25rem; }
.gh-content > * + h3,
.gh-content > * + h4 { margin-top: 2.5rem; }
.gh-content > h2 + *,
.gh-content > h3 + *,
.gh-content > h4 + * { margin-top: 0.75rem; }

.gh-content a { color: var(--accent); }
.gh-content a:hover { text-decoration-thickness: 2px; }

.gh-content ul,
.gh-content ol { padding-left: 1.4rem; }
.gh-content li + li { margin-top: 0.4rem; }
.gh-content li::marker { color: var(--muted); }

.gh-content blockquote {
    margin-inline: 0;
    padding-left: 1.25rem;
    border-left: 2px solid var(--ink);
    font-style: italic;
}
.gh-content blockquote.kg-blockquote-alt {
    padding: 0;
    border: 0;
    font-size: 1.5rem;
    line-height: 1.4;
    text-align: center;
    color: var(--muted);
}

.gh-content hr {
    height: 1px;
    border: 0;
    background: var(--rule);
    margin-block: 3rem;
}

.gh-content code {
    padding: 0.12em 0.36em;
    background: var(--wash);
    border-radius: 3px;
    font-family: var(--mono);
    font-size: 0.82em;
}
.gh-content pre {
    padding: 1.1rem 1.25rem;
    overflow-x: auto;
    background: var(--wash);
    border-radius: 6px;
    font-family: var(--mono);
    font-size: 0.875rem;
    line-height: 1.6;
}
.gh-content pre code { padding: 0; background: none; font-size: inherit; }

/* Tables: built for trade logs and stats */
.gh-content table {
    display: block;
    width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    font-family: var(--sans);
    font-size: 0.9375rem;
    line-height: 1.4;
    font-variant-numeric: tabular-nums;
}
.gh-content th,
.gh-content td {
    padding: 0.6rem 1.25rem 0.6rem 0;
    border-bottom: 1px solid var(--rule);
    text-align: left;
    white-space: nowrap;
}
.gh-content th {
    font-weight: 500;
    color: var(--muted);
    border-bottom-color: var(--ink);
}

.gh-content figure { margin-inline: 0; }
.gh-content figcaption,
.post-feature figcaption {
    margin-top: 0.6rem;
    font-family: var(--sans);
    font-size: 0.8125rem;
    line-height: 1.45;
    color: var(--muted);
    text-align: center;
}

.gh-content iframe { display: block; border: 0; }

/* 7. Koenig cards ------------------------------------------------------ */

.gh-content .kg-card + *,
.gh-content * + .kg-card { margin-top: 2.25rem; }

.kg-image-card img,
.kg-gallery-image img { border-radius: 3px; }

.kg-width-wide,
.kg-width-full {
    position: relative;
    left: 50%;
    transform: translateX(-50%);
}
.kg-width-wide { width: min(100vw - var(--gutter) * 2, 66.7rem); }
.kg-width-full { width: 100vw; }
.kg-width-wide img,
.kg-width-full img { width: 100%; }
.kg-width-full img { border-radius: 0; }

.kg-embed-card { display: flex; flex-direction: column; align-items: center; }
.kg-embed-card iframe[src*="youtube"],
.kg-embed-card iframe[src*="vimeo"] {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    border-radius: 6px;
}

.kg-bookmark-card a.kg-bookmark-container,
.kg-bookmark-card a.kg-bookmark-container:hover {
    color: var(--ink);
    border-color: var(--rule);
    border-radius: 6px;
    font-family: var(--sans);
}

.kg-callout-card { border-radius: 6px; }

/* 8. Footer ------------------------------------------------------------ */

.site-footer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.35rem 2rem;
    padding-block: 0 3rem;
    font-family: var(--sans);
    font-size: 0.8125rem;
    color: var(--muted);
}
.site-footer::before {
    content: "";
    grid-column: 1 / -1;
    height: 1px;
    margin-bottom: 1.4rem;
    background: var(--rule);
}
.site-footer > * { margin: 0; }
.footer-line { grid-column: 1; grid-row: 2; }
.footer-links { grid-column: 2; grid-row: 2; }
.footer-note { grid-column: 1 / -1; }

.footer-links,
.site-footer .nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1.25rem;
    list-style: none;
    padding-left: 0;
}
.site-footer .nav { grid-column: 1 / -1; margin-top: 0.5rem; }
.site-footer a { text-decoration: none; }

/* 9. Small screens and motion ------------------------------------------ */

@media (max-width: 560px) {
    :root { --gutter: 1.25rem; }
    body { font-size: 1.125rem; }
    .site-header { padding-top: 1.75rem; }
    .site-main { padding-block: 3rem 4rem; }
    .intro { margin-bottom: 2.5rem; }

    .entry-link {
        grid-template-columns: 1fr 1.25rem;
        row-gap: 0.15rem;
    }
    .entry-date { grid-column: 1; grid-row: 1; }
    .entry-main { grid-column: 1; grid-row: 2; }
    .entry-mark { grid-column: 2; grid-row: 1 / 3; align-self: center; }

    .post-nav { grid-template-columns: 1fr; }
    .post-nav-next { grid-column: 1; text-align: left; }
    .pagination { grid-template-columns: 1fr 1fr; }
    .pagination-count { grid-column: 1 / -1; grid-row: 2; }
}

@media (prefers-reduced-motion: no-preference) {
    a, .nav-button, .signup-button { transition: color 120ms ease, background-color 120ms ease; }
}
