/* ─── Tokens ──────────────────────────────────────────────────────────────── */

:root {
    color-scheme: light;

    /* spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;

    /* layout */
    --container: clamp(20rem, 92vw, 62rem);
    --container-wide: clamp(20rem, 94vw, 88rem);
    --gutter: clamp(1rem, 4vw, 2rem);

    /* palette — cream only */
    --bg: #fdfcfa;
    --surface: rgba(255, 254, 252, 0.6);
    --surface-2: rgba(255, 254, 252, 0.25);
    --border: rgba(180, 160, 120, 0.22);
    --text: #1c1a14;
    --text-muted: #6b6150;
    --accent: #5b4fd6;
    --accent-hover: #4a3fc0;
    --accent-contrast: #ffffff;
    --accent-ring: rgba(91, 79, 214, 0.28);
    --blob: rgba(130, 120, 220, 0.95);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 2px 16px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow: var(--shadow-md);
    --banner-bg: rgba(209, 250, 229, 0.75);
    --banner-border: rgba(110, 231, 183, 0.7);
    --banner-text: #065f46;

    /* radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-pill: 999px;

    /* measure */
    --measure: 65ch;

    /* typography */
    --font-body:
        "Supreme", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;
    --font-display: "Nunito", var(--font-body);
}

/* ─── Fonts ───────────────────────────────────────────────────────────────── */

@font-face {
    font-family: "Nunito";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("/static/fonts/Nunito-SemiBold.woff2") format("woff2");
    unicode-range:
        U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
        U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
        U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: "Nunito";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("/static/fonts/Nunito-Bold.woff2") format("woff2");
    unicode-range:
        U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
        U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
        U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: "Supreme";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("/static/fonts/Supreme-Regular.woff2") format("woff2");
    unicode-range:
        U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
        U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
        U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: "Supreme";
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("/static/fonts/Supreme-Medium.woff2") format("woff2");
    unicode-range:
        U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
        U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
        U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: "Supreme";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("/static/fonts/Supreme-Bold.woff2") format("woff2");
    unicode-range:
        U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
        U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
        U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ─── Reset ───────────────────────────────────────────────────────────────── */

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

/* ─── Base ────────────────────────────────────────────────────────────────── */

html {
    background: var(--bg);
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--font-body);
    color: var(--text);
    line-height: 1.5;
}

/* Subtle grain overlay for warmth */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 200px 200px;
    opacity: 0.025;
    pointer-events: none;
    z-index: -2;
}

/* ─── Animations ──────────────────────────────────────────────────────────── */

@keyframes post-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ─── Background blob ─────────────────────────────────────────────────────── */

@keyframes blob-drift {
    0% {
        transform: translate(-35%, -50%) rotate(0deg);
        border-radius: 47% 53% 70% 30% / 60% 40% 60% 40%;
    }
    20% {
        transform: translate(-36%, -51%) rotate(3deg);
        border-radius: 60% 40% 55% 45% / 45% 58% 42% 55%;
    }
    40% {
        transform: translate(-34%, -49%) rotate(6deg);
        border-radius: 52% 48% 38% 62% / 55% 35% 65% 45%;
    }
    60% {
        transform: translate(-37%, -50%) rotate(4deg);
        border-radius: 40% 60% 62% 38% / 62% 48% 52% 38%;
    }
    80% {
        transform: translate(-35%, -52%) rotate(7deg);
        border-radius: 58% 42% 48% 52% / 38% 62% 38% 62%;
    }
    100% {
        transform: translate(-37%, -48%) rotate(8deg);
        border-radius: 58% 42% 45% 55% / 50% 62% 38% 50%;
    }
}

.bg-blob {
    position: fixed;
    top: 50%;
    left: 65%;
    width: 90vmax;
    height: 75vmax;
    border-radius: 47% 53% 70% 30% / 60% 40% 60% 40%;
    background:
        radial-gradient(
            ellipse 60% 55% at 42% 44%,
            rgba(130, 120, 220, 0.38) 0%,
            transparent 60%
        ),
        radial-gradient(
            ellipse 52% 62% at 60% 58%,
            rgba(160, 150, 240, 0.22) 0%,
            transparent 55%
        ),
        radial-gradient(
            ellipse 72% 48% at 50% 50%,
            rgba(190, 185, 255, 0.18) 0%,
            transparent 65%
        );
    filter: blur(70px);
    z-index: -1;
    pointer-events: none;
    animation: blob-drift 28s ease-in-out infinite;
}

/* ─── Skip link ───────────────────────────────────────────────────────────── */

.skip-link {
    position: absolute;
    left: var(--space-2);
    top: var(--space-2);
    z-index: 10;
    padding: var(--space-2) var(--space-4);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    transform: translateY(-150%);
    transition: transform 0.15s;
}

.skip-link:focus {
    transform: translateY(0);
}

/* ─── Layout ──────────────────────────────────────────────────────────────── */

.shell {
    width: 100%;
    max-width: var(--container);
    margin-inline: auto;
    padding-inline: var(--gutter);
}

header {
    padding-block: var(--space-4);
}

.header-inner {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

main {
    flex: 1;
    padding-block: var(--space-6);
    padding-inline: var(--gutter);
    display: flex;
    flex-direction: column;
}

footer {
    padding-block: var(--space-6);
    border-top: 1px solid var(--border);
    margin-block-start: var(--space-6);
}

.footer-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
}

.footer-nav {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.footer-nav a {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.8125rem;
    transition: color 0.15s;
}

.footer-nav a:hover {
    color: var(--accent);
}

.footer-nav a + a::before {
    content: "·";
    color: var(--border);
    margin-inline-end: var(--space-4);
    pointer-events: none;
}

/* ─── Brand + nav ─────────────────────────────────────────────────────────── */

.brand {
    text-decoration: none;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

.brand-logo {
    display: block;
    flex-shrink: 0;
    width: 30px;
    height: 30px;
}

.brand span {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.brand:hover {
    color: var(--text);
}

.nav {
    margin-inline-start: auto;
    display: flex;
    gap: var(--space-6);
}

.nav a {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.875rem;
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-sm);
    transition:
        color 0.15s,
        background-color 0.15s,
        box-shadow 0.15s;
}

.nav a:hover,
.nav a[aria-current="page"] {
    color: var(--accent-contrast);
    background-color: var(--blob);
}

.nav a:focus-visible,
.footer-nav a:focus-visible,
.brand:focus-visible,
.banner-success button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ─── Links ───────────────────────────────────────────────────────────────── */

a {
    color: var(--accent);
}

a:hover {
    color: var(--accent-hover);
}

/* ─── Card (about / create pages) ────────────────────────────────────────── */

.card {
    width: 100%;
    max-width: clamp(20rem, 90vw, 46rem);
    margin-inline: auto;
    padding-block: var(--space-8);
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

/* ─── Create / submit form card ──────────────────────────────────────────── */

.create-card {
    max-width: clamp(20rem, 90vw, 34rem);
    gap: var(--space-5);
    padding-inline: var(--space-6);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.create-card__hint {
    margin-block-start: calc(var(--space-2) * -1);
}

.create-card .field input,
.create-card .field textarea {
    max-width: 100%;
}

.create-card .field textarea {
    resize: vertical;
}

.create-card form button[type="submit"] {
    align-self: stretch;
    width: 100%;
}

h1 {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.6rem, 1.25rem + 1.4vw, 2.15rem);
    line-height: 1.2;
    letter-spacing: 0.01em;
    text-wrap: balance;
}

.card h2 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0;
    text-wrap: balance;
}

.card > p {
    text-wrap: pretty;
}

.steps {
    padding-inline-start: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.steps li {
    color: var(--text);
    line-height: 1.65;
    text-wrap: pretty;
}

/* ─── Hero post list ──────────────────────────────────────────────────────── */

#post-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: var(--space-6);
    width: 100%;
    max-width: var(--container-wide);
    margin-inline: auto;
    animation: post-in 0.4s ease both;
}

.post-stage {
    flex: 1;
    min-height: 65vh;
    display: grid;
    place-items: center;
    position: relative;
    padding: var(--space-8);
    overflow: hidden;
    container-type: size;
}

/* Only the first (newest) post owns the viewport; later posts size to content
   so a multi-post latest list doesn't force a viewport of scrolling each. */
.post-stage:not(:first-child) {
    min-height: auto;
}

/* Hidden only while app.js measures the body for fit-to-box sizing. Applied by
   JS, so no-JS users keep the clamp() fallback visible (no flash). */
.post-stage.fitting .post-body {
    visibility: hidden;
}

.post-stage--empty {
    min-height: 50vh;
}

.post-body {
    font-weight: 700;
    line-height: 1.15;
    text-align: center;
    overflow-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
    max-width: 100%;
    color: var(--text);
    /* Fluid sizing relative to the stage (replaces fit-text.js). */
    font-size: clamp(1.5rem, 12cqi, 9rem);
}

/* ─── Post meta chip ──────────────────────────────────────────────────────── */

.post-meta {
    position: absolute;
    bottom: var(--space-4);
    right: var(--space-6);
    display: flex;
    align-items: center;
    padding: var(--space-1) var(--space-3);
    background: var(--surface);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-md);
}

.post-meta .author {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: lowercase;
    letter-spacing: 0.01em;
}

.post-meta .author::after {
    content: "·";
    margin-inline: var(--space-2);
    opacity: 0.5;
    font-weight: 400;
}

.post-meta .ts {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ─── Misc ────────────────────────────────────────────────────────────────── */

.muted {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.spinner {
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: var(--radius-pill);
    animation: spin 0.7s linear infinite;
}

.hidden {
    display: none !important;
}

.form-error {
    padding: var(--space-2) var(--space-3);
    background: rgba(220, 38, 38, 0.08);
    border: 1px solid rgba(220, 38, 38, 0.35);
    border-radius: var(--radius-md);
    color: #b91c1c;
    font-size: 0.9rem;
}

.char-count {
    justify-self: end;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ─── Forms ───────────────────────────────────────────────────────────────── */

form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.field {
    display: grid;
    gap: var(--space-1);
}

.field label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.field input,
.field textarea {
    width: 100%;
    max-width: 36rem;
    padding: var(--space-2) var(--space-3);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    transition:
        border-color 0.15s,
        box-shadow 0.15s;
}

.field input:focus-visible,
.field textarea:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

form button[type="submit"] {
    align-self: flex-start;
    padding: var(--space-2) var(--space-6);
    background: var(--accent);
    color: var(--accent-contrast);
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition:
        background 0.15s,
        opacity 0.15s,
        transform 0.15s;
}

form button[type="submit"]:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

form button[type="submit"]:active {
    opacity: 0.85;
    transform: translateY(0);
}

form button[type="submit"]:disabled {
    opacity: 0.6;
    cursor: progress;
}

/* htmx adds .htmx-request to the disabled submit during the in-flight request. */
form button[type="submit"].htmx-request::after {
    content: "…";
}

/* ─── Success banner ──────────────────────────────────────────────────────── */

.banner-success {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    width: fit-content;
    max-width: 100%;
    padding: var(--space-3) var(--space-4);
    background: var(--banner-bg);
    border: 1px solid var(--banner-border);
    border-radius: var(--radius-md);
    color: var(--banner-text);
    margin-block-end: var(--space-4);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.banner-success button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 var(--space-1);
    font-size: 1rem;
    line-height: 1;
    color: inherit;
}

/* ─── Footer ──────────────────────────────────────────────────────────────── */

footer small {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.footer-copy {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.footer-logo {
    opacity: 0.5;
}

/* ─── Archive table ───────────────────────────────────────────────────────── */

#archive-shell {
    width: 100%;
    max-width: var(--container);
    margin-inline: auto;
}

.archive-empty {
    text-align: center;
    padding-block: var(--space-8);
}

.archive-table {
    width: 100%;
    border-collapse: collapse;
}

.archive-table thead th {
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: var(--space-2) var(--space-4);
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.archive-row {
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.archive-row:last-child {
    border-bottom: none;
}

.archive-row:hover {
    background: rgba(180, 160, 120, 0.08);
    box-shadow: inset 3px 0 0 var(--accent);
}

.archive-row:focus-visible {
    outline: 2px solid var(--accent);
    background: rgba(180, 160, 120, 0.06);
}

.archive-row td {
    padding: var(--space-3) var(--space-4);
    vertical-align: middle;
}

.archive-row__body {
    font-size: 0.9rem;
    line-height: 1.45;
    color: var(--text);
    overflow-wrap: break-word;
    word-break: break-word;
}

.archive-row__author .author {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: lowercase;
    white-space: nowrap;
}

.archive-row__date .ts {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ─── Reduced motion ──────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }

    .bg-blob {
        animation: none;
    }
}

/* ─── Tablet ──────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .nav {
        gap: var(--space-4);
    }

    /* Archive table: stack into cards on tablet and below */
    .archive-table thead {
        display: none;
    }

    .archive-table,
    .archive-table tbody,
    .archive-row,
    .archive-row td {
        display: block;
        width: 100%;
    }

    .archive-row {
        padding: var(--space-4);
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        margin-block-end: var(--space-3);
    }

    .archive-row td {
        padding: var(--space-1) 0;
        border: none;
    }

    .archive-row td::before {
        display: block;
        font-size: 0.65rem;
        font-weight: 500;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: var(--text-muted);
        margin-block-end: 2px;
    }

    .archive-row__body::before {
        content: "Message";
    }
    .archive-row__author::before {
        content: "Author";
    }
    .archive-row__date::before {
        content: "Date";
    }
}

/* ─── Mobile ──────────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
    :root {
        --gutter: 0.75rem;
    }

    .header-inner {
        flex-wrap: wrap;
        row-gap: var(--space-2);
    }

    .nav {
        margin-inline-start: 0;
        width: 100%;
        justify-content: flex-start;
        gap: var(--space-4);
    }

    .bg-blob {
        width: 100vmax;
        height: 85vmax;
        filter: blur(60px);
    }

    .post-stage {
        min-height: 50vh;
        padding: var(--space-6);
    }

    .post-stage--empty {
        min-height: 35vh;
    }

    form button[type="submit"] {
        align-self: stretch;
        width: 100%;
    }

    .create-card {
        padding: var(--space-5);
        border-radius: 8px;
    }
}
