:root {
  --deepest: #050b16;
  --deep: #081626;
  --lit: #0c1e33;
  --aqua: #9bf6e0;
  --teal: #3fe0c8;
  --violet: #8a6bff;
  --warm: #ffc46b;
  --warm-core: #fff4de;
  --pink: #ff3d7f;
  --serif: "Space Grotesk", "Trebuchet MS", sans-serif;
  --mono: "Space Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

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

body {
  color: #e8fffa;
  font-family: var(--serif);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 38%, #0b2136 0%, #071a2c 52%, #040b14 100%);
}

#field {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* ---------- HUD ------------------------------------------------------- */

#hud {
  position: absolute;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: clamp(7px, 1.25vw, 18px);
  pointer-events: none;
  will-change: left, top;
}

.brand {
  position: relative;
  flex: 0 0 auto;
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(22px, 3.3vw, 46px);
  line-height: .82;
  letter-spacing: .005em;
  text-transform: uppercase;
  white-space: nowrap;
  background: linear-gradient(178deg, #ffffff 0%, #eafffb 32%, #9bf6e0 66%, #55c8b5 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 5px rgba(255,255,255,.5)) drop-shadow(0 0 15px rgba(155,246,224,.38)) drop-shadow(0 0 34px rgba(63,224,200,.20));
}

@keyframes brandBreath {
  0%, 100% { filter: drop-shadow(0 0 4px rgba(255,255,255,.42)) drop-shadow(0 0 13px rgba(155,246,224,.32)) drop-shadow(0 0 30px rgba(63,224,200,.16)); }
  50% { filter: drop-shadow(0 0 7px rgba(255,255,255,.6)) drop-shadow(0 0 21px rgba(155,246,224,.48)) drop-shadow(0 0 44px rgba(63,224,200,.26)); }
}

.slots {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, .9vw, 11px);
  min-width: 0;
}

.vessel {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(16px, 2.25vw, 30px);
  aspect-ratio: .86;
  border: 1px solid rgba(155,246,224,.30);
  border-radius: 4px 4px 12px 12px;
  background:
    radial-gradient(ellipse at 50% 96%, rgba(190,255,245,.48) 0%, rgba(63,224,200,.16) 38%, rgba(10,30,45,0) 74%),
    linear-gradient(180deg, rgba(10,28,44,.14), rgba(10,28,44,.46));
  box-shadow: inset 0 -6px 11px rgba(63,224,200,.13), inset 0 1px 0 rgba(200,255,245,.14), 0 0 12px rgba(63,224,200,.08);
  overflow: hidden;
}

.vessel svg {
  width: 62%;
  height: 62%;
  display: block;
  color: rgba(190,255,245,.38);
  transition: color .18s ease, filter .18s ease;
}

.vessel.active {
  border-color: var(--pw, #9bf6e0);
  box-shadow: inset 0 -6px 11px rgba(63,224,200,.20), 0 0 15px var(--pw, #9bf6e0);
}

.vessel.active svg {
  color: var(--pw, #9bf6e0);
  filter: drop-shadow(0 0 4px var(--pw, #9bf6e0));
}

.vessel::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 11%;
  width: 5px;
  height: 5px;
  margin-left: -2.5px;
  border-radius: 50%;
  background: rgba(190,255,245,.55);
  box-shadow: 0 0 8px rgba(155,246,224,.9);
  opacity: .6;
}

@keyframes vesselWait {
  0%, 100% { border-color: rgba(155,246,224,.24); box-shadow: inset 0 -5px 9px rgba(63,224,200,.09), 0 0 8px rgba(63,224,200,.06); }
  50% { border-color: rgba(155,246,224,.44); box-shadow: inset 0 -7px 13px rgba(63,224,200,.20), 0 0 16px rgba(63,224,200,.14); }
}

.meters {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: clamp(6px, 1vw, 14px);
}

.scorebox {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1;
}

.cap {
  font-family: var(--serif);
  font-weight: 300;
  font-size: clamp(7px, .78vw, 10px);
  letter-spacing: .26em;
  color: rgba(190,245,237,.48);
  text-transform: uppercase;
  margin-bottom: 3px;
}

.score {
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(15px, 1.65vw, 24px);
  letter-spacing: .08em;
  color: #dcfff8;
  text-shadow: 0 0 8px rgba(155,246,224,.3);
  font-variant-numeric: tabular-nums;
  transition: color .12s, text-shadow .12s;
}

.score.flare {
  color: #ffffff;
  text-shadow: 0 0 10px rgba(255,255,255,.9), 0 0 24px rgba(155,246,224,.75), 0 0 44px rgba(63,224,200,.45);
}

.level-chip {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: clamp(3px, .5vw, 6px) clamp(7px, 1vw, 13px) clamp(4px, .55vw, 8px);
  border: 1px solid rgba(155,246,224,.32);
  border-radius: 12px 12px 15px 15px;
  background: radial-gradient(ellipse at 50% 100%, rgba(63,224,200,.16), rgba(8,24,38,.25) 72%);
  box-shadow: inset 0 -4px 10px rgba(63,224,200,.08), 0 0 12px rgba(63,224,200,.06);
}

.level-chip b {
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(14px, 1.55vw, 22px);
  letter-spacing: .04em;
  color: #effffb;
  text-shadow: 0 0 10px rgba(155,246,224,.4);
}

.level-chip.pulse {
  animation: chipPulse .65s ease-out;
}

@keyframes chipPulse {
  0% { box-shadow: inset 0 -4px 10px rgba(63,224,200,.08), 0 0 12px rgba(63,224,200,.06); border-color: rgba(155,246,224,.32); }
  25% { box-shadow: inset 0 -6px 14px rgba(63,224,200,.3), 0 0 24px rgba(63,224,200,.4); border-color: rgba(220,255,248,.85); }
  100% { box-shadow: inset 0 -4px 10px rgba(63,224,200,.08), 0 0 12px rgba(63,224,200,.06); border-color: rgba(155,246,224,.32); }
}

/* ---------- FOOTER / START ------------------------------------------- */

#footer {
  position: absolute;
  z-index: 7;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(7px, 1.4vh, 14px);
  pointer-events: none;
  will-change: top;
}

.tray {
  position: relative;
  display: grid;
  place-items: center;
  min-width: clamp(150px, 46vw, 252px);
  height: clamp(48px, 6.4vh, 62px);
  padding: 0 26px;
  border: 1px solid rgba(196,255,246,.58);
  border-radius: 14px;
  background:
    radial-gradient(ellipse at 50% 10%, rgba(255,255,255,.22), rgba(155,246,224,.15) 26%, rgba(14,50,62,.56) 62%, rgba(5,18,30,.88) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.55),
    inset 0 -14px 24px rgba(63,224,200,.12),
    0 0 22px rgba(63,224,200,.18),
    0 12px 34px rgba(0,0,0,.45);
  color: #f3fffd;
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(15px, 1.5vw, 20px);
  letter-spacing: .24em;
  text-indent: .24em;
  text-shadow: 0 0 10px rgba(190,255,245,.8), 0 0 24px rgba(63,224,200,.5);
  cursor: pointer;
  touch-action: manipulation;
  pointer-events: auto;
  transition: transform .16s ease, box-shadow .2s ease, background .2s ease, opacity .25s ease;
  overflow: hidden;
}

.tray::before {
  content: "";
  position: absolute;
  left: 9%;
  right: 9%;
  top: 7%;
  height: 46%;
  border-radius: 50%;
  border-top: 1px solid rgba(255,255,255,.7);
  background: radial-gradient(ellipse at 50% 0%, rgba(255,255,255,.2), transparent 68%);
  filter: blur(.4px);
  opacity: .8;
  transition: top .22s ease, opacity .22s ease;
  pointer-events: none;
}

.tray::after {
  content: "";
  position: absolute;
  inset: auto 14% 10% 14%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(155,246,224,.5), transparent);
  opacity: .5;
  pointer-events: none;
}

.tray:hover {
  transform: translateY(-1px) scale(1.02);
  background:
    radial-gradient(ellipse at 50% 8%, rgba(255,255,255,.32), rgba(155,246,224,.24) 28%, rgba(20,72,84,.64) 64%, rgba(6,22,34,.9) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.7),
    inset 0 -16px 28px rgba(63,224,200,.2),
    0 0 30px rgba(63,224,200,.32),
    0 14px 38px rgba(0,0,0,.5);
}

.tray:hover::before { top: 1%; opacity: 1; }

.tray:active {
  transform: translateY(1px) scale(.99);
}

.tray.is-hidden {
  opacity: 0;
  transform: translateY(4px) scale(.96);
  pointer-events: none;
}

.hint {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(9px, .9vw, 12px);
  letter-spacing: .19em;
  text-align: center;
  color: rgba(190,245,237,.62);
  text-shadow: 0 0 10px rgba(63,224,200,.12);
  white-space: nowrap;
  pointer-events: none;
}

/* ---------- SHIP'S HELM ----------------------------------------------- */

.aim-hint {
  position: absolute;
  z-index: 8;
  left: max(18px, env(safe-area-inset-left));
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + clamp(112px, 12vw, 150px) + 7px);
  display: none;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(7px, .62vw, 8px);
  letter-spacing: .15em;
  color: rgba(196,248,239,.58);
  text-shadow: 0 0 8px rgba(3,10,18,.85);
  white-space: nowrap;
  pointer-events: none;
}

body.playing .aim-hint { display: block; }

body.touch .aim-hint {
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(max(40px, calc(env(safe-area-inset-bottom) + 38px)) + clamp(110px, 31vw, 136px) + 5px);
  text-align: center;
  font-size: 8px;
}


.helm {
  position: absolute;
  z-index: 9;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: clamp(112px, 12vw, 150px);
  height: clamp(112px, 12vw, 150px);
  display: none;
  border-radius: 50%;
  background: radial-gradient(circle at 48% 42%, rgba(63,224,200,.10), rgba(4,15,24,.42) 64%, rgba(4,12,20,.16));
  box-shadow: inset 0 0 22px rgba(63,224,200,.07), 0 0 26px rgba(63,224,200,.12);
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

body.playing .helm { display: block; }

.helm.grabbing { cursor: grabbing; }

.helm-rotor {
  width: 100%;
  height: 100%;
  transform-origin: 50% 50%;
  will-change: transform;
  pointer-events: none;
}

.helm svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

body.touch .helm {
  left: 50%;
  transform: translateX(-50%);
  bottom: max(40px, calc(env(safe-area-inset-bottom) + 38px));
  width: clamp(110px, 31vw, 136px);
  height: clamp(110px, 31vw, 136px);
}

@media (max-height: 680px) {
  body.touch .helm {
    width: 96px;
    height: 96px;
    bottom: max(34px, calc(env(safe-area-inset-bottom) + 32px));
  }
  body.touch .aim-hint {
    bottom: calc(max(34px, calc(env(safe-area-inset-bottom) + 32px)) + 96px + 5px);
  }
}

@media (max-height: 540px) {
  body.touch .helm {
    left: max(12px, env(safe-area-inset-left));
    transform: none;
    bottom: max(10px, env(safe-area-inset-bottom));
    width: 92px;
    height: 92px;
  }
  body.touch .aim-hint {
    left: max(12px, env(safe-area-inset-left));
    transform: none;
    bottom: calc(max(10px, env(safe-area-inset-bottom)) + 92px + 5px);
    text-align: left;
  }
}

/* ---------- SMALL GLASS BUTTONS -------------------------------------- */

.glass-btn {
  position: absolute;
  z-index: 12;
  top: max(10px, env(safe-area-inset-top));
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(155,246,224,.26);
  background: radial-gradient(circle at 50% 34%, rgba(155,246,224,.13), rgba(7,24,38,.58) 70%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.16), 0 0 12px rgba(63,224,200,.08);
  color: rgba(210,255,248,.8);
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}

.glass-btn svg { width: 22px; height: 22px; }

.glass-btn:hover {
  border-color: rgba(200,255,245,.55);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.24), 0 0 18px rgba(63,224,200,.22);
}

.glass-btn:active { transform: scale(.94); }

.glass-btn.sound { right: max(10px, env(safe-area-inset-right)); }
.glass-btn.pause { left: max(10px, env(safe-area-inset-left)); display: none; }
.glass-btn.pause.show { display: grid; }

.sound .slash { opacity: 0; transition: opacity .18s; }
.sound .wave { transition: opacity .18s; }
.sound.muted { color: rgba(150,190,190,.55); }
.sound.muted .wave { opacity: .12; }
.sound.muted .slash { opacity: .9; }

/* ---------- LEVEL FLASH ---------------------------------------------- */

.level-flash {
  position: absolute;
  z-index: 9;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  pointer-events: none;
  opacity: 0;
  text-align: center;
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(26px, 4.2vw, 52px);
  letter-spacing: .10em;
  color: transparent;
  background: linear-gradient(180deg, #ffffff 0%, #effffb 38%, #9bf6e0 72%, #45c5b2 100%);
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 0 10px rgba(255,255,255,.5)) drop-shadow(0 0 28px rgba(155,246,224,.55)) drop-shadow(0 0 60px rgba(63,224,200,.3));
}

.level-flash small {
  display: block;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(9px, 1.05vw, 14px);
  letter-spacing: .32em;
  text-indent: .32em;
  color: rgba(210,255,248,.62);
  background: none;
  -webkit-text-fill-color: rgba(210,255,248,.62);
  filter: none;
}

.level-flash.show { animation: levelFlash 1.2s cubic-bezier(.18,.75,.25,1) forwards; }

@keyframes levelFlash {
  0% { opacity: 0; transform: scale(.82); filter: blur(4px) drop-shadow(0 0 24px rgba(255,255,255,.8)); }
  18% { opacity: 1; transform: scale(1.02); filter: blur(0) drop-shadow(0 0 16px rgba(255,255,255,.7)) drop-shadow(0 0 46px rgba(155,246,224,.7)); }
  32% { transform: scale(1); }
  72% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.035); }
}

/* ---------- PAUSE OVERLAY -------------------------------------------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 48%, rgba(8,26,42,.55), rgba(2,7,13,.82));
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  animation: overlayIn .22s ease-out;
}

.overlay[hidden] { display: none; }

@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

.overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(13px, 2vh, 20px);
  text-align: center;
  padding: 28px;
}

.over-cap {
  margin: 0;
  font-size: clamp(8px, .9vw, 11px);
  font-weight: 500;
  letter-spacing: .4em;
  text-indent: .4em;
  color: rgba(190,245,237,.5);
}

.overlay-card h2 {
  margin: 0 0 4px;
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(38px, 6.5vw, 76px);
  letter-spacing: .06em;
  line-height: .9;
  background: linear-gradient(180deg, #ffffff, #c8fff5 50%, #54cbb8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 12px rgba(255,255,255,.4)) drop-shadow(0 0 34px rgba(155,246,224,.45));
}

.ghost-btn {
  border: 0;
  background: none;
  padding: 6px 10px;
  color: rgba(205,248,240,.66);
  font-family: var(--serif);
  font-weight: 500;
  font-size: 10px;
  letter-spacing: .26em;
  text-indent: .26em;
  cursor: pointer;
  transition: color .15s;
}

.ghost-btn:hover { color: rgba(230,255,250,.9); }

/* ---------- SEAL ------------------------------------------------------ */

.seal {
  position: absolute;
  z-index: 4;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: clamp(44px, 5.4vw, 64px);
  height: clamp(44px, 5.4vw, 64px);
  opacity: 1;
  filter: drop-shadow(0 0 9px rgba(155,246,224,.45)) drop-shadow(0 0 26px rgba(63,224,200,.24));
  pointer-events: none;
}

.seal svg { width: 100%; height: 100%; display: block; }

body.touch .seal {
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + clamp(74px, 19vw, 96px));
}

/* ---------- MOBILE HUD ------------------------------------------------ */

@media (max-width: 660px) {
  #hud {
    flex-wrap: wrap;
    justify-content: space-between;
    row-gap: 7px;
  }
  .brand { font-size: clamp(20px, 6vw, 27px); }
  .slots {
    order: 3;
    flex: 0 0 100%;
    justify-content: flex-start;
    padding-left: 2px;
  }
  .vessel { width: clamp(16px, 4.4vw, 21px); }
  .meters { margin-left: auto; }
  .hint { white-space: normal; max-width: 78vw; line-height: 1.6; }
}

@media (max-height: 540px) {
  .glass-btn { width: 32px; height: 32px; top: max(6px, env(safe-area-inset-top)); }
  .glass-btn svg { width: 18px; height: 18px; }
  .brand { font-size: clamp(18px, 2.4vw, 30px); }
  #hud { row-gap: 4px; }
  .cap { font-size: 7px; }
  .tray { height: 44px; min-width: 154px; font-size: 14px; }
  .hint { font-size: 7.5px; letter-spacing: .14em; }
  .seal { width: 38px; height: 38px; }
  body.touch .seal { bottom: calc(max(8px, env(safe-area-inset-bottom)) + 62px); }
}

@media (prefers-reduced-motion: reduce) {
  .brand, .vessel { animation: none; }
  .tray, .glass-btn { transition: none; }
  .level-flash.show { animation-duration: .6s; }
}
