* {
  box-sizing: border-box;
}

:root {
  /* Color — ocean surface to abyss */
  --ink: #e6f3f8;
  --ink-dim: #9fc6d6;
  --ink-faint: #8fb2c2;
  --surface-cyan: #2aa6b7;
  --surface-cyan-bright: #4fc9da;
  --bg-void: #062331;
  --bg-surface: #0a3346;
  --border-subtle: #1c4a5e;
  --focus-ring: 0 0 0 3px rgba(79, 201, 218, 0.35);
  --glass: rgba(8, 40, 56, 0.45);
  --color-info: #f2a65a;
  --color-error: #ff8a8a;

  /* Depth zone — set and tweened by parallax.js */
  --zone-bg-start: #2393ae;
  --zone-bg-end: #0d5a73;
  --zone-accent: #d4f6ff;
  --zone-rays-opacity: 1;

  /* Spacing (4px base) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;

  /* Radius */
  --radius-md: 0.6rem;
  --radius-pill: 999px;

  /* Type scale */
  --font-size-xs: 0.8rem;
  --font-size-sm: 0.9rem;
  --font-size-display: clamp(2rem, 5vw, 3.25rem);

  /* Elevation */
  --shadow-md: 0 1rem 3rem rgba(0, 0, 0, 0.45);

  /* Motion (from the animate skill: strong curves, not the built-ins) */
  --duration-fast: 150ms;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);

  /* Layout: room the fixed chrome takes from the stage */
  --chrome-top: 6.5rem;
  --chrome-bottom: 9.5rem;
}

html {
  color-scheme: dark;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: "Source Serif 4", Georgia, serif;
  background: var(--bg-void);
  color: var(--ink);
}

h1,
h2 {
  font-family: "Fraunces", Georgia, serif;
  font-optical-sizing: auto;
  margin: 0;
  text-wrap: balance;
}

button {
  min-height: 2.75rem;
  border: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition:
    background var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
}

button:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ---- The ocean ---- */

#ocean {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.ocean-bg {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, var(--zone-bg-start), var(--zone-bg-end));
}

/* Generated depth plates, crossfaded by --plate-N-opacity (see parallax.js).
   They stack cumulatively: each fades in over the one below, so there is never
   a moment where the gradient shows through a half-faded plate. Oversized like
   the other layers so pointer parallax never reveals an edge. A missing file
   just leaves the layer transparent and the gradient below carries the scene. */
.ocean-plate {
  position: absolute;
  inset: -10%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0;
  will-change: opacity;
}

.ocean-plate[data-plate="0"] {
  background-image: image-set(url("assets/zone-0.avif") type("image/avif"), url("assets/zone-0.webp") type("image/webp"));
  opacity: var(--plate-0-opacity, 0);
}

.ocean-plate[data-plate="1"] {
  background-image: image-set(url("assets/zone-1.avif") type("image/avif"), url("assets/zone-1.webp") type("image/webp"));
  opacity: var(--plate-1-opacity, 0);
}

.ocean-plate[data-plate="2"] {
  background-image: image-set(url("assets/zone-2.avif") type("image/avif"), url("assets/zone-2.webp") type("image/webp"));
  opacity: var(--plate-2-opacity, 0);
}

.ocean-plate[data-plate="3"] {
  background-image: image-set(url("assets/zone-3.avif") type("image/avif"), url("assets/zone-3.webp") type("image/webp"));
  opacity: var(--plate-3-opacity, 0);
}

.ocean-plate[data-plate="4"] {
  background-image: image-set(url("assets/zone-4.avif") type("image/avif"), url("assets/zone-4.webp") type("image/webp"));
  opacity: var(--plate-4-opacity, 0);
}

/* The shader canvas draws caustics and god rays over the plates. `screen` so
   it only ever adds light, never darkens — the abyss plate stays black. */
#water {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  mix-blend-mode: screen;
}

#particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ---- Brand + depth readout ---- */

.brand {
  text-shadow: 0 1px 12px rgba(2, 18, 26, 0.85), 0 1px 3px rgba(2, 18, 26, 0.7);
  position: fixed;
  top: calc(var(--space-5) + env(safe-area-inset-top));
  left: calc(var(--space-5) + env(safe-area-inset-left));
  z-index: 4;
}

.brand h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#zone-readout {
  margin: var(--space-1) 0 0;
  font-size: var(--font-size-xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--zone-accent);
}

/* ---- Stage: the one creature on screen ---- */

/* Snap-scrolls one creature per screen; parallax.js reads the scroll
   position to blend the water between depths. The gauge shows position,
   so the scrollbar itself is hidden. */
#stage {
  position: fixed;
  inset: 0;
  z-index: 2;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
}

#stage::-webkit-scrollbar {
  display: none;
}

body.is-diving #stage {
  overflow: hidden;
}

.slide {
  height: 100%;
  display: grid;
  place-items: center;
  padding: var(--chrome-top) clamp(4rem, 6vw, 6rem) var(--chrome-bottom);
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.creature-card {
  width: min(64rem, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: clamp(1.5rem, 4vw, 3.5rem);
  align-items: center;
}

.creature-card.no-photo {
  grid-template-columns: minmax(0, 40rem);
  justify-content: center;
}

.card-media {
  margin: 0;
}

.card-media img {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(62svh, 36rem);
  object-fit: cover;
  border-radius: var(--radius-md);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.08),
    var(--shadow-md),
    0 0 60px -12px var(--zone-accent);
}

.card-media figcaption {
  margin-top: var(--space-2);
  font-size: var(--font-size-xs);
  color: var(--ink-faint);
}

.card-text {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: min(62svh, 36rem);
}

.eyebrow {
  margin: 0 0 var(--space-2);
  font-size: var(--font-size-xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--zone-accent);
}

.card-text h2 {
  margin-bottom: var(--space-4);
  font-size: var(--font-size-display);
  line-height: 1.05;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.scientific-name {
  margin: calc(-1 * var(--space-2)) 0 var(--space-4);
  font-style: italic;
  color: var(--ink-dim);
}

.description {
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding-right: var(--space-2);
  line-height: 1.65;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

.description:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-md);
}

/* ---- Console: search bar floating in the water ---- */

/* Positioned with inset + margin rather than transforms, so GSAP owns
   transform freely for the bob, the plunge and the dock. */
#console {
  position: fixed;
  z-index: 5;
  inset: 0;
  margin: auto;
  width: min(36rem, calc(100% - 2 * var(--space-4)));
  height: fit-content;
  text-align: center;
}

#console.is-docked {
  inset: auto 0 calc(var(--space-5) + env(safe-area-inset-bottom)) 0;
  margin: 0 auto;
}

.surface-copy h2 {
  margin-bottom: var(--space-6);
  font-size: var(--font-size-display);
  line-height: 1.05;
  letter-spacing: -0.02em;
}

/* Frosted glass: light catches its top edge. Never put `filter` on an
   ancestor persistently — that would break this backdrop blur. */
#search-form {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-5);
  border-radius: var(--radius-pill);
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-top-color: rgba(255, 255, 255, 0.3);
  box-shadow: var(--shadow-md);
  transition:
    border-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
}

#search-form:focus-within {
  border-color: rgba(79, 201, 218, 0.6);
  box-shadow:
    var(--shadow-md),
    var(--focus-ring),
    0 0 48px -8px rgba(79, 201, 218, 0.55);
}

#prompt-input {
  flex: 1;
  min-width: 0;
  padding: var(--space-2) 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  outline: none;
}

#prompt-input::placeholder {
  color: var(--ink-faint);
}

#submit-btn {
  padding: 0 var(--space-5);
  border-radius: var(--radius-pill);
  background: var(--surface-cyan);
  color: var(--bg-void);
}

#submit-btn:active {
  transform: scale(0.96);
}

#status {
  min-height: 1.5rem;
  margin: var(--space-2) 0 0;
  font-size: var(--font-size-sm);
  color: var(--color-info);
}

#status[data-type="error"] {
  color: var(--color-error);
}

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.prompt-chip {
  padding: var(--space-2) var(--space-4);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font-size: var(--font-size-sm);
  font-weight: 400;
}

.prompt-chip:active {
  transform: scale(0.96);
}

/* ---- Depth gauge ---- */

#depth-gauge {
  position: fixed;
  z-index: 4;
  top: 0;
  bottom: 0;
  right: calc(var(--space-4) + env(safe-area-inset-right));
  height: fit-content;
  margin: auto 0;
}

/* ponytail: markers are fixed 44px targets, so ~12 finds fit on a laptop
   screen before the rail runs off; compress spacing if people dive deeper. */
#depth-gauge ol {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  padding: var(--space-2) 0;
  list-style: none;
}

#depth-gauge ol::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: rgba(255, 255, 255, 0.2);
}

.gauge-marker {
  position: relative;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  background: transparent;
}

.gauge-marker:focus-visible {
  box-shadow: none;
}

.gauge-dot {
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--marker-accent);
  border-radius: 50%;
  background: var(--bg-void);
  transition:
    transform var(--duration-fast) var(--ease-out),
    background var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
}

.gauge-marker[aria-current] .gauge-dot {
  background: var(--marker-accent);
  transform: scale(1.3);
  box-shadow: 0 0 12px var(--marker-accent);
}

.gauge-marker:focus-visible .gauge-dot {
  box-shadow: var(--focus-ring);
}

.gauge-label {
  position: absolute;
  top: 50%;
  right: 100%;
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  background: rgba(3, 20, 29, 0.75);
  color: var(--ink);
  font-size: var(--font-size-xs);
  font-weight: 400;
  letter-spacing: 0.06em;
  white-space: nowrap;
  opacity: 0;
  transform: translate(4px, -50%);
  pointer-events: none;
  transition:
    opacity var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

.gauge-marker:focus-visible .gauge-label {
  opacity: 1;
  transform: translate(0, -50%);
}

/* Hover effects only where hover is real: taps fire false hovers. */
@media (hover: hover) and (pointer: fine) {
  #submit-btn:hover {
    background: var(--surface-cyan-bright);
  }

  .prompt-chip:hover {
    border-color: var(--surface-cyan-bright);
    background: rgba(79, 201, 218, 0.14);
  }

  .gauge-marker:hover .gauge-dot {
    transform: scale(1.3);
  }

  .gauge-marker:hover .gauge-label {
    opacity: 1;
    transform: translate(0, -50%);
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Small screens ---- */

@media (max-width: 760px) {
  :root {
    --chrome-top: 5.5rem;
    --chrome-bottom: 8.75rem;
  }

  .brand {
    top: calc(var(--space-4) + env(safe-area-inset-top));
    left: calc(var(--space-4) + env(safe-area-inset-left));
  }

  .slide {
    padding-left: var(--space-4);
    padding-right: 3.25rem;
  }

  .creature-card {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4);
  }

  .card-media img {
    max-height: 28svh;
  }

  .card-text {
    max-height: calc(100svh - 28svh - var(--chrome-top) - var(--chrome-bottom) - 3.5rem);
  }

  #depth-gauge {
    right: env(safe-area-inset-right);
  }

  .gauge-label {
    display: none;
  }
}

/* ---- Preferences ---- */

@media (prefers-reduced-motion: reduce) {
  #submit-btn:active,
  .prompt-chip:active {
    transform: none;
  }
}

@media (prefers-reduced-transparency: reduce) {
  #search-form {
    background: var(--bg-surface);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}
