/* Quiet motion for the public pages. Everything here is decoration: with it removed, or with
   reduced motion asked for, every page reads and works the same. Phone sizes come first. */

/* ── Buttons and cards answer a touch or a pointer ── */
.portal-choice, .teacher-templates-promo, .feat-mini { transition: transform .25s cubic-bezier(.2,.7,.2,1), box-shadow .25s ease; }
.portal-character { transition: transform .35s cubic-bezier(.2,.7,.2,1); }
.portal-choice:active, .teacher-templates-promo:active { transform: scale(.985); }
.btn:active, .upload-btn:active, .tool-chip:active { transform: scale(.97); }
@media (hover: hover) {
  .portal-choice:hover { transform: translateY(-4px); box-shadow: 0 14px 30px rgba(141,27,61,.16), 0 0 0 2px rgba(201,168,76,.6); }
  .portal-choice:hover .portal-character { transform: translateY(-3px) scale(1.03); }
  .teacher-templates-promo:hover { transform: translateY(-4px); box-shadow: 0 16px 34px rgba(141,27,61,.16); }
}

/* ── Sections rise a shorter distance on a phone, where a long travel reads as lag ── */
@media (max-width: 640px) { .reveal { transform: translateY(14px); } }

/* ── The Doha skyline is drawn in from its edge once its band comes into view ── */
.cta-skyline.reveal .skyline-img { clip-path: inset(0 100% 0 0); }
.cta-skyline.reveal.visible .skyline-img { clip-path: inset(0 0 0 0); transition: clip-path 1.9s cubic-bezier(.3,.6,.3,1) .35s; }

/* ── Result tabs: three fit a phone, and a pill slides to the chosen one ── */
.result-tabs { position: relative; }
.result-tabs button { position: relative; z-index: 1; }
.result-tabs .tab-pill { position: absolute; z-index: 0; top: 5px; left: 0; height: calc(100% - 10px); border-radius: 10px;
  background: var(--card); box-shadow: 0 3px 12px rgba(141,27,61,.12); transition: transform .32s cubic-bezier(.3,.7,.2,1), width .32s cubic-bezier(.3,.7,.2,1); }
.result-tabs.has-pill button.active { background: transparent; box-shadow: none; }
@media (max-width: 640px) {
  .result-tabs { overflow-x: visible; }
  .result-tabs button { min-width: 0; padding: 11px 4px; font-size: .84rem; gap: 4px; }
  .result-tabs button svg { display: none; }
  /* A small round button in the corner instead of a wide one across the text. */
  .tool-page .feedback-fab, .example-library ~ .feedback-fab { left: 12px; bottom: 12px; width: 48px; height: 48px; padding: 0; justify-content: center; font-size: 0; gap: 0; }
}

/* ── Waiting for a lesson: an open book turning its pages, right to left like an Arabic book ── */
.book-loader { position: relative; width: 88px; height: 58px; margin: 4px auto 20px; perspective: 460px; }
.book-loader::before, .book-loader::after, .book-loader i { content: ""; position: absolute; top: 0; width: 50%; height: 100%; box-sizing: border-box;
  border: 2px solid var(--maroon); background: linear-gradient(90deg, #fff, #FBF3DF); }
.book-loader::before, .book-loader i { left: 0; border-radius: 10px 3px 3px 10px; border-inline-start-color: var(--gold); }
.book-loader::after { right: 0; border-radius: 3px 10px 10px 3px; }
.book-loader i { transform-origin: right center; opacity: 0; }

@media (prefers-reduced-motion: no-preference) {
  .book-loader i { animation: nibras-page-turn 2.1s cubic-bezier(.45,.05,.3,1) infinite; }
  .book-loader i:nth-child(2) { animation-delay: .7s; }
  .book-loader i:nth-child(3) { animation-delay: 1.4s; }
  @keyframes nibras-page-turn {
    0% { transform: rotateY(0); opacity: 0; }
    12% { opacity: 1; }
    62% { transform: rotateY(180deg); opacity: 1; }
    100% { transform: rotateY(180deg); opacity: 0; }
  }

  /* ── Home page: the opening lines arrive one after another, inside the first second ── */
  .landing-v3 .hero-v3-text > * { animation: nibras-rise .6s cubic-bezier(.2,.7,.2,1) both; }
  .landing-v3 .hero-v3-text > :nth-child(2) { animation-delay: .06s; }
  .landing-v3 .hero-v3-text > :nth-child(3) { animation-delay: .2s; }
  .landing-v3 .hero-v3-text > :nth-child(4) { animation-delay: .28s; }
  .landing-v3 .hero-v3-text > :nth-child(5) { animation-delay: .36s; }
  .landing-v3 .hero-v3-text > :nth-child(n+6) { animation-delay: .44s; }
  .landing-v3 .hero-v3 h1 .maroon-word, .landing-v3 .hero-v3 h1 .gold-word { display: inline-block; animation: nibras-rise .7s cubic-bezier(.2,.7,.2,1) both; }
  .landing-v3 .hero-v3 h1 .maroon-word { animation-delay: .08s; }
  .landing-v3 .hero-v3 h1 .gold-word { animation-delay: .2s; }
  @keyframes nibras-rise { from { opacity: 0; transform: translateY(14px); } }

  /* ── The lighthouse light turns slowly behind the logo ── */
  .landing-v3 .hero-v3-art { container-type: inline-size; --logo-w: min(100cqw, 340px); }
  .lighthouse-beam, .lighthouse-glow { position: absolute; left: 50%; top: 50%; pointer-events: none; border-radius: 50%; }
  /* The lantern sits 21% down the logo, so 0.2155 of the logo's width above its center. */
  .lighthouse-beam { z-index: 0; width: calc(var(--logo-w) * 2.3); height: calc(var(--logo-w) * 2.3);
    margin: calc(var(--logo-w) * -1.15 - var(--logo-w) * .2155) 0 0 calc(var(--logo-w) * -1.15);
    background: conic-gradient(from 78deg, transparent 0deg, rgba(201,168,76,.34) 9deg, transparent 22deg, transparent 180deg, rgba(201,168,76,.34) 189deg, transparent 202deg);
    -webkit-mask-image: radial-gradient(circle, #000 12%, transparent 68%); mask-image: radial-gradient(circle, #000 12%, transparent 68%);
    animation: nibras-beam-turn 18s linear infinite; }
  .lighthouse-glow { z-index: 2; width: calc(var(--logo-w) * .2); height: calc(var(--logo-w) * .2);
    margin: calc(var(--logo-w) * -.1 - var(--logo-w) * .2155) 0 0 calc(var(--logo-w) * -.1);
    background: radial-gradient(circle, rgba(255,236,170,.85), rgba(255,236,170,0) 68%); animation: nibras-glow 3.6s ease-in-out infinite; }
  @keyframes nibras-beam-turn { to { transform: rotate(360deg); } }
  @keyframes nibras-glow { 0%, 100% { opacity: .35; transform: scale(.9); } 50% { opacity: .9; transform: scale(1.15); } }

  /* On a phone the large logo is not shown, so a soft beam sweeps the top of the page from the logo in the bar. */
  @media (max-width: 860px) {
    .landing-v3 .hero-v3-text { z-index: 1; }
    .landing-v3 .hero-v3::after { content: ""; position: absolute; z-index: 0; top: 40px; right: 44px; width: 170vw; height: 170vw; margin: -85vw -85vw 0 0;
      pointer-events: none; border-radius: 50%;
      background: conic-gradient(from 0deg, transparent 0deg, rgba(201,168,76,.2) 10deg, transparent 24deg);
      -webkit-mask-image: radial-gradient(circle, #000 6%, transparent 62%); mask-image: radial-gradient(circle, #000 6%, transparent 62%);
      animation: nibras-beam-sweep 9s ease-in-out infinite alternate; }
    @keyframes nibras-beam-sweep { from { transform: rotate(182deg); } to { transform: rotate(252deg); } }
  }

  /* ── Phone menu: its rows arrive one after another as the card opens ── */
  @media (max-width: 860px) {
    #navLinks.open > * { animation: nibras-menu-row .36s cubic-bezier(.2,.7,.2,1) both; }
    #navLinks.open > :nth-child(1) { animation-delay: .04s; }
    #navLinks.open > :nth-child(2) { animation-delay: .08s; }
    #navLinks.open > :nth-child(3) { animation-delay: .12s; }
    #navLinks.open > :nth-child(4) { animation-delay: .16s; }
    #navLinks.open > :nth-child(5) { animation-delay: .2s; }
    #navLinks.open > :nth-child(6) { animation-delay: .24s; }
    #navLinks.open > :nth-child(n+7) { animation-delay: .28s; }
    @keyframes nibras-menu-row { from { opacity: 0; transform: translateX(14px); } }
  }

  ::view-transition-old(root), ::view-transition-new(root) { animation-duration: .24s; }
  .nav .approved-logo { view-transition-name: nibras-brand; }
}

/* ── Moving between pages: a short cross-fade while the logo stays where it is ──
   The opt-in itself is a one-line <style> at the top of each page, allowed by its hash in the content security policy.
   The browser reads it before the page body; from a stylesheet it arrives too late on a real network and the
   transition is dropped. Reduced motion is honored here by switching the transition's own animations off. */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
