/* Background photo on every page: stays put while you scroll, snowy peaks kept in view */
html {
    background: #1f4fa0 url("../images/background.jpg") center 30% / cover no-repeat fixed;
}

/* Keep content centered with fixed side margins; it stops growing past max-width */
body {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 80px;
    min-height: 100vh;
    display: flow-root; /* panel reaches the very top (no gap above the title) */
    /* light panel behind the content so text stays readable over the photo */
    background: rgba(255, 255, 255, 0.88);
}

/* Double-spaced paragraph text on every page */
p {
    line-height: 2;
}

nav {
    position: fixed;
    top: 0;
    /* line up with the right edge of the content column */
    right: max(80px, calc((100vw - 1560px) / 2 + 80px));
    padding: 10px;
    display: flex;
    gap: 20px; /* spacing between buttons */
}

nav button {
    padding: 10px 20px; /* button size */
}

.grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px; /* spacing between project tiles */
    margin-bottom: 14px; /* keeps the last row off the panel edge */
}

.grid a {
    text-decoration: none;
    color: white;
    display: block;
    position: relative; /* anchor for the hover text */
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.35); /* thin outline around each tile */
}

.grid img {
    width: 100%;
    height: auto;
    aspect-ratio: 7 / 6; /* tiles scale evenly instead of stretching */
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.grid p {
    line-height: normal; /* hover titles stay single-spaced */
    position: absolute;
    inset: 0; /* cover the whole image */
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    font-size: 1.2rem;
    background: rgba(0, 0, 0, 0.5); /* darken image so text is readable */
    color: white;
    opacity: 0; /* hidden until hover */
    transition: opacity 0.3s ease;
}

.grid a:hover p,
.grid a:focus p {
    opacity: 1;
}

.grid a:hover img {
    transform: scale(1.05); /* slight zoom on hover */
}

.project-content {
    padding: 40px;
    max-width: 1120px;
    font-size: 1.25rem; /* slightly larger body text on project pages */
}

.project-content video {
    float: left;
    width: 400px;
    margin: 0 30px 20px 0;
    border-radius: 4px;
}

/* Main project video (YouTube embed or local video): floats left so text wraps around it */
.project-content .project-video {
    float: left;
    width: 560px;
    max-width: 100%;
    aspect-ratio: 16 / 9;
    height: auto;
    border: 0;
    margin: 0 30px 20px 0;
    border-radius: 4px;
}

/* Photos inside project pages: float left so text wraps around them */
.project-content img.project-photo {
    float: left;
    width: 264px; /* native size of the current photo; larger would blur */
    max-width: 100%;
    height: auto;
    margin: 0 30px 20px 0;
    border-radius: 4px;
}

/* Two photos side by side, floated together so text wraps around the pair.
   Matching heights keep the pair looking like one band. */
.project-content .photo-pair {
    float: left;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin: 0 30px 20px 0;
    max-width: 100%;
}

.project-content .photo-pair img {
    float: none;
    height: 260px;
    width: auto;
    max-width: 100%;
    margin: 0;
    border-radius: 4px;
}

@media (max-width: 800px) {
    .project-content .photo-pair {
        float: none;
        flex-wrap: wrap;
        margin-right: 0;
    }
}

/* Section headings start below any floated video/photo */
.project-content h2 {
    clear: both;
}

/* Figure rows: figures stacked in a left column, text beside them.
   The figure column floats, so once the figures run out the text
   keeps going full width underneath them instead of staying in a
   narrow column. */
.figure-row {
    clear: both; /* start below any floated video/photo */
    margin: 20px 0;
}

/* Contain the floated figure column so the next row starts below it */
.figure-row::after {
    content: "";
    display: table;
    clear: both;
}

.figure-col {
    float: left;
    width: 480px;
    max-width: 100%;
    margin-right: 30px;
}

/* Mirror of .figure-col for figures that belong on the right of the text */
.figure-col.right {
    float: right;
    margin-right: 0;
    margin-left: 30px;
}

.text-col {
    /* no overflow/BFC here on purpose: text wraps around and under the figures */
}

.text-col p:first-child {
    margin-top: 0;
}

.project-figure {
    margin: 0 0 25px 0;
    text-align: center;
}

/* Small figures shown side by side in one band: saves vertical space
   when several related plots sit next to a long paragraph */
.figure-group {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin: 0 0 25px 0;
}

.figure-group .project-figure {
    flex: 1;
    min-width: 0;
    margin: 0;
}

.figure-group .project-figure img {
    width: 100%;
}

.figure-group figcaption {
    font-size: 0.8rem;
}

.project-figure img {
    width: 100%;
    height: auto;
    display: block;
}

/* Full-width figure band: a pair of figures side by side spanning the whole
   content column, so they break the page like a divider between sections.
   Each figure's flex-grow is set inline to its image aspect ratio, which
   makes the two images share the row at matching heights. */
.figure-band {
    clear: both; /* drop below any floated figure column */
    display: flex;
    align-items: flex-start;
    gap: 20px;
    margin: 10px 0 30px 0;
}

.figure-band .project-figure {
    flex-basis: 0;
    min-width: 0;
    margin: 0;
}

.figure-band .project-figure img {
    width: 100%;
    margin: 0 auto;
}

/* Small screens: stack the pair instead of squeezing both into one row */
@media (max-width: 800px) {
    .figure-band {
        flex-wrap: wrap;
    }

    .figure-band .project-figure {
        flex: 1 1 100%;
    }
}

/* Slideshow gallery: several photos in one frame, shown one at a time.
   The frame has a fixed aspect ratio and the photos are letterboxed inside it
   (object-fit: contain), so mixing portrait and landscape shots doesn't make
   the page jump height between slides. Driven by js/slideshow.js. */
.slideshow {
    margin: 0 0 25px 0;
}

.slideshow:focus-visible {
    outline: 2px solid #888;
    outline-offset: 4px;
}

.slideshow-frame {
    position: relative;
    aspect-ratio: 4 / 3;
    background: #111;
    border-radius: 4px;
    overflow: hidden;
}

.slideshow-frame img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    opacity: 0;
    transition: opacity 0.35s ease;
    pointer-events: none;
}

.slideshow-frame img.is-active {
    opacity: 1;
}

/* Prev/next arrows, overlaid on the left and right edges of the frame */
.slideshow-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.slideshow-nav:hover {
    background: rgba(0, 0, 0, 0.75);
}

.slideshow-nav.prev { left: 8px; }
.slideshow-nav.next { right: 8px; }

/* Slide counter in the corner of the frame */
.slideshow-counter {
    position: absolute;
    bottom: 8px;
    right: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: 0.8rem;
}

.slideshow-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
}

.slideshow-dot {
    width: 9px;
    height: 9px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #ccc;
    cursor: pointer;
    transition: background 0.2s ease;
}

.slideshow-dot:hover { background: #aaa; }
.slideshow-dot.is-active { background: #555; }

.slideshow-caption {
    margin-top: 8px;
    min-height: 2.6em; /* room for the longest caption, so dots don't shift */
    text-align: center;
    color: #777;
    font-size: 0.9rem;
}

/* Code blocks: dark panel with the source kept as selectable text */
.code-block {
    clear: both;
    margin: 10px 0 25px 0;
}

.code-block pre {
    /* shrink-wrap the panel to the longest line and centre it, so the block is
       mostly text instead of a wide slab of empty dark background */
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
    padding: 14px 18px;
    background: #1b1e23;
    color: #dfe3e8;
    border-radius: 4px;
    overflow-x: auto; /* long lines scroll instead of stretching the page */
    font-size: 0.95rem;
    line-height: 1.6;
    tab-size: 4;
}

.code-block code {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

.code-block figcaption {
    margin-top: 8px;
    text-align: center;
    color: #777;
    font-size: 0.9rem;
}

/* Wide diagrams that span the full text column instead of sitting beside it */
.project-figure.full {
    clear: both; /* drop below any floated photo */
    margin: 10px 0 25px 0;
}

/* Mid-sized renders: centered, but not stretched across the whole column */
.project-figure.medium img {
    width: 560px;
    margin: 0 auto;
}

/* Tall, skinny diagrams shouldn't fill the whole column width */
.project-figure.narrow img {
    width: 250px;
    margin: 0 auto;
}

/* Tall portrait images: keep them from getting too long */
.project-figure.tall img {
    width: 380px;
    max-width: 100%;
    margin: 0 auto;
}

/* Portrait (vertical) videos in a figure: keep them narrower */
.project-figure.tall video {
    width: 380px;
    max-width: 100%;
    margin: 0 auto;
}

/* Videos used as figures fill the figure column instead of floating */
.project-figure video {
    float: none;
    width: 100%;
    margin: 0;
    display: block;
}

.project-figure figcaption {
    margin-top: 8px;
    color: #777;
    font-size: 0.9rem;
}

/* Small screens: stack figures above the text */
@media (max-width: 800px) {
    .figure-col,
    .figure-col.right {
        float: none;
        width: auto;
        margin-right: 0;
        margin-left: 0;
    }
}

.project-content::after {
    content: "";
    display: table;
    clear: both;
}

.repo-link {
    display: flex; /* own line so the video floats below it */
    width: fit-content;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px; /* sits at the top, above the project content */
    color: inherit;
    text-decoration: none;
}

.repo-link svg {
    width: 32px;
    height: 32px;
    fill: currentColor;
    transition: transform 0.2s ease;
}

.repo-link span {
    text-decoration: underline;
}

.repo-link:hover svg,
.repo-link:focus svg {
    transform: scale(1.1);
}

/* About page write-up: sits above the photo gallery, centered on the page.
   Capped width keeps the lines short enough to read comfortably. */
.about-text {
    max-width: 720px;
    margin: 45px auto 55px; /* auto side margins centre the block */
    text-align: center;
    font-size: 1.3rem;
}

.about-text p {
    line-height: 1.8; /* a little tighter than the double-spaced default */
    margin: 0 0 1.1em 0;
}

.about-text p:last-child {
    margin-bottom: 0;
}

/* About page gallery: collage-style columns, photos keep their shape (no cropping) */
.gallery {
    columns: 3 260px;
    column-gap: 14px;
    margin: 30px 0;
}

.gallery img {
    width: 100%;
    display: block;
    margin-bottom: 14px;
    border-radius: 4px;
    break-inside: avoid;
    cursor: zoom-in;
    transition: opacity 0.2s ease;
}

.gallery img:hover {
    opacity: 0.85;
}

/* After gallery.js runs: equal-height columns so the gallery is a clean rectangle */
.gallery.balanced {
    columns: auto;
    display: flex;
    gap: 14px;
}

.gallery-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.gallery.balanced img {
    flex-basis: 0;
    min-height: 0;
    height: auto;
    margin: 0;
    object-fit: cover; /* trims a little off the edges to even out the columns */
}

/* Caption under the clicked photo */
.lightbox-caption {
    max-width: 90vw;
    margin: 0;
    color: white;
    font-size: 1.05rem;
    line-height: 1.5;
    text-align: center;
}

/* Click a photo to see it large */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    flex-direction: column; /* photo, then its caption */
    align-items: center;
    justify-content: center;
    gap: 14px;
    cursor: zoom-out;
    z-index: 10;
}

.lightbox.open {
    display: flex;
}

.lightbox img {
    max-width: 90vw;
    max-height: 80vh; /* leaves room for the caption */
    border-radius: 4px;
}
