/* ============================================================
   r1 — the gate: the dot ascends.
   one ember in the dark: the full stop of r1s.ing. touch it and it rises,
   the night clears from the fire up, and the ember settles in as the
   full stop of "Hi, I'm Aarohan." the motion is driven by js/gate.js.
   ============================================================ */

/* the site waits behind the gate */
html:not(.in) { overflow: hidden; scrollbar-gutter: stable; }   /* the gutter stays put, so nothing jumps sideways when the page unlocks */
html:not(.in) .navbar, html:not(.in) main, html:not(.in) .foot, html:not(.in) .sound { visibility: hidden; }
html:not(.in) .hero .rise { animation-play-state: paused; }
/* while the ember is in the air, the headline's own full stop waits for it */
html.gate-fly .hero h1 .dot { opacity: 0; }
/* the hero rises with the ember; the nav, the clock and the sound button come after, quietly */
html.gate-entering .navbar { animation: gate-chrome 0.9s ease 0.5s both; }
html.gate-entering .hero-foot, html.gate-entering .sound { animation: gate-chrome 1s ease 0.6s both; }
@keyframes gate-chrome { from { opacity: 0; } }

.gate {
  position: fixed; inset: 0; z-index: 49;          /* under the film grain (50); over the nav (40) and the sound button (45) */
  --x: 50%; --y: 57%;                              /* where the ember rests: a little below centre, so it has room to rise */
  -webkit-tap-highlight-color: transparent;
}
.gate:not(.ready) { background: rgba(0, 0, 0, 0.9); }   /* until the sky canvas has painted */
.gate.free { pointer-events: none; }               /* once the ember has landed, the page underneath is yours */

.gate-sky, .gate-wake { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }

/* the whole screen is the way in */
.gate-go {
  position: absolute; inset: 0; width: 100%; height: 100%;
  cursor: pointer; outline: none;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* r1s.ing, light and wide. the full stop is an empty slot; the ember sits in it */
.gate-word {
  --tr: 0.46em;
  position: absolute; left: var(--x); top: var(--y);
  transform: translate(-50%, -50%);
  padding-left: var(--tr);                         /* balances the tracking after the g, so the slot is dead centre */
  font-family: var(--mono); font-weight: 300; font-size: clamp(0.92rem, 0.8rem + 0.3vw, 1.05rem); line-height: 1;
  letter-spacing: var(--tr); color: rgba(154, 150, 140, 0.82);
  white-space: nowrap;
}
.gate-slot { display: inline-block; width: 0.6em; height: 0; margin-right: var(--tr); vertical-align: baseline; }   /* one mono cell, like a real full stop */
.gate-a, .gate-b {
  display: inline-block; opacity: 0; filter: blur(3px);
  transition: opacity 0.4s ease, transform 0.6s cubic-bezier(0.3, 0, 0.2, 1), filter 0.4s ease;
}
.gate-a { transform: translateX(0.45em); }         /* they start close to the ember and settle outward, as if lit by it */
.gate-b { transform: translateX(-0.45em); }
.gate.on .gate-a, .gate.on .gate-b {
  opacity: 1; transform: none; filter: none;
  transition: opacity 1.3s ease 0.85s, transform 1.6s cubic-bezier(0.2, 0.7, 0.2, 1) 0.85s, filter 1.2s ease 0.85s;
}
/* on the way in they let go, sinking a touch as the ember leaves them */
.gate.go .gate-a, .gate.go .gate-b {
  opacity: 0; filter: blur(2px);
  transition: opacity 0.35s ease, transform 0.6s cubic-bezier(0.3, 0, 0.2, 1), filter 0.35s ease;
}
.gate.go .gate-a { transform: translate(-0.35em, 0.3em); }
.gate.go .gate-b { transform: translate(0.35em, 0.3em); }

/* ---------- the ember ----------
   .gate-dot is a copy of the headline's full stop (same face, size and box, set by the js),
   so where it lands it is pixel-for-pixel the real one. --ox/--oy is the centre of its ink. */
.gate-ember {
  position: fixed; left: 0; top: 0; width: 0; height: 0;
  transform-origin: 0 0; pointer-events: none;
  will-change: transform, opacity;
}
.gate-press {
  position: absolute; left: 0; top: 0; width: 0; height: 0;
  transform-origin: var(--ox, 0) var(--oy, 0);
  opacity: 0; scale: 0.35;
  transition: transform 0.16s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.gate.on .gate-press { animation: gate-kindle 1.5s cubic-bezier(0.2, 0.7, 0.2, 1) 0.15s both; }
.gate.go .gate-press { animation: none; opacity: 1; scale: 1; }   /* touched mid-kindle: it's lit now */
@keyframes gate-kindle {
  0% { opacity: 0; scale: 0.35; }
  35% { opacity: 1; }
  100% { opacity: 1; scale: 1; }
}

.gate-dot {
  position: absolute; left: 0; top: 0; display: block; white-space: pre;
  font-family: var(--serif); font-size: 4.6rem; line-height: 1.05; letter-spacing: -0.015em;   /* overwritten from the real one */
  color: var(--sun);
  text-shadow: 0 0 0.05em rgba(255, 240, 170, 0.85), 0 0 0.14em rgba(244, 205, 40, 0.5);
}

/* the glow around it, breathing like a coal. two layers on different clocks so it never quite repeats.
   --g is how much bigger the glow is at rest than the ember itself (the ember is small there; its light isn't) */
.gate-near {
  position: absolute; left: var(--ox, 0); top: var(--oy, 0); width: 0; height: 0;
  opacity: calc(0.72 + 0.5 * max(var(--near, 0), var(--press, 0)));
  transform: scale(calc(var(--g, 1) * (1 + 0.3 * max(var(--near, 0), var(--press, 0)))));
  transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.gate-halo {
  position: absolute; left: calc(var(--d, 10px) * -7); top: calc(var(--d, 10px) * -7);
  width: calc(var(--d, 10px) * 14); height: calc(var(--d, 10px) * 14); border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 222, 110, 0.34), rgba(244, 186, 23, 0.12) 38%, rgba(244, 160, 23, 0.03) 70%, rgba(244, 160, 23, 0));
  animation: gate-breathe 3.9s ease-in-out infinite;
}
.gate-halo-2 {
  left: calc(var(--d, 10px) * -16); top: calc(var(--d, 10px) * -16);
  width: calc(var(--d, 10px) * 32); height: calc(var(--d, 10px) * 32);
  background: radial-gradient(closest-side, rgba(244, 180, 23, 0.075), rgba(244, 160, 23, 0.025) 50%, rgba(244, 160, 23, 0));
  animation: gate-breathe-2 6.3s ease-in-out -2.1s infinite;
}
@keyframes gate-breathe { 0%, 100% { opacity: 0.6; transform: scale(0.88); } 50% { opacity: 1; transform: scale(1.05); } }
@keyframes gate-breathe-2 { 0%, 100% { opacity: 0.55; transform: scale(0.94); } 45% { opacity: 1; transform: scale(1.04); } }

/* keyboard focus: a thin ring around the ember, nothing else */
.gate-ring {
  position: absolute; left: var(--ox, 0); top: var(--oy, 0);
  width: calc(var(--d, 10px) * 3 * var(--g, 1)); height: calc(var(--d, 10px) * 3 * var(--g, 1));
  translate: -50% -50%;
  border: 1px solid var(--sun-dim); border-radius: 50%;
  opacity: 0; transform: scale(0.8);
  transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.gate-go:focus-visible ~ .gate-ember .gate-ring { opacity: 0.6; transform: none; }
.gate.go .gate-ring { opacity: 0 !important; transition-duration: 0.15s; }

/* press: the ember tightens and flares under the finger, before the click lands */
.gate-go:active ~ .gate-ember { --press: 1; }
.gate-go:active ~ .gate-ember .gate-press { transform: scale(0.86); transition-duration: 0.08s; }

/* ---------- the cue ----------
   once the word has settled: a thin ring breathes out of the ember now and then, and a quiet
   line under the word says what to do. both let go the moment you touch. */
.gate-cue { position: absolute; inset: 0; pointer-events: none; transition: opacity 0.25s ease; }
.gate.go .gate-cue { opacity: 0; }
.gate-ripple {
  position: absolute; left: var(--rx, 50%); top: var(--ry, 57%);
  width: 10px; height: 10px; translate: -50% -50%;
  border: 1px solid rgba(244, 221, 23, 0.45); border-radius: 50%;
  opacity: 0;
}
/* one slow, wide breath out of the ember every seven seconds or so */
.gate.on .gate-ripple { animation: gate-ripple 7s cubic-bezier(0.2, 0.55, 0.35, 1) 2.5s infinite; }
@keyframes gate-ripple {
  0% { width: 10px; height: 10px; opacity: 0; }
  8% { opacity: 0.32; }
  58%, 100% { width: 240px; height: 240px; opacity: 0; }
}
.gate-hint {
  position: absolute; left: var(--rx, 50%); top: calc(var(--ry, 57%) + 2.6rem);
  translate: -50% 0; padding-left: 0.34em;         /* balances the tracking */
  font-family: var(--mono); font-weight: 300; font-size: 0.66rem; line-height: 1;
  letter-spacing: 0.34em; color: rgba(154, 150, 140, 0.72); white-space: nowrap;
  opacity: 0;
}
.gate.on .gate-hint { animation: gate-hint-in 1.4s ease 2.9s forwards, gate-hint-breathe 4.2s ease-in-out 4.3s infinite; }
@keyframes gate-hint-in { to { opacity: 1; } }
@keyframes gate-hint-breathe { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
.gate-hint-tap { display: none; }
@media (hover: none), (pointer: coarse) {
  .gate-hint-click { display: none; }
  .gate-hint-tap { display: inline; }
}

@media (prefers-reduced-motion: reduce) {
  .gate *, .gate *::before, .gate *::after { animation: none !important; }
  .gate-press { opacity: 1; scale: 1; }
  .gate-a, .gate-b { opacity: 1; transform: none; filter: none; }
  .gate-halo { opacity: 0.8; }
  .gate-ripple { display: none; }
  .gate-hint { opacity: 1; }
  html.gate-entering .navbar, html.gate-entering .hero-foot, html.gate-entering .sound { animation: none; }
}
