/* ── Case study layout ─────────────────────────────────────────────
   Shared long-form case study system used by fifteen, gearo, rchan,
   and any future qualifying project via src/_layouts/case-study.njk.
   Designed to match taybi.uk typography (Inter, #393939 on #EEEEE4)
   without dominating the article. */

.cs-main {
    display: flex;
    justify-content: center;
    padding: 0 1.5rem;
    /* Sit beneath the (non-sticky) site header with breathing room. */
    padding-top: 1.5rem;
}

/* ── Article wrapper: sticky sidebar + content column ───────────── */
.cs-article {
    display: grid;
    grid-template-columns: minmax(220px, 260px) 1fr;
    gap: clamp(2rem, 4vw, 3.5rem);
    max-width: 1400px;
    width: 100%;
    align-items: start;
}

/* ── Sidebar / TOC ──────────────────────────────────────────────── */
.cs-sidebar {
    position: sticky;
    top: 1.5rem;
    height: fit-content;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
    padding-right: 0.5rem;
}

.cs-toc {
    font-family: 'Inter', sans-serif;
    font-size: 0.8125rem;
    line-height: 1.6;
    color: #7e7e7e;
}

.cs-toc-header {
    font-weight: 700;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #393939;
    margin-bottom: 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 0.5px rgba(114, 114, 114, 0.14) solid;
}

.cs-toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.cs-toc-list li a {
    display: block;
    color: #7e7e7e;
    text-decoration: none;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    transition: color 0.15s ease, background-color 0.15s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cs-toc-list li a:hover {
    color: #393939;
    background-color: rgba(0, 0, 0, 0.03);
}

.cs-toc-list li a:focus-visible {
    outline: 2px solid #393939;
    outline-offset: 2px;
}

/* Active link — single-rule indicator, no layout shift */
.cs-toc-list li a.cs-toc-active {
    color: #393939;
    font-weight: 600;
    background-color: rgba(0, 0, 0, 0.04);
    border-left: 2px solid #393939;
    padding-left: calc(0.4rem - 2px);
}

/* Subsections (h3) indented under their parent h2 */
.cs-toc-list li.cs-toc-sub a {
    padding-left: 1.4rem;
    font-size: 0.78rem;
}

.cs-toc-list li.cs-toc-sub a.cs-toc-active {
    padding-left: calc(1.4rem - 2px);
}

/* Sidebar toggle (mobile only) */
.cs-sidebar-toggle {
    display: none;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: 0.5px rgba(114, 114, 114, 0.14) solid;
    border-radius: 5px;
    padding: 0.5rem 0.75rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.8125rem;
    color: #393939;
    cursor: pointer;
    margin-bottom: 0.75rem;
}

.cs-sidebar-toggle:focus-visible {
    outline: 2px solid #393939;
    outline-offset: 2px;
}

.cs-sidebar-toggle-label {
    font-weight: 600;
}

.cs-sidebar-toggle-icon {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-right: 2px solid #393939;
    border-bottom: 2px solid #393939;
    transform: rotate(45deg);
    transition: transform 0.15s ease;
}

.cs-sidebar-toggle[aria-expanded="true"] .cs-sidebar-toggle-icon {
    transform: rotate(-135deg);
}

/* ── Content wrapper ───────────────────────────────────────────── */
.cs-content-wrapper {
    min-width: 0;
    padding-bottom: 4rem;
}

/* ── Header area ───────────────────────────────────────────────── */
.cs-header {
    margin-bottom: 2.5rem;
}

.cs-title-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.cs-meta {
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    font-weight: bold;
    line-height: 13px;
    color: #7e7e7e;
    border: 0.5px rgba(114, 114, 114, 0.14) solid;
    border-radius: 5px;
    padding: 8px 10px;
    width: fit-content;
    flex: 0 0 auto;
    align-self: center;
}

.cs-title {
    font-family: 'Inter', sans-serif;
    font-size: clamp(1.75rem, 2.5vw + 0.5rem, 2.5rem);
    font-weight: 700;
    color: #393939;
    margin-top: 0.5rem;
    margin-bottom: 1rem;
    line-height: 1.25;
    margin-right: auto;
}

.cs-intro {
    font-size: clamp(1rem, 1vw + 0.25rem, 1.125rem);
    color: #393939;
    line-height: 1.7;
    /* Span the full content-column width, matching .cs-title-row. */
    max-width: none;
}

/* ── Body typography ───────────────────────────────────────────── */
.cs-body {
    font-family: 'Inter', sans-serif;
    font-size: 0.9375rem;
    line-height: 1.8;
    color: #393939;
}

/* Headings get stable anchor IDs + offset for the fixed site header */
.cs-body h2,
.cs-body h3 {
    position: relative;
    scroll-margin-top: 100px;
}

.cs-body h2 {
    font-size: 1.375rem;
    font-weight: 700;
    color: #393939;
    margin-top: 2.5rem;
    margin-bottom: 0.75rem;
    padding-top: 0.25rem;
}

.cs-body h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: #393939;
    margin-top: 1.75rem;
    margin-bottom: 0.5rem;
}

/* Hover/focus anchor link (the ¶ mark) injected by case-study.js */
.cs-anchor-link {
    position: absolute;
    left: -1.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: #7e7e7e;
    text-decoration: none;
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease;
    font-size: 0.875rem;
    padding: 0 0.25rem;
}

.cs-body h2:hover .cs-anchor-link,
.cs-body h3:hover .cs-anchor-link,
.cs-anchor-link:focus-visible {
    opacity: 1;
}

.cs-anchor-link:focus-visible {
    outline: 2px solid #393939;
    outline-offset: 2px;
}

.cs-body p {
    margin-bottom: 1rem;
}

.cs-body ul,
.cs-body ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.cs-body li {
    margin-bottom: 0.35rem;
}

.cs-body code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.875rem;
    background-color: rgba(0, 0, 0, 0.04);
    padding: 0.125rem 0.3rem;
    border-radius: 3px;
}

/* Responsive media — caps the inline widths some pages use so they
   never overflow the (narrower) content column on small screens. */
.cs-body img,
.cs-body video {
    max-width: 100%;
    height: auto;
}

.cs-body .centre {
    text-align: center;
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
}

.cs-body video.shadow,
.cs-body img.shadow {
    box-shadow: 3px 6px 24px -3px rgba(0, 0, 0, 0.137);
}

/* ── Media gallery / carousel ────────────────────────────────────
   A .cs-gallery with a single slide renders as a plain centered
   figure. With more than one slide, case-study.js upgrades it to a
   carousel (prev/next + dots + keyboard + swipe). Without JS, all
   slides stay visible stacked, so the content is never hidden. */
.cs-gallery {
    margin: 1.5rem 0 2rem;
}

.cs-gallery__viewport {
    position: relative;
}

.cs-gallery__track {
    list-style: none;
    margin: 0;
    padding: 0;
    /* No-JS fallback: slides stack vertically, all visible. */
    display: block;
}

.cs-gallery__slide {
    margin: 0 0 1rem;
}

.cs-gallery__slide:last-child {
    margin-bottom: 0;
}

.cs-gallery__slide img,
.cs-gallery__slide video {
    display: block;
    width: 100%;
    height: auto;
    max-width: 100%;
}

/* Carousel mode — activated by case-study.js when >1 slide */
.cs-gallery--carousel .cs-gallery__track {
    display: flex;
    overflow: hidden;
    transition: transform 0.3s ease;
    /* Height is set by case-study.js to match the active slide, so a
       taller sibling can't leave a gap underneath the shorter one. */
    position: relative;
}

.cs-gallery--carousel .cs-gallery__slide {
    flex: 0 0 100%;
    max-width: 100%;
    margin: 0;
    /* Stack slides in the same spot; the track height tracks the
       active slide, so off-screen slides don't stretch the box. */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
}

.cs-gallery__btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0.5px solid rgba(114, 114, 114, 0.35);
    border-radius: 0;
    background: rgba(238, 238, 228, 0.92);
    color: #393939;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}

.cs-gallery__btn:focus-visible {
    outline: 2px solid #393939;
    outline-offset: 2px;
}

.cs-gallery__prev { left: 0.5rem; }
.cs-gallery__next { right: 0.5rem; }

.cs-gallery__dots {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin: 0.75rem 0 0;
    padding: 0;
    list-style: none;
}

.cs-gallery__dot {
    width: 8px;
    height: 8px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(114, 114, 114, 0.35);
    cursor: pointer;
}

.cs-gallery__dot:focus-visible {
    outline: 2px solid #393939;
    outline-offset: 2px;
}

.cs-gallery__dot[aria-current="true"] {
    background: #393939;
}

/* ── Reduced motion ────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
    .cs-toc-list li a,
    .cs-sidebar-toggle-icon,
    .cs-anchor-link,
    .cs-gallery--carousel .cs-gallery__track {
        transition: none;
    }
}

/* ── Tablet: narrow sticky sidebar ─────────────────────────────── */
@media (max-width: 1024px) {
    .cs-article {
        grid-template-columns: minmax(180px, 200px) 1fr;
        gap: 1.5rem;
    }

    .cs-toc-header {
        font-size: 0.7rem;
    }

    .cs-toc-list li a {
        font-size: 0.78rem;
    }

    /* Anchor links are a pointer convenience; hide on touch widths. */
    .cs-body h2:hover .cs-anchor-link,
    .cs-body h3:hover .cs-anchor-link {
        opacity: 0;
    }
}

/* ── Mobile: collapsible "Contents" panel at top of article ────── */
@media (max-width: 768px) {
    .cs-main {
        padding: 0 1.25rem;
        padding-top: 1rem;
    }

    .cs-article {
        display: block;
    }

    .cs-sidebar {
        position: relative;
        top: 0;
        max-height: none;
        overflow: visible;
        margin-bottom: 1.5rem;
        /* Share the article's divider language for a tidy panel edge. */
        border-bottom: 0.5px rgba(114, 114, 114, 0.14) solid;
        padding-bottom: 1rem;
    }

    .cs-sidebar-toggle {
        display: flex;
        width: 100%;
    }

    .cs-toc {
        max-height: 0;
        overflow: hidden;
        opacity: 0;
        transition: max-height 0.2s ease, opacity 0.15s ease;
    }

    .cs-sidebar.is-open .cs-toc {
        max-height: 70vh;
        opacity: 1;
        overflow-y: auto;
    }

    .cs-body h2,
    .cs-body h3 {
        scroll-margin-top: 80px;
    }
}
