/* ---------- Design tokens ---------- */
:root {
    --bg: #fafaf9;
    --surface: #ffffff;
    --surface-2: #f4f4f2;
    --text: #18181b;
    --muted: #5f5f66;
    --border: #e6e6e3;
    --accent: #c2410c;
    --accent-soft: #fff1e8;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
    --radius: 14px;
    --max: 1120px;
    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --serif: "Source Serif 4", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f0f11;
        --surface: #17171a;
        --surface-2: #1e1e22;
        --text: #ececee;
        --muted: #a0a0a8;
        --border: #2a2a2f;
        --accent: #fb923c;
        --accent-soft: #2a1a10;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
    }
    .brand img { filter: invert(1); }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 17px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
}
main { flex: 1; }
img, video { max-width: 100%; display: block; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.02em; margin: 0; }

.container {
    width: 100%;
    max-width: var(--max);
    margin: 0 auto;
    padding: 0 24px;
}

/* ---------- Header ---------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
}
.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    font-weight: 700;
    font-size: 17px;
    letter-spacing: -0.01em;
}
.brand img {
    width: 32px;
    height: 32px;
    animation: rotate 18s linear infinite paused;
}
.brand:hover img { animation-play-state: running; }

.nav { display: flex; gap: 4px; }
.nav a {
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    color: var(--muted);
    padding: 8px 14px;
    border-radius: 8px;
    transition: color .15s, background .15s;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--text); }

#menu-toggle { display: none; }
.menu-button {
    display: none;
    cursor: pointer;
    padding: 8px;
    margin-right: -8px;
}
.menu-button span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text);
    margin: 5px 0;
    border-radius: 2px;
}

@media (max-width: 720px) {
    .menu-button { display: block; }
    .nav {
        display: none;
        position: absolute;
        top: 64px;
        left: 0;
        right: 0;
        flex-direction: column;
        gap: 0;
        padding: 8px 16px 16px;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
    }
    .nav a { padding: 12px; font-size: 16px; }
    #menu-toggle:checked ~ .nav { display: flex; }
}

/* ---------- Buttons & tags ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 11px 20px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid transparent;
    transition: transform .15s, background .15s, border-color .15s;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--muted); }
.btn svg { width: 18px; height: 18px; fill: currentColor; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.tags li {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 3px 10px;
    border-radius: 99px;
}

/* ---------- Hero ---------- */
.hero {
    position: relative;
    color: #fff;
    background: #111 url("../images/mars.jpg") center / cover no-repeat;
}
.hero::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(0,0,0,.78) 0%, rgba(0,0,0,.45) 55%, rgba(0,0,0,.15) 100%);
}
.hero .container {
    position: relative;
    padding-top: 120px;
    padding-bottom: 120px;
}
.eyebrow {
    display: inline-block;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 14px;
}
.hero .eyebrow { color: #fdba74; }
.hero h1 {
    font-size: clamp(40px, 6vw, 68px);
    font-weight: 800;
    letter-spacing: -0.035em;
}
.hero p {
    max-width: 560px;
    font-size: 19px;
    color: rgba(255,255,255,.85);
    margin: 18px 0 32px;
}
.hero .actions { display: flex; flex-wrap: wrap; gap: 12px; }
.hero .btn-secondary { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.3); }
.hero .btn-secondary:hover { background: rgba(255,255,255,.18); }

/* ---------- Sections ---------- */
.section { padding: 88px 0; }
.section + .section { padding-top: 0; }
.section-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 32px;
}
.section-head h2 { font-size: clamp(28px, 3.4vw, 36px); font-weight: 750; }
.section-head a { color: var(--accent); font-weight: 600; text-decoration: none; white-space: nowrap; }
.section-head a:hover { text-decoration: underline; }
.lead { color: var(--muted); font-size: 18px; max-width: 640px; margin: 10px 0 0; }

/* ---------- About ---------- */
.about {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 64px;
    align-items: center;
}
.about h2 { font-size: clamp(28px, 3.4vw, 36px); margin-bottom: 18px; }
.about p { color: var(--muted); margin: 0 0 16px; }
.about figure { margin: 0; }
.about img {
    width: 100%;
    max-width: 340px;
    aspect-ratio: 4 / 5;
    object-fit: cover;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-left: auto;
}
.about figcaption { text-align: right; font-size: 14px; color: var(--muted); margin-top: 10px; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 28px; }
.facts div { border-left: 2px solid var(--accent); padding-left: 14px; }
.facts strong { display: block; font-size: 15px; }
.facts span { font-size: 14px; color: var(--muted); }

@media (max-width: 820px) {
    .about { grid-template-columns: 1fr; gap: 32px; }
    .about img { margin: 0; max-width: 260px; }
    .about figcaption { text-align: left; }
    .facts { grid-template-columns: 1fr; }
}

/* ---------- Cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 24px; }
.card {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    text-decoration: none;
    transition: transform .2s, box-shadow .2s, border-color .2s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: transparent; }
.card-media {
    aspect-ratio: 16 / 10;
    background: var(--surface-2);
    overflow: hidden;
}
.card-media img { width: 100%; height: 100%; object-fit: cover; transition: transform .4s; }
.card:hover .card-media img { transform: scale(1.03); }
.card-media.placeholder {
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--accent-soft), var(--surface-2));
}
.card-media.placeholder svg { width: 56px; height: 56px; stroke: var(--accent); fill: none; stroke-width: 1.5; opacity: .85; }
.card-body { display: flex; flex-direction: column; gap: 10px; padding: 20px 22px 22px; flex: 1; }
.card-meta { font-size: 13px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.card h3 { font-size: 20px; font-weight: 700; }
.card p { margin: 0; color: var(--muted); font-size: 15.5px; line-height: 1.55; flex: 1; }
.card .tags { margin-top: 6px; }

/* ---------- Page header ---------- */
.page-head { padding-top: 72px; padding-bottom: 40px; }
.page-head h1 { font-size: clamp(36px, 5vw, 52px); font-weight: 800; letter-spacing: -0.03em; }

/* ---------- Article ---------- */
.article { max-width: 760px; margin: 0 auto; padding: 56px 24px 24px; }
.back {
    display: flex;
    width: fit-content;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
    margin-bottom: 28px;
}
.back:hover { color: var(--text); }
.article h1 { font-size: clamp(32px, 4.6vw, 46px); font-weight: 800; letter-spacing: -0.03em; margin-bottom: 16px; }
.article .summary { font-size: 20px; color: var(--muted); margin: 0 0 22px; line-height: 1.55; }
.article .tags { margin-bottom: 36px; }
.prose { font-family: var(--serif); font-size: 19px; line-height: 1.75; }
.prose p { margin: 0 0 22px; }
.prose a { color: var(--accent); }
.article .actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; }

.gallery {
    max-width: 1040px;
    margin: 40px auto 0;
    padding: 0 24px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
}
.gallery.two { grid-template-columns: repeat(2, 1fr); }
.gallery figure { margin: 0; }
.gallery img, .gallery video {
    width: 100%;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #000;
}
.gallery img.tall { max-height: 560px; object-fit: cover; }
.gallery figcaption { font-size: 14px; color: var(--muted); margin-top: 10px; text-align: center; }

/* ---------- Footer ---------- */
.site-footer {
    margin-top: 96px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.site-footer .container {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: center;
    justify-content: space-between;
    padding-top: 36px;
    padding-bottom: 36px;
}
.site-footer strong { display: block; font-size: 16px; }
.site-footer a.mail { color: var(--muted); text-decoration: none; font-size: 15px; }
.site-footer a.mail:hover { color: var(--accent); }
.social { display: flex; gap: 10px; }
.social a {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    border: 1px solid var(--border);
    color: var(--muted);
    transition: color .15s, border-color .15s;
}
.social a:hover { color: var(--text); border-color: var(--muted); }
.social svg { width: 20px; height: 20px; fill: currentColor; }
.copyright { width: 100%; font-size: 13px; color: var(--muted); }

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

@media (max-width: 600px) {
    body { font-size: 16px; }
    .container { padding: 0 16px; }
    .hero .container { padding-top: 80px; padding-bottom: 80px; }
    .hero p { font-size: 17px; }
    .section { padding: 64px 0; }
    .section-head { flex-direction: column; align-items: start; gap: 8px; }
    .page-head { padding-top: 48px; padding-bottom: 28px; }
    .article { padding: 36px 16px 8px; }
    .prose { font-size: 17.5px; }
    .gallery, .gallery.two { padding: 0 16px; grid-template-columns: 1fr; }
    .grid { grid-template-columns: 1fr; }
    .card-media.placeholder { aspect-ratio: 16 / 6; }
}

/* Wide vector renders (PCB) sit centred instead of being cropped */
.card-media img[src$=".svg"] { object-fit: contain; background: #0f3d2a; padding: 18px; }
.gallery img[src$=".svg"] { background: #0f3d2a; padding: 16px; }
.gallery:not(.two) figure:only-child { grid-column: 1 / -1; }

/* Uniform gallery tiles: photos fill, diagrams and plots stay whole */
.gallery img { aspect-ratio: 4 / 3; object-fit: cover; }
.gallery img[src$=".svg"],
.gallery img[src*="circuit"],
.gallery img[src*="board-scan"],
.gallery img[src*="sims/"],
.gallery img[src*="peltier-ui"],
.gallery img[src*="3d/"] { object-fit: contain; background: #f4f4f2; }
.gallery img[src$=".svg"] { background: #0f3d2a; }
.card-media img[src*="3d/"] { object-fit: contain; background: #f4f4f2; padding: 12px; }
.card-media img[src*="fpga/"] { object-fit: contain; background: #fff; padding: 8px; }
.gallery img[src*="fpga/"],
.gallery img[src*="web/"] { object-fit: contain; background: #fff; }
.gallery:has(img[src*="fpga/"]) { grid-template-columns: 1fr; max-width: 900px; }
.gallery img[src*="fpga/"],
.gallery img[src*="web/"] { aspect-ratio: auto; }
.gallery:has(img[src*="web/"]) { grid-template-columns: 1fr; max-width: 1000px; }
.gallery figure:has(img[src*="crack_strip"]),
.gallery figure:has(img[src*="crack_notch"]) { grid-column: 1 / -1; }
.gallery img[src*="crack_strip"],
.gallery img[src*="crack_notch"] { aspect-ratio: auto; object-fit: contain; background: #fff; }

/* Dark mode: frame light-background renders so they sit on the dark page */
.card-media picture, .gallery picture { display: contents; }
@media (prefers-color-scheme: dark) {
    .card-media img[src*="3d/"], .gallery img[src*="3d/"] { background: #1e1e22; }
    .card-media img[src*="fpga/"], .gallery img[src*="fpga/"] { background: #17171a; }
    .gallery img[src*="web/"], .gallery img[src*="sims/"], .gallery img[src*="circuit"],
    .gallery img[src*="board-scan"], .gallery img[src*="peltier-ui"],
    .gallery img[src*="crack_"] { background: var(--surface-2); }
}

/* ---------- Fullscreen image viewer ---------- */
.gallery img { cursor: zoom-in; }
.gallery img:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
html.lightbox-open { overflow: hidden; }
.lightbox {
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: rgba(10, 10, 12, 0.94);
    color: #ececee;
}
.lightbox::backdrop { background: rgba(10, 10, 12, 0.94); }
.lightbox-figure {
    margin: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 56px 72px 28px;
    box-sizing: border-box;
}
.lightbox-img {
    max-width: 100%;
    max-height: calc(100% - 48px);
    object-fit: contain;
    border-radius: 8px;
    cursor: default;
}
.lightbox-caption { font-size: 15px; color: #c8c8ce; text-align: center; max-width: 760px; }
.lightbox-count { position: absolute; top: 20px; left: 24px; font-size: 14px; color: #a0a0a8; }
.lightbox-btn {
    position: absolute;
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    transition: background .15s;
}
.lightbox-btn:hover { background: rgba(255, 255, 255, 0.18); }
.lightbox-btn:focus-visible { outline: 2px solid #fb923c; outline-offset: 2px; }
.lightbox-btn[hidden] { display: none; }
.lightbox-close { top: 14px; right: 16px; font-size: 30px; }
.lightbox-full { top: 14px; right: 72px; font-size: 20px; }
.lightbox-prev { left: 16px; top: 50%; transform: translateY(-50%); font-size: 34px; }
.lightbox-next { right: 16px; top: 50%; transform: translateY(-50%); font-size: 34px; }
@media (max-width: 600px) {
    .lightbox-figure { padding: 64px 12px 20px; }
    .lightbox-prev, .lightbox-next { top: auto; bottom: 18px; transform: none; }
}
.gallery img[src*="arrested_v2_v9"] { object-fit: contain; background: #fff; }

/* ---------- Galleries: uniform tiles, nothing cropped ---------- */
.gallery,
.gallery.two {
    max-width: 1200px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px;
    align-items: start;
}
/* 2 or 4 images -> two columns, 1 image -> one large tile */
.gallery:has(> figure:nth-child(2):last-child),
.gallery:has(> figure:nth-child(4):last-child) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.gallery:has(> figure:only-child) { grid-template-columns: minmax(0, 900px); justify-content: center; }

.gallery .tile {
    position: relative;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    isolation: isolate;
}
/* the same picture, blurred, fills the space the image leaves */
.gallery .tile::before {
    content: "";
    position: absolute;
    inset: -10%;
    background: var(--img) center / cover no-repeat;
    filter: blur(26px) saturate(1.15) brightness(0.92);
    z-index: -1;
}
.gallery .tile img {
    position: relative;
    display: block;
    width: 100% !important;
    height: 100% !important;
    max-height: none !important;
    aspect-ratio: auto !important;
    object-fit: contain !important;
    background: transparent !important;
    border: 0 !important;
    border-radius: 0 !important;
    padding: 0 !important;
}
.gallery video { aspect-ratio: 4 / 3; object-fit: contain; background: #000; }

/* wide plots and website screenshots keep their own shape, one per row */
.gallery.gallery:has(img[src*="web/"]),
.gallery.gallery:has(img[src*="fpga/"]) { grid-template-columns: minmax(0, 1100px); justify-content: center; }
.gallery:has(img[src*="web/"]) .tile,
.gallery:has(img[src*="fpga/"]) .tile { aspect-ratio: auto; }
.gallery:has(img[src*="web/"]) .tile::before,
.gallery:has(img[src*="fpga/"]) .tile::before { display: none; }
.gallery:has(img[src*="web/"]) .tile img,
.gallery:has(img[src*="fpga/"]) .tile img { height: auto !important; }

@media (prefers-color-scheme: dark) {
    .gallery .tile.has-dark::before { display: none; }
}
@media (max-width: 900px) {
    .gallery, .gallery.two,
    .gallery:has(> figure:nth-child(2):last-child),
    .gallery:has(> figure:nth-child(4):last-child) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
}
@media (max-width: 560px) {
    .gallery, .gallery.two,
    .gallery:has(> figure:nth-child(2):last-child),
    .gallery:has(> figure:nth-child(4):last-child) { grid-template-columns: 1fr; }
}

/* Renders, plots and diagrams: plain fill in their own background colour, no blur */
.gallery .tile:has(img[src*="3d/"]),
.gallery .tile:has(img[src*="hood-shroud-cad"]) { background: #f4f4f2; }
.gallery .tile:has(img[src*="sims/comsol_spacetime"]),
.gallery .tile:has(img[src*="sims/comsol_spectrum"]),
.gallery .tile:has(img[src*="sims/crack_"]),
.gallery .tile:has(img[src*="board-scan"]),
.gallery .tile:has(img[src*="circuit"]),
.gallery .tile:has(img[src*="fpga/"]),
.gallery .tile:has(img[src*="web/"]) { background: #fff; }
.gallery .tile:has(img[src$=".svg"]) { background: #0f3d2a; }
.gallery .tile:has(img[src*="3d/"])::before,
.gallery .tile:has(img[src*="hood-shroud-cad"])::before,
.gallery .tile:has(img[src*="sims/comsol_spacetime"])::before,
.gallery .tile:has(img[src*="sims/comsol_spectrum"])::before,
.gallery .tile:has(img[src*="sims/crack_"])::before,
.gallery .tile:has(img[src*="board-scan"])::before,
.gallery .tile:has(img[src*="circuit"])::before,
.gallery .tile:has(img[src$=".svg"])::before { display: none; }
@media (prefers-color-scheme: dark) {
    .gallery .tile.has-dark:has(img[src*="3d/"]) { background: #1e1e22; }
    .gallery .tile.has-dark:has(img[src*="fpga/"]) { background: #17171a; }
}
/* wide strips span the row at their natural shape */
.gallery .tile:has(img[src*="crack_strip"]),
.gallery .tile:has(img[src*="crack_notch"]) { aspect-ratio: auto; }
.gallery .tile:has(img[src*="crack_strip"]) img,
.gallery .tile:has(img[src*="crack_notch"]) img { height: auto !important; }
