:root {
  color-scheme: dark;
  background: #060813;
  color: #ecf5ff;
  font: 16px/1.5 system-ui, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --row-height: 48px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  position: relative;
  margin: 0;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: calc(30px + var(--rows, 4) * var(--row-height)) 24px;
  overflow-x: clip;
  background: radial-gradient(ellipse at 50% 30%, #152640, #060813 72%);
}

.scene { position: relative; perspective: 1200px; width: min(100%, 580px); }
main {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: clamp(20px, 4vw, 32px) clamp(16px, 5vw, 40px);
  text-align: center;
  background: #0a1020;
  border: 1px solid #293b55;
  border-radius: 24px;
  box-shadow: 0 28px 90px #0007;
  /* A real two-sided card: each face hides its back, so neither shows mirrored mid-turn. */
  transform-style: preserve-3d;
  transition: transform .6s cubic-bezier(.45, .05, .25, 1);
}
main.flipped { transform: rotateY(180deg); }
h1 { margin: 0; }
.brand { display: block; width: min(100%, 330px); height: auto; margin: -20px auto -27px; }
.email {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-top: 8px;
  min-height: 32px;
  color: #afc7e9;
  font: 500 clamp(13px, 3.6vw, 16px)/1.5 var(--mono);
  text-decoration: none;
}
.email svg { flex-shrink: 0; }
.email:hover { color: #fff; text-decoration: underline; text-underline-offset: 4px; }
.email:focus-visible, .clownfish:focus-visible { outline: 2px solid #afc7e9; outline-offset: 4px; }

/* The lanes sit outside the turning card, with one shark in each row. */
.lane {
  position: absolute;
  left: 50%;
  width: 100vw;
  height: calc(var(--rows, 4) * var(--row-height));
  transform: translateX(-50%);
  overflow: hidden;
  pointer-events: none;
}
.lane-top { bottom: calc(100% + 12px); }
.lane-bottom { top: calc(100% + 12px); }
.shark {
  position: absolute;
  left: 0;
  top: var(--depth);
  width: var(--size);
  opacity: var(--opacity);
  animation: swim var(--duration) linear var(--delay) infinite;
}
.shark img { display: block; width: 100%; height: auto; image-rendering: pixelated; animation: bob var(--bob-duration, 2s) steps(4, end) var(--bob-delay, 0s) infinite alternate; }
.lane-bottom .shark { animation-direction: reverse; }
.lane-bottom img { scale: -1 1; }
@keyframes swim { from { transform: translateX(-90px); } to { transform: translateX(calc(100vw + 5px)); } }
@keyframes bob { to { transform: translateY(-5px); } }

/* Horizontal travel and wave motion are nested so the hit target follows the fish. */
.fish-track { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.fish-drift {
  position: absolute;
  top: calc(50% - 22px);
  left: 0;
  width: 60px;
  height: 44px;
  animation: fish-swim 22s linear -3s infinite;
}
.clownfish {
  display: block;
  width: 60px;
  height: 44px;
  padding: 5px 0;
  border: 0;
  background: none;
  cursor: pointer;
  pointer-events: auto;
  animation: fish-wave 6s ease-in-out -1s infinite;
}
.clownfish svg { display: block; width: 100%; height: 100%; }
.fish-track:has(.clownfish:focus-visible) { z-index: 2; }
@keyframes fish-swim { from { transform: translateX(-85px); } to { transform: translateX(100vw); } }
@keyframes fish-wave { 0%, 100% { transform: translateY(-28px); } 50% { transform: translateY(28px); } }

.card-front, .card-back { -webkit-backface-visibility: hidden; backface-visibility: hidden; }
/* Visibility only keeps the hidden face out of reach; the turn itself hides it.
   The face being revealed appears at once, the one leaving goes after the turn. */
.card-front { visibility: visible; transition: visibility 0s; }
.card-back {
  position: absolute;
  inset: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  visibility: hidden;
  transform: rotateY(180deg);
  transition: visibility 0s .6s;
  pointer-events: none;
}
main.flipped .card-front { visibility: hidden; transition: visibility 0s .6s; }
main.flipped .card-back { visibility: visible; transition: visibility 0s; }
.card-back svg { display: block; width: min(100%, 240px); height: auto; min-height: 0; flex-shrink: 1; }
.build-caption {
  flex-shrink: 0;
  margin: 0;
  color: #afc7e9;
  font: 400 clamp(13px, 3.4vw, 16px)/1.5 var(--mono);
  letter-spacing: .015em;
}

/* The blueprint begins as the turn finishes, then resolves into three ribbons. */
main.flipped .reveal-outline { animation: trace 1.1s ease .4s both; }
main.flipped .ribbon { animation: assemble .55s cubic-bezier(.2, .7, .2, 1) both; }
main.flipped .ribbon:nth-of-type(1) { --x: -20px; --y: 0px; animation-delay: 1.1s; }
main.flipped .ribbon:nth-of-type(2) { --x: 0px; --y: 20px; animation-delay: 1.4s; }
main.flipped .ribbon:nth-of-type(3) { --x: 20px; --y: 0px; animation-delay: 1.7s; }
main.flipped .ready { animation: ready .35s ease 2.35s both; }
main.flipped .build-caption {
  -webkit-mask-image: linear-gradient(to right, #000 35%, transparent 65%);
  mask-image: linear-gradient(to right, #000 35%, transparent 65%);
  -webkit-mask-size: 300% 100%;
  mask-size: 300% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  animation: caption-reveal 1.1s ease 1.15s both;
}
@keyframes trace { from { stroke-dashoffset: 1; opacity: 0; } to { stroke-dashoffset: 0; opacity: .65; } }
@keyframes assemble { from { opacity: 0; transform: translate(var(--x), var(--y)); } to { opacity: 1; transform: translate(0, 0); } }
@keyframes ready { from { opacity: .15; } to { opacity: 1; } }
@keyframes caption-reveal {
  from { -webkit-mask-position: 100% 0; mask-position: 100% 0; }
  to { -webkit-mask-position: 0% 0; mask-position: 0% 0; }
}

@media (max-width: 600px) {
  /* Narrower card leaves wider gutters where the fish swims in the open and can be tapped. */
  .scene { width: min(calc(100% - 64px), 300px); }
  main { padding: 14px 8px; }
  .email { font-size: clamp(12.5px, 3.9vw, 16px); letter-spacing: .02em; gap: 6px; }
  .build-caption { font-size: clamp(14px, 4.2vw, 17px); letter-spacing: .03em; white-space: nowrap; }
}

