*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --clock-glow: rgba(120, 180, 255, 0.9);
  --clock-color: rgba(255, 255, 255, 0.97);
  --clock-ref-opacity: 0.25;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000011;
  font-family: 'Orbitron', monospace;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

/* ============ CSS CELESTIAL BODIES ============ */

/* --- MOON — silvery guardian of the night --- */
#css-moon {
  --size: 22vmin;
  position: fixed;
  width: var(--size);
  height: var(--size);
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1s ease;
  will-change: opacity, left, top;
  animation: moonFloat 8s ease-in-out infinite;
}

@keyframes moonFloat {
  0%   { transform: translateY(0) rotate(0deg); }
  35%  { transform: translateY(-0.6vmin) rotate(1.5deg); }
  65%  { transform: translateY(-1vmin) rotate(-1deg); }
  100% { transform: translateY(0) rotate(0deg); }
}

/* Cool blue-white glow — real moonlight */
.moon-glow {
  position: absolute;
  inset: -55%;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(200, 215, 240, 0.2) 0%,
    rgba(180, 200, 235, 0.08) 40%,
    transparent 68%
  );
  animation: moonGlowPulse 6s ease-in-out infinite alternate;
}
@keyframes moonGlowPulse {
  0%   { transform: scale(1); opacity: 0.5; }
  100% { transform: scale(1.25); opacity: 1; }
}

/* Silver-blue lunar body */
.moon-body {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%,
    #f0f0f5 0%, #dde0ea 25%, #c5cad8 50%, #a8b0c2 80%, #909aaf 100%
  );
  box-shadow:
    0 0 2vmin rgba(200, 215, 240, 0.6),
    0 0 5vmin rgba(180, 200, 235, 0.25),
    inset 0.5vmin 0.5vmin 2vmin rgba(240, 245, 255, 0.5),
    inset -0.4vmin -0.4vmin 1.5vmin rgba(100, 110, 140, 0.3);
  overflow: hidden;
}

/* Surface shimmer — light slowly moves across the face */
.moon-body::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(ellipse 40% 50% at 30% 35%,
    rgba(255, 255, 255, 0.15) 0%, transparent 100%
  );
  animation: moonShimmer 12s ease-in-out infinite;
}
@keyframes moonShimmer {
  0%   { opacity: 0.6; transform: translate(0, 0) rotate(0deg); }
  33%  { opacity: 0.9; transform: translate(8%, 5%) rotate(5deg); }
  66%  { opacity: 0.5; transform: translate(-5%, -3%) rotate(-3deg); }
  100% { opacity: 0.6; transform: translate(0, 0) rotate(0deg); }
}

/* Craters — dark blue-grey mare patches */
.moon-crater {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(90, 100, 130, 0.35) 0%, rgba(110, 120, 145, 0.1) 70%, transparent 100%
  );
}
.moon-crater.c1 {
  width: 20%; height: 20%;
  top: 18%; left: 15%;
  animation: craterDrift 10s ease-in-out infinite;
}
.moon-crater.c2 {
  width: 14%; height: 14%;
  top: 55%; left: 48%;
  animation: craterDrift 13s ease-in-out infinite reverse;
}
.moon-crater.c3 {
  width: 10%; height: 10%;
  top: 32%; left: 62%;
  animation: craterDrift 11s ease-in-out infinite 2s;
}
@keyframes craterDrift {
  0%, 100% { transform: translate(0, 0) scale(1); opacity: 0.5; }
  50%      { transform: translate(2%, -2%) scale(1.05); opacity: 0.3; }
}

/* Guardian eyes — wide, gentle, watchful */
.moon-eye {
  position: absolute;
  width: 11%;
  height: 13%;
  top: 38%;
  background: #2a3048;
  border-radius: 50%;
  box-shadow: inset 1px 1px 2px rgba(0,0,0,0.3);
  animation: moonWatch 8s ease-in-out infinite;
}
.moon-eye.left  { left: 28%; }
.moon-eye.right { right: 28%; }

/* White eye glint — light reflection */
.moon-eye::after {
  content: '';
  position: absolute;
  width: 30%;
  height: 30%;
  top: 18%;
  right: 18%;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
}

@keyframes moonWatch {
  /* Watching phase */
  0%       { transform: scaleY(1) translateY(0); }
  5%       { transform: scaleY(1) translateY(-4%); }
  15%      { transform: scaleY(1) translateY(0); }
  30%      { transform: scaleY(1) translateY(2%); }
  35%      { transform: scaleY(0.15); }               /* quick blink */
  38%      { transform: scaleY(1) translateY(0); }
  /* Falling asleep */
  50%      { transform: scaleY(0.6); }
  55%      { transform: scaleY(0.15); }               /* eyes close — sleeping */
  75%      { transform: scaleY(0.15); }               /* stays asleep */
  /* Waking back up */
  82%      { transform: scaleY(0.5); }
  88%      { transform: scaleY(1) translateY(0); }
  100%     { transform: scaleY(1) translateY(0); }
}

/* Serene gentle smile — the guardian's warmth */
.moon-mouth {
  position: absolute;
  width: 22%;
  height: 10%;
  bottom: 26%;
  left: 39%;
  border: none;
  border-bottom: 2px solid rgba(60, 70, 100, 0.5);
  border-radius: 0 0 50% 50%;
  animation: moonSmile 6s ease-in-out infinite;
}
@keyframes moonSmile {
  0%, 100% { transform: scaleX(1); opacity: 0.6; }
  50%      { transform: scaleX(1.1); opacity: 0.8; }
}

/* Floating Zzz — drifts up and right */
.moon-zzz {
  position: absolute;
  top: 8%;
  right: 5%;
  font-family: 'Georgia', serif;
  font-style: italic;
  font-weight: bold;
  color: rgba(200, 215, 240, 0.7);
  text-shadow: 0 0 8px rgba(180, 200, 240, 0.4);
  pointer-events: none;
  opacity: 0;
  animation: zzzFloat 4s ease-out infinite;
}
.moon-zzz.z1 {
  font-size: 2.5vmin;
  animation-delay: 0s;
}
.moon-zzz.z2 {
  font-size: 3.5vmin;
  animation-delay: 1.3s;
  right: 0%;
}
.moon-zzz.z3 {
  font-size: 4.5vmin;
  animation-delay: 2.6s;
  right: -5%;
}

@keyframes zzzFloat {
  0%   { opacity: 0; transform: translate(0, 0) scale(0.5) rotate(-10deg); }
  15%  { opacity: 0.7; }
  100% { opacity: 0; transform: translate(3vmin, -6vmin) scale(1.3) rotate(10deg); }
}

/* --- SUN --- */
#css-sun {
  --size: 34vmin;  /* body at inset:18% ≈ 22vmin circle, matches moon */
  position: fixed;
  width: var(--size);
  height: var(--size);
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1s ease;
  will-change: opacity, left, top;
  animation: sunBob 6s ease-in-out infinite;
}

@keyframes sunBob {
  0%   { transform: translateY(0); }
  50%  { transform: translateY(-0.8vmin); }
  100% { transform: translateY(0); }
}

.sun-glow {
  position: absolute;
  inset: -60%;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(255, 230, 100, 0.18) 0%,
    rgba(255, 180, 50, 0.06) 45%,
    transparent 70%
  );
  animation: sunGlowBreath 4s ease-in-out infinite alternate;
}
@keyframes sunGlowBreath {
  0%   { transform: scale(1); opacity: 0.5; }
  100% { transform: scale(1.4); opacity: 1; }
}

/* Spikes container — rotates slowly */
.sun-spikes {
  position: absolute;
  inset: 0;
  animation: spikeSpin 40s linear infinite;
}
@keyframes spikeSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* Individual spike — triangle shape that pops in/out */
.spike {
  position: absolute;
  left: 50%;
  top: 0;
  width: 8%;
  height: 32%;
  margin-left: -4%;
  transform-origin: 50% 155%;
  transform: rotate(calc(var(--i) * 36deg));
  background: linear-gradient(to top,
    rgba(255, 210, 60, 0.7) 0%,
    rgba(255, 190, 40, 0.35) 50%,
    rgba(255, 240, 160, 0.1) 100%
  );
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
  animation: spikePop 3s ease-in-out infinite;
  animation-delay: calc(var(--i) * 0.3s);
}

@keyframes spikePop {
  0%   { transform: rotate(calc(var(--i) * 36deg)) scaleY(0.3); opacity: 0.2; }
  50%  { transform: rotate(calc(var(--i) * 36deg)) scaleY(1);   opacity: 0.8; }
  100% { transform: rotate(calc(var(--i) * 36deg)) scaleY(0.3); opacity: 0.2; }
}

/* Sun body — the main circle with face */
.sun-body {
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: radial-gradient(circle at 42% 38%,
    #fffef0 0%, #fff5a0 20%, #ffda40 50%, #ffb010 80%, #ff8c00 100%
  );
  box-shadow:
    0 0 2vmin rgba(255, 200, 50, 0.7),
    0 0 4vmin rgba(255, 150, 0, 0.25),
    inset 0.5vmin 0.5vmin 1.5vmin rgba(255, 255, 200, 0.5),
    inset -0.3vmin -0.3vmin 1vmin rgba(255, 120, 0, 0.25);
  animation: sunBodyPulse 3.5s ease-in-out infinite alternate;
}
@keyframes sunBodyPulse {
  0%   { transform: scale(1); }
  100% { transform: scale(1.03); }
}

/* Eyes — simple dark dots that blink */
.sun-eye {
  position: absolute;
  width: 10%;
  height: 14%;
  top: 35%;
  background: #553300;
  border-radius: 50%;
  animation: eyeBlink 4s ease-in-out infinite;
}
.sun-eye.left  { left: 28%; }
.sun-eye.right { right: 28%; }

@keyframes eyeBlink {
  0%, 92%, 100% { transform: scaleY(1); }
  96%           { transform: scaleY(0.1); }
}

/* Smile — curved arc */
.sun-smile {
  position: absolute;
  width: 30%;
  height: 15%;
  bottom: 25%;
  left: 35%;
  border: none;
  border-bottom: 2.5px solid #664400;
  border-radius: 0 0 50% 50%;
  animation: smileWiggle 5s ease-in-out infinite;
}
@keyframes smileWiggle {
  0%, 100% { transform: scaleX(1); }
  50%      { transform: scaleX(1.15); }
}

/* ============ FISH ============ */
#fish-container {
  position: fixed;
  top: 55%;
  left: 0;
  width: 100%;
  height: 45%;
  z-index: 13;
  pointer-events: none;
  overflow: hidden;
}

.fish {
  position: absolute;
  width: var(--fish-size, 4vmin);
  height: calc(var(--fish-size, 4vmin) * 0.45);
  animation: var(--swim-dir, swimRight) var(--swim-dur, 12s) linear forwards;
  opacity: 0.6;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.2));
}

/* Fish body — ellipse */
.fish-body {
  position: absolute;
  inset: 0;
  border-radius: 50% 40% 40% 50%;
  background: var(--fish-color, rgba(100, 180, 220, 0.7));
}

/* Tail — triangle */
.fish-tail {
  position: absolute;
  right: -18%;
  top: 10%;
  width: 35%;
  height: 80%;
  background: var(--fish-color, rgba(100, 180, 220, 0.7));
  clip-path: polygon(0% 50%, 100% 0%, 100% 100%);
  transform-origin: left center;
  animation: tailFlap 0.4s ease-in-out infinite alternate;
}

/* Eye */
.fish-eye {
  position: absolute;
  width: 14%;
  height: 25%;
  top: 28%;
  left: 18%;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 50%;
}

@keyframes tailFlap {
  0%   { transform: rotate(-12deg) scaleX(0.9); }
  100% { transform: rotate(12deg) scaleX(1.1); }
}

/* Swimming right (left to right) */
@keyframes swimRight {
  0%   { left: -15%; opacity: 0; }
  5%   { opacity: 0.6; }
  50%  { transform: translateY(-2vmin); }
  95%  { opacity: 0.6; }
  100% { left: 110%; opacity: 0; transform: translateY(0); }
}

/* Swimming left (right to left) — fish is flipped */
@keyframes swimLeft {
  0%   { right: -15%; opacity: 0; transform: scaleX(-1); }
  5%   { opacity: 0.6; }
  50%  { transform: scaleX(-1) translateY(-2vmin); }
  95%  { opacity: 0.6; }
  100% { right: 110%; opacity: 0; transform: scaleX(-1) translateY(0); }
}

#scene-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

#water-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  pointer-events: auto;
}

#water-front {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 15;
  pointer-events: none;
}

/* ============ CLOCK ============ */
#clock-container {
  position: fixed;
  left: 50%;
  top: 52%;
  transform: translateX(-50%);
  z-index: 10;
  text-align: center;
  pointer-events: none;
  will-change: transform, top;
  transition: top 0.05s linear;
}

#clock-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

#clock-time {
  font-size: clamp(64px, 20vw, 160px);
  font-weight: 700;
  color: var(--clock-color);
  text-shadow:
    0 0 20px var(--clock-glow),
    0 0 40px var(--clock-glow),
    0 0 80px var(--clock-glow),
    0 0 120px var(--clock-glow);
  letter-spacing: 6px;
  line-height: 1;
  transform: scaleY(1.25);
  animation: glowPulse 4s ease-in-out infinite;
}

@keyframes glowPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.15); }
}

#clock-period {
  font-size: clamp(40px, 12vw, 100px);
  font-weight: 200;
  color: var(--clock-color);
  text-shadow:
    0 0 15px var(--clock-glow),
    0 0 40px var(--clock-glow);
  opacity: 0.8;
  letter-spacing: 2px;
  line-height: 1;
  transform: scaleY(1.25);
}

#clock-seconds {
  position: fixed;
  top: 30%;
  left: 50%;
  transform: translateX(-50%) scaleY(1.3) scale(1);
  font-size: clamp(80px, 25vw, 200px);
  font-weight: 200;
  color: var(--clock-color);
  text-shadow: 0 0 30px var(--clock-glow);
  opacity: 0.08;
  letter-spacing: 12px;
  text-align: center;
  z-index: 2;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease, text-shadow 0.4s ease;
}

#clock-seconds.tick {
  opacity: 0.15;
  transform: translateX(-50%) scaleY(1.3) scale(1.05);
  text-shadow: 0 0 50px var(--clock-glow), 0 0 100px var(--clock-glow);
}

/* ============ ELECTRIFIED EFFECT ============ */
#clock-container.electrified #clock-time,
#clock-container.electrified #clock-period,
#clock-container.electrified #clock-seconds {
  animation: electricZap 1.2s ease-out;
}

@keyframes electricZap {
  0%   { filter: brightness(1); transform: scaleY(1.25) scale(1); }
  3%   { filter: brightness(4) saturate(1.5); transform: scaleY(1.25) scale(1.06); text-shadow: 0 0 40px #00ffff, 0 0 80px #4488ff, 0 0 120px #0044ff; }
  6%   { filter: brightness(0.8); transform: scaleY(1.25) scale(0.99); }
  9%   { filter: brightness(5) saturate(2); transform: scaleY(1.25) scale(1.05); text-shadow: 0 0 50px #00ffff, 0 0 100px #6644ff, 0 0 150px #0066ff, 0 0 200px #00aaff; }
  13%  { filter: brightness(1.3); transform: scaleY(1.25) scale(1.01); }
  18%  { filter: brightness(3) saturate(1.3); transform: scaleY(1.25) scale(1.04); text-shadow: 0 0 30px #00ffff, 0 0 70px #4488ff; }
  25%  { filter: brightness(1.1); transform: scaleY(1.25) scale(1); }
  35%  { filter: brightness(2); transform: scaleY(1.25) scale(1.02); text-shadow: 0 0 20px #00ddff, 0 0 50px #4466ff; }
  50%  { filter: brightness(1.4); transform: scaleY(1.25) scale(1.01); }
  70%  { filter: brightness(1.1); transform: scaleY(1.25) scale(1); }
  100% { filter: brightness(1); transform: scaleY(1.25) scale(1); }
}

#clock-date {
  font-size: clamp(11px, 2.5vw, 16px);
  font-weight: 400;
  color: var(--clock-color);
  text-shadow: 0 0 15px var(--clock-glow);
  opacity: 0.5;
  margin-top: 6px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* ============ CLOCK REFLECTION ============ */
#clock-reflection {
  margin-top: 10px;
  transform: scaleY(-1);
  opacity: var(--clock-ref-opacity);
  filter: blur(2.5px);
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, transparent 70%);
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, transparent 70%);
  animation: reflectionWave 4s ease-in-out infinite;
}

#clock-reflection .ref-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

#clock-time-ref {
  font-size: clamp(64px, 20vw, 160px);
  font-weight: 700;
  color: var(--clock-color);
  text-shadow: 0 0 20px var(--clock-glow);
  letter-spacing: 4px;
  line-height: 1;
}

#clock-period-ref {
  font-size: clamp(40px, 12vw, 100px);
  font-weight: 200;
  color: var(--clock-color);
  opacity: 0.8;
  line-height: 1;
}

#clock-seconds-ref {
  font-size: clamp(14px, 3.5vw, 22px);
  font-weight: 300;
  color: var(--clock-color);
  opacity: 0.4;
  letter-spacing: 6px;
  text-align: center;
}

@keyframes reflectionWave {
  0%, 100% { transform: scaleY(-1) scaleX(1); }
  25% { transform: scaleY(-1) scaleX(1.005); }
  50% { transform: scaleY(-0.98) scaleX(0.995); }
  75% { transform: scaleY(-1.01) scaleX(1.003); }
}

/* ============ AUDIO TOGGLE ============ */
#audio-toggle {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  right: calc(24px + env(safe-area-inset-right));
  z-index: 20;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

#audio-toggle:hover,
#audio-toggle:active {
  background: rgba(255,255,255,0.15);
  color: white;
  transform: scale(1.1);
}

/* ============ TOUCH RIPPLE ============ */
#touch-ripple-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  pointer-events: none;
  overflow: hidden;
}

.touch-ripple {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  transform: translate(-50%, -50%) scale(0);
  animation: rippleExpand 1.5s ease-out forwards;
  pointer-events: none;
}

.touch-ripple::after {
  content: '';
  position: absolute;
  top: -8px;
  left: -8px;
  right: -8px;
  bottom: -8px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  animation: rippleExpandInner 1.5s ease-out 0.1s forwards;
  transform: scale(0);
}

@keyframes rippleExpand {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(60); opacity: 0; }
}

@keyframes rippleExpandInner {
  0% { transform: scale(0); opacity: 1; }
  100% { transform: scale(55); opacity: 0; }
}

/* ============ LOADING ============ */
#scene-canvas {
  opacity: 0;
  transition: opacity 1.5s ease;
}

#scene-canvas.loaded {
  opacity: 1;
}

/* ============ GYRO PERMISSION OVERLAY ============ */
#gyro-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 17, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
}

#gyro-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px 48px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: rgba(255, 255, 255, 0.9);
  font-family: 'Orbitron', monospace;
  font-size: 14px;
  letter-spacing: 2px;
  text-transform: uppercase;
  animation: promptPulse 2s ease-in-out infinite;
}

#gyro-prompt svg {
  opacity: 0.7;
  animation: gyroSpin 3s linear infinite;
}

@keyframes promptPulse {
  0%, 100% { box-shadow: 0 0 20px rgba(100, 150, 255, 0.1); }
  50% { box-shadow: 0 0 40px rgba(100, 150, 255, 0.25); }
}

@keyframes gyroSpin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
