/* ==========================================================================
   custom.css
   Page components shared by the inner pages: buttons, page intros, cards,
   post lists, long-form content (blog posts and project write-ups), the
   contact form, and the about page. Relies on the tokens in main.css.
   Home page layout lives in home.css.
   ========================================================================== */

/* --- BUTTONS --- */
/* Use .button on <a> for navigation and on <button> for actions */
.button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    min-height: var(--tap-target);
    padding: var(--space-xs) var(--space-m);
    border: 1px solid var(--color-text);
    border-radius: 999px;
    background-color: var(--color-text);
    color: var(--color-bg);
    font: inherit;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
}

.button:hover {
    background-color: transparent;
    color: var(--color-text);
}

.button-secondary {
    background-color: transparent;
    color: var(--color-text);
}

.button-secondary:hover {
    background-color: var(--color-text);
    color: var(--color-bg);
}

@media (prefers-reduced-motion: no-preference) {
    .button {
        transition:
            background-color 0.2s ease,
            color 0.2s ease;
    }
}

/* --- PAGE INTRO --- */
main > h1 {
    margin-top: 0;
}

/* Intro paragraph under a page's <h1> */
.lede {
    max-width: var(--reading-width);
    font-size: clamp(1.125rem, 1vw + 0.875rem, 1.375rem);
    line-height: 1.5;
    color: var(--color-text-muted);
}

/* --- CARDS (project previews) --- */
/*
 * list-style: none removes list semantics in Safari, so lists using these
 * classes add role="list" in the HTML to restore them.
 */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr));
    gap: var(--space-l);
    margin: var(--space-xl) 0 0;
    padding: 0;
    list-style: none;
}

.card {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
}

/*
 * The heading comes first in the HTML so screen readers reach it before the
 * image; `order: -1` moves the image to the top visually.
 */
.card img {
    order: -1;
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    border-radius: var(--radius);
    background-color: var(--color-surface);
}

.card-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: var(--space-xs);
    padding-top: var(--space-s);
}

.card-body h2,
.card-body h3 {
    margin: 0;
    font-size: 1.25rem;
}

.card-body a {
    text-decoration: none;
}

/* Makes the whole card clickable while the link text stays just the title */
.card-body a::after {
    content: "";
    position: absolute;
    inset: 0;
}

.card:hover .card-body a {
    text-decoration: underline;
}

.card-body p {
    margin: 0;
    color: var(--color-text-muted);
}

@media (prefers-reduced-motion: no-preference) {
    .card img {
        transition: transform 0.5s var(--ease-out);
    }

    .card:hover img {
        transform: scale(1.02);
    }
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin: auto 0 0; /* Pins tags to the bottom of the card */
    padding: var(--space-xs) 0 0;
    list-style: none;
}

.tag-list li {
    padding: 0.125rem 0.625rem;
    border: 1px solid var(--color-border-strong);
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

/* --- POST LIST (blog previews, also used on the home page) --- */
.post-list {
    margin: var(--space-xl) 0 0;
    padding: 0;
    list-style: none;
    border-top: 1px solid var(--color-border);
}

.post-list article {
    position: relative;
    display: grid;
    gap: var(--space-xs);
    padding-block: var(--space-m);
    border-bottom: 1px solid var(--color-border);
}

.post-list h2,
.post-list h3 {
    margin: 0;
    font-size: clamp(1.25rem, 1vw + 1rem, 1.5rem);
}

.post-list h2 a,
.post-list h3 a {
    text-decoration: none;
}

/* Makes the whole row clickable while the link text stays just the title */
.post-list h2 a::after,
.post-list h3 a::after {
    content: "";
    position: absolute;
    inset: 0;
}

.post-list article:hover :is(h2, h3) a {
    text-decoration: underline;
}

.post-list p {
    margin: 0;
    max-width: var(--reading-width);
    color: var(--color-text-muted);
}

.post-meta {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

/* Wide screens: date in its own column, left of the title */
@media (width >= 48rem) {
    .post-list article {
        grid-template-columns: 12rem 1fr;
        column-gap: var(--space-l);
    }

    .post-list article > * {
        grid-column: 2;
    }

    .post-list .post-meta {
        grid-column: 1;
        grid-row: 1;
        align-self: center;
    }
}

/* --- PROSE (blog posts, project write-ups, about page) --- */
.prose {
    max-width: var(--reading-width);
    font-size: 1.0625rem;
    line-height: 1.7;
}

.prose h1 {
    margin-top: 0;
}

.prose h2 {
    margin-top: var(--space-xl);
}

.prose h3 {
    margin-top: var(--space-l);
}

.prose li + li {
    margin-top: var(--space-xs);
}

figure {
    margin: var(--space-l) 0;
}

figure img {
    border-radius: var(--radius);
}

figcaption {
    margin-top: var(--space-xs);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

blockquote {
    margin: var(--space-l) 0;
    padding-left: var(--space-m);
    border-left: 2px solid var(--color-text);
    font-size: 1.25rem;
    line-height: 1.5;
}

pre {
    padding: var(--space-s);
    overflow-x: auto;
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    line-height: 1.6;
}

:not(pre) > code {
    padding: 0.1em 0.35em;
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 0.25rem;
    font-size: 0.875em;
}

.back-link {
    display: inline-block;
    margin-bottom: var(--space-l);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    text-decoration: none;
    color: var(--color-text-muted);
}

.back-link:hover {
    color: var(--color-text);
    text-decoration: underline;
}

/* Key/value details for a project (role, timeline, tools) */
.project-details {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: var(--space-xs) var(--space-l);
    padding-block: var(--space-m);
    border-block: 1px solid var(--color-border);
}

.project-details dt {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
    align-self: center;
}

.project-details dd {
    margin: 0;
}

/* --- CONTACT FORM --- */
.contact-form {
    display: grid;
    gap: var(--space-m);
    max-width: 40rem;
    margin-top: var(--space-xl);
}

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

.form-field label {
    font-weight: 500;
}

.form-hint {
    margin: 0;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.form-field input,
.form-field textarea {
    width: 100%;
    min-height: var(--tap-target);
    padding: 0.75rem;
    background-color: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
}

.form-field textarea {
    min-height: 10rem;
    resize: vertical;
}

/*
 * Errors can't be shown with red in a black-and-white palette, so an
 * invalid field gets a thicker border AND a written message with an icon.
 * Never rely on color alone anyway (WCAG 1.4.1).
 *
 * :user-invalid only matches after the visitor has interacted with the
 * field, so empty required fields aren't flagged on page load.
 * https://developer.mozilla.org/en-US/docs/Web/CSS/:user-invalid
 */
.form-field input:user-invalid,
.form-field textarea:user-invalid {
    border: 2px solid var(--color-text);
}

.field-error {
    display: none;
    align-items: center;
    gap: var(--space-xs);
    margin: 0;
    font-size: 0.875rem;
    font-weight: 500;
}

/* A circled "!" drawn in CSS; the `/ ""` hides it from screen readers */
.field-error::before {
    content: "!" / "";
    display: inline-grid;
    place-items: center;
    flex-shrink: 0;
    width: 1.25em;
    height: 1.25em;
    border-radius: 50%;
    background-color: var(--color-text);
    color: var(--color-bg);
    font-size: 0.75rem;
    font-weight: 700;
}

.form-field:has(:user-invalid) .field-error {
    display: flex;
}

.contact-form .button {
    justify-self: start;
}

/* --- ABOUT PAGE --- */
.about-photo {
    width: min(100%, 12rem);
    aspect-ratio: 1;
    object-fit: cover;
    /* Crops from a bit above center so tall portraits keep the face in frame */
    object-position: 50% 30%;
    border-radius: 50%;
}
