/* Case study reading page. Shares tokens, header, footer and buttons with index.css. */

.case-study-body {
    background: var(--color-black);
}

/* The homepage overlay is shaped around the Three.js scene. Reading pages get a calmer wash. */
.case-study-body::before {
    background:
        radial-gradient(120% 62% at 50% -8%, rgba(255, 255, 255, 0.05) 0%, rgba(2, 2, 2, 0) 62%),
        linear-gradient(180deg, rgba(2, 2, 2, 0) 0%, rgba(2, 2, 2, 0.45) 70%, rgba(2, 2, 2, 0.86) 100%);
}

/* The untangling spaghetti rail that runs down the page margin. */
#rail-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: var(--z-canvas);
    pointer-events: none;
}

/* Keeps the rope from competing with the prose it sits beside. */
.has-rail #rail-canvas {
    opacity: 0.9;
    -webkit-mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, #000 12%, #000 88%, rgba(0, 0, 0, 0) 100%);
    mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, #000 12%, #000 88%, rgba(0, 0, 0, 0) 100%);
}

/* Reserve the margin the rope occupies so no line of text can ever run beneath
   it. Logical padding so RTL mirrors the gutter along with the rail. */
.has-rail .case-study {
    padding-inline-end: clamp(320px, 25vw, 440px);
}

/* The rail only initialises at this width; see RAIL_MIN_WIDTH in case-study.js. */
@media (max-width: 1199px) {
    #rail-canvas {
        display: none;
    }
}

.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    z-index: calc(var(--z-header) + 1);
    background: rgba(255, 255, 255, 0.06);
}

.reading-progress span {
    display: block;
    height: 100%;
    background: var(--color-text);
    transform: scaleX(0);
    transform-origin: left;
}

body[data-language="ar"] .reading-progress span {
    transform-origin: right;
}

/* The rail is a background element; page furniture has to sit on top of it. */
.case-study-body .site-footer {
    position: relative;
    z-index: var(--z-content);
    background: var(--color-black);
}

.case-study,
.cs-missing {
    position: relative;
    z-index: var(--z-content);
    width: min(100%, var(--max-page));
    margin: 0 auto;
    padding: calc(var(--header-height) + 72px) clamp(20px, 4vw, 48px) 0;
}

/* ---------- Hero ---------- */

.cs-hero {
    padding-bottom: clamp(64px, 9vw, 128px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.cs-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 44px;
    color: var(--color-soft);
    font-size: 0.78rem;
    font-weight: 650;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-decoration: none;
    transition: color 180ms ease;
}

.cs-back::before {
    content: "\2190";
}

body[data-language="ar"] .cs-back::before {
    content: "\2192";
}

.cs-back:hover {
    color: var(--color-text);
}

/* Fixed box, contained: every client logo occupies the same slot whatever its aspect ratio.
   Flattened to a grey mark so mixed brand colours stay legible on the dark page. */
.cs-hero__logo {
    display: block;
    width: 160px;
    height: 40px;
    margin: 0 0 24px;
    object-fit: contain;
    object-position: left center;
    filter: grayscale(1) brightness(1.9);
    opacity: 0.9;
}

body[data-language="ar"] .cs-hero__logo {
    object-position: right center;
    margin-inline: auto 0;
}

.cs-hero__client {
    margin: 0 0 20px;
    color: var(--color-text);
    font-size: 0.78rem;
    font-weight: 720;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

body[data-language="ar"] .cs-hero__client {
    letter-spacing: 0.04em;
}

.cs-hero__title {
    max-width: 15ch;
    margin: 0 0 32px;
    font-size: clamp(2.6rem, 6.4vw, 5.2rem);
    font-weight: 520;
    line-height: 0.98;
    letter-spacing: -0.01em;
}

.cs-hero__summary {
    max-width: 58ch;
    margin: 0 0 52px;
    color: rgba(245, 245, 242, 0.72);
    font-size: clamp(1.05rem, 1.5vw, 1.32rem);
    line-height: 1.6;
}

/* dt/dd pairs read as vertical stacks sitting side by side. */
.cs-hero__meta {
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: auto auto;
    justify-content: start;
    gap: 0 clamp(32px, 5vw, 72px);
    margin: 0;
}

.cs-hero__meta dt {
    margin-bottom: 6px;
    color: var(--color-soft);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.cs-hero__meta dd {
    margin: 0;
    color: var(--color-text);
    font-size: 1rem;
    font-weight: 560;
}

.cs-hero__cover {
    margin: clamp(48px, 7vw, 88px) 0 0;
}

.cs-hero__cover img {
    display: block;
    width: 100%;
    height: auto;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
}

/* ---------- Metrics ---------- */

.cs-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: clamp(24px, 4vw, 56px);
    padding: clamp(48px, 6vw, 76px) 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.cs-metric {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cs-metric__value {
    color: var(--color-text);
    font-size: clamp(2.4rem, 4.4vw, 3.6rem);
    font-weight: 500;
    line-height: 0.95;
    letter-spacing: -0.01em;
}

.cs-metric__label {
    max-width: 24ch;
    color: rgba(245, 245, 242, 0.6);
    font-size: 0.86rem;
    line-height: 1.45;
}

/* ---------- Chapters ---------- */

.cs-chapters {
    display: grid;
    gap: clamp(72px, 11vw, 168px);
    padding: clamp(72px, 10vw, 152px) 0;
}

.cs-chapter {
    display: grid;
    grid-template-columns: minmax(140px, 200px) minmax(0, 1fr);
    gap: clamp(28px, 5vw, 88px);
    align-items: start;
}

.cs-chapter__aside {
    position: sticky;
    top: calc(var(--header-height) + 40px);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cs-chapter__number {
    color: rgba(245, 245, 242, 0.3);
    font-size: 0.72rem;
    font-weight: 720;
    letter-spacing: 0.14em;
}

.cs-chapter__label {
    color: var(--color-soft);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    line-height: 1.4;
}

body[data-language="ar"] .cs-chapter__label,
body[data-language="ar"] .cs-chapter__number {
    letter-spacing: 0.04em;
}

.cs-chapter__body h2 {
    max-width: 20ch;
    margin: 0 0 28px;
    font-size: clamp(1.7rem, 3vw, 2.6rem);
    font-weight: 540;
    line-height: 1.08;
}

.cs-chapter__body p {
    max-width: 62ch;
    margin: 0 0 22px;
    color: rgba(245, 245, 242, 0.74);
    font-size: clamp(1rem, 1.2vw, 1.12rem);
    line-height: 1.72;
}

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

/* Titled points: used where a chapter is a set of problems or components rather than prose. */
.cs-points {
    max-width: 62ch;
    margin: 0 0 22px;
    padding: 0;
    list-style: none;
}

.cs-point {
    padding: 22px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.cs-point:last-child {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.cs-point__title {
    margin: 0 0 10px;
    color: var(--color-text);
    font-size: clamp(1.02rem, 1.3vw, 1.16rem);
    font-weight: 640;
    line-height: 1.34;
}

.cs-chapter__body .cs-point p {
    margin: 0;
}

.cs-figure {
    margin: clamp(36px, 5vw, 56px) 0 0;
}

.cs-figure img {
    display: block;
    width: 100%;
    height: auto;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
}

.cs-figure figcaption {
    margin-top: 14px;
    color: var(--color-soft);
    font-size: 0.82rem;
    line-height: 1.5;
}

/* ---------- Quote ---------- */

.cs-quote {
    margin: 0;
    padding: clamp(56px, 8vw, 104px) 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.cs-quote blockquote {
    max-width: 26ch;
    margin: 0 0 26px;
    color: var(--color-text);
    font-size: clamp(1.6rem, 3.4vw, 2.9rem);
    font-weight: 500;
    line-height: 1.16;
    letter-spacing: -0.005em;
}

.cs-quote blockquote::before {
    content: "\201C";
}

.cs-quote blockquote::after {
    content: "\201D";
}

.cs-quote figcaption {
    color: var(--color-soft);
    font-size: 0.8rem;
    font-weight: 650;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* ---------- Stack ---------- */

.cs-stack {
    padding: clamp(56px, 7vw, 92px) 0;
}

.cs-stack__label {
    margin: 0 0 24px;
    color: var(--color-soft);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.cs-stack__list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.cs-stack__list li {
    padding: 8px 16px;
    color: rgba(245, 245, 242, 0.78);
    font-size: 0.84rem;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 999px;
}

/* ---------- Next ---------- */

.cs-next {
    display: grid;
    gap: 10px;
    padding: clamp(40px, 5vw, 64px) clamp(28px, 4vw, 48px);
    text-decoration: none;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    /* Near-opaque so the rail reads behind it rather than through the text. */
    background: rgba(8, 8, 9, 0.92);
    backdrop-filter: blur(6px);
    transition: border-color 220ms var(--ease-out), background 220ms var(--ease-out);
}

.cs-next:hover {
    border-color: rgba(255, 255, 255, 0.18);
    background: rgba(14, 14, 15, 0.95);
}

.cs-next__label {
    color: var(--color-soft);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.cs-next__client {
    color: var(--color-text);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.cs-next__title {
    max-width: 28ch;
    color: rgba(245, 245, 242, 0.78);
    font-size: clamp(1.3rem, 2.2vw, 1.9rem);
    font-weight: 540;
    line-height: 1.2;
}

/* ---------- Closing CTA ---------- */

.cs-cta {
    padding: clamp(72px, 10vw, 136px) 0 clamp(80px, 10vw, 140px);
}

.cs-cta h2 {
    max-width: 18ch;
    margin: 0 0 18px;
    font-size: clamp(2rem, 4vw, 3.4rem);
    font-weight: 520;
    line-height: 1.04;
}

.cs-cta p {
    max-width: 54ch;
    margin: 0;
    color: rgba(245, 245, 242, 0.72);
    font-size: 1.1rem;
    line-height: 1.58;
}

.cs-cta .button {
    min-height: 48px;
    padding: 0 26px;
}

/* ---------- Missing ---------- */

.cs-missing {
    min-height: 62vh;
    padding-bottom: 96px;
}

.cs-missing h1 {
    font-size: clamp(2rem, 4vw, 3.2rem);
    line-height: 1.05;
}

.cs-missing p {
    margin-bottom: 32px;
    color: var(--color-muted);
    font-size: 1.05rem;
}

.cs-missing .button {
    min-height: 46px;
}

/* ---------- Reveal ---------- */

.reveal {
    opacity: 0;
    transform: translateY(26px);
    transition: opacity 900ms var(--ease-out), transform 900ms var(--ease-out);
}

.reveal.is-visible {
    opacity: 1;
    transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
    .reveal {
        opacity: 1;
        transform: none;
        transition: none;
    }

    .cs-next {
        transition: none;
    }
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
    .cs-chapter {
        grid-template-columns: minmax(0, 1fr);
        gap: 18px;
    }

    .cs-chapter__aside {
        position: static;
        flex-direction: row;
        align-items: baseline;
        gap: 12px;
    }
}

@media (max-width: 720px) {
    .case-study,
    .cs-missing {
        padding-top: calc(var(--header-height) + 44px);
    }

    .cs-hero__meta {
        grid-auto-flow: row;
        grid-template-rows: none;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 22px 24px;
    }

    .cs-hero__meta dt {
        margin-bottom: 4px;
    }

    .cs-hero__title,
    .cs-chapter__body h2,
    .cs-quote blockquote,
    .cs-cta h2 {
        max-width: none;
    }
}
