* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: #000; overflow: hidden; }
canvas { display: block; }

#ui {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  color: #3af; font-family: monospace; font-size: 13px; text-align: center;
  text-shadow: 0 0 8px #0af; pointer-events: none; letter-spacing: 1px;
}

#crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  /* Container size */
  width: 10px;
  height: 10px;
  pointer-events: none;
}

#crosshair::before, #crosshair::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, 0.9);
}

/* Vertical line: 1px wide, 6px tall */
/* Centered: left = (container width / 2) - (line width / 2) = 5 - 0.5 = 4.5px */
#crosshair::before {
  width: 1px;
  height: 6px;
  left: 4.5px; 
  top: 2px;
}

/* Horizontal line: 6px wide, 1px tall */
/* Centered: top = (container height / 2) - (line height / 2) = 5 - 0.5 = 4.5px */
#crosshair::after {
  width: 6px;
  height: 1px;
  left: 2px;
  top: 4.5px;
}


#sonar-bar-wrap {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  text-align: center; pointer-events: none; z-index: 10;
}
#sonar-label {
  color: #3af; font-family: monospace; font-size: 11px;
  margin-bottom: 6px; letter-spacing: 2px; text-shadow: 0 0 6px #0af;
}
#sonar-bar {
  width: 150px; height: 8px;
  background: #001a2a; border: 1px solid #0af4;
  border-radius: 3px; overflow: hidden;
}
#sonar-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #005080, #0af);
  box-shadow: 0 0 6px #0af;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(1);
  transition: none;
}
#sonar-bar-fill.charging { transition: transform 0.05s linear; }
@keyframes sonar-ready-flash {
  0%   { box-shadow: 0 0 14px #0ff; background: #0ff; }
  100% { box-shadow: 0 0 6px #0af;  background: linear-gradient(90deg,#005080,#0af); }
}
#sonar-bar-fill.ready { animation: sonar-ready-flash 0.3s ease-out; }

/* ── Win screen ──────────────────────────────────────────────────────── */
#winscreen {
  position: fixed; inset: 0; z-index: 30;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  padding: 12vh 24px 28px;
  min-height: 100vh;
  background: rgba(0,0,0,0.93);
  color: #ffd84a; font-family: monospace;
  text-shadow: 0 0 18px #ffa020;
  pointer-events: auto;
}
.win-screen-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  width: 100%;
}
#win-title {
  font-size: 2.4rem; letter-spacing: 10px; margin: 0;
  animation: win-pulse 2s ease-in-out infinite;
}
@keyframes win-pulse {
  0%,100% { text-shadow: 0 0 18px #ffa020; }
  50%      { text-shadow: 0 0 40px #ffe060, 0 0 80px #ff8800; }
}
.win-sub {
  font-size: 0.82rem; opacity: 0.7; letter-spacing: 1px; margin: 0;
  color: #ffcf70;
}
#play-again-btn {
  font-family: monospace; font-size: 1rem; letter-spacing: 2px;
  padding: 12px 28px; cursor: pointer;
  color: #ffd84a; background: #1a0e00; border: 1px solid #ffa0206e;
  text-shadow: 0 0 8px #ffa020;
}
#play-again-btn:hover { background: #2a1800; border-color: #ffd84a; }

.win-exit-btn {
  font-family: monospace;
  font-size: 0.82rem;
  letter-spacing: 3px;
  padding: 10px 24px;
  cursor: pointer;
  color: #9a8a6a;
  background: rgba(20, 16, 10, 0.6);
  border: 1px solid rgba(120, 100, 70, 0.45);
  text-shadow: none;
}
.win-exit-btn:hover {
  color: #c4b090;
  border-color: rgba(180, 150, 100, 0.55);
  background: rgba(30, 24, 16, 0.85);
}

/* Gold expanding rings on win screen */
#win-rings {
  position: relative; width: 80px; height: 80px;
  display: flex; align-items: center; justify-content: center;
}
.win-ring {
  position: absolute; border-radius: 50%;
  border: 1.5px solid #ffd84a;
  animation: win-ring-expand 2s ease-out infinite;
}
.wr1 { width: 24px;  height: 24px;  animation-delay: 0s; }
.wr2 { width: 50px;  height: 50px;  animation-delay: 0.55s; }
.wr3 { width: 76px;  height: 76px;  animation-delay: 1.1s; }
@keyframes win-ring-expand {
  0%   { opacity: 0.9; transform: scale(0.3); box-shadow: 0 0 8px #ffa020; }
  100% { opacity: 0;   transform: scale(1);   box-shadow: none; }
}
.win-core {
  width: 12px; height: 12px; border-radius: 50%;
  background: #ffd84a; box-shadow: 0 0 14px #ffa020, 0 0 30px #ff8800;
  position: relative; z-index: 1;
}

#flash {
  position: fixed; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at 50% 50%, rgba(0,120,255,0.25) 0%, transparent 70%);
  transition: opacity 0.05s ease-out;
}

#overlay {
  position: fixed; inset: 0; background: #000; cursor: pointer; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #3af; font-family: monospace; text-shadow: 0 0 12px #0af;
  overflow: hidden;
}
#overlay .go {
  position: relative;
  z-index: 1;
  font-size: 0.95rem; animation: blink 1.4s ease-in-out infinite; opacity: 0.7; letter-spacing: 2px;
}

/* Full-screen sonar grid (cave fragShader palette) — pulse expands, fades, repeats */
.overlay-screen-sonar {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.overlay-title-cluster {
  position: relative;
  z-index: 1;
  display: inline-block;
  margin-bottom: 32px;
}
#overlay h1 {
  position: relative;
  z-index: 1;
  margin: 0;
  font-size: 2.4rem;
  letter-spacing: 6px;
}
/* Orthogonal + faint Z-ish lines; gridCol ≈ (0, 0.42, 1) */
.overlay-screen-grid {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 20, 55, 0.12);
  background-image:
    linear-gradient(
      0deg,
      rgba(0, 107, 255, 0.36) 0,
      rgba(0, 107, 255, 0.36) 1px,
      transparent 1px,
      transparent 100%
    ),
    linear-gradient(
      90deg,
      rgba(0, 107, 255, 0.32) 0,
      rgba(0, 107, 255, 0.32) 1px,
      transparent 1px,
      transparent 100%
    ),
    linear-gradient(
      128deg,
      rgba(0, 90, 220, 0.12) 0,
      rgba(0, 90, 220, 0.12) 1px,
      transparent 1px,
      transparent 100%
    );
  background-size: 11px 11px, 11px 11px, 15px 15px;
  background-position: 0 0, 0 0, 4px 2px;
  mix-blend-mode: screen;
  box-shadow: inset 0 0 48px rgba(115, 235, 255, 0.02);
}
.overlay-screen-sweep {
  position: absolute;
  inset: 0;
  clip-path: circle(1.5vmax at 50% 50%);
  opacity: 0;
  animation: overlay-sonar-sweep 3.1s ease-out infinite;
}
.overlay-screen-sweep-2 {
  animation-delay: 0.62s;
}
.overlay-screen-sweep-3 {
  animation-delay: 1.24s;
}
@keyframes overlay-sonar-sweep {
  0% {
    clip-path: circle(1.5vmax at 50% 50%);
    opacity: 0;
  }
  5% {
    opacity: 0.36;
  }
  45% {
    opacity: 0.14;
  }
  100% {
    /* vmax so the circle always clears screen corners on any aspect ratio */
    clip-path: circle(78vmax at 50% 50%);
    opacity: 0;
  }
}

/* ── Tutorial screen ───────────────────────────────────────── */
#tutorial {
  position: fixed; inset: 0; z-index: 19;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px;
  background: #000;
  color: #3af; font-family: monospace;
  opacity: 0; pointer-events: none;
  transition: opacity 0.6s ease;
}
#tutorial.visible  { opacity: 1; }
#tutorial.fade-out { opacity: 0; transition: opacity 1.2s ease; }

/* goal + exit preview (matches in-game gold rim / black void) */
.tut-goal-block {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 360px;
  padding: 0 8px;
}
.tut-exit-preview {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  box-sizing: border-box;
  border-radius: 50%;
  border: 3px solid #e9a82e;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
/* Solid black pit — only the outer border reads as the gold ring */
.tut-exit-hole {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #000000;
}
.tut-goal-text { text-align: left; }
.tut-goal-label {
  display: block;
  font-size: 0.78rem;
  color: #ffc84a;
  text-shadow: 0 0 10px #fa0a, 0 0 18px #f808;
  letter-spacing: 3px;
  margin-bottom: 2px;
  opacity: 1;
}
.tut-goal-desc {
  font-size: 0.65rem;
  line-height: 1.32;
  opacity: 0.78;
  letter-spacing: 0.35px;
  color: #9dd4ff;
  margin: 0;
}
.tut-gold-word {
  color: #ffc84a;
  text-shadow: 0 0 8px rgba(255, 180, 60, 0.5);
  font-weight: bold;
}

/* sonar callout */
.tut-sonar-block {
  display: flex;
  align-items: center;
  gap: 12px;
}
.sonar-rings {
  position: relative;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ring {
  position: absolute; border-radius: 50%;
  border: 1px solid #0af;
  animation: sonar-expand 2s ease-out infinite;
  opacity: 0;
}
.r1 { width: 16px; height: 16px; animation-delay: 0s; }
.r2 { width: 30px; height: 30px; animation-delay: 0.5s; }
.r3 { width: 46px; height: 46px; animation-delay: 1s; }
.sonar-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #0ff; box-shadow: 0 0 6px #0ff;
  position: relative; z-index: 1;
}
@keyframes sonar-expand {
  0%   { opacity: 0.9; transform: scale(0.3); }
  100% { opacity: 0;   transform: scale(1); }
}
.tut-sonar-text { text-align: left; }
.tut-sonar-text .tut-label {
  display: block;
  font-size: 0.82rem;
  color: #0ff;
  text-shadow: 0 0 8px #0ff;
  letter-spacing: 2px;
  margin-bottom: 2px;
}
.tut-sonar-text .tut-desc {
  font-size: 0.58rem;
  opacity: 0.52;
  letter-spacing: 0.3px;
  line-height: 1.35;
}
.tut-blind-emph {
  font-size: 0.82rem;
  font-weight: 700;
  color: #cfffff;
  letter-spacing: 0.06em;
  text-shadow: 0 0 12px #0ff, 0 0 22px #08c;
  margin-right: 0.25em;
}

.tut-divider { width: 200px; height: 1px; background: #0af2; }

/* controls row */
.tut-controls {
  display: flex; gap: 40px; align-items: flex-start;
}
.tut-group {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.tut-label {
  font-size: 0.65rem; letter-spacing: 2px; opacity: 0.55; margin-top: 4px;
  text-shadow: 0 0 6px #0af;
}

/* keys */
.key-row { display: flex; gap: 4px; justify-content: center; }
.key {
  min-width: 28px; height: 28px; padding: 0 5px;
  border: 1px solid #0af5; background: #001a2a;
  border-radius: 4px; display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; color: #0cf; letter-spacing: 1px;
  box-shadow: 0 0 6px #0af3, inset 0 -2px 0 #0af2;
  text-shadow: 0 0 6px #0af;
}
.key.sm   { min-width: 24px; font-size: 0.65rem; }
.key.wide { min-width: 46px; font-size: 0.6rem; letter-spacing: 0; }
.key-sep  { font-size: 0.65rem; opacity: 0.4; align-self: center; margin: 0 1px; }

/* mouse icon */
.mouse-icon { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.mouse-body {
  width: 24px; height: 36px;
  border: 1px solid #0af5; border-radius: 12px;
  background: #001a2a; overflow: hidden;
  display: flex; flex-direction: column; align-items: center;
  position: relative;
  box-shadow: 0 0 6px #0af3;
}
.mouse-btn {
  width: 50%; height: 12px;
  border-bottom: 1px solid #0af4;
  float: left;
}
.left-btn  { border-right: 1px solid #0af4; background: #002a3a; }
.right-btn { background: #001a2a; }
.mouse-scroll {
  clear: both; width: 3px; height: 7px;
  background: #0af; border-radius: 2px;
  margin: 2px auto 0; box-shadow: 0 0 4px #0af;
  position: absolute; top: 14px;
}
.mouse-arrows {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 1px; font-size: 0.6rem; opacity: 0.5;
  color: #0cf; line-height: 1;
}

/* hazard legend */
.tut-legend {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.65rem; opacity: 0.45; letter-spacing: 1px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.red  { background: #f44; box-shadow: 0 0 6px #f44; }
.dot.blue { background: #4af; box-shadow: 0 0 6px #4af; }

#gameover {
  position: fixed; inset: 0; z-index: 30;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.92);
  color: #f44; font-family: monospace; text-shadow: 0 0 14px #f008;
  pointer-events: auto;
}
#gameover h2 { font-size: 2rem; letter-spacing: 8px; margin-bottom: 12px; }
#gameover .reason { color: #faa; opacity: 0.85; font-size: 0.85rem; margin-bottom: 28px; }
#restart-btn {
  font-family: monospace; font-size: 1rem; letter-spacing: 2px;
  padding: 12px 28px; cursor: pointer;
  color: #0cf; background: #001820; border: 1px solid #0af6;
  text-shadow: 0 0 8px #0af;
}
#restart-btn:hover { background: #002a38; border-color: #6df; }

@keyframes blink { 0%,100%{opacity:0.3} 50%{opacity:1} }

#model-credit {
  position: fixed;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-family: monospace;
  font-size: 0.62rem;
  color: #2a5a70;
  opacity: 0.55;
  pointer-events: none;
  letter-spacing: 0.4px;
  z-index: 2;
}