/* ==========================================================================
   หน้าแรก — the landing page.

   welcome.webp is a fixed illustration with a hard-won empty band in it: the
   moon's lower limb reaches y ~30%, the sky is uniformly dark down to y ~62%,
   and the pampas grass starts lifting at y ~64% (measured — see
   assets/img/README.md). Every piece of copy is positioned as a percentage of
   the *stage*, not the viewport, and the stage keeps the artwork's own aspect
   ratio, so the text lands in that band on every screen instead of drifting
   into the moon on tall ones and into the grass on short ones.
   ========================================================================== */

.page-welcome {
  background: var(--sky-canvas);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.welcome {
  position: relative;
  width: 100%;
  max-width: var(--write-w);
  aspect-ratio: 941 / 1672;
  /* On a short landscape window the aspect ratio would push the stage past the
     fold; cap it by height and let the width follow. */
  max-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  isolation: isolate;
}

.welcome__art,
.welcome__grass {
  position: absolute;
  inset: 0;
  background: var(--sky-panel) url("../img/gen/welcome.webp") center / cover no-repeat;
  z-index: 0;
}

/* --- the pampas, moving ---------------------------------------------------
   Two copies of one illustration, clipped into complementary bands so nothing
   is drawn twice: sky above the seam, grass below it. The lower band is
   sheared from `transform-origin: 50% 100%`, which is what makes this read as
   grass rather than as a sliding picture — displacement is zero at the roots
   and greatest at the tips.

   Measured seams, not guessed: warm (grass) pixels are absent from 35% to 62%
   of the phone artwork and from 0% to 37% of the desktop one. Putting the cut
   in that empty band means the shear is at its largest exactly where there is
   nothing but flat sky to shear.

   scale(1.03) is the other half of it. Shearing a box pulls its top corners
   sideways and would expose a sliver of bare page at the seam; 3% of overhang
   covers that, and since the layer above draws no grass at all, the slightly
   larger grass has nothing to disagree with. */
.welcome__art   { clip-path: inset(0 0 38% 0); }
.welcome__grass {
  clip-path: inset(62% 0 0 0);
  transform-origin: 50% 100%;
  animation: pampasSway 7.5s ease-in-out infinite;
}

@keyframes pampasSway {
  0%, 100% { transform: skewX(-.5deg) scale(1.03); }
  /* A shade shorter at the far end of the lean: grass gives as it bends, and
     the tiny drop is what stops the motion reading as a rigid hinge. */
  50%      { transform: skewX(.5deg) scale(1.03) scaleY(.997); }
}

@media (prefers-reduced-motion: reduce) {
  .welcome__grass { animation: none; transform: scale(1.03); }
}

/* The phone artwork has its own moon painted in, so this layer is desktop-only
   and off by default. */
.welcome__moon { display: none; }

/* --- the stars go behind the moon -----------------------------------------
   The phone's moon is painted INTO the backdrop — into the video, and into the
   poster that stands in for it — so there is no element to stack behind. A hole
   in the star layer is the only way.

   The hole's centre and radius arrive as pixels from fitMoonHole() in
   welcome.js, which redoes the video's own `object-fit: cover` maths so the two
   crop together. The class goes on at the same moment, so a browser that never
   runs that code, or a layout where it cannot measure, gets NO mask at all and
   the stars simply cross in front of the moon.

   That fallback is the point. The previous version was an SVG data URI sized
   `cover` in the stylesheet, and when WebKit failed to resolve the <mask>
   reference inside it the layer went fully transparent — every shooting star
   vanished on phones while desktop, which has no mask, looked fine.

   Solid to .86 of the radius and fading over the rest, so a star slips out of
   sight at the limb instead of being cut off by a visible edge.

   Mobile only: past 1024px the moon is a real element and can simply be stacked
   over the stars instead. */
@media (max-width: 1023px) {
  .welcome .shooting.has-moon-hole {
    -webkit-mask-image: radial-gradient(circle var(--moon-r) at var(--moon-x) var(--moon-y),
      transparent 86%, #000 100%);
            mask-image: radial-gradient(circle var(--moon-r) at var(--moon-x) var(--moon-y),
      transparent 86%, #000 100%);
  }
}

/* ---- sparkles ----
   Behind the words, never on them: each one is placed by percentage against
   the copy box, and the six positions sit down the margins and in the corners
   where the centred lines do not reach.

   z-index 0 puts them above the scrim (-1) and below the text, which has no
   z-index of its own and so paints later in the same stacking context.

   The twinkle is deliberately slow and out of phase — every span carries its
   own --sd — because six emoji pulsing together reads as a loading state. */
.welcome__sparkles {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
.welcome__sparkles span {
  position: absolute;
  left: var(--sx);
  top: var(--sy);
  font-size: calc(15px * var(--ss, 1));
  line-height: 1;
  opacity: 0;
  /* The emoji is square and its own glyph box is what gets scaled, so the
     translate has to come first or the offset scales with it. */
  transform: translate(-50%, -50%);
  animation: sparkleTwinkle 6.5s ease-in-out infinite;
  animation-delay: var(--sd, 0s);
}

@keyframes sparkleTwinkle {
  0%, 72%, 100% { opacity: 0;   transform: translate(-50%, -50%) scale(.7); }
  12%           { opacity: .95; transform: translate(-50%, -50%) scale(1); }
  40%           { opacity: .5;  transform: translate(-50%, -50%) scale(.92); }
}

@media (prefers-reduced-motion: reduce) {
  /* Still there, just not moving: the sparkles are part of the composition, so
     removing them changes the picture rather than calming it. */
  .welcome__sparkles span { animation: none; opacity: .55; }
}

/* Just enough lift under the copy to hold contrast if the crop ever shifts a
   pampas frond up into the band. */
.welcome__copy::before {
  content: "";
  position: absolute;
  inset: -14% -12%;
  background: radial-gradient(ellipse at 50% 50%,
    rgba(8, 14, 34, .55) 0%, rgba(8, 14, 34, .28) 52%, transparent 76%);
  z-index: -1;
  pointer-events: none;
}

/* ------------------------------------------------------------------ logo */

/* REQ-02. Centred at the top on mobile, moved to the top-left on desktop by
   the >=1024 block below.

   The tap target is 44px tall even though the mark is 24px: that is the floor
   for a touch target, and padding rather than a bigger logo is how you get
   there without shouting. The art behind it is near-solid navy, so a white
   mark needs no shadow or plate to hold. */
.welcome__logo {
  position: absolute;
  z-index: 2;
  top: max(18px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 10px 12px;
}
.welcome__logo img { display: block; height: 24px; width: auto; }

/* ---- the copy block: pinned to the clear band, y 34%-60% ---- */

/* The box runs from under the moon down to exactly where the button starts —
   `bottom: 28%` is 100% minus the action's `top: 72%`. That makes the space
   between the title and the button this element's own free space, and the two
   auto margins on the copy below split free space evenly between them.

   So the gap under TSUKIMI and the gap above the button are equal by
   construction, on every screen, with no number to keep in step. They used to
   be 26px and 55px on a desktop and 20px and 124px on a phone, which is what
   made the copy look pinned to the title rather than sitting between the two. */
.welcome__copy {
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 34%;
  bottom: 28%;
  display: flex;
  flex-direction: column;
  transform: translateX(-50%);
  width: min(88%, 340px);
  text-align: center;
  isolation: isolate;
}

/* Three lines, two gaps, one number — and the gaps stay equal to each other at
   every type size because they are a `gap` and not two margins that have to be
   kept in step by hand. */
.welcome__lockup {
  display: flex;
  flex-direction: column;
  gap: clamp(7px, 2.1vw, 10px);
}

/* The two flanking lines are deliberately identical: same size, same tracking,
   same gold. It is what makes the block read as a lockup with TSUKIMI at its
   centre rather than a title with a date added underneath. */
.welcome__jp,
.welcome__year {
  font: 400 clamp(14px, 4.2vw, 17px)/1 var(--font-jp);
  letter-spacing: .3em;
  /* NO text-indent to "re-centre" this. There used to be one, equal to the
     letter-spacing, on the premise that tracking pads the right of the last
     glyph and centring therefore leans left. `text-align: center` does not
     count that trailing space, in Blink or in WebKit — measured on both: at
     text-indent 0 the glyph run's centre and the box's centre are the same
     point to within 0.00px, and every em of indent moves the run bodily
     right. So the compensation was not a correction, it WAS the offset: this
     line sat a full 0.16em right of centre, and on the poster it disagreed
     with the canvas export, which centres the tracked run by hand (see
     drawTracked in assets/js/poster.js) — so the words jumped sideways the
     moment the saved image was laid over the page. */
  color: var(--gold-a90);
}
/* พ.ศ. — digits, so the shop's own face rather than the Japanese one. */
.welcome__year {
  font-family: var(--font-en);
}

.welcome__en {
  font: 300 clamp(38px, 12.6vw, 58px)/1 var(--font-en);
  letter-spacing: .14em;
  /* No text-indent here — see the note beside the first of these. */
  color: var(--cream);
  text-shadow: 0 2px 24px rgba(6, 10, 26, .6);
}

/* THREE LINES, ONE PARAGRAPH. They are two elements for a reason — the first
   line is the lede and the two under it are the invitation — but they had two
   different type sizes and two different weights (16/400 against 15/300), which
   made the first line read as a heading over a caption rather than as the
   opening line of one thought. One font declaration for both now.

   And no margin between them. With the same line-height and nothing in between,
   the spacing of all three lines IS the leading, so the rhythm is even by
   construction instead of being a 7px margin tuned to look close to it. */
.welcome__lede,
.welcome__body {
  font: 400 clamp(14px, 4.2vw, 16px)/1.9 var(--font-thai);
  /* The sky behind this band is not uniformly dark — the moon's glow reaches
     it, and on desktop the button's gold spill comes up from below. A shadow
     the colour of the sky costs nothing where the sky is already dark and
     holds the line where it is not.

     --cream-80, not --cream-70: the last line sits closest to the button and
     its glow, and at 70% it was the first thing to wash out. */
  color: var(--cream-80);
  text-shadow: 0 1px 10px rgba(6, 10, 26, .75);
}

/* margin-top:auto here and margin-bottom:auto on the body are the whole
   mechanism — see .welcome__copy. */
.welcome__lede { margin-top: auto; }
.welcome__body { margin-bottom: auto; }

/* ---- the button: at 72%, over the grass but in the clear centre column ---- */

.welcome__action {
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 72%;
  transform: translateX(-50%);
  width: min(74%, 260px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* Paper-lantern gold, not the blue plastic pill it was. Gold is the site's
   accent everywhere else — the seals on the form, the save button, the active
   chip — so the one action on the landing page was the odd one out, and a
   cool blue on a cool navy sky had little to hold it up.

   The Japanese line above the Thai is doing the work the shape cannot: a
   wide-tracked はじめる in the same face as 月見 on the page above it. */
.welcome__cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 100%;
  padding: 12px 0 13px;
  border-radius: var(--r-pill);
  background: linear-gradient(180deg, var(--gold-lantern-1), var(--gold-lantern-2));
  color: var(--ink-moon);
  text-align: center;
  /* A warm glow rather than a drop shadow: the button sits on a night sky, and
     a dark shadow under a lit object is the wrong physics. The inset hairline
     is the lantern's own rim. */
  box-shadow:
    0 8px 26px rgba(240, 208, 122, .26),
    0 2px 6px rgba(6, 10, 26, .35),
    inset 0 1px 0 rgba(255, 250, 232, .55);
  transition: background .18s ease, box-shadow .18s ease, transform .18s ease;
}
/* Full width, centred by text-align — never a shrink-to-fit box centred by
   align-items. See the long note on .poster__head-name in
   assets/css/summary.css: a measured box collapses where the font that was
   measured is not the font that paints, and the line then runs off to one
   side by half its own width. */
.welcome__cta-jp,
.welcome__cta-th {
  width: 100%;
  text-align: center;
}

.welcome__cta-jp {
  font: 500 10px/1 var(--font-jp);
  letter-spacing: .34em;
  /* No text-indent here — see the note beside the first of these. */
  /* REQ-30. 0.62 composited this line to 3.35:1 against the button, under the
     4.5:1 that 10px type needs; 0.78 lands it at 4.93 normal and 6.11 hover.
     The Thai line was never the problem — it is 8.35:1, and the hover state
     the report measured at 1.15:1 belonged to the old blue button. */
  opacity: .78;
}
.welcome__cta-th {
  font: 500 16px/1 var(--font-thai);
  letter-spacing: .01em;
}
.welcome__cta:hover {
  background: linear-gradient(180deg, #fbeec0, #edc76a);
  /* Restated, or the blanket `a:hover` in base.css repaints this dark label
     pale gold on a pale gold button — 1.10:1, which is not a hover state, it is
     the text going out. */
  color: var(--ink-moon);
  box-shadow:
    0 10px 32px rgba(240, 208, 122, .38),
    0 2px 6px rgba(6, 10, 26, .35),
    inset 0 1px 0 rgba(255, 252, 240, .7);
  transform: translateY(-1px);
}
.welcome__cta:active { transform: translateY(1px); }

.welcome__skip {
  font: 300 12.5px/1 var(--font-sans);
  color: var(--cream-70);
  text-decoration: underline;
  text-underline-offset: 4px;
}
.welcome__skip:hover { color: var(--cream); }

/* ------------------------------------------------------- motion backdrop */

/* A <video>, not an animated image. The frames are decoded by the phone's
   hardware decoder instead of the main thread, which on a full-screen loop is
   the difference between a warm battery and a cool one — and it buys 1080p for
   less than an animated WebP of the same clip at 540p cost. */
.welcome__video { display: none; }
.welcome__patch { display: none; }

@media (max-width: 1023px) {
  .welcome__video {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Decoration. It must never take a tap meant for the button over it. */
    pointer-events: none;
  }

  /* Still art stays underneath as the fallback for a device that blocks
     autoplay, and as the thing on screen while the video is still arriving. */
  .welcome__art { clip-path: none; }

  .welcome__patch {
    display: block;
    position: absolute;
    left: 0;
    top: 0;
    z-index: 1;
    width: 20%;
    height: 7.5%;
    pointer-events: none;
    background: radial-gradient(120% 130% at 0 0,
      rgb(2, 12, 44) 0 52%, rgba(2, 12, 44, 0) 82%);
  }

  /* The artwork animates its own pampas; the CSS shear would be a second
     motion fighting the first on the same fronds. */
  .welcome__grass { display: none; }
}

/* A video cannot be paused from CSS, so reduced motion gets the still artwork
   and the element goes away entirely — with it hidden, autoplay never starts. */
@media (max-width: 1023px) and (prefers-reduced-motion: reduce) {
  .welcome__video,
  .welcome__patch { display: none; }
}

/* ------------------------------------------------------------- < 1024px */

/* Full-bleed on a phone. The stage used to keep the artwork's own 941:1672
   aspect, so a 390x844 screen got a 390x693 picture with 76px of flat sky above
   and below it — a letterbox that reads as a loading bug rather than a frame.

   Going edge to edge is safe for the copy, and that is not luck: every phone is
   *taller* in aspect than the art (0.46 vs 0.56), so `cover` matches the height
   exactly and spends the difference on the width. Every vertical percentage the
   copy is positioned with survives untouched; what is lost is about 5% of
   pampas off each side, which is edge filler.

   lvh on the stage — the LARGE viewport, toolbar retracted — so the picture is
   drawn taller than the part of the screen the browser leaves uncovered, and
   the bottom of it lives under the toolbar.

   This box used to be sized from the VISUAL viewport instead (`--welcome-vh`,
   which welcome.js measures). That is by definition the area a toolbar does
   NOT cover, so the artwork's bottom edge was the toolbar's top edge and it
   could not reach past it; what showed in the leftover strip was flat
   --sky-canvas, and iOS Safari's floating bar does not cover all of it. The
   reasoning behind that choice was "Safari's bottom bar is chrome, not an
   overlay on the page, so nothing can be painted beneath it", which was true of
   the old opaque bar and is not true of the floating one — every other page
   here already shows content running under it, because their background is on
   <body> and a body background paints the whole canvas. Only this page opts out
   of that, because its picture is a <div> inside a height-locked stage rather
   than a background on the root.

   Nothing needs to move to make room. Every offset in here is a percentage of
   this box, so the copy, the button and the artwork all scale together and the
   composition is identical — what changes is only how much of the frame the
   toolbar hides. The bottom 12-15% is pampas and ground; the button sits at
   72%, which clears a Safari-sized bar by ~75px and the tallest in-app browser
   chrome measured (LINE) by ~50px. Do not push .welcome__action past ~80%
   without re-checking that.

   The document is still allowed to reach 100lvh while only the visual viewport
   is on screen, and that difference is the scroll range Safari/LINE need before
   they will collapse their toolbar at all. The stage stays sticky so it does
   not slide away during that swipe. */
@media (max-width: 1023px) {
  /* Keep horizontal overflow locked, but leave the vertical root scrollable.
     Safari only retracts its browser chrome in response to a real scroll. */
  html {
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--sky-canvas);
  }

  .page-welcome {
    height: auto;
    min-height: 100vh;
    min-height: 100lvh;
    align-items: flex-start;
    justify-content: flex-start;
    overflow: visible;
  }

  .welcome {
    position: sticky;
    top: 0;
    flex: 0 0 auto;
    max-width: none;
    width: 100%;
    aspect-ratio: auto;
    height: 100vh;
    height: 100lvh;
    max-height: none;
  }
}

/* Home-screen web apps have no collapsible browser toolbar, so they do not
   need the lvh scroll runway. Keep that mode completely still and full-screen. */
@media (max-width: 1023px) and (display-mode: standalone) {
  html { overflow: hidden; }

  .page-welcome {
    height: var(--welcome-vh, 100dvh);
    min-height: 0;
    overflow: hidden;
  }

  .welcome { position: relative; }
}

/* ============================================================== desktop === */

/* The phone art is a 941x1672 portrait; this is a different composition, not
   the same picture letterboxed — moon top-centre, pampas down both edges,
   rabbits bottom-right. The copy sits in the band measured clear of all of it
   (x 28%-72%, y 40%-74%), so the stage stops being a phone-shaped panel and
   becomes the whole viewport. */
@media (min-width: 1024px) {
  .page-welcome { padding: 0; background: var(--sky-void); }

  .welcome {
    max-width: none;
    aspect-ratio: auto;
    max-height: none;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }

  /* The desktop illustration is a different composition: the pampas reaches
     much higher (first warm pixel at 37.6%, against 64% on the phone), so the
     seam moves up with it. The moon is its own element up at 21% and is not
     part of either band, so it never shears. */
  /* Landscape art for >= 1024px: a different composition, not the portrait
     one re-cropped. It ships WITHOUT its moon, which is laid over it as its own
     element below — the moon was painted into the old welcome-desktop.webp with
     its centre at x 53.75% while the copy centres at 50%, so the two never
     lined up and no amount of background-position could fix it without dragging
     the rabbits and the pampas along too. */
  .welcome__art,
  .welcome__grass { background-image: url("../img/gen/welcome-desktop-nomoon.webp"); }

  /* 23%, not 37%, and the difference is `cover`. The desktop stage is the whole
     window, so on anything wider than 16:9 the artwork is scaled to the width
     and cropped top and bottom — which pulls every element percentage toward
     the middle of the image. At 3440x900 element-37% lands on image-42%, well
     inside the pampas, and the seam would cut fronds in half.

     A centred crop maps element f to image 0.5 + (f - 0.5) * k, with k the
     visible fraction and k <= 1. Solving for image <= 37.6% at the worst k this
     layout can produce (0.465) gives f <= 23.3%. At k = 1 it is 23%, which is
     still empty sky. One number that holds from a laptop to an ultrawide. */
  .welcome__art   { clip-path: inset(0 0 77% 0); }
  .welcome__grass { clip-path: inset(23% 0 0 0); }

  /* Centred on the same axis as the copy, which is the whole reason the moon
     is a separate element now.
     
     translateY is -49.04%, not -50%: the disc's centre sits that far down its
     own canvas (the glow is not quite symmetric), so translating by half the
     element's height would leave the *disc* about 1% low. Horizontally the disc
     is dead centre, so -50% is exact.

     The width is 16.2vw because the disc is 80% of the canvas and the original
     composition drew it at 12.94% of the frame — 12.94 / 0.8. Clamped so it
     stays a moon rather than a coin on a small laptop or a sun on an ultrawide.
     Sized in vw and placed in %, which keeps it in the sky band the no-moon
     artwork leaves empty across every desktop aspect. */
  .welcome__moon {
    display: block;
    position: absolute;
    /* Above .shooting (1), so the falling stars pass behind the moon here the
       way the mask makes them on a phone. Safe at 2 alongside the logo: the
       logo is in the top-left corner on this tier and the moon is centred. */
    z-index: 2;
    left: 50%;
    top: 21.4%;
    width: clamp(190px, 16.2vw, 330px);
    aspect-ratio: 1;
    /* 1254px original; the bright disc is 80% of the canvas and the rest is
       the glow it is painted with, so an element sized W shows a disc of 0.8W.
       Its centre sits at (50.00%, 49.04%) of the canvas — the 0.96% is
       compensated for wherever the moon has to land on an exact point. */
    background: url("../img/gen/moon.webp") center / contain no-repeat;
    /* moon.png's alpha steps rather than fades at its rim (250 to 53 across two
       percent of the width), which on a plain sky shows as an outline. The
       drop-shadows put light outside that cut, in the shape of the moon's own
       alpha, so the edge has somewhere to fade into. */
    filter:
      drop-shadow(0 0 16px rgba(255, 240, 190, .30))
      drop-shadow(0 0 46px rgba(240, 208, 122, .18));
    transform: translate(-50%, -49.04%);
    /* Not the shared `bob`: its keyframes set transform outright and would drop
       the centring on frame one. */
    animation: moonDrift 9s ease-in-out infinite;
  }

  @keyframes moonDrift {
    0%, 100% { transform: translate(-50%, -49.04%); }
    50%      { transform: translate(-50%, calc(-49.04% - 7px)); }
  }

  @media (prefers-reduced-motion: reduce) {
    .welcome__moon { animation: none; }
  }

  /* REQ-02: 32px from both edges, 32px tall. translateX is cleared because it
     is no longer centred on anything. */
  .welcome__logo {
    top: 32px;
    left: 32px;
    transform: none;
    padding: 0;
    min-width: 0;
    min-height: 0;
  }
  .welcome__logo img { height: 32px; }

  .welcome__copy {
    top: 40%;
    /* Tracks .welcome__action's top on this tier, which is 74%. */
    bottom: 26%;
    width: min(44%, 620px);
  }
  /* The band is genuinely clear, so the scrim only has to take the edge off
     the sky's own texture. */
  .welcome__copy::before { inset: -10% -14%; opacity: .55; }

  .welcome__jp,
  .welcome__year { font-size: 19px; }
  .welcome__en { font-size: clamp(58px, 5.4vw, 84px); }
  /* margin-top stays auto — only the type changes on this tier. */
  /* One size for the three lines here too, and one leading. */
  .welcome__lede,
  .welcome__body { font-size: 17px; line-height: 2.05; }

  .welcome__action {
    top: 74%;
    width: min(30%, 320px);
    gap: 18px;
  }
  .welcome__cta { padding: 17px 0; font-size: 17px; }
  .welcome__skip { font-size: 13.5px; }
}
