:root {
  --bg: #070814;
  --panel: rgba(9, 13, 34, 0.78);
  --line: rgba(255, 255, 255, 0.12);
  --text: #eff4ff;
  --muted: #afbddf;
  --accent: #5ec5ff;
  --accent-2: #ffb14a;
  --danger: #ff627d;
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 30% 15%, rgba(97, 66, 255, 0.25), transparent 26%),
    radial-gradient(circle at 70% 80%, rgba(0, 203, 255, 0.1), transparent 20%),
    linear-gradient(180deg, #0d0829 0%, #090c1f 40%, #050712 100%);
  color: var(--text);
  font-family: Inter, Arial, Helvetica, sans-serif;
  touch-action: none;
}
body {
  display: flex;
  align-items: center;
  justify-content: center;
}
#game-shell {
  position: relative;
  width: min(100vw, calc(100vh * 0.6));
  height: min(100vh, calc(100vw / 0.6));
  max-width: 520px;
  max-height: 100vh;
  min-width: 280px;
  background: rgba(0,0,0,0.15);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.05), 0 24px 60px rgba(0,0,0,0.45);
  overflow: hidden;
}
#game-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.08), transparent 18%, transparent 82%, rgba(255,255,255,0.03));
  pointer-events: none;
  z-index: 1;
}
#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
}
#hud {
  position: absolute;
  z-index: 5;
  top: 12px;
  left: 10px;
  right: 10px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  pointer-events: none;
}
.hud-pill {
  background: rgba(4, 9, 24, 0.72);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  border-radius: 999px;
  padding: 8px 10px;
  text-align: center;
  box-shadow: 0 8px 22px rgba(0,0,0,0.25);
  min-width: 0;
}
.hud-pill .label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.hud-pill span:last-child {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.button {
  color: var(--text);
  pointer-events: auto;
  cursor: pointer;
  font-size: 18px;
}
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(2, 5, 15, 0.65);
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
}
.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}
.small-overlay {
  background: transparent;
  align-items: start;
  padding-top: 90px;
}
.small-overlay .panel {
  width: min(80%, 320px);
  padding: 18px 18px;
  border-radius: 24px;
}
.level-panel h2 { margin-bottom: 6px; }
.panel {
  width: min(88%, 380px);
  padding: 28px 22px;
  border-radius: 28px;
  border: 1px solid rgba(255,255,255,0.14);
  background: linear-gradient(180deg, rgba(10, 16, 40, 0.92), rgba(7, 11, 29, 0.92));
  box-shadow: 0 20px 45px rgba(0,0,0,0.45);
  text-align: center;
}
.logo {
  font-size: 40px;
  margin-bottom: 8px;
}
h1, h2 {
  margin: 0 0 10px;
  font-size: clamp(24px, 4vw, 32px);
}
p {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.45;
}
.controls {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: #d4e4ff;
  margin: 16px 0 18px;
}
.action {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #8b9cff);
  color: #03101c;
  cursor: pointer;
  box-shadow: 0 12px 26px rgba(94, 197, 255, 0.25);
}
@media (max-width: 640px) {
  #game-shell {
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
  }
  #hud {
    top: 8px;
    left: 8px;
    right: 8px;
    gap: 6px;
  }
  .hud-pill {
    padding: 7px 7px;
  }
  .hud-pill .label { font-size: 9px; }
  .hud-pill span:last-child { font-size: 12px; }
}


.hud-icon {
  font-size: 13px;
  line-height: 1;
}
.hud-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.hud-pill .label { display:none; }
#hud {
  align-items: center;
}
#soundBtn {
  padding-inline: 0;
}
@media (max-width: 640px) {
  #hud {
    top: 6px;
    left: 6px;
    right: 6px;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
  }
  .hud-pill {
    min-height: 34px;
    padding: 6px 4px;
    border-radius: 14px;
    background: rgba(4, 9, 24, 0.6);
    backdrop-filter: blur(4px);
    box-shadow: 0 6px 14px rgba(0,0,0,0.2);
  }
  .hud-icon { font-size: 11px; }
  .hud-pill span:last-child {
    font-size: 11px;
    max-width: 42px;
  }
  #soundBtn {
    font-size: 15px;
  }
  .small-overlay {
    padding-top: 52px;
  }
  .panel {
    width: min(92%, 340px);
    padding: 22px 16px;
    border-radius: 22px;
  }
  .controls {
    font-size: 12px;
    gap: 4px;
  }
}
@media (max-width: 420px) {
  #hud {
    top: env(safe-area-inset-top, 6px);
  }
  .hud-pill {
    min-height: 30px;
    padding: 5px 3px;
    border-radius: 12px;
  }
  .hud-icon { font-size: 10px; }
  .hud-pill span:last-child {
    font-size: 10px;
    max-width: 34px;
  }
  .panel {
    padding: 18px 14px;
  }
  h1, h2 {
    font-size: clamp(20px, 6vw, 28px);
  }
  p {
    font-size: 13px;
  }
}


/* Cleaner readable mobile HUD */
@media (max-width: 640px) {
  #hud {
    top: 8px;
    left: 8px;
    right: 8px;
    grid-template-columns: repeat(2, minmax(0,1fr)) 44px;
    grid-template-rows: repeat(2, auto);
    gap: 6px;
  }
  #hud .hud-pill:nth-child(1) { grid-column: 1; grid-row: 1; }
  #hud .hud-pill:nth-child(2) { grid-column: 2; grid-row: 1; }
  #hud .hud-pill:nth-child(3) { grid-column: 1; grid-row: 2; }
  #hud .hud-pill:nth-child(4) { grid-column: 2; grid-row: 2; }
  #soundBtn { grid-column: 3; grid-row: 1 / span 2; min-height: 100%; border-radius: 16px; }
  .hud-pill {
    justify-content: flex-start;
    padding: 7px 10px;
    min-height: 34px;
    background: rgba(5, 10, 28, 0.78);
    border: 1px solid rgba(255,255,255,0.15);
  }
  .hud-icon { font-size: 12px; flex: 0 0 auto; }
  .hud-pill span:last-child {
    font-size: 11px;
    max-width: none;
    overflow: visible;
    text-overflow: clip;
  }
}
@media (max-width: 420px) {
  #hud {
    top: calc(env(safe-area-inset-top, 0px) + 6px);
    left: 6px;
    right: 6px;
    gap: 5px;
    grid-template-columns: repeat(2, minmax(0,1fr)) 40px;
  }
  .hud-pill { padding: 6px 8px; min-height: 32px; }
  .hud-pill span:last-child { font-size: 10px; }
  #soundBtn { font-size: 14px; }
}
