/*
  Convocation — ATLAS SkillTech University
  Small companion stylesheet to the Tailwind CDN build.
  Holds only what utilities can't express cleanly: the preloader (must render
  before Tailwind's runtime compiles), Lenis rules, component classes shared
  with JS-rendered markup, and reduced-motion fallbacks.
*/

/* Lock the cascade order so these components sit between Tailwind's base and utilities. */
@layer theme, base, components, utilities;

/* ---------- Tokens (mirrors the @theme block in index.html) ---------- */
:root {
  --ink: #0e0e33;
  --ink-2: #17174a;
  --indigo: #313187;
  --gown: #3434d1;
  --gold: #d6ae55;
  --gold-light: #efd592;
  --stole: #f5f6fc;
  --teal: #10a8b6;
  --ease-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --header-h: 4.5rem;
}

/* ---------- Preloader (unlayered on purpose: must win before Tailwind loads) ---------- */
.preloader {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--stole);
  /* Failsafe: if scripts never run, get out of the way after 4s. */
  animation: preloader-failsafe 0.6s ease 4s forwards;
}
.preloader__inner {
  display: grid;
  justify-items: center;
  gap: 1.25rem;
  text-align: center;
}
.preloader__mark {
  width: 44px;
  height: auto;
  animation: preloader-float 2.4s ease-in-out infinite;
}
.preloader__word {
  font-family: "Bodoni Moda", Georgia, serif;
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1;
}
.preloader__line {
  position: relative;
  width: min(220px, 50vw);
  height: 1px;
  overflow: hidden;
  background: rgb(245 246 252 / 0.15);
}
.preloader__line::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--gold);
  transform-origin: left;
  animation: preloader-line 1.1s var(--ease-expo) forwards;
}
.preloader__caption {
  font-family: "Schibsted Grotesk", system-ui, sans-serif;
  font-size: 0.8125rem;
  letter-spacing: 0.02em;
  color: rgb(245 246 252 / 0.6);
}
@keyframes preloader-line { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes preloader-float { 50% { transform: translateY(-6px); } }
@keyframes preloader-failsafe { to { opacity: 0; visibility: hidden; } }

html.is-loading,
html.is-loading body { overflow: hidden; }

/* ---------- Lenis ---------- */
html.lenis, html.lenis body { height: auto; }
.lenis:not(.lenis-autoToggle).lenis-stopped { overflow: clip; }
.lenis.lenis-smooth [data-lenis-prevent] { overscroll-behavior: contain; }
.lenis.lenis-smooth iframe { pointer-events: none; }
.lenis.lenis-smooth dialog iframe { pointer-events: auto; }

@layer base {
  html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }
  body { overflow-x: clip; }
  ::selection { background: var(--gold); color: var(--ink); }
  :focus-visible {
    outline: 2px solid var(--teal);
    outline-offset: 3px;
    border-radius: 2px;
  }
  img { user-select: none; -webkit-user-drag: none; }
}

@layer components {
  /* Page container: one gutter system for every section */
  .wrap {
    width: 100%;
    max-width: 90rem;
    margin-inline: auto;
    padding-inline: 1rem;
  }
  @media (min-width: 640px) { .wrap { padding-inline: 1.5rem; } }
  @media (min-width: 1024px) { .wrap { padding-inline: 2.5rem; } }

  /* ---------- Buttons ---------- */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    min-height: 3.25rem;
    padding: 0 1.625rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.9375rem;
    line-height: 1;
    white-space: nowrap;
    transition: background-color 0.35s var(--ease-expo), color 0.35s var(--ease-expo),
      border-color 0.35s var(--ease-expo);
    will-change: transform;
  }
  .btn svg { width: 1rem; height: 1rem; flex: none; }
  .btn--gold { background: var(--gold); color: var(--ink); }
  .btn--gold:hover { background: var(--gold-light); }
  .btn--line { border: 1px solid rgb(245 246 252 / 0.35); color: var(--stole); }
  .btn--line:hover { background: var(--stole); color: var(--ink); border-color: var(--stole); }
  .btn--ink { background: var(--ink); color: var(--stole); }
  .btn--ink:hover { background: var(--gown); }
  .btn--line-ink { border: 1px solid rgb(14 14 51 / 0.25); color: var(--ink); }
  .btn--line-ink:hover { background: var(--ink); color: var(--stole); border-color: var(--ink); }
  .btn--sm { min-height: 2.5rem; padding: 0 1.125rem; font-size: 0.875rem; }
  @media (max-width: 479px) {
    .btn:not(.btn--sm) { min-height: 3rem; padding: 0 1.125rem; font-size: 0.875rem; gap: 0.5rem; }
  }

  /* ---------- Header ---------- */
  .site-header {
    transition: transform 0.6s var(--ease-expo), background-color 0.4s ease, border-color 0.4s ease;
    border-bottom: 1px solid transparent;
  }
  .site-header.is-scrolled {
    background-color: rgb(14 14 51 / 0.82);
    backdrop-filter: blur(14px) saturate(140%);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    border-bottom-color: rgb(245 246 252 / 0.08);
  }
  .site-header.is-hidden { transform: translateY(-100%); }

  .nav-link {
    position: relative;
    padding-block: 0.5rem;
    color: rgb(245 246 252 / 0.72);
    transition: color 0.3s ease;
  }
  .nav-link::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0.1rem;
    height: 1px;
    background: var(--gold);
    transform: scaleX(0);
    transform-origin: right;
    transition: transform 0.5s var(--ease-expo);
  }
  .nav-link:hover,
  .nav-link[aria-current="true"] { color: var(--stole); }
  .nav-link:hover::after,
  .nav-link[aria-current="true"]::after { transform: scaleX(1); transform-origin: left; }

  /* Hamburger → close morph */
  .menu-icon { position: relative; width: 22px; height: 12px; }
  .menu-icon span {
    position: absolute;
    left: 0;
    width: 100%;
    height: 1.5px;
    background: currentColor;
    transition: transform 0.5s var(--ease-expo), top 0.5s var(--ease-expo);
  }
  .menu-icon span:first-child { top: 0; }
  .menu-icon span:last-child { top: 10px; }
  [aria-expanded="true"] .menu-icon span:first-child { top: 5px; transform: rotate(45deg); }
  [aria-expanded="true"] .menu-icon span:last-child { top: 5px; transform: rotate(-45deg); }

  /* ---------- Hero window: the photo is clipped to a "doorway" that opens on scroll ---------- */
  /* Pre-JS approximation; JS fits the window to the text block below 1024px */
  .hero-media { clip-path: inset(11% 4% 42% 4% round 6px); }
  @media (min-width: 640px) { .hero-media { clip-path: inset(10% 6% 40% 6% round 6px); } }
  @media (min-width: 1024px) and (orientation: landscape) { .hero-media { clip-path: inset(12% 30% 40% 30% round 6px); } }

  .hero-title { font-size: 16.5vw; } /* refined by JS fitText to span the container exactly */

  .scroll-cue { position: relative; width: 1px; height: 3rem; overflow: hidden; background: rgb(245 246 252 / 0.2); }
  .scroll-cue::after {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--gold);
    animation: scroll-cue 2.2s var(--ease-expo) infinite;
  }
  @keyframes scroll-cue {
    0% { transform: translateY(-100%); }
    60%, 100% { transform: translateY(100%); }
  }

  /* ---------- Chapters (horizontal on desktop via GSAP; vertical stack elsewhere) ---------- */
  .chapter-num {
    font-family: "Bodoni Moda", Georgia, serif;
    font-weight: 500;
    line-height: 0.8;
    color: transparent;
    -webkit-text-stroke: 1px rgb(214 174 85 / 0.7);
  }

  /* ---------- Marquee ---------- */
  .marquee { overflow: hidden; }
  .marquee__track { display: flex; width: max-content; gap: 0.75rem; }
  .marquee__item {
    flex: none;
    width: clamp(9.5rem, 17vw, 14.5rem);
    aspect-ratio: 3 / 2;
    overflow: hidden;
    border-radius: 0.375rem;
    background: var(--ink-2);
  }
  .marquee__item img { width: 100%; height: 100%; object-fit: cover; }

  /* ---------- Film cards (rendered by JS) ---------- */
  .rail {
    display: flex;
    gap: 1.25rem;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 1rem;
    padding-bottom: 0.5rem;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
  }
  .rail::-webkit-scrollbar { display: none; }
  .film-card {
    flex: none;
    width: min(82%, 22rem);
    scroll-snap-align: start;
  }
  @media (min-width: 640px) { .film-card { width: calc((100% - 1.25rem) / 2); } }
  @media (min-width: 1024px) { .film-card { width: calc((100% - 2.5rem) / 3); } }
  .film-card__btn { display: block; width: 100%; text-align: left; }
  .film-card__media {
    position: relative;
    display: block;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: 0.375rem;
    background: var(--ink-2);
  }
  .film-card__media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scale(1.02);
    transition: transform 0.9s var(--ease-expo), opacity 0.4s ease;
    opacity: 0.85;
  }
  .film-card__btn:hover .film-card__media img,
  .film-card__btn:focus-visible .film-card__media img { transform: scale(1.07); opacity: 1; }
  .film-card__title {
    display: block;
    margin-top: 1rem;
    font-family: "Bodoni Moda", Georgia, serif;
    font-size: 1.3125rem;
    line-height: 1.2;
    color: var(--stole);
    text-wrap: balance;
  }

  .play-badge {
    position: absolute;
    left: 1rem;
    bottom: 1rem;
    display: grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    border-radius: 999px;
    background: var(--stole);
    color: var(--ink);
    transition: transform 0.5s var(--ease-expo), background-color 0.3s ease;
  }
  .play-badge svg { width: 0.875rem; height: 0.875rem; margin-left: 2px; }
  .film-card__btn:hover .play-badge,
  .dignitary:hover .play-badge { transform: scale(1.12); background: var(--gold); }

  /* ---------- Tabs ---------- */
  .tab {
    min-height: 2.75rem;
    padding: 0 1.25rem;
    border-radius: 999px;
    border: 1px solid rgb(245 246 252 / 0.2);
    color: rgb(245 246 252 / 0.72);
    font-size: 0.9375rem;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.35s var(--ease-expo);
  }
  .tab:hover { color: var(--stole); border-color: rgb(245 246 252 / 0.5); }
  .tab[aria-selected="true"] { background: var(--stole); color: var(--ink); border-color: var(--stole); }

  /* ---------- Dialogs (lightbox + video) ---------- */
  .modal {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--stole);
  }
  .modal::backdrop {
    background: rgb(14 14 51 / 0.94);
    backdrop-filter: blur(6px);
  }
  .icon-btn {
    display: grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    border-radius: 999px;
    border: 1px solid rgb(245 246 252 / 0.25);
    color: var(--stole);
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
  }
  .icon-btn:hover { background: var(--stole); color: var(--ink); border-color: var(--stole); }
  .icon-btn svg { width: 1.125rem; height: 1.125rem; }
  .icon-btn--ink { border-color: rgb(14 14 51 / 0.2); color: var(--ink); }
  .icon-btn--ink:hover { background: var(--ink); color: var(--stole); border-color: var(--ink); }

  /* ---------- Logo walls ---------- */
  .logo-tile img { transition: filter 0.5s ease, opacity 0.5s ease, transform 0.6s var(--ease-expo); }
  .logo-tile--mono img { filter: grayscale(1); opacity: 0.75; }
  .logo-tile--mono:hover img { filter: none; opacity: 1; transform: scale(1.04); }
}

/* ---------- Reduced motion: everything readable, nothing moves ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .chapters-track { flex-direction: column !important; width: auto !important; height: auto !important; }
  .chapter { width: 100% !important; height: auto !important; }
  .marquee { overflow-x: auto; }
  [data-chapter-hint] { display: none !important; }
}
