/* ============================================================
   LANDING GATE — "wvdh" over a honeycomb of doors
   ------------------------------------------------------------
   ~20 BIG hexagons tessellated into one opaque dark-green sheet
   over the live site. Flipping a hex punches a hexagonal window
   through to the portfolio underneath — the tiles are doors, not
   decoration.

   ⚠ Once .is-ready lands, #gate must stay TRANSPARENT and there
   must be no full-screen overlay (vignette, noise, glow). The hexes
   ARE the cover; any layer above them tints every reveal. Depth is
   done per-tile via --face lightness, set in JS by distance from
   centre. #gate IS opaque before .is-ready — for the ~1.5s the grid
   is assembling there are gaps between the arriving hexes, and a
   transparent gate would strobe the bright site through them.

   ⚠ The single face uses backface-visibility:hidden, so past 90°
   nothing is painted and you see straight through. Do NOT add a
   solid back face "to finish the flip" — that seals the door.

   ⚠ clip-path must live on the FACES, never on .hx-in — a
   clip-path on a transform-style:preserve-3d element flattens it
   in WebKit and the flip goes 2D.

   Earlier version built the wordmark out of ~1250 small hexes and
   ran at 20fps (112fps with the grid hidden); per-tile perspective
   was the biggest single cost. The wordmark is real type now and
   the tile count is ~2% of that, so perspective is affordable.
   ============================================================ */

#gate {
  --g-bg: #0b1a13;          /* deepest green-black            */
  --g-tile: #16301f;        /* hex fill, centre               */
  --g-tile-far: #0e2116;    /* hex fill, screen edge          */
  --g-line: #27452f;        /* hairline between hexes         */
  --g-sage: #6d9078;        /* site accent                    */
  --g-cream: #f5f1eb;       /* off-white                      */

  --hw: 280px;              /* hex width  (set by JS)         */
  --hh: 323px;              /* hex height (set by JS)         */
  --flip-ms: 720ms;
  --ease: cubic-bezier(0.32, 0.72, 0.24, 1);

  position: fixed;
  inset: 0;
  z-index: 99999;
  background: var(--g-bg);  /* see ⚠ above — dropped once .is-ready */
  overflow: hidden;
  cursor: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

/* No JS (or a broken gate script) must never lock anyone out: the
   attribute is only ever set by the inline head script. */
#gate { display: none; }
html[data-gate="on"] #gate { display: block; }

/* The sheet is continuous now, so the ground can drop away and the
   opened hexes become real windows onto the page underneath. */
#gate.is-ready { background: transparent; }

html[data-gate="on"],
html[data-gate="on"] body {
  overflow: hidden;
  overscroll-behavior: none;
}

/* ---------- the honeycomb ---------- */

.gate-grid {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.hx {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--hw);
  height: var(--hh);
  transform: translate3d(var(--tx), var(--ty), 0);
  perspective: 1400px;
}

.hx-in {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform var(--flip-ms) var(--ease);
}

.hx-in::before,
.hx-in::after {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* ::before is the hairline — scaled slightly OVER its neighbours so
   sub-pixel seams can't leak the bright site through the sheet. */
.hx-in::before {
  background: var(--g-line);
  transform: scale(1.014);
}

/* ::after is the fill, inset just enough to leave the hairline showing */
.hx-in::after {
  background: var(--face, var(--g-tile));
  transform: scale(0.9945);
}

.hx.is-flipped .hx-in {
  transform: rotateX(calc(180deg * var(--dir, 1)));
}

/* Deliberate deviation from junni: their panels sweep OVER the logotype,
   because logo and tiles share one 3D space. Here the wordmark stays on
   top and always legible — .gate-grid's own z-index makes it a stacking
   context, so a hex can never rise above .gate-ui anyway. Raising a
   flipped hex's z-index does nothing; don't add it back. */

/* ---------- assemble-in ---------- */

.gate-grid.is-building .hx {
  opacity: 0;
  animation: hx-arrive 760ms var(--ease) forwards;
  animation-delay: var(--in-delay, 0ms);
}

@keyframes hx-arrive {
  from { opacity: 0; transform: translate3d(var(--tx), var(--ty), -520px); }
  to   { opacity: 1; transform: translate3d(var(--tx), var(--ty), 0); }
}

/* ---------- wordmark ---------- */

.gate-ui {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
}

.gate-word {
  margin: 0;
  font-family: 'Space Grotesk', 'IBM Plex Sans', system-ui, sans-serif;
  font-weight: 700;
  font-size: clamp(4.5rem, 19vw, 17rem);
  line-height: 0.86;
  letter-spacing: -0.045em;
  color: var(--g-cream);
  opacity: 0;
  animation: gate-word-in 1000ms var(--ease) 260ms forwards;
}

@keyframes gate-word-in {
  from { opacity: 0; transform: translateY(18px) scale(0.97); filter: blur(6px); }
  to   { opacity: 1; transform: none; filter: blur(0); }
}

.gate-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: clamp(38px, 8vh, 84px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.gate-prompt {
  margin: 0;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  letter-spacing: 0.22em;
  color: rgba(245, 241, 235, 0.66);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  animation: gate-fade-up 700ms ease 1100ms forwards;
}

.gate-prompt-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--g-sage);
  box-shadow: 0 0 10px rgba(109, 144, 120, 0.9);
  animation: gate-pulse 1.8s ease-in-out infinite;
}

.gate-sub {
  margin: 0;
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 10.5px;
  letter-spacing: 0.16em;
  color: rgba(245, 241, 235, 0.3);
  opacity: 0;
  animation: gate-fade-up 700ms ease 1320ms forwards;
}

@keyframes gate-fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes gate-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.35; transform: scale(0.72); }
}

/* Keyboard entry — hidden until focused, so the gate is never a trap. */
.gate-skip {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translate(-50%, -180%);
  z-index: 6;
  pointer-events: auto;
  padding: 10px 18px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--g-bg);
  background: var(--g-cream);
  border: 0;
  border-radius: 2px;
  cursor: pointer;
  transition: transform 220ms ease;
}
.gate-skip:focus-visible {
  transform: translate(-50%, 0);
  outline: 2px solid var(--g-sage);
  outline-offset: 3px;
}

/* ---------- hold ring + cursor ---------- */

.gate-ring {
  position: fixed;
  left: 0;
  top: 0;
  width: 76px;
  height: 76px;
  margin: -38px 0 0 -38px;
  z-index: 5;
  pointer-events: none;
  transform: translate3d(var(--rx, 50vw), var(--ry, 50vh), 0);
  opacity: 0;
  transition: opacity 220ms ease;
}
.gate-ring.is-live { opacity: 1; }

.gate-ring circle {
  fill: none;
  stroke-width: 2;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}
.gate-ring .ring-track { stroke: rgba(245, 241, 235, 0.18); }
.gate-ring .ring-fill {
  stroke: var(--g-cream);
  stroke-linecap: round;
  /* circumference of r=36 ≈ 226.19 — JS drives stroke-dashoffset */
  stroke-dasharray: 226.19;
  stroke-dashoffset: 226.19;
  filter: drop-shadow(0 0 6px rgba(109, 144, 120, 0.85));
}

.gate-dot {
  position: fixed;
  left: 0;
  top: 0;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: var(--g-cream);
  z-index: 5;
  pointer-events: none;
  transform: translate3d(var(--rx, 50vw), var(--ry, 50vh), 0);
  transition: opacity 200ms ease;
}

.gate-target {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 80px;
  height: 80px;
  margin: -40px 0 0 -40px;
  z-index: 4;
  display: none;
  border-radius: 50%;
  border: 1px solid rgba(245, 241, 235, 0.24);
  background: rgba(11, 26, 19, 0.5);
  pointer-events: auto;
  cursor: pointer;
}
.gate-target::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: var(--g-sage);
  box-shadow: 0 0 14px rgba(109, 144, 120, 0.9);
  animation: gate-pulse 1.8s ease-in-out infinite;
}

/* ---------- exit ---------- */

/* Only the chrome fades. The hexes must NOT fade — they're already
   swinging open, and fading them turns a door into a dissolve. */
#gate.is-leaving .gate-ui,
#gate.is-leaving .gate-dot,
#gate.is-leaving .gate-ring {
  transition: opacity 420ms ease;
  opacity: 0;
}

/* ---------- touch ---------- */

@media (hover: none), (pointer: coarse) {
  #gate { cursor: default; }
  .gate-dot { display: none; }
  .gate-target { display: block; }
  .gate-ring {
    position: absolute;
    left: 50%;
    transform: none;
    margin: -38px 0 0 -38px;
  }
  /* Parked below the wordmark, not dead-centre: at 50% the target's
     translucent disc sits on top of "wvdh" and muddies the letterforms. */
  .gate-target,
  .gate-ring { top: 68%; }
}

@media (max-width: 768px) {
  .gate-prompt { font-size: 11px; letter-spacing: 0.18em; }
  .gate-word { font-size: clamp(3.5rem, 26vw, 9rem); }
  .gate-foot { bottom: clamp(28px, 7vh, 60px); }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .hx-in { transition: none; }
  .gate-grid.is-building .hx { opacity: 1; animation: none; }
  .gate-word,
  .gate-prompt,
  .gate-sub { opacity: 1; animation: none; filter: none; transform: none; }
  .gate-prompt-dot,
  .gate-target::after { animation: none; }
}
