/*
 * home.css — Home page layout
 *
 * Sections, in order:
 *   .hero           — bilingual EN + ZH hero
 *   .belief         — "Learning itself is the point"
 *   .principles     — five principle pairs with alternating video layout
 *   .outcomes       — dark emphasis block with university logos
 *   .recent-writing — two latest blog cards (populated by latest-posts.js)
 *   .closing-cta    — dark emphasis block with primary CTA
 */

@layer pages {
  /* ────────────────────────────────────────────────────────────────── */
  /* Hero                                                                */
  /* ────────────────────────────────────────────────────────────────── */

  .hero {
    padding-block: var(--sp-3xl) var(--sp-3xl-lg);
  }

  @media (min-width: 64rem) {
    .hero {
      padding-block: var(--sp-3xl-lg) var(--sp-4xl);
      /* Full-viewport-height hero on desktop with a 40rem floor so short
         viewports (e.g. 600px laptops) stay comfortable. Video heros add
         the pull-up amount so the visible portion still fills 100vh after
         the negative-margin that tucks them behind the sticky header. */
      min-height: max(100vh, 40rem);
      display: flex;
      flex-direction: column;
      justify-content: center;
    }

    .hero--video {
      min-height: max(
        calc(100vh + var(--sp-3xl) + var(--sp-sm)),
        40rem
      );
    }
  }

  /* ────────────────────────────────────────────────────────────────── */
  /* Hero — video background variant                                    */
  /* ────────────────────────────────────────────────────────────────── */

  .hero--video {
    position: relative;
    overflow: hidden;
    background: var(--bg-emphasis); /* fallback before video paints */
    color: var(--text-inverse);
    isolation: isolate;
    /* Pull the section up behind the sticky site-header so the video
       shows through the glass pill that floats over it. The extra
       padding-top clears the pill + its top inset. */
    margin-top: calc(-1 * (var(--sp-3xl) + var(--sp-sm)));
    padding-top: calc(var(--sp-3xl) + var(--sp-sm) + var(--sp-3xl-lg));
  }

  .hero__video,
  .hero__overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }

  .hero__video {
    object-fit: cover;
    z-index: 0;
    pointer-events: none;
  }

  /* Ink-tinted overlay — darker at the bottom where most copy sits. */
  .hero__overlay {
    z-index: 1;
    background: linear-gradient(180deg, rgba(19, 26, 35, 0.9));
  }

  .hero--video > .container {
    position: relative;
    z-index: 2;
  }

  /* Light-theme text overrides for the video hero. */
  .hero--video .hero__headline,
  .hero--video .hero__zh-horizontal,
  .hero--video .hero__en-horizontal,
  .hero--video .hero__zh-vertical {
    color: var(--text-inverse);
  }

  .hero--video .hero__sub,
  .hero--video .hero__zh-sub,
  .hero--video .hero__en-sub {
    color: var(--neutral-200);
  }

  .hero__grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--sp-2xl);
    align-items: start;
  }

  @media (min-width: 64rem) {
    .hero__grid {
      grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
      gap: var(--sp-3xl);
      align-items: center;
    }
  }

  .hero__en {
    max-width: 60rem;
  }

  .hero__headline {
    font-family: var(--font-display);
    /* Capped one step below the previous 4.25rem so the lede fits in 2–3
       lines on a 1440px viewport inside the 1.3fr grid column. */
    font-size: clamp(2.25rem, 1.1rem + 4vw, 3.75rem);
    font-weight: var(--fw-medium);
    line-height: 1.08;
    letter-spacing: -0.022em;
    color: var(--text-primary);
    margin-bottom: var(--sp-lg);
  }

  .hero__sub {
    font-size: var(--fs-body-lg);
    line-height: 1.5;
    color: var(--text-secondary);
    max-width: 36rem;
    margin-bottom: var(--sp-xl);
  }

  .hero__cta {
    margin-top: var(--sp-2xl);
    display: flex;
    justify-content: center;
  }

  /* Chinese vertical hero — desktop: 3 separate columns reading right-to-left.
     Parent is horizontal flex (row-reverse so the first span is rightmost).
     Each span gets its own writing-mode so characters stack vertically
     within that column — NOT as one continuous flow across all three. */
  .hero__zh-vertical {
    display: none;
    font-family: var(--font-display-zh);
    font-weight: var(--fw-semibold);
    color: var(--text-primary);
    letter-spacing: 0.06em;
    line-height: 1;
    padding-block: var(--sp-md);
  }

  .hero__zh-vertical[data-animate] {
    transform: translateY(0) translateX(12px);
  }
  .hero__zh-vertical[data-animate].is-visible {
    transform: none;
  }

  @media (min-width: 64rem) {
    .hero__zh-vertical {
      display: flex;
      /* row-reverse so the first source span (把話想清楚) sits visually
         rightmost, read right-to-left per Traditional Chinese convention.
         In row-reverse, flex-start aligns items to the visual right edge,
         so the ZH block hugs the container's right boundary and the hero
         reads symmetrically on the viewport. */
      flex-direction: row-reverse;
      justify-content: flex-start;
      gap: var(--sp-xl);
      font-size: clamp(2.5rem, 1.2rem + 3vw, 3.5rem);
      min-height: 16rem;
    }
  }

  .hero__zh-vertical span {
    writing-mode: vertical-rl;
    text-orientation: upright;
    display: block;
    white-space: nowrap;
  }

  /* Chinese horizontal hero — mobile/tablet fallback */
  .hero__zh-horizontal {
    font-family: var(--font-display-zh);
    font-weight: var(--fw-semibold);
    color: var(--text-primary);
    font-size: clamp(1.5rem, 1rem + 2vw, 2rem);
    line-height: var(--lh-zh-body);
    padding-block: var(--sp-lg);
    max-width: 32rem;
  }

  @media (min-width: 64rem) {
    .hero__zh-horizontal {
      display: none;
    }
  }

  .hero__zh-sub {
    color: var(--text-secondary);
    font-size: var(--fs-body);
    margin-top: var(--sp-sm);
    font-family: var(--font-body-zh);
  }

  /* ZH-dominant hero variant (/zh-hant/): primary headline runs Chinese. */
  .hero__headline--zh {
    font-family: var(--font-display-zh);
    font-weight: var(--fw-semibold);
    line-height: var(--lh-zh-body);
    letter-spacing: 0;
  }

  .hero__sub--zh {
    font-family: var(--font-body-zh);
    line-height: var(--lh-zh-body);
  }

  /* English horizontal hero — fallback under ZH headline on narrow viewports. */
  .hero__en-horizontal {
    font-family: var(--font-display);
    font-weight: var(--fw-medium);
    color: var(--text-primary);
    font-size: clamp(1.375rem, 0.95rem + 1.8vw, 1.75rem);
    line-height: 1.2;
    padding-block: var(--sp-lg);
    max-width: 36rem;
  }

  @media (min-width: 64rem) {
    .hero__en-horizontal {
      display: none;
    }
  }

  .hero__en-sub {
    color: var(--text-secondary);
    font-size: var(--fs-body);
    margin-top: var(--sp-sm);
    font-family: var(--font-body);
  }

  /* ────────────────────────────────────────────────────────────────── */
  /* Belief block                                                        */
  /* ────────────────────────────────────────────────────────────────── */

  .belief__grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--sp-xl);
    max-width: 72rem;
  }

  @media (min-width: 64rem) {
    .belief__grid {
      grid-template-columns: 1fr 1fr;
      gap: var(--sp-3xl);
    }
  }

  .belief__heading {
    font-family: var(--font-display);
    font-size: clamp(2rem, 1.5rem + 2vw, 2.75rem);
    font-weight: var(--fw-medium);
    line-height: 1.15;
    letter-spacing: var(--ls-h1);
    margin-top: var(--sp-base-sm);
  }

  .belief__heading-zh {
    font-family: var(--font-display-zh);
    font-size: clamp(1.75rem, 1.4rem + 1.5vw, 2.25rem);
    font-weight: var(--fw-semibold);
    line-height: 1.3;
    margin-top: var(--sp-base-sm);
  }

  .belief__body {
    font-size: var(--fs-body-lg);
    line-height: 1.6;
    color: var(--text-secondary);
    margin-top: var(--sp-md);
    max-width: 34rem;
  }

  .belief__body-zh {
    font-family: var(--font-body-zh);
    line-height: var(--lh-zh-body);
  }

  /* ────────────────────────────────────────────────────────────────── */
  /* Principles                                                          */
  /* ────────────────────────────────────────────────────────────────── */

  .principles__list {
    display: flex;
    flex-direction: column;
    gap: var(--sp-4xl);
  }

  @media (min-width: 48rem) {
    .principles__list {
      gap: var(--sp-5xl);
    }
  }

  .principle {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--sp-xl);
    align-items: center;
  }

  @media (min-width: 48rem) {
    .principle {
      grid-template-columns: 1fr 1fr;
      gap: var(--sp-2xl);
    }
  }

  @media (min-width: 64rem) {
    .principle {
      gap: var(--sp-3xl);
      perspective: 1000px;
    }

    /* Alternate layout: even-numbered principles flip text + video */
    .principle--reverse .principle__text {
      order: 2;
    }
    .principle--reverse .principle__media {
      order: 1;
    }

    /* Media leans its inner edge toward the page centre once the article
       reaches the near-centre of the viewport. .is-tilted is added by a
       dedicated IntersectionObserver in site.js (rootMargin trims top
       and bottom by 30% so the trigger fires later than the generic
       .is-visible fade-in). */
    .principle__media {
      transform: rotateY(0);
      transform-origin: center;
      transition: transform var(--duration-slow) var(--ease-out);
    }

    .principle.is-tilted .principle__media {
      transform: rotateY(-8deg);
    }

    .principle.is-tilted.principle--reverse .principle__media {
      transform: rotateY(8deg);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .principle__media,
    .principle.is-tilted .principle__media,
    .principle.is-tilted.principle--reverse .principle__media {
      transform: none;
      transition: none;
    }
  }

  .principle__number {
    font-family: var(--font-display);
    font-size: clamp(2.5rem, 2rem + 2vw, 3.5rem);
    font-weight: var(--fw-regular);
    line-height: 1;
    color: var(--accent);
    margin-bottom: var(--sp-sm);
  }

  .principle__eyebrow {
    margin-bottom: var(--sp-base-sm);
  }

  .principle__title-en {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 1.2rem + 1.25vw, 2rem);
    font-weight: var(--fw-semibold);
    line-height: 1.2;
    letter-spacing: var(--ls-h2);
    color: var(--text-primary);
  }

  .principle__title-zh {
    font-family: var(--font-display-zh);
    font-size: clamp(1.25rem, 1.1rem + 0.6vw, 1.5rem);
    font-weight: var(--fw-semibold);
    line-height: 1.4;
    color: var(--text-secondary);
    margin-top: var(--sp-xs);
  }

  /* ZH page: principle titles reverse visual weight —
     the <h3> carries the Chinese (primary), the <p> carries English. */
  html[lang="zh-Hant"] .principle__title-zh {
    font-size: clamp(1.5rem, 1.2rem + 1.25vw, 2rem);
    color: var(--text-primary);
    margin-top: 0;
  }

  html[lang="zh-Hant"] .principle__title-en {
    font-family: var(--font-display);
    font-size: clamp(1.125rem, 1rem + 0.4vw, 1.3125rem);
    font-weight: var(--fw-medium);
    color: var(--text-secondary);
    margin-top: var(--sp-xs);
    letter-spacing: 0;
  }

  .principle__body {
    font-size: var(--fs-body);
    line-height: 1.6;
    color: var(--text-secondary);
    margin-top: var(--sp-md);
    max-width: 30rem;
  }

  /* Dark emphasis background. The .principle__* rules above live in the
     `pages` layer and beat the `layout`-layer .section--emphasis :is(h1…h4)
     rule despite lower specificity, so we have to re-state every text colour
     here. ZH page swaps the primary/secondary roles, handled below. */
  .section--emphasis .principle__title-en {
    color: var(--text-inverse);
  }

  .section--emphasis .principle__title-zh,
  .section--emphasis .principle__body {
    color: var(--neutral-200);
  }

  html[lang="zh-Hant"] .section--emphasis .principle__title-zh {
    color: var(--text-inverse);
  }

  html[lang="zh-Hant"] .section--emphasis .principle__title-en {
    color: var(--neutral-200);
  }

  /* ────────────────────────────────────────────────────────────────── */
  /* Outcomes — three auto-scrolling rows (ltr, rtl, ltr)                */
  /* Generated by scripts/build-school-marquee.py on every build         */
  /* ────────────────────────────────────────────────────────────────── */

  .schools-marquee {
    display: flex;
    flex-direction: column;
    gap: var(--sp-3xl);
    margin-top: var(--sp-2xl);
    /* Fade the left/right edges so logos drift in and out instead of
       clipping hard at the container bounds. */
    mask-image: linear-gradient(
      to right,
      transparent 0,
      black 4%,
      black 96%,
      transparent 100%
    );
    -webkit-mask-image: linear-gradient(
      to right,
      transparent 0,
      black 4%,
      black 96%,
      transparent 100%
    );
  }

  .marquee {
    overflow: hidden;
    width: 100%;
  }

  /* The track is a flex container holding the row content duplicated 6×
     (see MARQUEE_COPIES in build-school-marquee.py). All inter-item AND
     inter-group spacing comes from the track's `gap` plus a matching
     trailing padding-right, so every visible interval is identical and
     the seam between copies is invisible. KEEP `padding-right` IN SYNC
     with `gap` — that's what makes -100%/N translate cleanly to one
     copy-width. */
  .marquee__track {
    display: flex;
    width: max-content;
    gap: var(--sp-2xl);
    padding-right: var(--sp-2xl);
  }

  .marquee--ltr .marquee__track {
    animation: marquee-scroll-ltr 60s linear infinite;
  }

  .marquee--rtl .marquee__track {
    animation: marquee-scroll-rtl 60s linear infinite;
  }

  .marquee__group {
    display: flex;
    align-items: center;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: var(--sp-2xl);
  }

  /* width + min-width:0 pin every slot to exactly 10rem regardless of the
     logo's intrinsic size. Without this, flex items default to
     min-width:auto (= content min-content), and any wide SVG would inflate
     its slot, breaking the uniform spacing the marquee loop depends on. */
  .marquee__item {
    flex: 0 0 10rem;
    width: 10rem;
    min-width: 0;
    height: 4.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    list-style: none;
  }

  .outcome-logo {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
  }

  /* Translate by -100%/MARQUEE_COPIES (6 copies → -16.6667%) per cycle,
     which equals exactly one copy-slot. KEEP IN SYNC with MARQUEE_COPIES
     in scripts/build-school-marquee.py. */
  @keyframes marquee-scroll-ltr {
    /* Track shifts rightward: items appear at left, exit at right. */
    from { transform: translate3d(-16.6667%, 0, 0); }
    to { transform: translate3d(0, 0, 0); }
  }

  @keyframes marquee-scroll-rtl {
    /* Track shifts leftward: items appear at right, exit at left. */
    from { transform: translate3d(0, 0, 0); }
    to { transform: translate3d(-16.6667%, 0, 0); }
  }

  @media (prefers-reduced-motion: reduce) {
    .marquee--ltr .marquee__track,
    .marquee--rtl .marquee__track {
      animation: none;
      transform: none;
    }
    /* Without motion, hide the duplicate so overflow doesn't reveal it. */
    .marquee__group--echo {
      display: none;
    }
  }

  /* ────────────────────────────────────────────────────────────────── */
  /* Recent writing                                                      */
  /* ────────────────────────────────────────────────────────────────── */

  .recent-writing__grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--sp-xl);
  }

  @media (min-width: 48rem) {
    .recent-writing__grid {
      grid-template-columns: 1fr 1fr;
    }
  }

  .post-card {
    display: flex;
    flex-direction: column;
    gap: var(--sp-md);
    padding: var(--sp-lg);
    background: var(--bg-canvas);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    transition:
      box-shadow var(--duration-fast) var(--ease-out),
      transform var(--duration-fast) var(--ease-out);
    color: inherit;
    text-decoration: none;
  }

  .post-card:hover {
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
    color: inherit;
  }

  .post-card__meta {
    font-size: var(--fs-caption);
    color: var(--text-secondary);
  }

  .post-card__title {
    font-family: var(--font-display);
    font-size: var(--fs-h3);
    font-weight: var(--fw-semibold);
    line-height: 1.3;
    color: var(--text-primary);
  }

  .post-card__summary {
    color: var(--text-secondary);
    line-height: 1.5;
  }

  .post-card__cta {
    margin-top: auto;
    padding-top: var(--sp-sm);
  }

  /* Skeleton while fetching */
  .post-card--skeleton .post-card__title,
  .post-card--skeleton .post-card__summary {
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    color: transparent;
  }

  .post-card--skeleton .post-card__title {
    height: 2.5em;
    animation: pulse 1.5s ease-in-out infinite;
  }

  .post-card--skeleton .post-card__summary {
    height: 3em;
    animation: pulse 1.5s ease-in-out infinite;
    animation-delay: 150ms;
  }

  @keyframes pulse {
    0%,
    100% {
      opacity: 1;
    }
    50% {
      opacity: 0.6;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .post-card--skeleton .post-card__title,
    .post-card--skeleton .post-card__summary {
      animation: none;
    }
  }

  .recent-writing__all {
    margin-top: var(--sp-xl);
  }

  /* ────────────────────────────────────────────────────────────────── */
  /* Closing CTA                                                         */
  /* ────────────────────────────────────────────────────────────────── */

  .closing-cta {
    text-align: center;
  }

  .closing-cta__grid {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-lg);
    max-width: 48rem;
    margin-inline: auto;
  }

  /* At ≥48rem, render EN · button · ZH on one row with the BUTTON at the
     viewport's true horizontal center. A 3-col grid with matching 1fr outer
     columns guarantees the button sits in the middle regardless of how
     wide the EN and ZH phrases are. Source order stays EN, ZH, button;
     `order` rearranges the visual flow. */
  @media (min-width: 48rem) {
    .closing-cta__grid {
      display: grid;
      grid-template-columns: 1fr auto 1fr;
      align-items: center;
      gap: var(--sp-2xl);
      max-width: none;
    }

    .closing-cta__en {
      order: 1;
      justify-self: start;
      text-align: start;
    }
    .closing-cta__grid > div {
      order: 2;
      justify-self: center;
    }
    .closing-cta__zh {
      order: 3;
      justify-self: end;
      text-align: end;
    }
  }

  .closing-cta__en {
    font-family: var(--font-display);
    font-size: clamp(2rem, 1.5rem + 2vw, 2.75rem);
    font-weight: var(--fw-medium);
    line-height: 1.15;
    color: var(--text-inverse);
  }

  .closing-cta__zh {
    font-family: var(--font-display-zh);
    /* Matches .closing-cta__en — peer hierarchy, equal weight. */
    font-size: clamp(2rem, 1.5rem + 2vw, 2.75rem);
    font-weight: var(--fw-semibold);
    line-height: 1.15;
    color: var(--text-inverse);
    opacity: 0.95;
  }

  .closing-cta__sub {
    font-size: var(--fs-body-lg);
    color: var(--neutral-200);
    max-width: 36rem;
  }
}
