:root {
  color-scheme: light;
  --title-top: 2vh;
  --controls-bottom: 1.5rem;
  --panel-accent: #7dd6f5;
  --panel-bg: linear-gradient(145deg, rgba(18, 52, 84, 0.56), rgba(5, 27, 51, 0.7));
  --panel-border: rgba(180, 233, 255, 0.3);
  --overlay-side-pad: clamp(0.5rem, 2vw, 2rem);
  --panel-width: min(34vw, 27rem);
  --panel-gap: 1.1rem;

  /* 16 tier colours — light-blue → cyan → teal → green → lime → yellow → amber → orange → red → crimson → rose → pink → purple → violet → indigo → gold */
  --t1:  #5bc8ff;
  --t2:  #38d9f5;
  --t3:  #22e8d8;
  --t4:  #20e896;
  --t5:  #45ed6a;
  --t6:  #8cf53a;
  --t7:  #c0f230;
  --t8:  #f0e030;
  --t9:  #f5b820;
  --t10: #f08020;
  --t11: #f05030;
  --t12: #e02860;
  --t13: #d030a0;
  --t14: #a030e0;
  --t15: #7040f8;
  --t16: #ffd700;
}

@font-face {
  font-family: "Ginga";
  src: url("../assets/fonts/Ginga-r09p.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  margin: 0;
  font-family: "Times New Roman";
  overflow: hidden;
}

/* ── Canvases ── */
#bg-canvas {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block; z-index: 0;
}
#fish-canvas {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block; z-index: 1;
  pointer-events: none;
}

/* ── Hero ── */
.hero {
  position: absolute; z-index: 2;
  width: 100%;
  top: var(--title-top);
  left: 50%; transform: translateX(-50%);
  display: grid; gap: 0.75rem;
  padding: 0 1rem; text-align: center;
  color: #ecf7ff;
  text-shadow: 0 0.15rem 1rem rgba(0,0,0,0.45);
}
.hero h1 { margin: 0; line-height: 0.95; }
.hero-title-main {
  display: block; font-family: "Ginga";
  font-size: clamp(4.5rem, 16vw, 20rem);
  letter-spacing: 0.02em; font-weight: 400;
}
.hero-title-sub {
  display: block; margin-top: 0.55rem;
  font-size: clamp(1.6rem, 3.8vw, 3rem);
  font-weight: 400; letter-spacing: 0.03em;
}
.hero-title-link {
  color: inherit;
  text-decoration: none;
  transition: opacity 0.15s ease;
}
.hero-title-link:hover { opacity: 0.86; }
.hero-title-link:focus-visible {
  outline: 2px solid #b9ebff;
  outline-offset: 4px;
  border-radius: 0.35rem;
}
.hero p { margin: 0; font-size: clamp(1rem, 2vw, 2rem); }

.social-dock {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  gap: 0.85rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid rgba(188, 235, 255, 0.25);
  border-radius: 999px;
  background: rgba(7, 24, 41, 0.34);
  backdrop-filter: blur(10px);
  box-shadow: 0 14px 38px rgba(0, 22, 47, 0.24);
}
.social-dock__link {
  min-width: 3.25rem;
  height: 3.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0 1rem;
  border-radius: 999px;
  border: 1px solid rgba(210, 244, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: #f2fbff;
  text-decoration: none;
  font-size: 0.98rem;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.social-dock__link:hover {
  transform: translateY(-3px);
  background: rgba(129, 218, 255, 0.14);
  border-color: rgba(210, 244, 255, 0.52);
}
.social-dock__link:focus-visible {
  outline: 2px solid #b9ebff;
  outline-offset: 3px;
}
.social-dock__link svg {
  width: 1.45rem;
  height: 1.45rem;
  fill: currentColor;
  flex: 0 0 auto;
}
.social-dock__link span {
  white-space: nowrap;
}

/* ── Warp Panel ── */
.warp-panel {
  position: fixed; left: 50%; top: 55%;
  transform: translateX(-50%);
  z-index: 4; display: flex;
  gap: 0.6rem; align-items: center;
  padding: 0.6rem; border-radius: 999px;
  background: rgba(8,24,40,0.35);
  backdrop-filter: blur(6px);
}
.warp-panel input {
  border: 0; outline: none;
  width: min(58vw, 28rem); border-radius: 999px;
  padding: 0.7rem 1rem;
  font-size: 1.05rem; color: #0c1f30;
  transition: box-shadow 0.2s;
}
.warp-panel input:focus { box-shadow: 0 0 0 2px var(--panel-accent); }
.warp-panel input:focus-visible {
  box-shadow: 0 0 0 3px rgba(125, 214, 245, 0.55);
}
.warp-panel button {
  border: 0; border-radius: 999px;
  padding: 0.7rem 1.4rem;
  font-size: 1.05rem; font-weight: 700;
  color: #052b3b; background: #bdeeff; cursor: pointer;
  transition: background 0.18s, transform 0.12s;
}
.warp-panel button:hover:not(:disabled) {
  background: #9ae6ff; transform: scale(1.05);
}
.warp-panel button:focus-visible {
  outline: 2px solid #b9ebff;
  outline-offset: 2px;
}




/* ── Sound Button ── */
#sound-btn {
  position: fixed; top: 1.2rem; right: 1.3rem;
  z-index: 10;
  border: 1px solid rgba(180,233,255,0.28);
  border-radius: 999px; padding: 0.45rem 0.85rem;
  font-size: 1.2rem; line-height: 1;
  background: rgba(8,24,40,0.45); backdrop-filter: blur(6px);
  color: #eef7ff; cursor: pointer;
  transition: background 0.18s, transform 0.12s;
}
#sound-btn:hover { background: rgba(8,24,40,0.75); transform: scale(1.08); }
#sound-btn:focus-visible {
  outline: 2px solid #b9ebff;
  outline-offset: 2px;
}

/* ── Overlay shell ── */
#black-overlay {
  position: fixed; inset: 0; z-index: 9;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#black-overlay.active { pointer-events: auto; }

.overlay-video {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity 120ms linear;
  transform: translateZ(0); backface-visibility: hidden;
  will-change: transform, opacity;
}
.overlay-video.is-active { opacity: 1; }

/* ── 3-column layout inside overlay ── */
/* Left pane: fish + viz  |  hidden centre gap  |  Right pane: stats */
.overlay-left-pane {
  position: absolute;
  left: var(--overlay-side-pad);
  right: calc(var(--panel-width) + var(--overlay-side-pad) + var(--panel-gap));
  top: 0; bottom: 0;
  width: auto;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1rem;
  z-index: 1; pointer-events: none;
}

/* ── Fish canvas — properly centred in the left pane ── */
#overlay-fish-canvas {
  width: 100%;
  height: min(72vh, 42rem);
  flex-shrink: 0;
  opacity: 0;
  border-radius: 1rem;
  pointer-events: none;
}

#model-loader {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.42rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(160, 226, 255, 0.35);
  background: rgba(9, 34, 58, 0.5);
  color: #d6f3ff;
  font-size: 0.84rem;
  letter-spacing: 0.02em;
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 20px rgba(0, 20, 44, 0.3);
}
#model-loader[hidden] {
  display: none !important;
}
.loader-spinner {
  width: 0.92rem;
  height: 0.92rem;
  border-radius: 50%;
  border: 2px solid rgba(173, 233, 255, 0.28);
  border-top-color: #84defe;
  animation: modelLoaderSpin 0.8s linear infinite;
}
.loader-text {
  white-space: nowrap;
}

@keyframes modelLoaderSpin {
  to { transform: rotate(360deg); }
}

/* ── Fish name label above the canvas ── */
#overlay-fish-name {
  width: 100%;
  text-align: center;
  font-family: "Times New Roman", serif;
  font-size: clamp(1rem, 1.8vw, 1.35rem);
  font-style: italic;
  letter-spacing: 0.04em;
  color: #d0f4ff;
  text-shadow: 0 0 18px rgba(100, 220, 255, 0.85),
               0 0 40px rgba(60, 180, 255, 0.5);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.45s ease, transform 0.45s ease;
  pointer-events: none;
}
#overlay-fish-name.visible {
  opacity: 1;
  transform: translateY(0);
}


/* ── Fish Size Visualization ── */
#fish-viz {
  width: 100%;
  display: flex; flex-direction: column;
  align-items: center; gap: 0.45rem;
  opacity: 0; transition: opacity 0.55s ease;
  pointer-events: none;
}
#fish-viz.visible { opacity: 1; }

.fish-viz-ruler {
  display: flex; align-items: center;
  width: 100%; gap: 0;
}
.fish-viz-arrow {
  color: var(--panel-accent);
  font-size: 1.05rem; font-weight: 700;
  flex-shrink: 0; padding: 0 2px;
}
.fish-viz-ruler-line {
  flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(125,214,245,0.5), transparent);
}
.fish-viz-count {
  font-size: clamp(0.7rem, 1.15vw, 0.9rem);
  font-weight: 700; color: #d4f5ff;
  white-space: nowrap; padding: 0 0.4rem;
  text-shadow: 0 0 12px rgba(100,220,255,0.7);
}
.fish-viz-width {
  display: flex; align-items: center;
  gap: 0.25rem;
  font-size: clamp(0.65rem, 1.05vw, 0.82rem);
  color: #9de8ff; opacity: 0.88;
}
.fish-viz-width-bracket-left,
.fish-viz-width-bracket-right {
  color: var(--panel-accent); font-size: 1.1em;
}
.fish-viz-width-unit { opacity: 0.7; }

/* ── Return button — pinned to bottom centre ── */
#return-btn {
  position: absolute;
  bottom: 2.2rem; left: 50%; transform: translateX(-50%);
  z-index: 2;
  border: 0; border-radius: 999px;
  padding: 0.85rem 2.2rem;
  font-size: 1.1rem; font-weight: 700;
  color: #06233a; background: #dbf6ff; cursor: pointer;
  transition: background 0.18s, transform 0.15s, box-shadow 0.18s;
  box-shadow: 0 4px 24px rgba(0,180,255,0.22);
  letter-spacing: 0.01em;
}
#return-btn:hover {
  background: #b2efff; transform: translateX(-50%) scale(1.06);
  box-shadow: 0 6px 32px rgba(0,200,255,0.35);
}
#return-btn:focus-visible {
  outline: 2px solid #b9ebff;
  outline-offset: 2px;
}

/* ── GitHub panel ── */
#github-panel {
  position: absolute;
  right: var(--overlay-side-pad);
  top: 50%; transform: translateY(-50%);
  z-index: 1;
  width: var(--panel-width);
  padding: 1.4rem 1.5rem 1.2rem;
  border-radius: 1.55rem;
  color: #eef7ff;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(10px) saturate(1.08);
  box-shadow:
    0 8px 26px rgba(0, 18, 44, 0.38),
    0 0 0 1px rgba(170, 229, 255, 0.08) inset,
    0 1px 0 rgba(255, 255, 255, 0.18) inset;
}
#github-panel::-webkit-scrollbar { width: 8px; }
#github-panel::-webkit-scrollbar-track { background: transparent; }
#github-panel::-webkit-scrollbar-thumb {
  background: rgba(149, 214, 245, 0.35);
  border-radius: 999px;
}

#github-panel::before {
  content: "";
  position: absolute;
  inset: 0.35rem;
  border-radius: 1.2rem;
  pointer-events: none;
  background: radial-gradient(120% 90% at 15% 0%, rgba(168, 236, 255, 0.2), transparent 58%);
  mix-blend-mode: screen;
}

#github-panel h2 {
  margin: 0 0 1rem 0;
  font-size: clamp(1.15rem, 2.3vw, 1.7rem);
  color: #d6f4ff; letter-spacing: 0.01em;
  border-bottom: 1px solid rgba(125,214,245,0.15);
  padding-bottom: 0.65rem;
}

.stat-row {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.65rem;
  margin: 0.12rem 0;
  border-radius: 0.72rem; cursor: default;
  transition: background 0.18s, border-color 0.18s;
  gap: 0.5rem;
  border: 1px solid transparent;
  background: rgba(167, 225, 255, 0.04);
}
.stat-row:hover {
  background: rgba(125,214,245,0.12);
  border-color: rgba(159, 224, 255, 0.2);
}
.stat-label {
  font-size: clamp(0.82rem, 1.25vw, 0.98rem);
  opacity: 0.7; white-space: nowrap;
}
.stat-value {
  font-size: clamp(0.9rem, 1.4vw, 1.08rem);
  color: #c0ecff; text-align: right; word-break: break-all;
}
.stat-row--fish {
  margin-top: 0.5rem;
  background: linear-gradient(90deg, rgba(117, 220, 255, 0.16), rgba(104, 160, 255, 0.09));
  border: 1px solid rgba(154,230,255,0.24);
}
.stat-value--fish {
  color: var(--panel-accent);
  font-size: clamp(0.88rem, 1.35vw, 1.04rem);
  text-shadow: 0 0 14px rgba(90, 208, 255, 0.52);
}

@keyframes countPop {
  0%   { transform: scale(1.3); opacity: 0.5; }
  100% { transform: scale(1);   opacity: 1; }
}
.stat-value.pop { animation: countPop 0.3s ease-out forwards; }

.tier-band-row {
  display: flex;
  gap: 0.45rem;
  margin: 0.4rem 0 0.6rem;
}
.tier-band {
  flex: 1;
  text-align: center;
  font-size: 0.65rem;
  color: #c2eeff;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.32rem 0.42rem;
  border-radius: 999px;
  border: 1px solid rgba(163, 228, 255, 0.26);
  background: rgba(107, 196, 244, 0.12);
}

/* ── Tier Grid ── */
.tier-grid-wrap {
  margin: 0.76rem 0 0.4rem;
  padding: 0.65rem 0.6rem 0.55rem;
  border-radius: 0.8rem;
  background: rgba(0,20,40,0.38);
  border: 1px solid rgba(125,214,245,0.2);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.03) inset;
}
.tier-grid-label {
  font-size: 0.65rem; letter-spacing: 0.08em; text-transform: uppercase;
  opacity: 0.5; color: #aee9ff; margin-bottom: 0.45rem;
}
.tier-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 5px;
}
.tier-cell {
  position: relative;
  height: 24px; border-radius: 6px;
  cursor: pointer;
  opacity: 0.28;
  transition: opacity 0.25s, transform 0.22s, box-shadow 0.25s, outline 0.15s, filter 0.2s;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(255,255,255,0.12);
  filter: saturate(0.95);
}
.tier-cell:hover {
  opacity: 0.86;
  transform: scaleY(1.2);
  filter: saturate(1.12);
}
/* Tooltip: fish name on hover */
.tier-cell::after {
  content: attr(data-fish);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%; transform: translateX(-50%);
  background: rgba(5,16,30,0.92);
  color: #b6e9ff;
  font-size: 0.6rem; font-family: "Times New Roman";
  white-space: nowrap; padding: 3px 7px;
  border-radius: 5px;
  border: 1px solid rgba(125,214,245,0.25);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s;
  z-index: 10;
}
.tier-cell:hover::after { opacity: 1; }
.tier-cell .tier-num {
  font-size: 0.55rem; font-weight: 700;
  color: rgba(255,255,255,0.7);
  line-height: 1;
  pointer-events: none;
}
.tier-cell.active {
  opacity: 1;
  transform: scaleY(1.4);
  box-shadow: 0 0 14px 4px var(--cell-color, #7dd6f5);
}
.tier-cell.below-active { opacity: 0.55; }
/* Previewing ring — when user clicks a different tier to peek at that fish */
.tier-cell.previewing {
  opacity: 1;
  outline: 2px solid rgba(255,255,255,0.75);
  outline-offset: 2px;
  transform: scaleY(1.2);
}
/* Colour each tier via inline CSS var set by JS */
.tier-cell { background: var(--cell-color, #5bc8ff); }

.fish-lore {
  margin: 0.55rem 0 0;
  padding: 0.6rem 0.72rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(154,230,255,0.22);
  background: linear-gradient(120deg, rgba(107, 196, 244, 0.15), rgba(56, 121, 207, 0.12));
  color: #d7f4ff;
  font-size: clamp(0.72rem, 1.05vw, 0.88rem);
  line-height: 1.45;
  min-height: 3.6em;
}

#github-status {
  margin-top: 0.62rem;
  font-style: italic; opacity: 0.7;
  font-size: clamp(0.72rem, 1.1vw, 0.88rem);
  line-height: 1.45; color: #aacfe8;
}

/* Tablet */
@media (max-width: 1100px) {
  :root {
    --panel-width: min(40vw, 23rem);
    --overlay-side-pad: 0.75rem;
    --panel-gap: 0.9rem;
  }
  .overlay-left-pane {
    left: var(--overlay-side-pad);
    right: calc(var(--panel-width) + var(--panel-gap));
  }
  #overlay-fish-canvas { height: min(64vh, 34rem); }
  #github-panel {
    width: var(--panel-width);
    padding: 1rem 1rem 0.9rem;
    max-height: min(84dvh, 48rem);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  #return-btn {
    padding: 0.72rem 1.55rem;
    font-size: 1rem;
  }
}

/* Small laptop / large tablet landscape */
@media (max-width: 920px) {
  :root {
    --panel-width: min(44vw, 21rem);
    --panel-gap: 0.7rem;
  }
  #overlay-fish-canvas { height: min(60vh, 30rem); }
  #github-panel h2 { font-size: clamp(1.05rem, 2.2vw, 1.45rem); }
  .tier-cell { height: 22px; }
}

/* Mobile */
@media (max-width: 700px) {
  :root { --title-top: 1.5vh; --controls-bottom: 1rem; }

  .warp-panel { top: 58%; width: min(92vw, 30rem); }
  .warp-panel input { width: 100%; font-size: 0.95rem; }
  .social-dock {
    bottom: 1rem;
    gap: 0.6rem;
    padding: 0.45rem 0.55rem;
  }
  .social-dock__link {
    min-width: 0;
    height: 2.9rem;
    padding: 0 0.8rem;
    font-size: 0.9rem;
  }

  .overlay-left-pane {
    left: 0.75rem;
    right: 0.75rem;
    width: auto;
    top: max(0.4rem, env(safe-area-inset-top));
    bottom: auto;
    height: auto;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 0.25rem;
    gap: 0.45rem;
  }
  #overlay-fish-canvas {
    height: clamp(15rem, 46vh, 21rem);
    width: 100%;
  }
  #overlay-fish-name {
    font-size: clamp(0.95rem, 4.3vw, 1.2rem);
  }
  #fish-viz { display: none; }

  #github-panel {
    right: 0.75rem;
    left: 0.75rem;
    top: auto;
    bottom: calc(4.8rem + env(safe-area-inset-bottom));
    transform: none;
    width: auto;
    max-height: 40vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 0.85rem 0.85rem 0.8rem;
  }
  #github-panel h2 {
    margin-bottom: 0.6rem;
    padding-bottom: 0.45rem;
  }
  .tier-grid-wrap { margin-top: 0.55rem; }
  .tier-grid { grid-template-columns: repeat(8, 1fr); gap: 4px; }
  .tier-cell { height: 22px; }
  .fish-lore {
    font-size: 0.82rem;
    line-height: 1.35;
    padding: 0.5rem 0.6rem;
    min-height: 0;
  }
  #return-btn {
    bottom: max(0.45rem, env(safe-area-inset-bottom));
    width: min(92vw, 20rem);
    padding: 0.72rem 1.1rem;
    font-size: 1rem;
  }
}

@media (max-height: 760px) and (max-width: 900px) {
  #overlay-fish-canvas { height: 42vh; }
  #github-panel { max-height: 38vh; }
}

/* Very small phones */
@media (max-width: 420px) {
  .overlay-left-pane { left: 0.5rem; right: 0.5rem; }
  #overlay-fish-canvas { height: clamp(13.5rem, 44vh, 17rem); }
  #github-panel {
    left: 0.5rem;
    right: 0.5rem;
    padding: 0.72rem 0.72rem 0.68rem;
    max-height: 42vh;
  }
  .stat-row { padding: 0.42rem 0.5rem; }
  .tier-band-row { gap: 0.3rem; }
  .tier-band { font-size: 0.6rem; }
  #return-btn { width: min(96vw, 18rem); }
}

/* Landscape phones with short height */
@media (max-height: 500px) and (orientation: landscape) {
  .overlay-left-pane {
    left: 0.55rem;
    right: calc(min(46vw, 20rem) + 0.55rem);
  }
  #overlay-fish-canvas { height: 72vh; }
  #github-panel {
    width: min(46vw, 20rem);
    max-height: 80vh;
    padding: 0.72rem 0.72rem 0.68rem;
  }
  #return-btn {
    bottom: 0.35rem;
    padding: 0.58rem 1rem;
    font-size: 0.92rem;
  }
}

/* Ultrawide displays */
@media (min-width: 1700px) {
  :root {
    --panel-width: min(30vw, 30rem);
    --overlay-side-pad: clamp(1rem, 2.2vw, 3rem);
    --panel-gap: 1.4rem;
  }
  #overlay-fish-canvas { height: min(74vh, 48rem); }
}

@media (hover: none) and (pointer: coarse) {
  .tier-cell::after { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
