/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Theme palette — day (default). Night mode overrides these below. */
:root {
    --bg: #FFF4ED;            /* Light cream background from Figma */
    --text: #2C2D20;          /* Primary text */
    --text-strong: rgba(44, 45, 32, 0.88);
    --text-body: #6B6C5E;     /* Case study body copy */
    --text-muted: #8A8B7C;
    --text-faint: #A3A497;    /* Captions, metadata */
    --text-subtle: rgba(0, 0, 0, 0.47);
    --accent: #725F51;        /* Brown from Figma */
    --surface: rgba(44, 45, 32, 0.05); /* Figure plate */
    --rule: rgba(44, 45, 32, 0.14);    /* Hairline dividers */
    --mark: #000000;          /* Logo circle + custom cursor dot */
    --hover-miyi: #f1a1a1;
}

/* Night mode (the default) — near-black ground with a pale chartreuse cream.
   Every text tier is that same cream, stepped down in opacity to keep hierarchy. */
:root[data-theme="dark"] {
    --bg: #111310;
    --text: #E8E8C8;
    --text-strong: rgba(232, 232, 200, 0.88);
    --text-body: rgba(232, 232, 200, 0.72);
    --text-muted: rgba(232, 232, 200, 0.62);
    --text-faint: rgba(232, 232, 200, 0.5);
    --text-subtle: rgba(232, 232, 200, 0.5);
    --accent: rgba(232, 232, 200, 0.62);
    --surface: rgba(232, 232, 200, 0.06);
    --rule: rgba(232, 232, 200, 0.16);
    --mark: #E8E8C8;
    --hover-miyi: #4A3132;
}

body {
    font-family: 'Geist', 'Geist Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    cursor: none; /* Hide default cursor */
    transition: background-color 1s ease; /* Smooth background color transition */
}

/* Full-bleed background video. Sits above the body background (negative z-index)
   but below all page content, so text and the carousel stay on top. */
.bg-video {
    position: fixed;
    inset: 0;
    z-index: -1;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.6s ease;
}

.bg-video.is-visible {
    opacity: 1;
}

.bg-video video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Scrim in the current theme colour — keeps the hero and nav legible over the footage */
.bg-video::after {
    content: '';
    position: absolute;
    inset: 0;
    background-color: var(--bg);
    opacity: 0.45;
}

/* Custom Cursor */
.custom-cursor {
    width: 21px;
    height: 21px;
    border-radius: 50%;
    background-color: var(--mark);
    position: fixed;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 10000;
    transform: translate(-50%, -50%);
    transition: transform 0.3s ease, width 0.3s ease, height 0.3s ease;
    display: flex;
    align-items: center;
}

/* Drag label styles from Figma JSON */
.cursor-label {
    position: absolute;
    left: 24px; /* Offset it to the right of the dot */
    width: 154px;
    height: 50px;
    background-color: rgb(17, 34, 143); /* Converted from JSON float values */
    color: #FFFFFF;
    font-family: 'Geist', 'Geist Sans', sans-serif;
    font-size: 22px;
    text-transform: lowercase; /* "drag to engage" */
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    opacity: 0; /* Hidden by default */
    transition: opacity 0.3s ease, width 0.3s ease;
}

/* State to show the label */
.custom-cursor.is-hovering-carousel .cursor-label {
    opacity: 1;
}

/* Reduced width when showing "view" */
.cursor-label.is-view {
    width: 77px; /* 50% of 154px */
}

/* Held by the header mark's magnet — the dot swells to read as landed on it,
   which is also the point from which a click is guaranteed to hit */
.custom-cursor.is-magnet {
    transform: translate(-50%, -50%) scale(1.35);
}

/* Visual feedback when holding/dragging */
.custom-cursor.is-dragging {
    transform: translate(-50%, -50%) scale(0.85) !important; /* Shrink slightly to mimic pressure */
}

/* Hide cursor on touch devices */
@media (hover: none) {
    body {
        cursor: auto;
    }
    
    .custom-cursor {
        display: none;
    }
}

/* Navigation */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 87px;
    background: transparent;
    z-index: 1000;
}

.nav-container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 64px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Home logo — SVG circle in navbar */
.nav-logo {
    display: flex;
    align-items: center;
    cursor: none;
    flex-shrink: 0;
    color: var(--mark); /* The circle is fill="currentColor" */
}

.nav-logo circle {
    transition: transform 0.3s ease;
    transform-origin: center;
    transform-box: fill-box;
}

@keyframes logo-pulse {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.45); }
    100% { transform: scale(1); }
}

.nav-logo:hover circle {
    animation: logo-pulse 0.8s ease-in-out infinite;
}

/* Right-hand nav group — links plus the theme toggle */
.nav-right {
    display: flex;
    align-items: center;
    gap: 40px;
}

.nav-links {
    display: flex;
    gap: 115px; /* Spacing from Figma */
    align-items: center;
}

.nav-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 20px;
    font-weight: 400;
    transition: color 0.3s ease;
    cursor: none;
}

.nav-link:hover {
    color: var(--text);
}

/* Night mode toggle */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--accent);
    cursor: none;
    transition: color 0.3s ease;
    flex-shrink: 0;
    font: inherit;
}

.theme-toggle:hover {
    color: var(--text);
}

.theme-toggle svg {
    display: block;
    width: 20px;
    height: 20px;
}

/* Show the icon for the theme you'd switch *to* */
.theme-toggle .icon-moon {
    display: block;
}

.theme-toggle .icon-sun {
    display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
    display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
    display: block;
}

/* Main content */
.main-content {
    margin-top: 87px; /* Account for fixed navbar */
    padding: 0 64px;
    max-width: 1440px;
    margin-left: auto;
    margin-right: auto;
}

/* Hero section (now within projects) */
.hero-title {
    font-size: 22px;
    font-weight: 400;
    line-height: 1.2;
    color: var(--text-strong);
    max-width: 1041px;
    margin-bottom: 20px;
}

.hero-subtitle {
    font-size: 18px;
    font-weight: 400;
    color: var(--text-subtle);
    max-width: 495px;
    margin-bottom: 0px;
}

/* Projects section */

/* Project Page Styles — wide case study.
   Header pairs a large title with a right-hand facts cluster; body sections run
   two-up (label left, prose right); figures are large rounded plates. */
.case-study {
    --cs-gap: 40px;
    max-width: 1350px;
    margin: 0 auto;
    padding: 64px 0 120px;
}

/* Header — title left, project facts right, divider beneath */
.cs-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 64px;
    padding-bottom: 40px;
    border-bottom: 1px solid var(--rule);
}

.cs-header h1 {
    font-size: 56px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.1;
    letter-spacing: -0.02em;
    margin: 0;
}

.cs-facts {
    display: flex;
    gap: 48px;
    flex-shrink: 0;
    margin: 6px 0 0;
}

.cs-facts dt {
    font-size: 14px;
    font-weight: 400;
    color: var(--text-faint);
    line-height: 1.4;
    margin-bottom: 6px;
}

.cs-facts dd {
    font-size: 18px;
    font-weight: 400;
    color: var(--text);
    line-height: 1.4;
    margin: 0;
    max-width: 220px;
}

/* Body sections — heading in the left column, copy in the right */
.cs-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--cs-gap);
    margin: 100px 0;
}

.cs-section h2 {
    font-size: 24px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.3;
    margin: 0;
}

.cs-body p {
    font-size: 18px;
    font-weight: 400;
    color: var(--text);
    line-height: 1.55;
    margin: 0 0 20px;
}

.cs-body ul {
    margin: 0 0 20px;
    padding-left: 20px;
}

.cs-body li {
    font-size: 18px;
    font-weight: 400;
    color: var(--text);
    line-height: 1.55;
    margin-bottom: 10px;
}

.cs-body > *:last-child,
.cs-body li:last-child {
    margin-bottom: 0;
}

.cs-body strong {
    font-weight: 500;
}

/* Figures — large rounded plates */
.cs-figure {
    margin: 100px 0;
}

.cs-figure-media {
    border-radius: 16px;
    overflow: hidden;
    background: var(--surface);
}

.cs-figure img {
    display: block;
    width: 100%;
    height: auto;
    -webkit-user-drag: none;
    user-select: none;
}

/* Mobile screenshots are ~1:4, so cap them to phone width rather than filling the plate */
.cs-figure--phone .cs-figure-media {
    max-width: 300px;
    margin: 0 auto;
}

/* Portrait artwork would run over 1500px tall at full container width */
.cs-figure--tall .cs-figure-media {
    max-width: 620px;
    margin: 0 auto;
}

.cs-figure--phone figcaption,
.cs-figure--tall figcaption {
    text-align: center;
}

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

/* Two-up figure row */
.cs-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 22px;
    margin: 100px 0;
}

.cs-grid .cs-figure {
    margin: 0;
}

/* Other projects */
.cs-more {
    margin-top: 140px;
    padding-top: 56px;
    border-top: 1px solid var(--rule);
}

.cs-more h2 {
    font-size: 48px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.1;
    letter-spacing: -0.02em;
    margin: 0 0 8px;
}

.cs-more-card {
    display: block;
    padding: 40px 0;
    border-bottom: 1px solid var(--rule);
    text-decoration: none;
    cursor: none;
}

.cs-more-card h3 {
    font-size: 24px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.3;
    margin: 0 0 10px;
    transition: color 0.3s ease;
}

.cs-more-card p {
    font-size: 18px;
    color: var(--text-muted);
    line-height: 1.55;
    margin: 0 0 24px;
    max-width: 640px;
}

.cs-more-card:hover h3 {
    color: var(--accent);
}

.cs-more-card .cs-facts {
    margin: 0;
}

/* Stack to a single column once two columns stop being comfortable */
@media (max-width: 1000px) {
    .case-study {
        padding: 48px 0 100px;
    }

    .cs-header {
        flex-direction: column;
        gap: 32px;
    }

    .cs-header h1 {
        font-size: 44px;
    }

    .cs-facts {
        margin: 0;
        gap: 40px;
        flex-wrap: wrap;
    }

    .cs-section {
        grid-template-columns: 1fr;
        gap: 20px;
        margin: 72px 0;
    }

    .cs-figure,
    .cs-grid {
        margin: 72px 0;
    }

    .cs-more {
        margin-top: 100px;
    }

    .cs-more h2 {
        font-size: 36px;
    }
}

@media (max-width: 700px) {
    .cs-header h1 {
        font-size: 34px;
    }

    .cs-facts {
        gap: 24px;
    }

    .cs-facts dd {
        font-size: 16px;
    }

    .cs-section h2 {
        font-size: 20px;
    }

    .cs-body p,
    .cs-body li {
        font-size: 16px;
    }

    /* Two-up rows stack rather than squeezing */
    .cs-grid {
        grid-template-columns: 1fr;
        gap: 40px;
    }

    .cs-figure,
    .cs-grid {
        margin: 56px 0;
    }
}

/* About Page — oversized wordmark, then photo alongside the intro copy */
.about {
    max-width: 1350px;
    margin: 0 auto;
    padding: 64px 0 120px;
}

.about-title {
    font-size: clamp(72px, 15.5vw, 210px);
    font-weight: 600;
    color: var(--text);
    line-height: 0.95;
    letter-spacing: -0.04em;
    text-transform: lowercase;
    margin: 40px 0 80px;
}

.about-intro {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    align-items: start;
}

.about-photo {
    border-radius: 16px;
    overflow: hidden;
    background: var(--surface);
    margin: 0;
}

.about-photo img {
    display: block;
    width: 100%;
    height: auto;
    -webkit-user-drag: none;
    user-select: none;
}

/* Body copy and experience descriptions both match .hero-subtitle —
   line-height is left to inherit from body, as it does there */
.about-copy p,
.about-role p.about-role-body {
    font-size: 18px;
    font-weight: 400;
    color: var(--text-subtle);
}

.about-copy p {
    margin: 0 0 20px;
}

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

/* Experience list */
.about-experience {
    margin-top: 140px;
}

.about-experience h2 {
    font-size: 36px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.2;
    letter-spacing: -0.02em;
    margin: 0 0 40px;
}

.about-role {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    padding: 32px 0;
    border-top: 1px solid var(--rule);
    text-decoration: none;
    cursor: none;
}

.about-role:last-child {
    border-bottom: 1px solid var(--rule);
}

.about-role h3 {
    font-size: 24px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.3;
    margin: 0 0 6px;
    transition: color 0.3s ease;
}

a.about-role:hover h3 {
    color: var(--accent);
}

.about-role .about-role-meta {
    font-size: 16px;
    color: var(--text-faint);
    line-height: 1.4;
    margin: 0;
}

.about-role p.about-role-body {
    margin: 0;
}

@media (max-width: 1000px) {
    .about {
        padding: 48px 0 100px;
    }

    .about-title {
        margin: 24px 0 56px;
    }

    .about-intro,
    .about-role {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .about-photo {
        max-width: 520px;
    }

    .about-experience {
        margin-top: 100px;
    }

    .about-experience h2 {
        font-size: 28px;
    }
}

@media (max-width: 700px) {
    .about-role h3 {
        font-size: 20px;
    }
}

/* 3D Carousel */
.carousel-container {
    width: 100%;
    height: 80vh;
    min-height: 600px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 1400px;
    touch-action: none;
    user-select: none;
    position: relative;
    cursor: none;
}

.carousel-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-style: preserve-3d;
}

.carousel-3d {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-style: preserve-3d;
    transition: transform 0.1s ease-out;
}

.carousel-item {
    position: absolute;
    transform-style: preserve-3d;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    transition: transform 0.25s cubic-bezier(0.22, 0.61, 0.36, 1);
    width: 100%;
    height: 100%;
}

.project-link {
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    cursor: none;
    width: 100%;
    height: 100%;
    position: relative; /* Containing block for .distort-layer */
    transform-origin: center center;
    transition: transform 0.25s cubic-bezier(0.22, 0.61, 0.36, 1);
    /* Prevent browser native dragging */
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
}

.project-image {
    width: auto;
    height: auto;
    max-width: 600px;
    max-height: 500px;
    object-fit: contain;
    display: block;
    border-radius: 0;
    transition: transform 0.3s ease;
    pointer-events: none;
    /* Prevent browser native dragging and selection */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
}

.project-link:hover .project-image {
    transform: scale(1.05);
}

/* Filter definitions — present in the DOM but never rendered */
.distort-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
    pointer-events: none;
}

/* Warped copy of the thumbnail, masked to a circle that follows the cursor.
   Built by distort.js on first hover and laid exactly over the original. */
.distort-layer {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.distort-layer img {
    /* Mirrors .project-image so the copy lands exactly on the original.
       distort.js sets mask-image on this element, in its own local pixels. */
    width: auto;
    height: auto;
    max-width: 600px;
    max-height: 500px;
    object-fit: contain;
    display: block;
    filter: url(#thumb-distort);
    transition: transform 0.3s ease;
}

.project-link.is-distorting .distort-layer {
    opacity: 1;
}

/* Match the 1.05 lift the underlying thumbnail gets on hover */
.project-link:hover .distort-layer img {
    transform: scale(1.05);
}

/* Footer */
.footer {
    width: 100%;
    padding: 64px 64px 40px;
}

.footer-container {
    max-width: 1440px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 40px;
    align-items: start;
}

.footer-copyright p,
.footer-social,
.footer-contact {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.6;
}

.footer-link {
    color: var(--text);
    text-decoration: none;
    transition: color 0.3s ease;
    cursor: none;
    display: inline-block;
}

.footer-link:hover {
    color: var(--accent);
}

/* Responsive design */
@media (max-width: 1200px) {
    .main-content {
        padding: 0 40px;
    }
    
    .nav-container {
        padding: 0 40px;
    }
    
    .nav-links {
        gap: 60px;
    }
    
    .footer {
        padding: 64px 40px 40px;
    }
}

@media (max-width: 768px) {
    .main-content {
        padding: 0 24px;
    }
    
    .nav-container {
        padding: 0 24px;
    }
    
    .nav-links {
        gap: 40px;
    }
    
    .hero-title {
        font-size: 22px;
        line-height: 1.3;
    }
    
    .hero-subtitle {
        font-size: 18px;
    }
    
    .projects {
        padding-top: 80px;
    }
    
    /* Reduce carousel size for tablet */
    .carousel-container {
        height: 60vh;
        min-height: 400px;
        perspective: 1000px;
    }
    
    .project-image {
        max-width: 400px;
        max-height: 300px;
    }
    
    /* Footer adjustments for tablet */
    .footer {
        padding: 64px 24px 40px;
        margin-top: 80px;
    }
    
    .footer-container {
        gap: 30px;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 0 16px;
    }
    
    .nav-container {
        padding: 0 16px;
    }
    
    .nav-links {
        gap: 24px;
        flex-wrap: wrap;
    }

    .nav-right {
        gap: 20px;
    }
    
    .nav-link {
        font-size: 18px;
    }
    
    .projects {
        padding-top: 80px;
    }
    
    .hero-title {
        font-size: 32px;
        line-height: 1.4;
    }
    
    .hero-subtitle {
        font-size: 22px;
        margin-bottom: 40px;
    }
    
    /* Reduce carousel size for mobile */
    .carousel-container {
        height: 50vh;
        min-height: 300px;
        perspective: 800px;
    }
    
    .project-image {
        max-width: 280px;
        max-height: 200px;
    }
    
    /* Footer adjustments for mobile */
    .footer {
        padding: 40px 16px 32px;
        margin-top: 60px;
    }
    
    .footer-container {
        grid-template-columns: 1fr;
        gap: 24px;
    }
    
    .footer-copyright p,
    .footer-social,
    .footer-contact {
        font-size: 15px;
    }
}

/* Smooth scrolling for anchor links */
html {
    scroll-behavior: smooth;
}

/* Focus states for accessibility */
.nav-link:focus,
.theme-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Ensure proper spacing on very large screens */
@media (min-width: 1440px) {
    .main-content {
        padding: 0 64px;
    }
    
    .footer {
        padding: 64px 64px 40px;
    }
}
