/* ─── Tokens ───────────────────────────────────────────────────────────────── */

:root {
    --bg:     #f4efe8;
    --ink:    #16120f;
    --muted:  #756b61;
    --line:   rgba(22, 18, 15, .16);
    --card:   rgba(255, 252, 247, .82);
    --radius: 28px;
    --gap:    24px;
    --serif:  Georgia, serif;
    --text-sm: clamp(12px, 1.1vw, 14px);
    --text-md: clamp(14px, 1.4vw, 16px);
    --text-lg: clamp(28px, 4vw, 56px);
}

/* ─── Reset ────────────────────────────────────────────────────────────────── */

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

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    font-family: system-ui, sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 15% 10%, rgba(181, 74, 48, .2), transparent 30vw),
        var(--bg);
}

input, textarea, button {
    font: inherit;
    color: inherit;
    cursor: pointer;
}

/* ─── Layout ───────────────────────────────────────────────────────────────── */

.app {
    position: fixed;
    inset: 28px;
}

.screen {
    height: 100%;
    display: grid;
    grid-template-columns: minmax(360px, .58fr) 1fr;
    gap: var(--gap);
}

/* ─── Cards ────────────────────────────────────────────────────────────────── */

.copy-card,
.content-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: 0 24px 70px rgba(22, 18, 15, .16);
    overflow: hidden;
}

.copy-card {
    position: relative;
    display: flex;
    flex-direction: column;
    isolation: isolate;
}

.content-card { padding: 20px }

/* ─── Copy content ─────────────────────────────────────────────────────────── */

.copy-content {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 26px 46px 24px;
    position: relative;
    z-index: 1;
}

h1 {
    font-family: var(--serif);
    font-weight: 400;
    font-size: var(--text-lg);
    line-height: .96;
    margin: 0;
    letter-spacing: -.03em;
}

.page-heading {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: clamp(6px, 2vw, 12px);
}

.home-icon-button {
    width: .96em;
    height: .96em;
    margin-top: -.02em;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--home-button-colour, var(--ink));
    font-size: var(--text-lg);
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    transition: color .18s ease, opacity .18s ease;
}

.home-icon-button svg {
    width: 100%;
    height: 100%;
    display: block;
    fill: currentColor;
    stroke: none;
}

.home-icon-button:hover {
    opacity: .78;
    filter: brightness(.95);
}

.home-icon-button:active { opacity: .52 }
.home-icon-button:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 4px;
}
.home-icon-button.is-home {
    pointer-events: none;
    opacity: .32;
}

.lede, .support {
    font-size: var(--text-md);
    color: var(--muted);
    line-height: 1.45;
}

/* ─── Desktop copy-card texture ────────────────────────────────────────────── */

@media (min-width: 761px) {
    .copy-card::before {
        content: "";
        position: absolute;
        inset: 0;
        z-index: 0;
        pointer-events: none;
        background:
            linear-gradient(rgba(22, 18, 15, .045) 1px, transparent 1px),
            linear-gradient(90deg, rgba(22, 18, 15, .045) 1px, transparent 1px),
            radial-gradient(circle at 18% 18%, rgba(181, 74, 48, .16), transparent 24%),
            radial-gradient(circle at 88% 78%, rgba(38, 58, 89, .12), transparent 28%);
        background-size: 34px 34px, 34px 34px, 100% 100%, 100% 100%;
        mask-image: linear-gradient(to bottom, transparent, #000 18%, #000 88%, transparent);
    }

    .copy-card::after {
        content: "DS";
        position: absolute;
        right: -0.08em;
        bottom: .18em;
        z-index: 0;
        pointer-events: none;
        font-family: var(--serif);
        font-size: clamp(150px, 19vw, 330px);
        line-height: .72;
        letter-spacing: -.12em;
        color: rgba(22, 18, 15, .045);
    }
}

/* ─── Content-card view states ─────────────────────────────────────────────── */

.content-card.is-home .focus-carousel,
.content-card.is-home .contact-form { display: none }

.content-card.is-gallery .category-grid,
.content-card.is-gallery .contact-form { display: none }

.content-card.is-contact .category-grid,
.content-card.is-contact .focus-carousel { display: none }

/* ─── Category grid ────────────────────────────────────────────────────────── */

.category-grid {
    height: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 12px;
    min-height: 0;
}

.category-tile {
    display: grid;
    grid-template-rows: minmax(0, 1fr) 36px;
    min-height: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    border-radius: 22px;
    overflow: hidden;
    background: var(--tile-colour, #333);
    color: #fff;
    text-align: left;
}

.category-tile img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    grid-row: 1;
}

.category-tile strong {
    grid-row: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    align-items: center;
    padding: 4px 14px;
    background: var(--tile-colour, #333);
    color: #fff;
    font-family: var(--serif);
    font-size: clamp(15px, 1.8vw + 0.4vh, 22px);
    font-weight: 400;
    line-height: 1.15;
    letter-spacing: -0.01em;
}

@media (max-width: 980px) {
    .category-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-rows: repeat(3, minmax(0, 1fr));
    }
    .category-tile { grid-template-rows: minmax(0, 1fr) 30px }
    .category-tile strong { font-size: clamp(15px, 1.4vw + 0.45rem, 22px) }
}

/* ─── Focus carousel ───────────────────────────────────────────────────────── */

.focus-carousel {
    position: relative;
    height: 100%;
}

.image-track {
    height: 100%;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 100%;
    overflow-x: scroll;
    overflow-y: hidden;
    border-radius: 22px;
    touch-action: pan-y;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;          /* Firefox */
    -webkit-overflow-scrolling: touch;
}

.image-track::-webkit-scrollbar { display: none }

.image-item {
    position: relative;
    border: 0;
    padding: 0;
    background: #fff;
    opacity: .2;
    min-height: 0;
    transition: opacity .2s;
    scroll-snap-align: start;
}

.image-item.is-active { opacity: 1 }

.image-item img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ─── Image caption ────────────────────────────────────────────────────────── */

.image-caption-single {
    position: absolute;
    left: clamp(8px, 1.2vw, 14px);
    right: clamp(8px, 1.2vw, 14px);
    bottom: clamp(8px, 1.2vw, 14px);
    padding: clamp(8px, 1vw, 12px) clamp(10px, 1.2vw, 16px);
    border-radius: 16px;
    color: var(--ink);
    background: var(--card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--line);
    font-size: var(--text-sm);
    line-height: 1.3;
    overflow: hidden;
    scrollbar-width: none;
}

.image-caption-single::-webkit-scrollbar { display: none }

.image-caption-single strong {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-family: var(--serif);
    font-size: var(--text-md);
    font-weight: 400;
    line-height: 1.15;
}

.empty-gallery {
    height: 100%;
    display: grid;
    place-items: center;
    text-align: center;
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 22px;
}

/* ─── Image arrows (carousel + lightbox shared style) ──────────────────────── */

.image-arrow,
.lightbox-arrow {
    position: absolute;
    z-index: 3;
    top: 50%;
    translate: 0 -50%;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.lightbox-arrow {
    transition: filter .15s, transform .15s;
}

.image-arrow {
    background: var(--ink);
    color: #fff;
}

.lightbox-arrow {
    background: var(--ink);
    color: #fff;
}

.image-arrow svg,
.lightbox-arrow svg {
    width: 18px;
    height: 18px;
    display: block;
}

.image-arrow-left,  .lightbox-arrow-left  { left: 12px }
.image-arrow-right, .lightbox-arrow-right { right: 12px }

.lightbox-arrow:hover { filter: brightness(1.18) }

.image-arrow:hover,
.image-arrow:active {
    filter: none;
    transform: none;
}

/* ─── Contact form ─────────────────────────────────────────────────────────── */

.contact-form {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 14px;
    padding: 24px;
}

.contact-form label,
.contact-form input,
.contact-form textarea,
.contact-form button { max-width: 100% }

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
}

input, textarea {
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 12px;
    background: #fffaf4;
}

.contact-form textarea {
    min-height: clamp(110px, 24vh, 180px);
}

.hidden-field {
    position: absolute;
    left: -9999px;
}

.submit-button {
    border: 0;
    border-radius: 999px;
    padding: 12px 18px;
    align-self: flex-start;
    background: var(--ink);
    color: #fff;
    font-family: var(--serif);
}

.submit-button:hover { filter: brightness(1.1) }

/* ─── Inline contact link ──────────────────────────────────────────────────── */

.contact-inline-wrapper { margin-top: 18px }

.contact-inline {
    font-family: var(--serif);
    font-size: var(--text-md);
    color: var(--ink);
    text-decoration: none;
    border-bottom: 1px solid var(--line);
    padding-bottom: 2px;
}

.contact-inline:hover { border-color: var(--ink) }

/* ─── Lightbox ─────────────────────────────────────────────────────────────── */

.lightbox {
    width: min(1180px, calc(100vw - 28px));
    height: min(820px, calc(100vh - 28px));
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    background: #111;
    color: #fff;
    overflow: hidden;
    touch-action: pan-y;
}

.lightbox::backdrop { background: rgba(0, 0, 0, .7) }

.lightbox figure {
    margin: 0;
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.lightbox img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.lightbox figcaption {
    position: absolute;
    left: 14px;
    bottom: 14px;
    padding: 12px;
    border-radius: 18px;
    background: rgba(0, 0, 0, .55);
    overflow: hidden;
    scrollbar-width: none;
    max-width: min(680px, calc(100% - 28px));
}

.lightbox figcaption::-webkit-scrollbar { display: none }

.lightbox figcaption strong {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-family: var(--serif);
    font-size: var(--text-md);
    font-weight: 400;
    line-height: 1.15;
}

.lightbox figcaption p { display: none }

/* Close button */
.close {
    position: absolute;
    z-index: 5;
    top: 12px;
    right: 12px;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 252, 247, .92);
    color: var(--ink);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: filter .15s, transform .15s;
}

.close svg { width: 18px; height: 18px; display: block }

.close:hover { filter: brightness(.88) }
.close:active { transform: scale(.92) }

/* ─── Mobile portrait ──────────────────────────────────────────────────────── */

@media (max-width: 760px) and (min-height: 501px) {
    .app {
        position: fixed !important;
        inset: 12px;
        min-height: 0;
        height: auto;
        padding: 0;
    }

    .screen {
        position: absolute;
        inset: 0;
        height: 100%;
        min-height: 0;
        display: grid;
        grid-template-columns: 1fr;
        /* Description + category nav: 50% of portrait/mobile viewport; content: remaining 50%. */
        grid-template-rows: minmax(0, 50%) minmax(0, 1fr);
        gap: 12px;
    }

    .copy-card {
        height: 100%;
        min-height: 0;
        max-height: none;
        padding: 10px 10px 0;
    }

    .copy-content {
        padding: 16px 16px 2px;
        background:
            linear-gradient(#fffcf7 30%, #fffcf700) top,
            linear-gradient(#fffcf700, #fffcf7 70%) bottom,
            radial-gradient(farthest-side at 50% 0,   rgba(22,18,15,.24), transparent) top,
            radial-gradient(farthest-side at 50% 100%, rgba(22,18,15,.24), transparent) bottom;
        background-repeat: no-repeat;
        background-size: 100% 34px, 100% 34px, 100% 14px, 100% 14px;
        background-attachment: local, local, scroll, scroll;
    }

    .content-card {
        min-height: 0;
        height: auto;
        overflow: hidden;
        padding: 12px;
    }

    .category-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-rows: repeat(3, minmax(0, 1fr));
    }

    .category-tile { grid-template-rows: minmax(0, 1fr) 26px }

    .category-tile strong {
        font-size: clamp(14px, 2.2vw + 0.35rem, 18px);
    }

    .category-grid,
    .focus-carousel,
    .image-track {
        min-height: 0;
        height: 100%;
    }

    .page-heading { gap: 12px; }
    .home-icon-button { width: .9em; height: .9em; }

    #closeLightbox { width: 38px; height: 38px }
}

/* ─── Landscape mobile ─────────────────────────────────────────────────────── */

@media (max-height: 500px) and (max-width: 1024px) {
    html, body { height: 100%; overflow: hidden }

    .app {
        position: fixed !important;
        inset: 10px !important;
        height: auto !important;
        padding: 0 !important;
    }

    .screen {
        position: absolute !important;
        inset: 0 !important;
        height: 100% !important;
        display: grid !important;
        grid-template-columns: minmax(220px, .48fr) 1fr !important;
        grid-template-rows: 1fr !important;
        gap: 10px !important;
    }

    .copy-card {
        max-height: none !important;
        height: 100% !important;
    }

    .copy-content { padding: 14px 16px 8px !important }

    .content-card { height: 100% !important; overflow: hidden !important }

    .category-grid { grid-template-columns: repeat(3, 1fr) !important }

    .category-grid, .focus-carousel, .image-track { height: 100% !important }

    h1 { font-size: clamp(22px, 4vw, 42px) }
}

/* ─── Contact page scroll unlock (mobile) ──────────────────────────────────── */

@media (max-width: 760px) {
    body:has(.content-card.is-contact) {
        height: auto !important;
        min-height: 100%;
        overflow-x: hidden;
        overflow-y: auto;
        padding-bottom: calc(82px + env(safe-area-inset-bottom));
    }

    body:has(.content-card.is-contact) .app {
        position: relative !important;
        inset: auto;
        min-height: calc(100dvh - 82px);
        padding: 12px;
    }

    body:has(.content-card.is-contact) .screen {
        position: relative !important;
        inset: auto;
        height: auto;
        min-height: 0;
        grid-template-rows: auto auto;
    }

    body:has(.content-card.is-contact) .copy-card {
        max-height: none;
        overflow: visible;
    }

    body:has(.content-card.is-contact) .content-card.is-contact {
        height: auto;
        max-height: none;
        overflow: visible;
    }

    .content-card.is-contact .contact-form {
        display: flex !important;
        height: auto;
        min-height: 0;
        max-height: none;
        overflow: visible;
        justify-content: flex-start;
        padding: 8px;
        gap: 10px;
    }

    .content-card.is-contact input,
    .content-card.is-contact textarea { width: 100%; min-width: 0 }

    .content-card.is-contact textarea { min-height: 120px; max-height: 220px }

    .content-card.is-contact .submit-button { width: 100%; text-align: center }

    /* :has() fallback */
    body.contact-scroll {
        height: auto !important;
        min-height: 100%;
        overflow-y: auto;
        padding-bottom: calc(82px + env(safe-area-inset-bottom));
    }
}

@media (max-width: 430px), (max-height: 680px) {
    .content-card.is-contact .contact-form { padding: 4px }
    .content-card.is-contact textarea { min-height: 96px }
}

@media (max-height: 720px) {
    .image-caption-single { padding: 8px 12px }
    .lightbox figcaption { left: 10px; right: 10px; bottom: 10px; max-width: calc(100% - 20px) }
}

/* ─── Compact landscape / small viewport fix ─────────────────────────────────
   At 980 × 500 and below, tighten the layout so the home category tiles fit
   without leaving a large unused gap. This intentionally appears late in the
   file so it wins over the broader max-height:500 / max-width:1024 rules. */
@media (max-width: 980px) and (max-height: 500px) {
    .app {
        inset: 6px !important;
    }

    .screen {
        grid-template-columns: minmax(200px, 40%) minmax(0, 1fr) !important;
        gap: 6px !important;
    }

    .copy-card,
    .content-card {
        border-radius: 18px !important;
    }

    .copy-card {
        height: 100% !important;
        min-height: 0 !important;
    }

    .copy-content {
        padding: 10px 12px 6px !important;
    }

    h1 {
        font-size: clamp(20px, 3.5vw, 34px) !important;
        line-height: .94 !important;
    }

    .lede,
    .support {
        font-size: clamp(12px, 1.5vw, 14px) !important;
        line-height: 1.32 !important;
    }

    .content-card {
        height: 100% !important;
        min-height: 0 !important;
        padding: 6px !important;
        overflow: hidden !important;
    }

    .category-grid {
        height: 100% !important;
        min-height: 0 !important;
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        grid-template-rows: repeat(2, minmax(0, 1fr)) !important;
        gap: 6px !important;
    }

    .category-tile {
        min-height: 0 !important;
        border-radius: 14px !important;
        grid-template-rows: minmax(0, 1fr) 24px !important;
    }

    .category-tile strong {
        min-height: 0 !important;
        padding: 3px 9px !important;
        font-size: clamp(12px, 1.6vw, 15px) !important;
        line-height: 1.05 !important;
        -webkit-line-clamp: 1 !important;
        line-clamp: 1 !important;
    }
}

/* ─── Simple centred category nav ──────────────────────────────────────────── */

:root {
    --nav-button-width: 100px;
    --nav-button-height: 38px;
    --nav-button-gap: 10px;
    --nav-arrow-size: 40px;
}

/*
   The nav has three stable columns:
   previous arrow / centred category viewport / next arrow.
*/
.copy-nav {
    flex: 0 0 auto !important;
    position: relative !important;
    z-index: 1 !important;

    display: grid !important;
    grid-template-columns: var(--nav-arrow-size) minmax(0, 1fr) var(--nav-arrow-size) !important;
    align-items: center !important;
    gap: 8px !important;

    padding: 6px 12px 6px !important;
    border-top: 1px solid var(--line) !important;
    border-radius: 0 0 var(--radius) var(--radius) !important;

    background: rgba(255, 252, 247, .95) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
}

/* Stable previous/next controls. */
.nav-arrow-button {
    width: var(--nav-arrow-size) !important;
    height: var(--nav-arrow-size) !important;
    min-width: var(--nav-arrow-size) !important;
    min-height: var(--nav-arrow-size) !important;

    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;

    padding: 0 !important;
    border: 0 !important;
    border-radius: 999px !important;

    background: var(--ink) !important;
    color: #fff !important;

    transition: filter .15s ease, transform .15s ease !important;
}

.nav-arrow-button svg {
    width: 18px !important;
    height: 18px !important;
    display: block !important;

    fill: none !important;
    stroke: currentColor !important;
    stroke-width: 2.2 !important;
    stroke-linecap: round !important;
    stroke-linejoin: round !important;
}

.nav-arrow-button:hover {
    filter: brightness(1.18) !important;
}

.nav-arrow-button:active {
    transform: scale(.94) !important;
}

.nav-arrow-button:focus-visible {
    outline: 2px solid var(--ink) !important;
    outline-offset: 3px !important;
}

/*
   This viewport is the only responsive part.
   JS calculates how many fixed-width buttons fit inside this space.
*/
.nav-category-list {
    min-width: 0 !important;
    width: 100% !important;
    height: calc(var(--nav-button-height) + 8px) !important;

    display: flex !important;
    align-items: center !important;
    justify-content: center !important;

    overflow: hidden !important;

    mask-image: none !important;
    -webkit-mask-image: none !important;
}

/*
   Track width is based on the number of visible buttons.
   The active item is always rendered in the centre slot by JS.
*/
.nav-category-track {
    width: max-content !important;
    height: 100% !important;

    display: grid !important;
    grid-template-columns: repeat(
        var(--nav-visible-count, 1),
        var(--nav-button-width)
    ) !important;
    gap: var(--nav-button-gap) !important;

    align-items: center !important;
    justify-content: center !important;

    padding: 0 !important;
    margin: 0 auto !important;
}

/*
   Fixed-width category buttons.
   Active/inactive states never change layout dimensions.
*/
.nav-category-button,
.nav-category-track > .nav-category-button,
.nav-category-button.is-active,
.nav-category-button[aria-current="page"] {
    position: relative !important;

    width: var(--nav-button-width) !important;
    min-width: var(--nav-button-width) !important;
    max-width: var(--nav-button-width) !important;

    height: var(--nav-button-height) !important;
    min-height: var(--nav-button-height) !important;
    max-height: var(--nav-button-height) !important;

    display: flex !important;
    align-items: center !important;
    justify-content: center !important;

    padding: 4px 10px !important;
    border: 0 !important;
    border-radius: 999px !important;

    background: var(--nav-colour, #333) !important;
    color: #fff !important;

    font-family: var(--serif) !important;
    font-size: 13px !important;
    font-weight: 400 !important;
    line-height: 1.05 !important;
    text-align: center !important;

    white-space: normal !important;
    overflow: hidden !important;

    opacity: .55 !important;
    transform: none !important;

    transition:
        opacity .15s ease,
        box-shadow .15s ease,
        filter .15s ease !important;
}

.nav-category-button:hover {
    opacity: .85 !important;
    filter: brightness(1.05) !important;
}

.nav-category-button.is-active,
.nav-category-button[aria-current="page"] {
    opacity: 1 !important;
    filter: none !important;

    /*
       Highlight without changing the button size.
       No scaling, no padding changes, no layout shift.
    */
    box-shadow:
        0 0 0 2px rgba(255, 255, 255, .95) inset,
        0 0 0 2px var(--nav-colour, #333),
        0 8px 18px rgba(22, 18, 15, .18) !important;
}

.nav-category-button::after {
    content: "" !important;
    position: absolute !important;

    left: 18px !important;
    right: 18px !important;
    bottom: 6px !important;

    height: 2px !important;
    border-radius: 999px !important;

    background: rgba(255, 255, 255, .95) !important;

    opacity: 0 !important;
    transform: none !important;
    transition: opacity .15s ease !important;
}

.nav-category-button.is-active::after,
.nav-category-button[aria-current="page"]::after {
    opacity: 1 !important;
}

.nav-category-button:focus-visible {
    outline: 2px solid var(--ink) !important;
    outline-offset: 3px !important;
}

@media (prefers-reduced-motion: reduce) {
    .nav-arrow-button,
    .nav-category-button,
    .nav-category-button::after {
        transition: none !important;
    }
}

.nav-category-list {
    touch-action: pan-y !important;
}
