/* Selected work uses the typography and section colours of the existing home page. */
.work-container {
    width: 100%;
    max-width: 1100px;
    padding-inline: 1rem;
    margin-inline: auto;
}

.selected-work {
    background: #fff;
    padding: 4rem 0 4.5rem;
    margin-top: 3rem;
    scroll-margin-top: 1.5rem;
}

.selected-work h2 {
    color: #111;
    font-size: 2.4rem;
    line-height: 1.2;
    text-align: center;
    margin-bottom: 2.75rem;
    letter-spacing: -.035em;
}

/* One project at a time, with the devices as the main visual. */
.selected-work [hidden] { display: none !important; }
.work-showcase {
    display: grid;
    grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
    align-items: center;
    gap: 3rem;
    min-height: 430px;
    padding-bottom: 2rem;
}
.work-showcase + .work-showcase { margin-top: 3rem; }
.work-carousel-ready .work-showcase { margin-top: 0; animation: work-reveal .3s ease-out both; }
.work-devices { display: block; position: relative; width: 100%; aspect-ratio: 1.5; isolation: isolate; }
.device-spot { display: block; position: absolute; }
.device-spot--laptop { width: 78%; left: 5%; top: 10%; z-index: 1; }
.device-spot--tablet { width: 31%; right: 7%; top: 29%; z-index: 2; }
.device-spot--phone { width: 16%; right: 0; top: 46%; z-index: 3; }
.work-devices--rothes .device-spot--tablet { width: 47%; right: 8%; top: 40%; }
:is(.work-devices--house-log, .work-devices--oddly-safe) .device-spot--1 { width: 27%; left: 12%; right: auto; top: 12%; z-index: 1; }
:is(.work-devices--house-log, .work-devices--oddly-safe) .device-spot--2 { width: 30%; left: 36%; right: auto; top: 2%; z-index: 3; }
:is(.work-devices--house-log, .work-devices--oddly-safe) .device-spot--3 { width: 27%; right: 9%; top: 12%; z-index: 2; }
.work-project-copy h3 { font-size: clamp(1.8rem, 3vw, 2.5rem); font-weight: 700; line-height: 1.15; letter-spacing: -.045em; color: #111; margin-bottom: 1rem; }
.work-project-copy p { font-size: 1.05rem; line-height: 1.7; color: #60656e; max-width: 32ch; }
.work-project-copy .work-link { margin-top: 1.25rem; }
.work-carousel-controls { display: flex; justify-content: flex-end; align-items: center; padding-top: 1.25rem; }
.work-carousel-arrows { display: flex; gap: .5rem; }
@keyframes work-reveal { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .work-carousel-ready .work-showcase { animation: none; } }

.work-link {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    font-size: .93rem;
    font-weight: 600;
    color: #171717;
    min-height: 44px;
}

.work-link i { font-size: 1.3rem; }
.work-link:hover { text-decoration: underline; text-underline-offset: 4px; }
.selected-work a:focus-visible, .selected-work button:focus-visible, .work-link:focus-visible,
.project-gallery a:focus-visible, .project-gallery button:focus-visible {
    outline: 2px solid #245bd6;
    outline-offset: 5px;
    border-radius: 4px;
}

/* Project pages keep the gallery separate from the short project explanation. */
.project-page { background: #fff; }
.project-back { margin-top: 1.5rem; color: #555b64; }
.project-heading { padding: 2rem 0 2.5rem; text-align: center; }
.project-heading h1 { color: #111; font-size: clamp(2.2rem, 5vw, 3.4rem); line-height: 1.15; letter-spacing: -.045em; }
.project-summary { color: #60656e; margin: .85rem auto 0; max-width: 42rem; font-size: 1.08rem; }
.project-gallery { --gallery-image-height: min(58vh, 540px); }
.project-gallery [hidden] { display: none !important; }
.gallery-slide { margin-bottom: 1rem; }
.gallery-stage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    padding: 1.5rem;
    height: calc(var(--gallery-image-height) + 3rem);
    background: transparent;
    overflow: hidden;
    cursor: zoom-in;
}

/* CSS crops remove simulator surrounds without modifying the captured app UI. */
.screen-frame {
    display: block;
    position: relative;
    flex: none;
    overflow: hidden;
    aspect-ratio: var(--screen-ratio);
    width: min(100%, calc(var(--gallery-image-height) * var(--display-ratio)));
    border-radius: 4px;
}

.screen-frame img {
    display: block;
    position: absolute;
    width: var(--screen-width);
    max-width: none;
    height: auto;
    top: var(--screen-top);
    left: var(--screen-left);
}

/* Reusable device frames. Screen pixels are not redrawn or stretched. */
.portfolio-device {
    display: block;
    position: relative;
    flex: none;
    width: min(94%, calc(var(--gallery-image-height, 440px) * var(--display-ratio) * .9));
    filter: drop-shadow(0 10px 12px #16202c24);
}
.device-spot .portfolio-device { width: 100%; }
.portfolio-device-body {
    display: block;
    position: relative;
    background: #17181b;
    border: 1px solid #73777e;
    box-shadow: inset 0 0 0 1px #b6bac180, inset 0 0 0 3px #101113;
}
.portfolio-device .screen-frame { width: 100%; }
.portfolio-device--laptop .portfolio-device-body { padding: 2.2% 1.4% 1.5%; border-radius: 2.5% 2.5% .6% .6% / 4% 4% 1% 1%; }
.portfolio-device--laptop .screen-frame { border-radius: 1px; }
.portfolio-device--laptop .portfolio-device-body::before { content: ''; position: absolute; top: 1%; left: calc(50% - 1px); width: 3px; height: 3px; background: #40444a; border-radius: 50%; }
.portfolio-device-base { display: block; position: relative; width: 112%; margin: -1px 0 0 -6%; aspect-ratio: 42; border-radius: 0 0 12% 12% / 0 0 80% 80%; background: linear-gradient(#e0e2e6 0%, #babdc3 38%, #74777e 86%, #54565b 100%); box-shadow: 0 1px 1px #2225; }
.portfolio-device-base::before { content: ''; position: absolute; width: 15%; height: 28%; left: 42.5%; top: 0; background: #92969e; border-radius: 0 0 5px 5px; box-shadow: inset 0 -1px 1px #fff8; }
.portfolio-device--tablet .portfolio-device-body { padding: 3%; border-radius: 5.5% / 4.1%; }
.portfolio-device--tablet .screen-frame { border-radius: 3% / 2.25%; }
.portfolio-device--tablet.portfolio-device--landscape .portfolio-device-body { border-radius: 4.1% / 5.5%; }
.portfolio-device--tablet.portfolio-device--landscape .screen-frame { border-radius: 2.25% / 3%; }
.portfolio-device-screen { display: block; }
.portfolio-device--phone { filter: drop-shadow(0 12px 12px #16202c20); }
.portfolio-device--phone .portfolio-device-body {
    padding: 2.6%;
    border: 1px solid #555755;
    border-radius: 17% / 8%;
    background: linear-gradient(110deg, #a2a29f, #454644 13%, #171817 28%, #5c5d59 75%, #a2a29f);
    box-shadow: inset 0 0 0 1px #d1d0cbb3, inset 0 0 0 3px #111;
}
.portfolio-phone-screen { display: block; position: relative; overflow: hidden; border-radius: 15% / 7%; background: #0a151e; box-shadow: 0 0 0 1px #050505; }
.portfolio-device--phone .screen-frame { border-radius: 0; background: #101113; }
.portfolio-phone-status { display: block; width: 100%; height: auto; color: #fff; background: #0a151e; }
.portfolio-phone-home { display: block; position: relative; aspect-ratio: 390 / 25; background: #0a151e; }
.portfolio-phone-home::after { content: ''; position: absolute; width: 34%; height: 16%; left: 33%; bottom: 28%; border-radius: 99px; background: #fff; }
.portfolio-device--phone::before, .portfolio-device--phone::after, .portfolio-phone-buttons { content: ''; display: block; position: absolute; width: 1.4%; background: linear-gradient(90deg, #494a47, #a8a8a1, #42433f); border-radius: 2px; z-index: -1; }
.portfolio-device--phone::before { top: 16%; left: -.7%; height: 3%; }
.portfolio-device--phone::after { top: 28%; right: -.7%; height: 12%; }
.portfolio-phone-buttons { left: -.7%; top: 23%; height: 6.5%; }
.portfolio-phone-buttons::after { content: ''; position: absolute; inset: 125% 0 auto; height: 100%; border-radius: inherit; background: inherit; }

.gallery-expand {
    position: absolute;
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    right: 1rem;
    bottom: 1rem;
    padding: .45rem .65rem;
    border-radius: 5px;
    background: #fff;
    color: #333;
    box-shadow: 0 1px 5px #00000015;
    font-size: .8rem;
}
.gallery-expand i { font-size: 1.1rem; }
.gallery-enhanced .gallery-slide:not([hidden]) { animation: work-reveal .3s ease-out both; }
@media (prefers-reduced-motion: reduce) { .gallery-enhanced .gallery-slide:not([hidden]) { animation: none; } }
.gallery-enhanced .gallery-slide { margin: 0; }
.gallery-controls { display: flex; justify-content: flex-end; align-items: center; margin-top: .65rem; }
.gallery-arrows { display: flex; gap: .25rem; flex: none; }
.gallery-icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex: none;
    border: 1px solid #dce0e5;
    background: #fff;
    color: #333;
    border-radius: 50%;
    cursor: pointer;
}
.gallery-icon-button i { font-size: 1.6rem; }
.gallery-icon-button:hover { background: #f3f4f6; }
.carousel-rotation { position: relative; border: 0; }
.carousel-countdown { position: absolute; inset: 0; display: block; width: 44px; height: 44px; color: inherit; pointer-events: none; }
.carousel-countdown svg { display: block; width: 100%; height: 100%; fill: none; transform: rotate(-90deg); }
.carousel-countdown-track { stroke: #dce0e5; stroke-width: 1; }
.carousel-countdown-progress { stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: 0; }
.carousel-countdown[data-running="false"] .carousel-countdown-progress { opacity: .35; }
.project-about { display: grid; grid-template-columns: 1.65fr 1fr; gap: 5rem; padding: 3.5rem 0 4.5rem; }
.project-about h2 { font-size: 1.45rem; color: #111; letter-spacing: -.025em; margin-bottom: .75rem; }
.project-about p { color: #60656e; line-height: 1.75; }
.project-contribution h3 { font-size: .95rem; margin: .25rem 0 1rem; color: #333; }
.project-contribution ul { list-style: none; color: #60656e; font-size: .95rem; }
.project-contribution li + li { margin-top: .65rem; }
.project-external { margin-top: 1rem; }
.project-contact { background: #f3f4f6; text-align: center; padding: 3rem 1rem; }
.project-contact h2 { font-size: 1.75rem; color: #111; letter-spacing: -.025em; }
.project-contact p { color: #60656e; margin: .5rem 0; }

/* Native dialog supplies focus containment and Escape dismissal. */
body.gallery-viewer-open { overflow: hidden; }
.gallery-dialog { width: min(1440px, calc(100vw - 2rem)); max-width: none; height: calc(100dvh - 2rem); max-height: none; padding: 1rem 1.5rem; margin: auto; background: #fff; color: #333; border: 0; border-radius: 10px; }
.gallery-dialog::backdrop { background: #111d; }
.gallery-dialog[open] { display: flex; flex-direction: column; }
.viewer-toolbar, .viewer-bottom { display: flex; align-items: center; justify-content: space-between; flex: none; gap: 1rem; min-height: 44px; }
.viewer-label { color: #60656e; font-size: .9rem; }
.viewer-image { --gallery-image-height: calc(100dvh - 12rem); display: flex; align-items: center; justify-content: center; flex: 1; min-height: 0; margin-block: 1rem; overflow: hidden; }
.viewer-caption { text-align: center; font-size: .9rem; }

@media (max-width: 900px) {
    .work-showcase { gap: 1.5rem; min-height: 350px; }
    .work-project-copy h3 { font-size: 1.8rem; }
    .work-project-copy p { font-size: .95rem; }
}

@media (max-width: 700px) {
    .selected-work { padding: 2.25rem 0 2.5rem; }
    .selected-work h2 { font-size: 2rem; margin-bottom: 1.5rem; }
    .work-showcase { grid-template-columns: 1fr; gap: 1.25rem; min-height: 0; padding-bottom: 0; }
    .work-devices { max-width: 440px; margin-inline: auto; aspect-ratio: 1.35; }
    .device-spot--laptop { width: 82%; left: 4%; top: 8%; }
    .device-spot--tablet { width: 34%; right: 12%; top: auto; bottom: 7%; }
    .device-spot--phone { width: 20%; right: 1%; top: auto; bottom: 0; }
    .work-devices--rothes .device-spot--tablet { width: 48%; right: 14%; top: auto; }
    :is(.work-devices--house-log, .work-devices--oddly-safe) .device-spot--1 { width: 29%; left: 7%; top: 10%; bottom: auto; }
    :is(.work-devices--house-log, .work-devices--oddly-safe) .device-spot--2 { width: 32%; left: 34%; top: 0; bottom: auto; }
    :is(.work-devices--house-log, .work-devices--oddly-safe) .device-spot--3 { width: 29%; right: 5%; top: 10%; bottom: auto; }
    .work-project-copy { text-align: center; min-height: 0; }
    .work-project-copy h3 { font-size: clamp(1.6rem, 7.5vw, 2rem); margin-bottom: .65rem; }
    .work-project-copy p { margin-inline: auto; min-height: 3.4em; }
    .work-project-copy .work-link { margin-top: .65rem; }
    .work-carousel-controls { justify-content: center; padding-top: 1rem; }
    .work-carousel-arrows { margin-top: 0; }
    .project-heading { padding: 1rem 0 1.25rem; }
    .project-heading h1 { font-size: clamp(1.8rem, 8vw, 2.2rem); text-wrap: balance; }
    .project-summary { font-size: 1rem; }
    .project-back { margin-top: 1rem; }
    .project-gallery { --gallery-image-height: min(54svh, 420px); }
    .gallery-stage { padding: .5rem 0 3rem; height: var(--gallery-image-height); }
    .gallery-stage .portfolio-device { width: min(94%, calc((var(--gallery-image-height) - 3.5rem) * var(--display-ratio) * .94)); }
    .gallery-stage .portfolio-device--laptop { max-width: 87%; }
    .gallery-expand { right: 0; bottom: 0; min-width: 44px; min-height: 44px; justify-content: center; }
    .gallery-expand span { display: none; }
    .gallery-controls { justify-content: center; margin-top: .5rem; }
    .project-about { grid-template-columns: 1fr; gap: 1.75rem; padding: 2rem 0 3rem; }
    .gallery-dialog { width: 100vw; height: 100dvh; border-radius: 0; padding: .75rem; }
    .viewer-image { --gallery-image-height: calc(100dvh - 11rem); }
    .viewer-caption { font-size: .8rem; }
}
