:root {
    --bg-top: #f3f0e8;
    --bg-bottom: #fdfaf6;
    --bg-glow: #f2d8bf;
    --surface: #fffdf9;
    --surface-strong: #fffefb;
    --line: #dfd7ca;
    --text: #1f1b17;
    --muted: #6d645b;
    --accent: #22676b;
    --accent-soft: #d8ecee;
    --warn: #8a4b14;
    --error: #8a1f2b;
    --hero-top: #fffefb;
    --hero-bottom: #fff7eb;
    --thread-head-top: #fbf7f1;
    --thread-head-bottom: #fffdfb;
    --media-bg: #f1ece3;
    --button-top: #2f8085;
    --button-bottom: #205f63;
    --shadow: 0 18px 45px -28px rgba(24, 18, 12, 0.42);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-top: #111518;
        --bg-bottom: #0d1013;
        --bg-glow: #2b2521;
        --surface: #171c21;
        --surface-strong: #141a1f;
        --line: #2b333c;
        --text: #e8e3dc;
        --muted: #b4aa9f;
        --accent: #67b3b7;
        --accent-soft: #1e3a3c;
        --warn: #d39a59;
        --error: #f39eab;
        --hero-top: #1a2026;
        --hero-bottom: #161b20;
        --thread-head-top: #1b2229;
        --thread-head-bottom: #171d24;
        --media-bg: #1f262d;
        --button-top: #3a8f95;
        --button-bottom: #2c6f74;
        --shadow: 0 20px 45px -30px rgba(0, 0, 0, 0.72);
    }

    html {
        color-scheme: dark;
    }
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background:
        radial-gradient(
            1100px 460px at 100% -10%,
            var(--bg-glow) 0%,
            transparent 70%
        ),
        linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
    background-attachment: fixed;
    background-color: var(--bg-bottom);
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Source Sans 3", "Avenir Next", "Segoe UI", sans-serif;
    color: var(--text);
    background: transparent;
}

body.modal-open {
    overflow: hidden;
}

.page-shell {
    width: min(860px, calc(100% - 2rem));
    margin: 2.25rem auto 3rem;
}

.hero {
    background: linear-gradient(180deg, var(--hero-top), var(--hero-bottom));
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 1.2rem 1.15rem 1.35rem;
    box-shadow: var(--shadow);
}

.kicker {
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 700;
}

h1 {
    font-family: "Literata", "Iowan Old Style", "Palatino Linotype", serif;
    margin: 0.3rem 0 0.55rem;
    font-size: clamp(1.95rem, 3.3vw, 2.5rem);
    line-height: 1.1;
}

.lead {
    margin: 0;
    line-height: 1.45;
}

.unfurl-form {
    display: grid;
    gap: 0.65rem;
    grid-template-columns: 1fr auto;
    margin: 1rem 0 0;
}

.unfurl-form input,
.unfurl-form button {
    border-radius: 10px;
    border: 1px solid var(--line);
    font: inherit;
}

.unfurl-form input {
    min-width: 0;
    background: var(--surface);
    color: var(--text);
    padding: 0.7rem 0.85rem;
}

.unfurl-form input:focus-visible,
.unfurl-form button:focus-visible,
.status-link:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--accent) 70%, #ffffff 30%);
    outline-offset: 2px;
}

.unfurl-form button {
    color: white;
    border-color: color-mix(in srgb, var(--accent) 70%, black 30%);
    background: linear-gradient(
        180deg,
        var(--button-top),
        var(--button-bottom)
    );
    padding: 0.7rem 1rem;
    font-weight: 700;
    cursor: pointer;
}

.unfurl-form button[disabled] {
    opacity: 0.68;
    cursor: progress;
}

.status-line {
    margin-top: 0.9rem;
    min-height: 1.25rem;
    color: var(--muted);
}

.status-line[data-tone="error"] {
    color: var(--error);
}

.status-line[data-tone="warning"] {
    color: var(--warn);
}

.thread-root {
    margin-top: 1rem;
    overflow: visible;
}

.thread-shell {
    border-radius: 16px;
    border: 1px solid var(--line);
    background: var(--surface-strong);
    box-shadow: var(--shadow);
    overflow: visible;
    width: 100%;
}

.thread-head {
    padding: 1rem 1.1rem;
    background: linear-gradient(
        180deg,
        var(--thread-head-top),
        var(--thread-head-bottom)
    );
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
}

.thread-head h1,
.thread-head h2 {
    font-family: "Literata", "Iowan Old Style", "Palatino Linotype", serif;
    margin: 0;
    font-size: clamp(1.2rem, 2vw, 1.45rem);
}

.thread-meta {
    margin: 0.35rem 0 0;
    color: var(--muted);
}

.branch-note {
    margin-top: 0.45rem;
    font-size: 0.95rem;
    color: var(--muted);
}

.post-row {
    position: relative;
    min-height: 0;
    padding: 0 1.1rem;
    animation: reveal 220ms ease both;
}

.post-row:last-child {
    padding-bottom: 0.45rem;
}

.post-card {
    min-width: 0;
    padding: 0.28rem 0;
}

.cw-content details > summary {
    cursor: pointer;
    font-weight: 700;
}

.cw-content details {
    border: 1px dashed color-mix(in srgb, var(--warn) 35%, var(--line) 65%);
    border-radius: 10px;
    padding: 0.58rem 0.7rem;
    background: color-mix(in srgb, var(--surface) 90%, var(--warn) 10%);
}

.cw-content details[open] {
    padding-bottom: 0.35rem;
}

.post-content {
    font-family: "Literata", "Iowan Old Style", "Palatino Linotype", serif;
    line-height: 1.72;
    font-size: clamp(1.03rem, 1.3vw, 1.11rem);
    overflow-wrap: anywhere;
}

.post-content :first-child {
    margin-top: 0;
}

.post-content :last-child {
    margin-bottom: 0;
}

.post-content a {
    color: var(--accent);
    overflow-wrap: anywhere;
    word-break: break-word;
}

.media-grid {
    margin-top: 0.85rem;
    display: grid;
    gap: 0.5rem;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.media-item {
    margin: 0;
}

.media-trigger-link {
    display: block;
    width: 100%;
    border: 0;
    padding: 0;
    margin: 0;
    border-radius: 10px;
    overflow: hidden;
    background: none;
    cursor: zoom-in;
}

.media-trigger-link {
    text-decoration: none;
}

.media-trigger-link:focus-visible,
.media-modal-close:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--accent) 70%, #ffffff 30%);
    outline-offset: 2px;
}

.media-item img,
.media-item video {
    width: 100%;
    border-radius: 10px;
    border: 1px solid var(--line);
    display: block;
    background: var(--media-bg);
}

@media (min-width: 721px) {
    .media-item img {
        width: auto;
        max-width: 100%;
        height: auto;
        max-height: 520px;
        margin-inline: auto;
    }
}

.media-preview-video {
    width: 100%;
    display: block;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--media-bg);
}

.media-item figcaption {
    margin-top: 0.25rem;
    color: var(--muted);
    font-size: 0.84rem;
    line-height: 1.3;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.media-item audio {
    width: 100%;
}

.post-meta {
    position: absolute;
    top: 0.28rem;
    left: calc(100% + 1rem);
    width: min(170px, max(0px, calc((100vw - 860px) / 2 - 1rem)));
    font-size: 0.82rem;
    color: var(--muted);
    text-align: left;
    line-height: 1.4;
}

.status-link {
    color: var(--accent);
    text-decoration-thickness: 1px;
}

.post-meta-date-link {
    display: inline-block;
    max-width: 100%;
    color: inherit;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.media-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(10, 10, 10, 0.74);
    backdrop-filter: blur(2px);
}

.media-modal.is-open {
    display: flex;
}

.media-modal-panel {
    position: relative;
    width: fit-content;
    height: fit-content;
    max-width: 96vw;
    max-height: 94vh;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface-strong);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.media-modal-close {
    position: absolute;
    top: 0.55rem;
    right: 0.55rem;
    z-index: 2;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: color-mix(in srgb, var(--surface-strong) 82%, #000 18%);
    color: var(--text);
    font: inherit;
    width: 2rem;
    height: 2rem;
    padding: 0;
    display: grid;
    place-items: center;
    line-height: 1;
    font-size: 1.2rem;
    cursor: pointer;
}

.media-modal-content {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    min-width: 0;
    line-height: 0;
    padding: 0;
}

.media-modal-media {
    display: block;
    max-width: min(96vw, 1400px);
    max-height: calc(94vh - 4.2rem);
    object-fit: contain;
    border-radius: 0;
    background: var(--media-bg);
}

.media-modal-content audio {
    width: min(680px, 100%);
}

.media-modal-foot {
    min-width: 0;
    padding: 0.65rem 0.8rem 0.78rem;
}

.media-modal-caption {
    max-width: 100%;
    margin: 0;
    white-space: normal;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.empty-state {
    border: 1px dashed var(--line);
    border-radius: 14px;
    padding: 1.2rem;
    color: var(--muted);
    background: color-mix(
        in srgb,
        var(--surface) 92%,
        var(--surface-strong) 8%
    );
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@keyframes reveal {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 720px) {
    .page-shell {
        width: min(860px, calc(100% - 1rem));
        margin-top: 1rem;
    }

    .thread-shell {
        width: 100%;
    }

    .hero,
    .thread-head,
    .post-row {
        padding-left: 0.85rem;
        padding-right: 0.85rem;
    }

    .unfurl-form {
        grid-template-columns: 1fr;
    }

    .post-meta {
        display: none;
    }
}
