/* Deep Sea Dive — minimalist storybook.

   Flat muted palette, paper grain, glassmorphic UI that inverts as the water
   darkens, and depth-driven cross-faded water gradient. */

:root {
  /* UI ink + paper. The scene is dark from the very first frame, so the UI
     starts light-on-dark and only cools slightly as the water goes black. */
  --ink: #e6e0d4;
  --ink-soft: #a49d90;
  --paper: #efe9dd;
  --glass: rgba(232, 226, 214, 0.12);
  --glass-line: rgba(232, 226, 214, 0.22);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --font: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua",
    Georgia, "Times New Roman", serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  /* The scene is a fixed full-bleed stage; nothing scrolls natively. */
  overflow: hidden;
  background: #0a1a20;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  /* Stop the browser claiming drags for back-swipe or pinch-zoom. */
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

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

.grain-defs {
  position: absolute;
  width: 0;
  height: 0;
}

/* ------------------------------------------------------- depth gradient */

.water {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: #2f2d29;
}

/* Each stop is one flat layer, faded in as depth passes its threshold. */
.water-layer {
  position: absolute;
  inset: 0;
  background: var(--c);
  opacity: 0;
  will-change: opacity;
}

/* ------------------------------------------------------------- rays */

.rays {
  position: fixed;
  inset: 0;
  z-index: 1;
  /* screen, not overlay: overlay over a near-black ground is almost invisible,
     and the reference reads its light as additive glow. */
  mix-blend-mode: screen;
  pointer-events: none;
  /* JS scales this down to 0 by ~200m. */
  opacity: 1;
  will-change: opacity;
}

.ray {
  position: absolute;
  top: -12%;
  left: var(--x);
  width: var(--w);
  height: 130%;
  background: linear-gradient(
    180deg,
    rgba(255, 252, 240, var(--o)) 0%,
    rgba(255, 252, 240, calc(var(--o) * 0.55)) 34%,
    rgba(255, 252, 240, 0) 78%
  );
  filter: blur(14px);
  transform-origin: 50% 0%;
  animation: sway var(--d) ease-in-out infinite alternate;
}

@keyframes sway {
  from {
    transform: rotate(-1.4deg) scaleY(0.98);
  }
  to {
    transform: rotate(1.4deg) scaleY(1.04);
  }
}

/* ------------------------------------------------------------- stage */

.stage {
  position: fixed;
  inset: 0;
  z-index: 2;
  touch-action: none;
}

#sea {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* Paper grain: a single fixed noise tile over the whole scene. */
.grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
  mix-blend-mode: overlay;
}

/* ------------------------------------------------------------- glass */

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  border: 1px solid var(--glass-line);
  box-shadow: var(--shadow);
  color: var(--ink);
}

.hud {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

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

.gauge {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 999px;
}

.gauge-track {
  position: relative;
  width: 3px;
  height: min(46vh, 300px);
  border-radius: 999px;
  background: currentColor;
  opacity: 0.24;
}

/* The sea surface, pinned to the top of the gauge so the scale has an anchor. */
.gauge-surface {
  position: absolute;
  left: -6px;
  right: -6px;
  top: -1px;
  height: 1px;
  background: currentColor;
  opacity: 0.7;
}

.gauge-marker {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -50%);
  will-change: transform;
}

.gauge-readout {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: baseline;
  gap: 1px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  border: 1px solid var(--glass-line);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* A tiny diver riding the scale: depth becomes a place, not a number. */
.gauge-diver {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 15px;
  height: 15px;
  transform: translate(-160%, -50%);
  color: var(--ink);
  opacity: 0.9;
}

.gauge-diver svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
  stroke: none;
}

.gauge-readout strong {
  font-size: 0.98rem;
  font-weight: 500;
  letter-spacing: 0;
}

.gauge-readout em {
  font-style: normal;
  font-size: 0.68rem;
  color: var(--ink-soft);
}

.gauge-zone {
  max-width: 108px;
  font-size: 0.92rem;
  line-height: 1.2;
  color: var(--ink);
}

.discovered {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.slash {
  color: var(--ink-soft);
  margin: 0 1px;
}

/* ------------------------------------------------------- zone banner */

.zone-banner {
  position: absolute;
  left: 50%;
  top: 24%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s var(--ease);
  color: var(--ink);
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.25);
}

.zone-banner[data-open="true"] {
  opacity: 1;
}

.zone-banner-name {
  font-size: 1.5rem;
  letter-spacing: 0.01em;
}

.zone-banner-depth {
  font-size: 0.82rem;
  color: var(--ink-soft);
}

/* ---------------------------------------------------------- name card */

.name-card {
  position: fixed;
  left: 50%;
  bottom: max(30px, env(safe-area-inset-bottom));
  z-index: 5;
  width: min(86vw, 420px);
  padding: 16px 22px 18px;
  border-radius: 20px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%) translateY(14px);
  transition:
    opacity 0.4s var(--ease),
    transform 0.4s var(--ease);
}

.name-card[data-open="true"] {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.name-card-name {
  display: block;
  font-size: 1.45rem;
  letter-spacing: 0.01em;
}

.name-card-fact {
  display: block;
  margin-top: 5px;
  font-size: 0.92rem;
  line-height: 1.4;
  color: var(--ink-soft);
}

/* ------------------------------------------------------------- sound */

.sound {
  position: fixed;
  right: 16px;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 5;
  width: 46px;
  height: 46px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  cursor: pointer;
  color: var(--ink);
}

.sound svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sound .cross {
  display: none;
  fill: none;
}

.sound[aria-pressed="false"] .wave {
  display: none;
}

.sound[aria-pressed="false"] .cross {
  display: block;
}

/* --------------------------------------------------------------- gate */

.gate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(24, 23, 21, 0.78);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: opacity 0.6s var(--ease);
}

.gate[data-open="false"] {
  opacity: 0;
  pointer-events: none;
}

.gate-inner {
  text-align: center;
  padding: 24px;
  color: #e6e0d4;
}

.gate-title {
  margin: 0 0 8px;
  font-size: clamp(2rem, 8vw, 3.2rem);
  font-weight: 400;
  letter-spacing: 0.01em;
}

.gate-sub {
  margin: 0 0 26px;
  max-width: 26ch;
  font-size: 1rem;
  line-height: 1.5;
  color: #a49d90;
}

.gate-btn {
  appearance: none;
  border: 1px solid rgba(230, 224, 212, 0.35);
  background: #efe9dd;
  color: #1c1c1a;
  font: inherit;
  font-size: 1.06rem;
  letter-spacing: 0.02em;
  padding: 13px 34px;
  border-radius: 999px;
  cursor: pointer;
  transition:
    transform 0.25s var(--ease),
    box-shadow 0.25s var(--ease);
}

.gate-btn:active {
  transform: scale(0.97);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

@media (prefers-reduced-motion: reduce) {
  .ray {
    animation: none;
  }
  .zone-banner,
  .name-card,
  .gate,
  .gate-btn {
    transition-duration: 0.01ms;
  }
}
