:root {
    --fg: #000;
    --bg: #fff;
    --muted: #666;
    --rule: #e5e5e5;
    --card-bg: #fafafa;
    --card-border: #d4d4d4;
    --card-bg-open: #f3f3f3;
    --card-border-open: #999;
    --accent-rule: #000;
    --link: #1e3a6e;
    --tag-bg: #efefef;
    --tag-fg: #555;
    --timestamp-accent: #8a5a2b;
}

@media (prefers-color-scheme: dark) {
    :root {
        --fg: #f0f0f0;
        --bg: #0a0a0a;
        --muted: #999;
        --rule: #2a2a2a;
        --card-bg: #151515;
        --card-border: #333;
        --card-bg-open: #1c1c1c;
        --card-border-open: #555;
        --accent-rule: #f0f0f0;
        --link: #a8b8d8;
        --tag-bg: #222;
        --tag-fg: #aaa;
        --timestamp-accent: #c89060;
    }
}

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

::selection {
    background: var(--fg);
    color: var(--bg);
}

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

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    color: var(--fg);
    background: var(--bg);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

main {
    max-width: 60ch;
    margin: 0 auto;
    padding: 2rem 1.25rem 4rem;
}

a {
    color: var(--link);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

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

/* External-link arrow indicator (modernheritage pattern) */
a[href^="http"]::after,
a[target="_blank"]::after {
    content: '\00a0↗';
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: normal;
    font-style: normal;
    text-decoration: none;
    display: inline-block;
}

/* Suppress arrow on image-only / video-thumb links */
.video-thumb > a::after,
a.no-arrow::after {
    content: none;
}

/* --- Header --- */

header {
    margin-bottom: 2rem;
    border-left: 3px solid var(--accent-rule);
    padding-left: 1rem;
}

header .eyebrow {
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted);
    margin: 0 0 0.5rem;
    font-variant-numeric: tabular-nums;
}

header .title {
    font-size: clamp(1.75rem, 7vw, 2.5rem);
    font-weight: 700;
    margin: 0 0 0.15em;
    line-height: 1.05;
    letter-spacing: -0.02em;
    text-transform: uppercase;
}

header .title-light {
    font-weight: 300;
}

header .subtitle {
    font-size: clamp(0.95rem, 3vw, 1.05rem);
    font-weight: 400;
    font-style: italic;
    margin: 0 0 1rem;
    color: var(--muted);
}

header .author {
    font-size: 0.92rem;
    color: var(--fg);
    margin: 0;
    line-height: 1.45;
}

header .affiliation {
    font-size: 0.82rem;
    color: var(--muted);
    margin: 0.2rem 0 0;
    line-height: 1.55;
}

.row-content p.affiliation {
    font-size: 0.85rem;
    color: var(--muted);
    line-height: 1.55;
    margin: 0.2rem 0 0.85rem;
}

/* --- Folding rows --- */

details {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 4px;
    margin-bottom: 0.5rem;
    overflow: hidden;
    transition: background 0.12s ease, border-color 0.12s ease;
}

details[open] {
    background: var(--card-bg-open);
    border-color: var(--card-border-open);
}

summary {
    cursor: pointer;
    list-style: none;
    padding: 0.85rem 1rem;
    user-select: none;
    -webkit-user-select: none;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    column-gap: 0.75rem;
    row-gap: 0.2rem;
}

summary::-webkit-details-marker {
    display: none;
}

summary::after {
    content: "+";
    grid-column: 2;
    grid-row: 1 / -1;
    font-size: 1.2rem;
    font-weight: 400;
    color: var(--muted);
    line-height: 1;
    align-self: center;
}

details[open] summary::after {
    content: "−";
    color: var(--fg);
}

.row-type {
    grid-column: 1;
    grid-row: 1;
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted);
    line-height: 1.4;
    font-variant-numeric: tabular-nums;
}

.row-brief {
    grid-column: 1;
    grid-row: 2;
    font-size: 1.02rem;
    color: var(--fg);
    line-height: 1.35;
    font-weight: 500;
}

/* Abstract: single bold uppercase summary */
details#abstract summary {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto;
    align-items: center;
}

details#abstract summary > span,
details#abstract summary {
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

details#abstract summary::after {
    grid-row: 1;
}

/* Materials, Contact: type label + brief on a single row */
details#materials summary,
details#contact summary {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto;
    align-items: baseline;
}

details#materials .row-type,
details#contact .row-type {
    grid-column: 1;
    grid-row: 1;
}

details#materials .row-brief,
details#contact .row-brief {
    grid-column: 2;
    grid-row: 1;
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--muted);
}

details#materials summary::after,
details#contact summary::after {
    grid-column: 3;
    grid-row: 1;
}

/* --- Project header inside row-content --- */

.row-content h3.project-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 0.9rem;
    line-height: 1.3;
    color: var(--fg);
    letter-spacing: -0.005em;
}

.row-content h3.project-name .project-year {
    font-weight: 400;
    color: var(--muted);
    font-size: 0.82em;
    margin-left: 0.35em;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 380px) {
    .row-content h3.project-name {
        font-size: 1.02rem;
    }

    .row-brief {
        font-size: 0.95rem;
    }
}

/* --- Row content --- */

.row-content {
    padding: 0.5rem 1rem 1.25rem;
    border-top: 1px solid var(--rule);
}

.row-content p {
    margin: 0 0 0.85rem;
    font-size: 0.95rem;
    line-height: 1.6;
}

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

.row-content p.closer {
    margin-top: 1rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--rule);
    font-size: 1rem;
    color: var(--fg);
}

.row-content strong {
    color: var(--fg);
    font-weight: 600;
}

/* --- Media --- */

figure.row-media {
    margin: 0 0 1rem;
}

figure.row-media img,
figure.row-media video {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 3px;
    background: var(--card-bg);
    aspect-ratio: 16 / 10;
    object-fit: cover;
}

/* Empty src placeholder so layout doesn't collapse */
figure.row-media img:not([src]),
figure.row-media img[src=""] {
    background: repeating-linear-gradient(
        45deg,
        var(--card-bg) 0px,
        var(--card-bg) 8px,
        var(--card-bg-open) 8px,
        var(--card-bg-open) 16px
    );
    border: 1px dashed var(--card-border-open);
    min-height: 180px;
}

figure.row-media figcaption {
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 0.5rem;
    line-height: 1.45;
    font-style: italic;
}

/* --- Links and analogues --- */

.row-content p.links {
    font-size: 0.85rem;
    margin-top: 0.85rem;
}

.row-content p.analogues {
    font-size: 0.8rem;
    color: var(--muted);
    margin: 0 0 1rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px dotted var(--rule);
    line-height: 1.55;
}

.row-content p.analogues a {
    color: var(--link);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-decoration-color: var(--card-border);
    text-underline-offset: 2px;
    transition: text-decoration-color 0.15s ease;
}

.row-content p.analogues a:hover {
    text-decoration-color: var(--link);
    color: var(--fg);
}

.row-content p.analogues .label {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.7rem;
    color: var(--fg);
    font-weight: 500;
}

.row-content ul.materials-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.row-content ul.materials-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--rule);
    font-size: 0.95rem;
}

.row-content ul.materials-list li:last-child {
    border-bottom: none;
}

.row-content .muted {
    color: var(--muted);
    font-size: 0.85rem;
}

.row-content h4.credits-heading {
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted);
    margin: 1.5rem 0 0.75rem;
    padding-top: 1rem;
    border-top: 1px dotted var(--rule);
}

/* --- Footer --- */

footer {
    margin-top: 3rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--rule);
    text-align: center;
}

footer .timestamp {
    font-size: 0.75rem;
    color: var(--muted);
    margin: 0;
    font-variant-numeric: tabular-nums;
}

footer .timestamp .mono {
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
    font-size: 0.7rem;
    padding: 0.1rem 0.35rem;
    background: var(--card-bg);
    border: 1px solid var(--rule);
    border-radius: 3px;
    color: var(--fg);
}

/* --- iPhone SE3 portrait (375px wide) --- */

@media (max-width: 380px) {
    main {
        padding: 1.5rem 0.9rem 3rem;
    }

    summary {
        padding: 0.8rem 0.85rem;
        column-gap: 0.4rem;
    }

    .row-content {
        padding: 0.5rem 0.85rem 1.1rem;
    }

    .row-project {
        font-size: 0.95rem;
    }

    .row-brief {
        font-size: 0.82rem;
    }

    header .title {
        font-size: 1.6rem;
    }

    header {
        padding-left: 0.85rem;
    }
}

/* --- Wider screens --- */

@media (min-width: 720px) {
    main {
        max-width: 80ch;
        padding: 3rem 2rem 5rem;
    }

    summary {
        padding: 1rem 1.25rem;
    }

    .row-content {
        padding: 0.75rem 1.25rem 1.5rem;
    }
}

@media (min-width: 1100px) {
    main {
        max-width: 100ch;
        padding: 4rem 3rem 6rem;
    }

    summary {
        padding: 1.1rem 1.5rem;
    }

    .row-content {
        padding: 0.85rem 1.5rem 1.75rem;
    }

    /* Constrain prose to readable line length even when page is wide */
    .row-content > p {
        max-width: 72ch;
    }

    .row-content p.analogues,
    .row-content p.links {
        max-width: 72ch;
    }
}

/* --- Video gallery (e.g., HPS1 row) --- */

.row-media-gallery {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin: 0 0 1.25rem;
}

.video-thumb {
    margin: 0;
}

.video-thumb > a {
    display: block;
    position: relative;
    border-radius: 3px;
    overflow: hidden;
    text-decoration: none;
    background: var(--card-bg);
    aspect-ratio: 16 / 9;
}

.video-thumb > a img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.15s ease;
}

.video-thumb > a::after {
    content: "▶";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.1rem;
    color: white;
    background: rgba(0, 0, 0, 0.65);
    border-radius: 50%;
    width: 42px;
    height: 42px;
    line-height: 42px;
    text-align: center;
    pointer-events: none;
    transition: background 0.15s ease, transform 0.15s ease;
}

.video-thumb > a:hover::after {
    background: rgba(0, 0, 0, 0.85);
    transform: translate(-50%, -50%) scale(1.08);
}

.video-thumb > a:hover img {
    opacity: 0.85;
}

.video-thumb figcaption {
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 0.4rem;
    line-height: 1.4;
    font-style: italic;
}

/* Stack the gallery on phone */
@media (max-width: 480px) {
    .row-media-gallery {
        grid-template-columns: 1fr;
        gap: 0.6rem;
    }
}

/* --- Touch tap targets --- */

@media (hover: none) and (pointer: coarse) {
    summary {
        min-height: 44px;
    }
}
