/* =========================================================================
   Below the Surface — styles
   The ocean is the interface: fixed environment layers behind native,
   freely scrolling content. Editorial type, generous negative space.
   ========================================================================= */

:root {
  --ink: #e6f2f7;
  --ink-dim: #a7c2ce;
  --ink-faint: #6f94a3;
  --accent: #7ee8d8;
  --accent-soft: #9fdcf2;
  --panel: rgba(3, 16, 26, 0.42);
  --panel-line: rgba(159, 220, 242, 0.22);
  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --hud-w: 180px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: #04283c; /* JS blends this continuously by depth */
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- fixed environment layers ---------------- */

#bg, #sunglow {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
#bg { background: linear-gradient(#7fd4ee, #04364f); }
#sunglow {
  background:
    radial-gradient(60% 42% at 50% -6%, rgba(255, 255, 244, 0.85), rgba(255, 255, 244, 0) 70%),
    radial-gradient(38% 20% at 50% 0%, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 75%);
  opacity: 1;
  transition: opacity 0.4s linear;
}
#oceanfx {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  width: 100vw;
  height: 100vh;
  display: block;
}

main { position: relative; z-index: 2; }

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

/* ---------------- persistent depth indicator (HUD) ---------------- */

.hud {
  position: fixed;
  left: 0; top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px 8px 10px;
  pointer-events: none;
}
.hud-rail { width: 34px; }
.rail-track {
  position: relative;
  height: min(46vh, 380px);
  width: 4px;
  margin: 0 auto;
  border-radius: 4px;
  background: linear-gradient(#aee6f7, #06283f 45%, #010910);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.rail-tick {
  position: absolute;
  left: 50%;
  width: 10px; height: 2px;
  transform: translateX(-50%);
  background: rgba(230, 242, 247, 0.55);
  border-radius: 2px;
}
.rail-tick-label {
  position: absolute;
  left: 16px;
  transform: translateY(-50%);
  font-size: 9px;
  letter-spacing: 0.06em;
  color: rgba(167, 194, 206, 0.75);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.rail-marker {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -50%);
  width: 16px; height: 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(2, 12, 20, 0.5);
  border: 1px solid rgba(158, 232, 247, 0.5);
  transition: top 0.15s linear;
}
.rail-marker-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent-soft);
  box-shadow: 0 0 8px rgba(159, 220, 242, 0.9);
}
.hud-readout {
  background: rgba(2, 14, 22, 0.55);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 10px 14px;
  min-width: 118px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.hud-depth {
  font-family: var(--serif);
  font-size: 24px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.hud-zone {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--accent-soft);
  margin-top: 4px;
}
.hud-sub {
  margin-top: 6px;
  font-size: 11px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.hud-sep { margin: 0 5px; opacity: 0.5; }

/* ---------------- typography & layout ---------------- */

main { display: block; }
section { position: relative; }

.hero {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4rem var(--hud-w) 6rem;
}
.hero-kicker {
  margin: 0 0 1.4rem;
  font-size: 12px;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: #0b4a63;
}
.hero-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(3.4rem, 11vw, 7.5rem);
  line-height: 0.98;
  letter-spacing: -0.01em;
  color: #052b3f;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
}
.hero-sub {
  margin: 1.6rem 0 0;
  font-size: clamp(1.05rem, 2.2vw, 1.35rem);
  color: #083a52;
}
.hero-hint {
  margin: 2.2rem 0 0;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #0b5069;
}

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 14px 26px;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.btn-primary {
  margin-top: 2.4rem;
  background: #06344c;
  color: #d9f2fb;
  border-color: rgba(220, 245, 252, 0.6);
  box-shadow: 0 10px 30px rgba(3, 40, 60, 0.45);
}
.hero .btn-primary { background: rgba(5, 43, 63, 0.9); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(3, 40, 60, 0.55); }
.btn-arrow { font-size: 15px; }

/* chapters */
.chapter { padding: 12vh var(--hud-w) 10vh; }
.chapter-head {
  max-width: 680px;
  margin: 0 auto 10vh;
  text-align: left;
}
.zone-meta {
  display: flex;
  align-items: baseline;
  gap: 14px;
  color: var(--ink-faint);
}
.zone-num {
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0.3em;
  color: var(--accent-soft);
}
.zone-sci { font-size: 11px; letter-spacing: 0.32em; text-transform: uppercase; }
.zone-title {
  margin: 0.4rem 0 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(3rem, 8vw, 5.6rem);
  line-height: 1;
  color: var(--ink);
}
.zone-range {
  margin: 0.8rem 0 0;
  font-size: 13px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}
.zone-intro {
  margin: 2.2rem 0 0;
  font-family: var(--serif);
  font-size: clamp(1.05rem, 2vw, 1.3rem);
  line-height: 1.65;
  color: var(--ink-dim);
  max-width: 34em;
}
.zone-stats {
  list-style: none;
  margin: 2.2rem 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
  max-width: 30em;
}
.zone-stats li {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 12px;
  font-size: 12px;
  color: var(--ink-faint);
  border-top: 1px solid var(--panel-line);
  padding-top: 10px;
}
.zone-stats b {
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
}
.zone-note {
  max-width: 560px;
  margin: 10vh auto 0;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--ink-faint);
  border-left: 2px solid var(--panel-line);
  padding-left: 16px;
  font-style: italic;
}

/* ---------------- specimen cards ---------------- */

.specimens {
  display: grid;
  gap: 16vh;
  max-width: 1080px;
  margin: 0 auto;
}
.spec-card {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: clamp(1.4rem, 4vw, 3.4rem);
  align-items: center;
  opacity: 0;
  transform: translateY(28px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}
.spec-card.visible { opacity: 1; transform: none; }
.spec-card.flip { grid-template-columns: 0.9fr 1.1fr; }
.spec-card.flip .spec-art { order: 2; }

.spec-art {
  position: relative;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  min-height: 300px;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 3vw, 2.4rem);
  overflow: hidden;
}
.spec-art::after { /* faint horizon glow inside the card */
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 90% at 50% -20%, rgba(159, 220, 242, 0.12), transparent 60%);
  pointer-events: none;
}
.spec-art svg {
  max-width: 100%;
  max-height: 340px;
  width: auto;
  height: auto;
  filter: drop-shadow(0 14px 18px rgba(0, 10, 18, 0.45));
  will-change: transform;
}
.spec-depth-tag {
  position: absolute;
  top: 12px;
  left: 14px;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.spec-info h3 {
  margin: 0.2rem 0 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.6rem, 3.4vw, 2.4rem);
  line-height: 1.1;
}
.spec-latin {
  margin: 0.5rem 0 0;
  font-style: italic;
  font-size: 13px;
  color: var(--accent-soft);
  font-family: var(--serif);
}
.spec-blurb {
  margin: 1.1rem 0 0;
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink-dim);
  max-width: 34em;
}
.spec-actions { margin-top: 1.5rem; display: flex; flex-wrap: wrap; gap: 10px; }
.btn-chip {
  background: rgba(159, 220, 242, 0.08);
  color: var(--ink);
  border-color: var(--panel-line);
  padding: 10px 18px;
  font-size: 11.5px;
}
.btn-chip:hover { background: rgba(159, 220, 242, 0.18); }
.btn-chip[aria-pressed="true"] {
  background: rgba(126, 232, 216, 0.16);
  border-color: var(--accent);
  color: #d9fff7;
}
.spec-biolum-tag {
  display: inline-block;
  margin-top: 12px;
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid rgba(126, 232, 216, 0.35);
  border-radius: 999px;
  padding: 5px 12px;
}

/* ---------------- SVG specimen internals ---------------- */

.photophore circle, .photophore path { fill: #cfeee6; }
.biolum-on .photophore circle, .biolum-on .photophore path {
  fill: #aefde8;
  filter: drop-shadow(0 0 5px #6ff9dd) drop-shadow(0 0 14px #3ed9c0);
  animation: photopulse 2.6s ease-in-out infinite;
}
@keyframes photopulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
.an { opacity: 0; transition: opacity 0.45s ease; pointer-events: none; }
.show-annot .an { opacity: 1; }
.an .ann text {
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0.02em;
}
.an .ann path, .an .ann circle { opacity: 0.9; }
.an .ann circle { stroke: none; }
.an .ann path { stroke-width: 1.2; stroke-dasharray: 3 3; }

/* ---------------- trench interactive ---------------- */

.trench-wrap {
  max-width: 1080px;
  margin: 14vh auto 0;
}
.trench-head { max-width: 640px; margin-bottom: 2rem; }
.trench-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.6rem, 3.6vw, 2.4rem);
}
.trench-sub { margin: 0.8rem 0 0; font-size: 13.5px; line-height: 1.7; color: var(--ink-dim); }
.trench-stage {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 14px;
  border: 1px solid var(--panel-line);
  border-radius: 16px;
  overflow: hidden;
  background: #020a12;
}
#trenchCanvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 10;
  cursor: crosshair;
  touch-action: none;
  outline: none;
}
#trenchCanvas:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}
.trench-legend {
  padding: 16px;
  background: rgba(2, 12, 20, 0.6);
  font-size: 12px;
  min-width: 0;
}
.trench-legend-title {
  margin: 0 0 10px;
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.trench-legend ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.trench-legend li {
  color: var(--ink-faint);
  display: grid;
  grid-template-columns: 14px 1fr;
  gap: 8px;
  align-items: start;
  transition: color 0.4s ease;
}
.trench-legend li .marker { font-size: 12px; line-height: 1.4; }
.trench-legend li.found { color: var(--ink); }
.trench-legend li.found .marker { color: var(--accent); }
.trench-legend li em {
  display: block;
  font-style: normal;
  font-size: 10.5px;
  color: var(--ink-faint);
  margin-top: 2px;
}

/* ---------------- summary & sources ---------------- */

.summary { padding: 16vh var(--hud-w) 10vh; }
.summary-inner { max-width: 760px; margin: 0 auto; }
.summary-kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.summary-title {
  margin: 0.6rem 0 3rem;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.2rem, 6vw, 3.6rem);
}
.summary-list { list-style: none; margin: 0; padding: 0; }
.summary-item {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 18px;
  padding: 22px 0;
  border-top: 1px solid var(--panel-line);
}
.summary-chip {
  width: 12px; height: 12px;
  border-radius: 50%;
  margin-top: 7px;
  box-shadow: 0 0 10px currentColor;
}
.summary-item h3 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.35rem;
}
.summary-item h3 span { color: var(--ink-faint); font-size: 0.85em; }
.summary-range {
  margin: 4px 0 0;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-soft);
  font-variant-numeric: tabular-nums;
}
.summary-item p { margin: 10px 0 0; font-size: 13px; line-height: 1.65; color: var(--ink-dim); }
.summary-species { margin: 10px 0 0; font-size: 11.5px; color: var(--ink-faint); font-style: italic; }
.summary-return { margin-top: 5rem; text-align: center; }
.summary-hint { margin: 1.2rem 0 0; font-size: 11.5px; color: var(--ink-faint); font-style: italic; }

.sources { padding: 6vh var(--hud-w) 6vh; background: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.72)); }
.sources-inner { max-width: 760px; margin: 0 auto; }
.sources-title { margin: 0 0 0.8rem; font-family: var(--serif); font-weight: 400; font-size: 1.8rem; }
.sources-note { margin: 0 0 2rem; font-size: 12.5px; line-height: 1.7; color: var(--ink-faint); }
.sources-list { list-style: none; margin: 0; padding: 0; }
.sources-list li {
  padding: 14px 0;
  border-top: 1px solid var(--panel-line);
  font-size: 12.5px;
  line-height: 1.6;
}
.sources-list a { color: var(--ink); text-decoration-color: var(--accent-soft); text-underline-offset: 3px; }
.sources-list a:hover { color: #fff; }
.sources-list .src-detail { display: block; margin-top: 3px; color: var(--ink-faint); }
.footer {
  margin-top: 4rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--panel-line);
  font-size: 11.5px;
  color: var(--ink-faint);
  line-height: 1.7;
}
.footer p { margin: 0 0 0.4rem; }

/* ---------------- dialogs ---------------- */

dialog {
  border: 1px solid var(--panel-line);
  border-radius: 18px;
  background: #04121d;
  color: var(--ink);
  padding: 0;
  max-width: min(1060px, 94vw);
  width: 94vw;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
dialog::backdrop { background: rgba(1, 6, 10, 0.72); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.dialog-grid { display: grid; grid-template-columns: 1.15fr 0.85fr; }
.dialog-stage-wrap { position: relative; background: radial-gradient(120% 100% at 50% 0%, #0a2334, #030d16 70%); min-height: 420px; display: flex; }
.dialog-stage {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 34px;
  perspective: 900px;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}
.dialog-stage:active { cursor: grabbing; }
.dialog-stage .spin { transform-style: preserve-3d; will-change: transform; }
.dialog-stage svg { max-width: 100%; max-height: 480px; width: auto; height: auto; filter: drop-shadow(0 18px 26px rgba(0, 8, 14, 0.6)); }
.dialog-stage-hint {
  position: absolute;
  bottom: 12px; left: 0; right: 0;
  margin: 0;
  text-align: center;
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.dialog-panel {
  padding: 30px 32px 34px;
  border-left: 1px solid var(--panel-line);
  max-height: min(82vh, 720px);
  overflow-y: auto;
  position: relative;
}
.dialog-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--panel-line);
  background: rgba(159, 220, 242, 0.06);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s ease;
}
.dialog-close:hover { background: rgba(159, 220, 242, 0.2); }
.dialog-close:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.dialog-kicker {
  margin: 0 0 0.6rem;
  font-size: 10px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--accent-soft);
}
.dialog-title { margin: 0; font-family: var(--serif); font-weight: 400; font-size: 1.9rem; line-height: 1.1; }
.dialog-latin { margin: 0.4rem 0 0; font-style: italic; font-family: var(--serif); font-size: 13px; color: var(--ink-faint); }
.dialog-stats { margin: 1.2rem 0 0; display: grid; gap: 8px; }
.dialog-stats > div { display: grid; grid-template-columns: 64px 1fr; gap: 10px; font-size: 12.5px; }
.dialog-stats dt { text-transform: uppercase; letter-spacing: 0.14em; font-size: 10px; color: var(--ink-faint); padding-top: 2px; }
.dialog-stats dd { margin: 0; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.dialog-blurb { margin: 1.2rem 0 0; font-size: 13.5px; line-height: 1.7; color: var(--ink-dim); }
.dialog-facts { margin: 1.2rem 0 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.dialog-facts li { font-size: 12.5px; line-height: 1.6; color: var(--ink-faint); padding-left: 16px; position: relative; }
.dialog-facts li::before { content: "—"; position: absolute; left: 0; color: var(--accent-soft); }
.dialog-actions { margin-top: 1.6rem; display: flex; flex-wrap: wrap; gap: 10px; }

/* compare dialog */
.compare-dialog { max-width: min(1120px, 96vw); }
.compare-grid { display: grid; grid-template-columns: 1.25fr 0.75fr; }
.compare-stage-wrap { position: relative; background: linear-gradient(#07182a, #030b14); display: flex; flex-direction: column; min-height: 420px; }
.compare-stage { flex: 1; padding: 26px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; min-width: 0; }
.compare-stage svg { width: 100%; height: auto; max-height: 500px; }
.compare-stage svg + svg { max-width: min(420px, 100%); border: 1px dashed rgba(159, 220, 242, 0.25); border-radius: 10px; padding: 8px; }
.compare-scale-note {
  margin: 0;
  padding: 10px 22px 16px;
  font-size: 11.5px;
  color: var(--ink-faint);
  border-top: 1px solid var(--panel-line);
}
.compare-refs { margin-top: 1.2rem; display: grid; gap: 8px; font-size: 12px; color: var(--ink-faint); }
.compare-refs .ref-row { display: grid; grid-template-columns: 16px 1fr auto; gap: 10px; align-items: center; }
.compare-refs .swatch { width: 12px; height: 12px; border-radius: 3px; }
.compare-hint { margin-top: 1.4rem; font-size: 11.5px; color: var(--ink-faint); font-style: italic; line-height: 1.6; }

/* ---------------- responsive ---------------- */

@media (max-width: 900px) {
  .spec-card, .spec-card.flip { grid-template-columns: 1fr; gap: 1.2rem; }
  .spec-card.flip .spec-art { order: 0; }
  .dialog-grid, .compare-grid { grid-template-columns: 1fr; }
  .dialog-panel { border-left: none; border-top: 1px solid var(--panel-line); max-height: 45vh; }
  .trench-stage { grid-template-columns: 1fr; }
  .trench-legend { border-top: 1px solid var(--panel-line); }
}
@media (max-width: 720px) {
  :root { --hud-w: 20px; }
  .hud {
    top: 0; left: 0; right: 0;
    transform: none;
    padding: 8px 10px;
    justify-content: center;
    gap: 12px;
  }
  .hud-rail { display: none; }
  .hud-readout {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 7px 14px;
    min-width: 0;
  }
  .hud-depth { font-size: 18px; }
  .hud-zone { margin: 0; font-size: 9px; }
  .hud-sub { margin: 0; font-size: 10px; white-space: nowrap; }
  .hero, .chapter, .summary, .sources { padding-left: 16px; padding-right: 16px; padding-top: 84px; }
  .hero { padding-top: 4rem; }
  .zone-stats li { grid-template-columns: 72px 1fr; }
  .dialog-stage { min-height: 300px; }
  .rail-tick-label { display: none; }
}

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

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .btn { transition: none; }
  .spec-card { opacity: 1; transform: none; transition: none; }
  .rail-marker { transition: none; }
  .biolum-on .photophore circle, .biolum-on .photophore path { animation: none; }
  #sunglow { transition: none; }
}
