:root {
  color-scheme: dark;
  --ink: #eafff4;
  --muted: #a9c0ee;
  --green: #59ff8f;
  --green-deep: #17bb61;
  --blue: #4b6fd6;
  --red: #ff2b47;
  --gold: #ffd23f;
  font-family: ui-rounded, "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  background: #050718;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  min-height: 100dvh;
  padding: 14px clamp(8px, 2.4vw, 24px) calc(30px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background:
    radial-gradient(circle at 15% 8%, #1b1b5a 0, transparent 42%),
    radial-gradient(circle at 88% 16%, #2a0d4f 0, transparent 38%),
    radial-gradient(circle at 50% 110%, #0b2b3e 0, transparent 55%),
    #050718;
}

header { width: min(100%, 840px); text-align: center; }

h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 3.2rem);
  letter-spacing: .2em;
  color: var(--green);
  text-shadow: 0 0 16px #59ff8f99, 0 0 46px #17bb6155;
}

.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: clamp(.8rem, 2.4vw, 1rem);
}

.game-shell {
  position: relative;
  width: min(100%, 840px);
  aspect-ratio: 4 / 3;
  border: 3px solid #2b3f8a;
  border-radius: 20px;
  overflow: hidden;
  background: #050718;
  box-shadow: 0 18px 50px #0009, 0 0 0 1px #59ff8f18 inset;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
}

.hud {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: clamp(6px, 1.6vw, 12px) clamp(8px, 2vw, 16px);
  pointer-events: none;
  font-weight: 800;
  font-size: clamp(.62rem, 1.8vw, .95rem);
  letter-spacing: .06em;
  text-shadow: 0 2px 6px #000;
}

.pill {
  padding: 4px 10px;
  border: 1px solid #3956a8;
  border-radius: 999px;
  background: #081023cc;
  backdrop-filter: blur(4px);
  white-space: nowrap;
}

#hearts { color: #ff6b81; letter-spacing: 2px; }
#levelLabel { color: #9fe8ff; }
#scoreLabel { color: #ffd23f; }

.charge {
  position: absolute;
  top: clamp(42px, 7vw, 64px);
  left: 50%;
  width: min(66%, 420px);
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 2;
}

.charge[hidden] { display: none; }

.charge-label {
  margin-bottom: 3px;
  text-align: center;
  color: #bcd6ff;
  font-size: clamp(.6rem, 1.7vw, .82rem);
  font-weight: 800;
  letter-spacing: .12em;
  text-shadow: 0 2px 6px #000;
}

.charge-track {
  height: clamp(8px, 1.4vw, 12px);
  overflow: hidden;
  border: 1px solid #4166c8;
  border-radius: 999px;
  background: #0a1430cc;
}

#chargeFill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #39d7ff, var(--green));
  transition: width .1s linear;
}

.charge.ready .charge-label {
  color: var(--gold);
  animation: pulseText .7s infinite alternate;
}

.charge.ready #chargeFill {
  background: linear-gradient(90deg, var(--gold), var(--red));
  box-shadow: 0 0 16px #ff2b47aa;
}

.hint {
  position: absolute;
  left: 50%;
  bottom: clamp(8px, 1.6vw, 16px);
  transform: translateX(-50%);
  width: max-content;
  max-width: 90%;
  margin: 0;
  padding: 4px 12px;
  border: 1px solid #3a5cae;
  border-radius: 999px;
  background: #081023d9;
  color: #d9f6ff;
  font-size: clamp(.62rem, 1.7vw, .86rem);
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  z-index: 2;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: clamp(14px, 4vw, 28px);
  text-align: center;
  background: radial-gradient(circle at 50% 45%, #0b164fe8, #050718f5);
}

.overlay[hidden] { display: none; }

.overlay h2 {
  margin: 0;
  color: var(--green);
  font-size: clamp(1.7rem, 6vw, 3rem);
  letter-spacing: .08em;
  text-shadow: 0 0 22px #59ff8f66;
}

.overlay .start-title {
  font-size: clamp(2.4rem, 12vw, 5.2rem);
  letter-spacing: .16em;
}

.overlay p {
  max-width: 560px;
  margin: 0;
  color: #c9e5ff;
  font-size: clamp(.8rem, 2.2vw, 1rem);
  line-height: 1.45;
}

.overlay .eyebrow {
  margin: 0;
  color: #8fb1ff;
  font-size: clamp(.65rem, 1.9vw, .85rem);
  font-weight: 800;
  letter-spacing: .22em;
  text-transform: uppercase;
}

.overlay .small {
  color: #91aadb;
  font-size: clamp(.62rem, 1.8vw, .8rem);
}

.touch-help { display: none; }
@media (hover: none), (pointer: coarse) {
  .desktop-help { display: none; }
  .touch-help { display: inline; }
}

.overlay .end-score {
  color: var(--gold);
  font-size: clamp(1rem, 3.4vw, 1.4rem);
  font-weight: 900;
  letter-spacing: .06em;
}

button.primary {
  border: 0;
  border-radius: 999px;
  padding: 12px 30px;
  background: linear-gradient(#7dffab, var(--green-deep));
  color: #04240f;
  font: inherit;
  font-size: clamp(1rem, 3vw, 1.2rem);
  font-weight: 900;
  letter-spacing: .04em;
  cursor: pointer;
  box-shadow: 0 6px 0 #0a7a3d, 0 0 26px #59ff8f66;
}

button.primary:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #0a7a3d, 0 0 20px #59ff8f55;
}

button.primary:focus-visible,
.red-button:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 4px;
}

.controls {
  width: min(100%, 840px);
  min-height: 104px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 4px;
}

.joystick {
  position: relative;
  flex: 0 0 104px;
  width: 104px;
  height: 104px;
  border: 2px solid #4867c8;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #18245a, #080d24 70%);
  box-shadow: inset 0 0 22px #0008, 0 0 20px #2b3f8a55;
  touch-action: none;
  user-select: none;
}

.knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border: 2px solid #f0fff7;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #d8ffe7, #2fd874 60%, #129c4d);
  box-shadow: 0 0 18px #59ff8f99;
  pointer-events: none;
}

.key-hint {
  flex: 1;
  margin: 0;
  color: #9fb8e6;
  font-size: clamp(.78rem, 2.1vw, .95rem);
  line-height: 1.7;
  text-align: center;
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  margin: 0 1px;
  padding: 1px 5px;
  border: 1px solid #4a67b8;
  border-bottom-width: 3px;
  border-radius: 6px;
  background: #101a3c;
  color: #e8f2ff;
  font: inherit;
  font-size: .9em;
  font-weight: 800;
}

.red-button {
  flex: 0 0 auto;
  width: clamp(92px, 17vw, 112px);
  height: clamp(92px, 17vw, 112px);
  border: 3px solid #ffb3be;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #ff8a9b, #d70827 52%, #6b0012);
  color: #fff;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 8px 0 #5c0010, 0 0 0 6px #ff2b4733, 0 0 24px #ff2b4755;
  transition: filter .15s, box-shadow .15s, transform .1s;
}

.red-button span {
  display: block;
  padding: 0 6px;
  font-size: clamp(.62rem, 1.8vw, .82rem);
  line-height: 1.05;
  text-shadow: 0 2px 4px #000;
}

.red-button small {
  display: block;
  margin-top: 2px;
  font-size: clamp(.6rem, 1.7vw, .78rem);
  opacity: .9;
}

.red-button:disabled {
  filter: grayscale(.6) brightness(.55);
  cursor: default;
  box-shadow: 0 8px 0 #240008;
}

.red-button.ready {
  animation: redPulse .6s infinite alternate;
  box-shadow: 0 8px 0 #5c0010, 0 0 0 8px #ff2b4744, 0 0 38px #ff2b47cc;
}

.red-button.ready:active { transform: translateY(3px); }

.how-to {
  width: min(100%, 840px);
  margin: 0;
  color: #8fa8d8;
  font-size: clamp(.75rem, 2.1vw, .92rem);
  text-align: center;
}

@media (hover: hover) and (pointer: fine) {
  .joystick { display: none; }
  .key-hint { text-align: center; }
}

@media (hover: none), (pointer: coarse) {
  .key-hint { display: none; }
}

@media (orientation: landscape) and (max-height: 640px) {
  body {
    gap: 4px;
    padding: 2px 8px calc(6px + env(safe-area-inset-bottom));
  }
  header, .how-to { display: none; }
  .game-shell { width: min(100%, calc((100dvh - 94px) * 4 / 3)); }
  .controls { width: min(100%, calc((100dvh - 94px) * 4 / 3)); min-height: 84px; }
  .joystick { flex-basis: 78px; width: 78px; height: 78px; }
  .knob { width: 36px; height: 36px; margin: -18px 0 0 -18px; }
  .red-button { width: 78px; height: 78px; }
  .hint { display: none; }
  .charge { top: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  .charge.ready .charge-label, .red-button.ready { animation: none; }
}

@keyframes redPulse {
  from { filter: brightness(1); transform: scale(1); }
  to { filter: brightness(1.25); transform: scale(1.06); }
}

@keyframes pulseText {
  from { opacity: .7; }
  to { opacity: 1; }
}

/* Readable game information stays below the play area at every screen size. */
.game-guide {
  box-sizing: border-box;
  width: 100%;
  max-width: 800px;
  margin: 24px auto;
  padding: 20px;
  border: 1px solid currentColor;
  border-radius: 16px;
  background: transparent;
  color: inherit;
  text-align: left;
  font-size: 1rem;
  line-height: 1.65;
  overflow-wrap: break-word;
}
.game-guide h2 { margin: 0 0 8px; font-size: 1.35rem; }
.game-guide h3 { margin: 18px 0 8px; font-size: 1.1rem; }
.game-guide p { margin: 0 0 12px; }
.game-guide a { color: inherit; text-underline-offset: 3px; }
.game-guide .guide-home { margin-bottom: 0; }
