/* ==========================================================================
   Kaikawaka.com — "You shouldn't be here"
   A cold, dark room with one dim light left on. Something is watching.
   ========================================================================== */

@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;500;600;700&display=swap");

:root {
  --void: #010207;
  --deep: #040a1c;
  --blue: #3a6fd8;
  --sky: #86b2e0;
  --ice: #cfe0f5;
  --mist: #6f89b3;
  --glow: rgba(60, 110, 220, 0.3);

  --font: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", sans-serif;

  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   Base + atmosphere
   -------------------------------------------------------------------------- */

html {
  height: 100%;
  background-color: var(--void);
  background-image:
    /* the one dim light in the room */
    radial-gradient(ellipse 60% 45% at 50% 40%, rgba(30, 62, 140, 0.3) 0%, transparent 100%),
    linear-gradient(175deg, #02040c 0%, #050c24 55%, #0a0822 100%);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(2rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right))
    max(2rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.75rem, 3vh, 1.5rem);
  text-align: center;
  overflow-x: hidden;

  font-family: var(--font);
  color: var(--ice);

  /* The page surfaces out of total darkness. */
  animation: awaken 4s ease-out both;
}

/* Everything real sits above the atmosphere layers. */
body > * {
  position: relative;
  z-index: 1;
  margin: 0;
}

/* Slow fog with a layer of film grain on top of it */
body::before {
  content: "";
  position: fixed;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(40% 30% at 20% 30%, rgba(60, 100, 220, 0.1), transparent 70%),
    radial-gradient(35% 28% at 80% 60%, rgba(100, 85, 210, 0.08), transparent 70%),
    radial-gradient(70% 30% at 50% 100%, rgba(25, 55, 150, 0.22), transparent 75%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .65 0 0 0 0 1 0 0 0 .14 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: drift 40s ease-in-out infinite alternate;
}

/* Vignette: the edges of the room are swallowed by darkness.
   It slowly tightens and relaxes, as if the room is breathing. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 22%, rgba(0, 0, 0, 0.96) 100%);
  animation: dread 8s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   Eyes in the dark
   Two pairs that open, blink, and vanish at different intervals.
   Tap the button and they snap open and stare for as long as you hold it.
   -------------------------------------------------------------------------- */

html::before,
html::after {
  content: "";
  position: fixed;
  z-index: 1;
  pointer-events: none;
  width: 10px;
  height: 6px;
  border-radius: 50%;
  background: var(--sky);
  /* first eye + its glow, second eye (32px over) + its glow */
  box-shadow:
    0 0 6px 1px var(--glow),
    32px 0 0 0 var(--sky),
    32px 0 6px 1px var(--glow);
  opacity: 0;
}

html::before {
  top: 74%;
  left: 7%;
  animation: lurk 23s linear infinite;
}

html::after {
  top: 19%;
  right: 12%;
  animation: lurk 34s linear 9s infinite;
}

html:has(#tapButton:active)::before,
html:has(#tapButton:active)::after {
  animation: none;
  opacity: 0.95;
}

/* --------------------------------------------------------------------------
   Title — a light that is not doing well
   -------------------------------------------------------------------------- */

#title {
  font-size: clamp(2rem, 9vw, 4.75rem);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: 0.06em;
  overflow-wrap: anywhere;
  color: var(--ice);
  filter: drop-shadow(0 0 18px rgba(60, 110, 220, 0.25)) drop-shadow(0 3px 3px rgba(0, 0, 0, 0.8));
  animation: flicker 11s linear infinite;
}

/* --------------------------------------------------------------------------
   Tagline — it arrives late, once you've already noticed the quiet
   -------------------------------------------------------------------------- */

#tagLine {
  font-size: clamp(1rem, 4.2vw, 1.35rem);
  font-weight: 300;
  letter-spacing: 0.24em;
  color: var(--mist);
  animation:
    surface 4s ease-out 3s both,
    breathe 6s ease-in-out 7s infinite;
}

/* --------------------------------------------------------------------------
   Counter — the one thing on the page that feels alive
   -------------------------------------------------------------------------- */

#counter {
  min-width: 2ch;
  margin-block: clamp(0.5rem, 2vh, 1.25rem) clamp(0.75rem, 3vh, 1.5rem);
  font-size: clamp(4.5rem, 20vw, 8.5rem);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: lining-nums tabular-nums;
  overflow-wrap: anywhere;
  color: var(--sky);
  filter: drop-shadow(0 0 16px rgba(60, 110, 220, 0.3)) drop-shadow(0 4px 4px rgba(0, 0, 0, 0.8));
  user-select: none;
  -webkit-user-select: none;
  animation: heartbeat 6s ease-in-out infinite;
  transition: filter 0.6s ease-out; /* slow fade after the flash */
}

/* The number flares the instant you press, then cools off */
html:has(#tapButton:active) #counter {
  filter: drop-shadow(0 0 30px rgba(120, 180, 255, 0.75)) drop-shadow(0 4px 4px rgba(0, 0, 0, 0.8))
    brightness(1.35);
  transition-duration: 0s;
}

/* Gradient fill for the big type (falls back to flat colour if unsupported) */
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  #title {
    background-image: linear-gradient(180deg, #dbe8fa 5%, #8aa9d6 55%, #3f62ab 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
  }

  #counter {
    background-image: linear-gradient(180deg, #c4dcf5 10%, #6f9fe0 60%, #4a63c4 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
  }
}

/* --------------------------------------------------------------------------
   Button — a dark slab with real weight to it
   It rests on a ledge. Press it and it drops into the page, light blooms
   beneath the surface, a shockwave rolls outward, and it springs back up.
   -------------------------------------------------------------------------- */

#tapButton {
  --ledge: #0e1946; /* the visible "thickness" under the slab */

  /* reset */
  appearance: none;
  -webkit-appearance: none;
  margin: 0;

  font-family: var(--font);
  font-size: 1.15rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: lowercase;
  color: var(--ice);

  min-width: 10.5rem;
  min-height: 3.75rem;
  padding: 1rem 2.75rem;
  /* letter-spacing adds trailing space; balance it so "tap" looks centred */
  padding-left: calc(2.75rem + 0.14em);

  background-image: linear-gradient(135deg, rgba(58, 111, 216, 0.22) 0%, rgba(10, 12, 40, 0.8) 100%);
  background-color: rgba(3, 6, 20, 0.9);
  border: 1px solid rgba(134, 178, 224, 0.28);
  border-radius: 18px;

  /* Four layers, always in this order, so every state can animate into every other:
     ledge, cast shadow, top highlight, inner shade */
  box-shadow:
    0 6px 0 var(--ledge),
    0 14px 26px rgba(0, 0, 0, 0.8),
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 -8px 14px rgba(0, 0, 0, 0.45);

  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* no double-tap zoom while tapping fast */
  user-select: none;
  -webkit-user-select: none;

  /* Release: a springy overshoot, so it pops back up and settles */
  transition:
    transform 0.45s cubic-bezier(0.2, 1.7, 0.4, 1),
    box-shadow 0.3s ease-out,
    filter 0.3s ease,
    border-color 0.3s ease;
}

/* Idle: a slow ring radiates outward like sonar. Begging to be pressed. */
#tapButton::after {
  content: "";
  position: absolute;
  inset: -1px;
  border: 1px solid rgba(134, 178, 224, 0.5);
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  animation: ping 4s ease-out infinite;
}

/* Light that blooms under the surface on press, then fades like an afterimage */
#tapButton::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1; /* above the slab's background, below its label */
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(
    ellipse 70% 120% at 50% 50%,
    rgba(142, 197, 255, 0.6) 0%,
    rgba(58, 111, 216, 0.25) 45%,
    transparent 75%
  );
  opacity: 0;
  transform: scale(0.7);
  transition:
    opacity 0.6s ease-out,
    transform 0.6s ease-out;
}

/* Anticipation: on devices with a mouse it lifts slightly and glows from below */
@media (hover: hover) {
  #tapButton:hover {
    transform: translateY(-2px);
    filter: brightness(1.35);
    border-color: rgba(134, 178, 224, 0.6);
    box-shadow:
      0 8px 0 var(--ledge),
      0 20px 36px rgba(30, 70, 200, 0.35),
      inset 0 1px 0 rgba(255, 255, 255, 0.14),
      inset 0 -8px 14px rgba(0, 0, 0, 0.45);
  }
}

/* Press: fast and hard. It drops onto its ledge and the surface goes concave. */
#tapButton:active {
  transform: translateY(5px) scale(0.985, 0.96);
  filter: brightness(1.3);
  border-color: var(--sky);
  box-shadow:
    0 1px 0 var(--ledge),
    0 3px 8px rgba(0, 0, 0, 0.85),
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    inset 0 8px 16px rgba(0, 0, 0, 0.55);
  /* transform, box-shadow, filter, border-color */
  transition-duration: 0.04s, 0.04s, 0s, 0s;
}

#tapButton:active::before {
  opacity: 1;
  transform: scale(1.05);
  transition-duration: 0.05s;
}

/* A shockwave on every press */
#tapButton:active::after {
  border-color: rgba(190, 225, 255, 0.9);
  animation: burst 0.5s ease-out;
}

#tapButton:focus-visible {
  outline: 2px solid var(--sky);
  outline-offset: 8px;
}

/* --------------------------------------------------------------------------
   Short landscape screens (phones on their side)
   -------------------------------------------------------------------------- */

@media (max-height: 480px) {
  body {
    gap: 0.5rem;
  }
  #counter {
    font-size: clamp(3rem, 14vh, 5rem);
    margin-block: 0.25rem;
  }
  #tapButton {
    min-height: 3.25rem;
    padding-block: 0.75rem;
  }
}

/* --------------------------------------------------------------------------
   Keyframes
   -------------------------------------------------------------------------- */

@keyframes awaken {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes drift {
  from {
    transform: translate3d(-4%, -2%, 0) scale(1);
  }
  to {
    transform: translate3d(4%, 3%, 0) scale(1.15);
  }
}

@keyframes dread {
  0%,
  100% {
    opacity: 0.8;
  }
  50% {
    opacity: 1;
  }
}

/* Stutters, one brief blackout, and a small glitch */
@keyframes flicker {
  0%,
  11%,
  14%,
  16%,
  38%,
  42%,
  66%,
  69%,
  90%,
  100% {
    opacity: 1;
    transform: none;
  }
  12%,
  15% {
    opacity: 0.2;
  }
  40% {
    opacity: 0.55;
  }
  67% {
    opacity: 0.05;
  }
  68% {
    opacity: 0.7;
  }
  91% {
    opacity: 0.8;
    transform: translateX(-4px) skewX(-3deg);
  }
  92% {
    opacity: 1;
    transform: translateX(4px) skewX(3deg);
  }
  93% {
    transform: translateX(-1px);
  }
  94% {
    transform: none;
  }
}

/* The tagline loosens out of the dark, then pulses faintly */
@keyframes surface {
  from {
    opacity: 0;
    filter: blur(8px);
  }
  to {
    opacity: 0.5;
    filter: blur(0);
  }
}

@keyframes breathe {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 0.95;
  }
}

/* Slow, uneven: two beats, a long wait, then it stumbles */
@keyframes heartbeat {
  0%,
  34%,
  100% {
    transform: scale(1);
  }
  6% {
    transform: scale(1.04);
  }
  12% {
    transform: scale(1);
  }
  17% {
    transform: scale(1.03);
  }
  23% {
    transform: scale(1);
  }
}

@keyframes ping {
  0% {
    opacity: 0.45;
    transform: scale(1);
  }
  70%,
  100% {
    opacity: 0;
    transform: scale(1.25, 1.5);
  }
}

@keyframes burst {
  from {
    opacity: 0.9;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(1.5, 2.1);
  }
}

/* Eyes: hidden → open → blink → stare → blink → gone */
@keyframes lurk {
  0%,
  40% {
    opacity: 0;
    transform: scaleY(1);
  }
  42% {
    opacity: 0.9;
  }
  44% {
    transform: scaleY(0.08);
  }
  45% {
    transform: scaleY(1);
  }
  50% {
    opacity: 0.9;
    transform: scaleY(1);
  }
  51% {
    transform: scaleY(0.08);
  }
  52% {
    opacity: 0.9;
    transform: scaleY(1);
  }
  54%,
  100% {
    opacity: 0;
  }
}

/* --------------------------------------------------------------------------
   Jumpscare — built by jumpscare.js when the counter reaches 100
   Lights out → silence → eyes slam in with a flash and a shake → fade back
   -------------------------------------------------------------------------- */

.scare {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(1rem, 4vmin, 2.5rem);
  background: #000;
  overflow: hidden;
  cursor: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  animation: scareDark 0.25s ease-in both; /* the lights cut out */
}

/* One white-blue flash at the moment of impact */
.scare::before {
  content: "";
  position: absolute;
  inset: 0;
  background: #dcecff;
  opacity: 0;
  pointer-events: none;
}

.scare-eyes {
  width: min(125vw, 170vh);
  max-width: none;
  height: auto;
  opacity: 0;
  filter: drop-shadow(0 0 40px rgba(110, 170, 255, 0.8));
}

.scare-text {
  margin: 0;
  padding: 0 1rem;
  text-align: center;
  font-family: var(--font);
  font-size: clamp(1.5rem, 6.5vw, 3rem);
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ice);
  text-shadow: 0 0 24px rgba(60, 110, 220, 0.7);
  opacity: 0;
}

/* Impact */
.scare.boom::before {
  animation: scareFlash 0.4s ease-out both;
}

.scare.boom .scare-eyes {
  opacity: 1;
  animation:
    scareLunge 0.14s cubic-bezier(0.2, 0.9, 0.3, 1) both,
    scareShake 0.07s linear 0.14s infinite;
}

.scare.boom .scare-text {
  animation: scareDark 0.25s ease-out 0.5s both;
}

/* Leaving: the dark lifts and the page is back, slightly different */
.scare.out {
  animation: scareOut 0.7s ease-in both;
}

/* Reduced-motion version: no flash, shake or zoom. Everything just appears. */
.scare.calm.boom .scare-text {
  opacity: 1;
}

@keyframes scareDark {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes scareOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes scareFlash {
  from {
    opacity: 0.95;
  }
  to {
    opacity: 0;
  }
}

@keyframes scareLunge {
  from {
    opacity: 1;
    transform: scale(0.12);
  }
  70% {
    opacity: 1;
    transform: scale(1.18);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes scareShake {
  0%,
  100% {
    transform: translate(-7px, 3px) rotate(-0.4deg);
  }
  25% {
    transform: translate(6px, -4px) rotate(0.5deg);
  }
  50% {
    transform: translate(-4px, -6px) rotate(-0.3deg);
  }
  75% {
    transform: translate(7px, 4px) rotate(0.4deg);
  }
}

/* --------------------------------------------------------------------------
   Respect reduced-motion preferences (keeps the mood, drops the movement)
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  /* with animations off the tagline would otherwise sit at full opacity */
  #tagLine {
    opacity: 0.7;
  }
}
