:root {
  --night: #101A26;
  --lake: #1E3A45;
  --mist: #4E6B72;
  --pale: #8FA9A8;
  --pine: #22301F;
  --sun: #E8A55C;
  --cream: #F6D9A8;
  --flesh: #C97A5A;
  --serif: "Newsreader", Georgia, serif;
  --sign: "Barlow Semi Condensed", "Arial Narrow", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--night);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--sign);
  color: var(--cream);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to top, rgba(16,26,38,0.62) 0%, rgba(16,26,38,0.20) 12%, rgba(16,26,38,0) 28%),
    radial-gradient(ellipse 90% 80% at 50% 44%, rgba(16,26,38,0) 56%, rgba(16,26,38,0.30) 100%);
  mix-blend-mode: multiply;
}

#grain {
  position: absolute;
  inset: -20%;
  pointer-events: none;
  opacity: 0.055;
  mix-blend-mode: overlay;
  background-repeat: repeat;
  animation: grainShift 0.9s steps(2, end) infinite;
}

@keyframes grainShift {
  0% { transform: translate3d(0, 0, 0); }
  50% { transform: translate3d(-1.5%, 1%, 0); }
  100% { transform: translate3d(1%, -1%, 0); }
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.mono {
  font-family: var(--mono);
  font-weight: 400;
  letter-spacing: 0.18em;
}

#titleWrap {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  margin: 0;
  padding: 0;
  pointer-events: none;
  color: var(--cream);
  font-family: var(--serif);
  font-weight: 300;
  font-size: clamp(38px, 4.5vw, 62px);
  line-height: 0.88;
  letter-spacing: 0.015em;
  opacity: 0.97;
  -webkit-font-smoothing: antialiased;
}

#titleWrap .tLine {
  display: block;
  white-space: nowrap;
  -webkit-text-stroke: 0.4px rgba(16, 26, 38, 0.42);
}

#titleWrap .tLineTwo {
  position: relative;
  padding-left: 0.30em;
}

.titleFish {
  position: absolute;
  left: -0.20em;
  top: 0.12em;
  width: 2.15em;
  height: auto;
  fill: #1b2d3b;
  opacity: 0.95;
  z-index: 0;
}

.tLineTwo .tWord { position: relative; z-index: 1; }

#clock {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  right: max(20px, env(safe-area-inset-right));
  font-size: 10px;
  color: rgba(246, 217, 168, 0.62);
}

#readout {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(22px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-family: var(--mono);
  font-size: 10px;
  color: rgba(246, 217, 168, 0.60);
}

#readout .row {
  display: flex;
  align-items: baseline;
  gap: 7px;
  line-height: 1;
}

#readout .k {
  width: 34px;
  color: rgba(143, 169, 168, 0.80);
  letter-spacing: 0.20em;
}

#readout .v {
  min-width: 36px;
  text-align: right;
  color: rgba(246, 217, 168, 0.82);
  letter-spacing: 0.10em;
}

#readout .u {
  color: rgba(143, 169, 168, 0.55);
  letter-spacing: 0.14em;
}

#log {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: calc(max(22px, env(safe-area-inset-bottom)) + 48px);
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 9px;
  color: rgba(143, 169, 168, 0.72);
}

#logFish {
  width: 42px;
  height: auto;
  opacity: 0.62;
  filter: saturate(0.85);
}

#logCount {
  font-size: 10px;
  color: rgba(246, 217, 168, 0.78);
  letter-spacing: 0.06em;
}

.logCap {
  letter-spacing: 0.24em;
  font-size: 8px;
  color: rgba(143, 169, 168, 0.64);
}

#hint {
  position: absolute;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: rgba(246, 217, 168, 0.92);
  white-space: nowrap;
  transition: opacity 500ms ease;
}

#hintIcon {
  width: 11px;
  height: auto;
  opacity: 0.7;
  transform: rotate(-18deg);
}

#hint.pulse {
  animation: hintPulse 2.6s ease-in-out infinite;
}

@keyframes hintPulse {
  0%, 100% { opacity: 0.72; }
  50% { opacity: 1; }
}

#card {
  position: absolute;
  right: clamp(18px, 4.5vw, 64px);
  bottom: max(58px, 8vh);
  width: min(330px, 24vw);
  transform: translate3d(calc(100% + 12vw), 0, 0);
  opacity: 0;
  transition: transform 0.55s cubic-bezier(0.22, 0.85, 0.2, 1), opacity 0.3s ease;
  pointer-events: none;
}

#card.visible {
  transform: translate3d(0, 0, 0);
  opacity: 1;
}

#card img {
  display: block;
  width: 100%;
  height: auto;
}

#cardBody {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 15% 16% 18%;
  color: #f2e6cd;
}

#card .species {
  font-family: var(--font-catch, var(--serif));
  font-weight: 400;
  font-size: clamp(26px, 2.6vw, 38px);
  line-height: 1;
  letter-spacing: 0.01em;
  margin: 0.22em 0 0.10em;
  color: var(--cream);
}

#card .latin {
  font-family: var(--sign);
  font-size: 7.5px;
  letter-spacing: 0.30em;
  color: rgba(143, 169, 168, 0.76);
  text-transform: uppercase;
}

#card .dims {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: rgba(246, 217, 168, 0.90);
}

#card .meta {
  margin-top: 1.3em;
  font-family: var(--sign);
  font-size: 7.5px;
  letter-spacing: 0.26em;
  color: rgba(143, 169, 168, 0.64);
}

#tension {
  position: absolute;
  right: max(20px, env(safe-area-inset-right));
  bottom: calc(max(24px, env(safe-area-inset-bottom)) + 4px);
  width: clamp(78px, 9vw, 118px);
  opacity: 0;
  transform: translateY(7px);
  transition: opacity 0.45s ease, transform 0.45s ease;
}

#tension.visible {
  opacity: 1;
  transform: translateY(0);
}

#tension svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

#tensionArc {
  stroke-dasharray: 0 999;
  transition: stroke 0.2s linear;
}

.tensionLabel {
  margin-top: 2px;
  text-align: center;
  font-size: 7.5px;
  font-weight: 500;
  letter-spacing: 0.26em;
  color: rgba(143, 169, 168, 0.70);
}

#sound {
  position: absolute;
  top: calc(max(20px, env(safe-area-inset-top)) + 20px);
  right: max(20px, env(safe-area-inset-right));
  background: none;
  border: 0;
  padding: 4px 0;
  font-family: var(--sign);
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.24em;
  color: rgba(143, 169, 168, 0.66);
  cursor: pointer;
  pointer-events: auto;
  transition: color 0.2s ease;
}

#sound:hover, #sound:focus-visible { color: rgba(246, 217, 168, 0.92); }
#sound:focus-visible { outline: 1px solid rgba(246, 217, 168, 0.4); outline-offset: 4px; }

#notice {
  position: absolute;
  left: 50%;
  top: 19%;
  transform: translateX(-50%);
  font-family: var(--serif);
  font-size: clamp(15px, 1.4vw, 20px);
  letter-spacing: 0.02em;
  color: rgba(246, 217, 168, 0.92);
  opacity: 0;
  transition: opacity 0.6s ease;
  text-align: center;
  width: 80vw;
  pointer-events: none;
}

#notice.visible { opacity: 1; }

#loading {
  position: absolute;
  inset: 0;
  background: var(--night);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  transition: opacity 0.3s ease;
  z-index: 20;
}

#loading.hide {
  opacity: 0;
  pointer-events: none;
}

#loading img {
  width: min(260px, 56vw);
  opacity: 0.92;
}

#loading .mono {
  font-size: 8.5px;
  letter-spacing: 0.34em;
  color: rgba(143, 169, 168, 0.62);
}

@media (max-aspect-ratio: 1/1) {
  #titleWrap { font-size: clamp(29px, 8.4vw, 40px); top: max(14px, env(safe-area-inset-top)); }
  #card {
    right: max(10px, env(safe-area-inset-right));
    left: auto;
    top: max(104px, env(safe-area-inset-top));
    bottom: auto;
    width: min(240px, 64vw);
    transform: translate3d(calc(100% + 12vw), 0, 0);
  }
  #card.visible { transform: translate3d(0, 0, 0); }
  #tension {
    right: max(16px, env(safe-area-inset-right));
    bottom: calc(max(22px, env(safe-area-inset-bottom)) + 4px);
    width: 70px;
  }
  #hint {
    bottom: max(20px, env(safe-area-inset-bottom));
    font-size: 9px;
    letter-spacing: 0.20em;
  }
  #readout {
    font-size: 9px;
    bottom: calc(max(18px, env(safe-area-inset-bottom)) + 26px);
  }
  #log {
    bottom: calc(max(18px, env(safe-area-inset-bottom)) + 68px);
  }
  #notice { top: 14%; font-size: 16px; }
}

@media (max-height: 430px) and (min-aspect-ratio: 3/2) {
  #titleWrap { width: clamp(140px, 20vw, 240px); top: 10px; left: 14px; }
  #clock { top: 14px; right: 16px; }
  #sound { top: 32px; right: 16px; }
  #hint { bottom: 12px; font-size: 9px; }
  #readout { bottom: 12px; font-size: 9px; }
  #log { bottom: 58px; }
  #tension { width: 74px; bottom: 12px; }
  #card { width: min(280px, 26vw); }
}

@media (max-width: 520px) and (max-height: 700px) {
  #logFish { width: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  #grain { animation: none; }
  #hint.pulse { animation: none; }
  #card { transition-duration: 0.01ms; }
}
