/* ============================================================
   JOSHI PERERA — PORTFOLIO
   Google Fonts loaded via <link> in each HTML <head>
   ============================================================ */

:root {
  --bg:          #F7F3EC;
  --text:        #1C1C1C;
  --text-muted:  rgba(28, 28, 28, 0.45);
  --font-serif:  'Cormorant Garamond', Georgia, serif;
  --font-sans:   'DM Sans', system-ui, sans-serif;
  --space:       20px;
  --track-h:     50vh;
  --ease:        cubic-bezier(0.25, 0.46, 0.45, 0.94);

  /* Plyr video player skin (project-video pages) */
  --plyr-color-main:      #F7F3EC;   /* cream accent — matches palette */
  --plyr-font-family:     'DM Sans', system-ui, sans-serif;
  --plyr-font-size-base:  13px;
  --plyr-control-spacing: 8px;
  --plyr-video-background: #111;
}

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

/* Images are not draggable — pairs with the JS contextmenu guard in script.js */
img { -webkit-user-drag: none; }

/* ── Shimmer keyframe (shared) ─────────────────────────── */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}


/* ── GIF HOVER PREVIEW (video cards — projects page) ──────────────────────── */

.card__gif {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
  /* Override the .card img shimmer — gif must be transparent while loading */
  background: none;
  animation: none;
  min-height: 0;
}

/* Opacity is driven entirely by JS once the GIF has loaded — no CSS hover rule */


/* ── CREDITS (nav__desc — project pages) ──────────────────────────────────── */

.nav__credits {
  margin-top: 10px;
  line-height: 2;
  opacity: 0.7;
}


/* ── VIDEO POSTER (thumbnail + play overlay — all breakpoints) ────────────── */

.video-poster {
  position: absolute;
  inset: 0;
  z-index: 2;
  cursor: pointer;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-poster__play {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(247, 243, 236, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s var(--ease), background 0.2s var(--ease);
}

.video-poster:hover .video-poster__play {
  transform: scale(1.1);
  background: rgba(247, 243, 236, 1);
}

.video-poster__play svg {
  width: 22px;
  height: 22px;
  margin-left: 3px; /* optical centre for play triangle */
  fill: var(--text);
}


/* ============================================================
   DESKTOP  (min-width: 800px)
   ============================================================ */
@media (min-width: 800px) {

  html { scrollbar-width: none; }
  html::-webkit-scrollbar { display: none; }

  body {
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: clamp(13px, 1.5vw, 15px);
    font-weight: 400;
    line-height: 1.5;
    margin: 0;
    padding: 0;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    font-optical-sizing: auto;
  }

  a { text-decoration: none; color: inherit; }
  p { margin: 0; }

  h1, h2 {
    font-family: var(--font-sans);
    font-size: clamp(13px, 1.5vw, 15px);
    font-weight: 400;
    color: var(--text);
    margin: 0;
  }


  /* ── NAV ───────────────────────────────────────────── */

  .nav {
    margin: var(--space);
    width: calc(100% - 40px);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    column-gap: var(--space);
    height: auto;
    position: relative;
    z-index: 10;
  }

  .nav__logo {
    font-family: var(--font-serif);
    font-size: clamp(20px, 3vw, 38px);
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.2;
    text-transform: lowercase;
    padding-left: 12px;
    user-select: none;
    -webkit-user-select: none;
  }

  .nav__logo a { color: inherit; }

  /* Logo link on project pages — inherits nav__logo size */
  .logo-link {
    display: block;
    transition: opacity 0.15s;
  }
  .logo-link:hover { opacity: 0.6; }

  /* Back link below logo on project pages */
  .back-link {
    display: block;
    font-family: var(--font-sans);
    font-size: clamp(11px, 1.2vw, 13px);
    font-weight: 400;
    opacity: 0.38;
    margin-top: 8px;
    letter-spacing: 0;
    transition: opacity 0.15s;
  }
  .back-link:hover { opacity: 0.9; }

  .nav__links { grid-column-start: 2; }
  .nav__desc  { grid-column-start: 3; line-height: 1.6; }

  .nav__links a {
    display: block;
    width: fit-content;     /* hitbox hugs the text, not the full column */
    opacity: 0.45;
    transition: opacity 0.15s;
    color: inherit;
    line-height: 1.7;
  }

  .nav__links a:hover { opacity: 1; }
  .nav__links a.active-page { opacity: 1; }
  .nav__links a.nav-toggle--open { opacity: 1; }

  .expandable {
    display: none;
    margin-top: 6px;
    margin-bottom: 16px;
    line-height: 1.6;
    opacity: 0.8;
  }


  /* ── FILTER BAR  (projects.html) ───────────────────── */

  .filter-bar {
    margin-top: 2px;
    margin-bottom: 16px;
    padding-left: 0;
  }

  .filter-btn {
    background: none;
    border: none;
    font-family: var(--font-sans);
    font-size: clamp(13px, 1.5vw, 15px);
    color: var(--text);
    cursor: pointer;
    padding: 0;
    display: block;
    line-height: 1.7;
    opacity: 0.38;
    transition: opacity 0.15s;
  }

  .filter-btn.active,
  .filter-btn:hover { opacity: 1; }


  /* ── SCROLL TRACK ──────────────────────────────────── */

  .scroll-track {
    overflow-x: auto;
    overflow-y: hidden;
    position: absolute;
    bottom: var(--space);
    left: 0;
    width: 100%;
    white-space: nowrap;
  }

  .scroll-track { scrollbar-width: none; }
  .scroll-track::-webkit-scrollbar { display: none; }


  /* ── CARDS ─────────────────────────────────────────── */

  .card {
    display: inline-block;
    margin-left: var(--space);
    position: relative;
    vertical-align: bottom;
    overflow: hidden;               /* contain image scale on hover */
  }

  .card img {
    display: block;
    height: var(--track-h);
    width: auto;
    /* Reserve space while loading so the track doesn't collapse */
    min-width:  calc(var(--track-h) * 0.67);
    min-height: var(--track-h);
    /* Shimmer placeholder — visible on the image itself until it loads */
    background: linear-gradient(90deg, #eae6df 25%, #f2ede8 50%, #eae6df 75%);
    background-size: 200% 100%;
    animation: shimmer 1.8s ease-in-out infinite;
    /* Hover transition */
    transition: transform 0.45s var(--ease), opacity 0.2s ease;
  }

  .card:hover img {
    transform: scale(1.03);
  }

  /* Clicking photos in photo project pages opens lightbox */
  .page-project-photo .card img {
    cursor: pointer;
  }

  .card__title {
    display: block;
    margin-bottom: 10px;
    color: var(--text);
    transition: opacity 0.15s;
  }

  .card:hover .card__title { opacity: 0.55; }

  .card__client {
    display: block;
    opacity: 0.45;
    margin-bottom: 14px;
  }

  .desk-sep  { display: inline; }
  .mob-break { display: none; }


  /* ── VIDEO CARDS ───────────────────────────────────── */

  /* Native video / iframe on video project pages (pre-Plyr or fallback) */
  .card--video video,
  .card--video iframe {
    display: block;
    height: var(--track-h);
    aspect-ratio: 16 / 9;
    border: none;
    background: #111;   /* dark placeholder while loading */
    animation: none;    /* no shimmer */
  }

  /* Plyr wrapper — keeps the player at track height once it initialises */
  .card--video .plyr--video {
    height: var(--track-h);
    aspect-ratio: 16 / 9;
  }

  /* Bigger video on the dedicated project page */
  body.page-project-video {
    --track-h: 70vh;
  }

  /* ── FOOTER CARD ───────────────────────────────────── */

  .footer-card {
    display: inline-block;
    margin-left: var(--space);
    vertical-align: bottom;
    height: var(--track-h);
    position: relative;
  }

  .footer-inner {
    position: absolute;
    bottom: 0;
    width: calc(100vw / 3 - 5px);
  }

  .footer-inner p {
    margin-top: var(--space);
    opacity: 0.45;
    line-height: 1.6;
  }

  .footer-inner a:hover { text-decoration: underline; }


  /* ── HOME PAGE  (index.html) ───────────────────────── */

  .hero-video {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 0;
    object-fit: cover;
    pointer-events: none;   /* cursor:none works natively on <video> */
  }

  /* Horizontal video: visible on desktop */
  .hero-video--h {
    opacity: 1;
    transition: opacity 0.8s ease;
  }

  /* Vertical video: hidden on desktop */
  .hero-video--v {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.8s ease;
  }

  /* Subtle gradient so nav text stays readable over bright video */
  body.page-home::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 25vh;
    background: linear-gradient(to bottom, rgba(0,0,0,0.28) 0%, transparent 100%);
    z-index: 1;
    pointer-events: none;
  }

  body.page-home .nav {
    position: fixed;
    top: 0; left: 0;
    color: #ffffff;
    z-index: 6;
  }

  body.page-home .nav a,
  body.page-home .nav p,
  body.page-home .nav__logo,
  body.page-home .expandable {
    color: #ffffff;
  }


  /* ── PROJECT PAGES — BACK NAVIGATION ─────────────── */
  /*
    On project pages, nav col 1 has the normal Joshi Perera logo
    with a small "← All Work" back link underneath it.
  */

  /* (logo-link and back-link defined above under .nav__logo) */


  /* ── LIGHTBOX ──────────────────────────────────────── */

  .lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    align-items: center;
    justify-content: center;
  }

  .lightbox.open { display: flex; }

  .lightbox__backdrop {
    position: absolute; inset: 0;
    background: rgba(247, 243, 236, 0.95);
  }

  .lightbox__img {
    position: relative; z-index: 1;
    max-height: 90vh; max-width: 88vw;
    object-fit: contain;
    display: block;
  }

  .lightbox__close,
  .lightbox__prev,
  .lightbox__next {
    position: absolute; z-index: 2;
    background: none; border: none;
    cursor: pointer;
    font-family: var(--font-sans);
    color: var(--text);
    opacity: 0.4;
    transition: opacity 0.15s;
    line-height: 1;
    padding: 0;
  }

  .lightbox__close:hover,
  .lightbox__prev:hover,
  .lightbox__next:hover { opacity: 1; }

  .lightbox__close {
    top: var(--space); right: var(--space);
    font-size: 1em; letter-spacing: 0.05em;
  }

  .lightbox__prev {
    left: var(--space);
    top: 50%; transform: translateY(-50%);
    font-size: 2.4em;
  }

  .lightbox__next {
    right: var(--space);
    top: 50%; transform: translateY(-50%);
    font-size: 2.4em;
  }

  .lightbox__counter {
    position: absolute;
    bottom: var(--space); left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    font-size: 0.85em;
    opacity: 0.4;
  }


  /* ── CUSTOM CURSOR ─────────────────────────────────── */
  /* Desktop-only; injected div#custom-cursor via script.js  */

  /*
    mix-blend-mode: difference with solid white = cursor color is always
    the inverse of whatever is underneath → visually reliable on any background:
      – cream (#F7F3EC) → cursor appears near-black (#080C13) ✓
      – dark video      → cursor appears near-white ✓
      – any image       → always contrasts ✓
    No backdrop-filter needed.
  */
  .custom-cursor {
    position: fixed;
    left: 0; top: 0;
    width: 20px; height: 20px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 100002;
    box-sizing: border-box;
    transform: translate(-50%, -50%);
    will-change: left, top, transform;
    border: none;
    background: #ffffff;
    mix-blend-mode: difference;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    transition: transform 0.12s var(--ease), opacity 0.35s var(--ease);
  }

  /* All interactive targets expand to the same size */
  .custom-cursor--hover,
  .custom-cursor--hover.custom-cursor--link {
    transform: translate(-50%, -50%) scale(1.175);
  }

  /* Thin bar for text inputs */
  .custom-cursor--text {
    width: 2px; height: 18px;
    border-radius: 1px;
    transform: translate(-50%, -50%) scale(1);
  }

  body:not(.use-custom-cursor) .custom-cursor,
  .custom-cursor[hidden] {
    display: none !important;
  }

  .custom-cursor.custom-cursor--hidden {
    opacity: 0;
  }

} /* end desktop */


/* ============================================================
   MOBILE  (max-width: 800px)
   ============================================================ */
@media (max-width: 800px) {

  html { scrollbar-width: none; }
  html::-webkit-scrollbar { display: none; }

  body {
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: clamp(15px, 4.5vw, 18px);
    font-weight: 400;
    line-height: 1.5;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    font-optical-sizing: auto;
  }

  a { text-decoration: none; color: inherit; }
  p { margin: 0; }

  h1, h2 {
    font-family: var(--font-sans);
    font-size: clamp(15px, 4.5vw, 18px);
    font-weight: 400;
    margin: 0;
  }


  /* ── NAV ───────────────────────────────────────────── */

  .nav {
    display: flex;
    flex-direction: column;
    padding: var(--space);
    width: calc(100% - 40px);
  }

  .nav__logo {
    font-family: var(--font-serif);
    font-size: clamp(21px, 6vw, 32px);
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.2;
    text-transform: lowercase;
    order: 0;
    user-select: none;
    -webkit-user-select: none;
  }

  /* Logo link on project pages */
  .logo-link { display: block; }

  /* Back link on project pages */
  .back-link {
    display: block;
    font-family: var(--font-sans);
    font-size: 0.82em;
    opacity: 0.38;
    margin-top: 6px;
    margin-bottom: 6px;
  }

  .nav__links {
    margin-top: 60px;
    order: 1;
  }

  .nav__links a {
    display: block;
    width: fit-content;
    line-height: 1.9;
    opacity: 0.45;
    color: inherit;
  }

  .nav__links a:hover { opacity: 1; }
  .nav__links a.active-page { opacity: 1; }

  .nav__desc {
    order: 2;
    margin-top: 20px;
    width: 85%;
    line-height: 1.6;
  }

  .expandable {
    display: none;
    margin-top: 6px;
    margin-bottom: 16px;
    line-height: 1.6;
  }


  /* ── FILTER BAR (mobile) ───────────────────────────── */

  .filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    margin-top: 4px;
    margin-bottom: 16px;
  }

  .filter-btn {
    background: none; border: none;
    font-family: var(--font-sans);
    font-size: clamp(15px, 4.5vw, 18px);
    color: var(--text);
    cursor: pointer; padding: 0;
    display: inline-block;
    opacity: 0.38;
  }

  .filter-btn.active { opacity: 1; }


  /* ── SCROLL TRACK (mobile — vertical stack) ──────── */

  .scroll-track {
    position: static;
    display: block !important;
    overflow-x: visible;
    white-space: normal;
    margin: 0 var(--space);
    margin-top: 24px;
    padding-bottom: 60px;
  }


  /* ── CARDS (mobile) ────────────────────────────────── */

  .card {
    display: block;
    margin-left: 0;
    margin-top: var(--space);
    overflow: hidden;
    position: relative; /* needed so .video-poster { position: absolute } anchors here */
  }

  .card img {
    width: 100%; height: auto;
    display: block;
    min-height: 40vw; /* prevents collapse before load */
    /* Shimmer on the image itself */
    background: linear-gradient(90deg, #eae6df 25%, #f2ede8 50%, #eae6df 75%);
    background-size: 200% 100%;
    animation: shimmer 1.8s ease-in-out infinite;
  }

  .page-project-photo .card img { cursor: pointer; }

  .card__title {
    display: block; margin-bottom: 8px;
    transition: opacity 0.15s;
  }
  .card__client { display: block; opacity: 0.45; margin-bottom: 12px; }

  .desk-sep  { display: none; }
  .mob-break { display: inline; }


  /* ── VIDEO CARDS (mobile) ──────────────────────────── */

  /* Give the card itself an aspect ratio so it has height even when the
     <video> has no src yet (poster mode — the video element is 0px tall). */
  .card--video {
    width: 100%;
    aspect-ratio: 16 / 9;
  }

  .card--video video,
  .card--video iframe,
  .card--video .plyr--video {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    border: none;
    height: auto;
    background: #111;
  }


  /* ── FOOTER CARD (mobile) ──────────────────────────── */

  .footer-card {
    display: block; margin: 0;
  }

  .footer-inner {
    display: block;
    width: 100%; height: auto;
    padding: 40px 0;
    position: static;
  }

  .footer-inner p {
    margin-top: var(--space);
    opacity: 0.45; line-height: 1.6;
  }

  .footer-inner a:hover { text-decoration: underline; }


  /* ── HOME PAGE (mobile) ────────────────────────────── */

  body.page-home {
    overflow: hidden;
  }

  .hero-video {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 0;
    object-fit: cover;
  }

  /* Vertical video: visible on mobile */
  .hero-video--h {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.8s ease;
  }

  /* Horizontal video: hidden on mobile */
  .hero-video--v {
    opacity: 1;
    transition: opacity 0.8s ease;
  }

  body.page-home::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 30vh;
    background: linear-gradient(to bottom, rgba(0,0,0,0.28) 0%, transparent 100%);
    z-index: 1;
    pointer-events: none;
  }

  body.page-home .nav {
    position: fixed;
    top: 0; left: 0;
    z-index: 6;
    color: #ffffff;
    width: 100%;
  }

  body.page-home .nav a,
  body.page-home .nav p,
  body.page-home .nav__logo,
  body.page-home .expandable {
    color: #ffffff;
  }


  /* ── LIGHTBOX (mobile) ─────────────────────────────── */

  .lightbox {
    display: none;
    position: fixed;
    inset: 0; z-index: 100;
    align-items: center; justify-content: center;
  }

  .lightbox.open { display: flex; }

  .lightbox__backdrop {
    position: absolute; inset: 0;
    background: rgba(247, 243, 236, 0.97);
  }

  .lightbox__img {
    position: relative; z-index: 1;
    max-height: 85vh; max-width: 95vw;
    object-fit: contain; display: block;
  }

  .lightbox__close,
  .lightbox__prev,
  .lightbox__next {
    position: absolute; z-index: 2;
    background: none; border: none;
    cursor: pointer; padding: 8px;
    font-family: var(--font-sans);
    color: var(--text); opacity: 0.5;
  }

  .lightbox__close { top: 12px; right: 12px; font-size: 1.1em; }
  .lightbox__prev  { left: 6px; top: 50%; transform: translateY(-50%); font-size: 2.2em; }
  .lightbox__next  { right: 6px; top: 50%; transform: translateY(-50%); font-size: 2.2em; }

  .lightbox__counter {
    position: absolute; bottom: 14px; left: 50%;
    transform: translateX(-50%);
    z-index: 2; font-size: 0.85em; opacity: 0.4;
  }

} /* end mobile */


/* ============================================================
   CUSTOM CURSOR — cursor:none (top-level, not nested)
   Needs to be outside the breakpoint blocks so it isn't
   affected by @media nesting quirks. Applied to html so
   there's no gap between body and viewport edge.
   ============================================================ */
@media (min-width: 800px) and (hover: hover) and (pointer: fine) {
  html.use-cursor-active,
  html.use-cursor-active body,
  html.use-cursor-active * {
    cursor: none !important;
  }
}


/* ============================================================
   HERO VIDEO FADE-IN
   data-loading keeps the video invisible until it starts playing.
   Removing the attribute triggers the CSS opacity transition (fade-in).
   !important ensures this overrides the h/v opacity rules in both
   breakpoints while the attribute is present.
   ============================================================ */
.hero-video[data-loading] {
  opacity: 0 !important;
}


/* ============================================================
   BACK ARROW ANIMATION
   The ← in "← All Projects" slides left on hover.
   ============================================================ */
.back-arrow {
  display: inline-block;
  transition: transform 0.25s var(--ease);
}

.back-link:hover .back-arrow {
  transform: translateX(-5px);
}


/* ============================================================
   SOCIAL LINKS  (inside expandable contact panel)
   ============================================================ */
.social-link {
  display: block;
  line-height: 1.7;
  color: inherit;
  text-decoration: none;
}

.social-link svg {
  display: inline;
  vertical-align: middle;
  margin-right: 5px;
  margin-top: -2px;   /* optical centre with cap-height */
  flex-shrink: 0;
}


/* ============================================================
   PROJECT PAGES — NAV LAYOUT OVERRIDES
   On video/photo project pages, col 2 (nav__links) becomes a
   flex row: back link on the left, project title on the right.
   ============================================================ */
@media (min-width: 800px) {

  .page-project-video .nav__links,
  .page-project-photo .nav__links {
    display: flex;
    flex-direction: row;
    align-items: baseline;  /* aligns back-link text baseline with h1 baseline */
    gap: 20px;
  }

  /* Back link in the flex row — same size/weight as the project title */
  .page-project-video .nav__links .back-link,
  .page-project-photo .nav__links .back-link {
    font-size: clamp(13px, 1.5vw, 15px);  /* matches h1 body text size */
    font-weight: 400;
    line-height: 1.5;   /* match h1 line-height so baselines align cleanly */
    margin-top: 0;
    flex-shrink: 0;
    white-space: nowrap;
  }

  /* Wrapper for h1 + year/client in the flex row */
  .project-meta { flex: 1; }

}
