:root {
  --ink: #eef6ff;
  --muted: #9fb2c8;
  --panel: rgba(8, 15, 29, 0.78);
  --line: rgba(255, 255, 255, 0.18);
  --gold: #ffd166;
  --danger: #ff2f5f;
  --cyan: #55d6ff;
  --green: #45e394;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: #050911;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  appearance: none;
  border: 0;
  color: inherit;
  font: inherit;
  touch-action: manipulation;
}

#gameShell {
  position: fixed;
  inset: 0;
  min-width: 100vw;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% 18%, rgba(85, 214, 255, 0.12), transparent 34%),
    linear-gradient(180deg, #07111f, #050911);
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#hud {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.brand,
.stats {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.035)),
    linear-gradient(180deg, rgba(255, 209, 102, 0.08), rgba(85, 214, 255, 0.035)),
    rgba(5, 10, 20, 0.66);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(18px) saturate(130%);
}

.brand {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.title {
  color: #ffe39a;
  text-shadow: 0 0 16px rgba(255, 209, 102, 0.22);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0;
}

.state-label,
#levelName,
#actionHints {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.stats {
  font-size: 18px;
  font-weight: 800;
  white-space: nowrap;
}

.stats .sound-toggle {
  pointer-events: auto;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  color: #dff7ff;
  background:
    linear-gradient(180deg, rgba(85, 214, 255, 0.2), rgba(255, 255, 255, 0.06)),
    rgba(4, 9, 18, 0.52);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
}

.stats .sound-toggle[aria-pressed="false"] {
  color: #ffccd7;
  border-color: rgba(255, 47, 95, 0.38);
  background:
    linear-gradient(180deg, rgba(255, 47, 95, 0.2), rgba(255, 255, 255, 0.04)),
    rgba(4, 9, 18, 0.52);
}

.alarm {
  color: white;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--danger);
  text-shadow: 0 0 14px rgba(255, 47, 95, 0.8);
}

.alarm:not(.hidden) {
  animation: pulseAlarm 0.52s steps(2, end) infinite;
}

.hidden {
  display: none !important;
}

.panel {
  position: absolute;
  z-index: 6;
  top: 50%;
  left: 50%;
  width: min(92vw, 520px);
  transform: translate(-50%, -50%);
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.025)),
    radial-gradient(circle at 50% 0%, rgba(255, 209, 102, 0.12), transparent 45%),
    var(--panel);
  box-shadow: 0 30px 110px rgba(0, 0, 0, 0.58), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(20px) saturate(128%);
  text-align: center;
}

.panel h1,
.panel h2 {
  margin: 0 0 10px;
  color: var(--gold);
  font-size: clamp(30px, 5vw, 54px);
  line-height: 1;
  letter-spacing: 0;
}

.panel h2 {
  font-size: clamp(28px, 4vw, 44px);
}

.panel p {
  margin: 0 auto 20px;
  max-width: 38ch;
  color: #c7d4e5;
  font-size: 16px;
  line-height: 1.5;
}

.difficulty-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.difficulty,
.primary-button {
  min-height: 46px;
  border-radius: 8px;
  font-weight: 900;
  cursor: pointer;
}

.difficulty {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04));
}

.difficulty.selected {
  color: #07101f;
  background: var(--gold);
}

.primary-button {
  width: 100%;
  background: linear-gradient(135deg, #ffe39a, #ffd166 48%, #f7934c);
  color: #08101d;
  box-shadow: 0 16px 34px rgba(247, 147, 76, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.joystick {
  position: absolute;
  z-index: 5;
  bottom: max(76px, calc(env(safe-area-inset-bottom) + 76px));
  width: 132px;
  height: 132px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  background:
    radial-gradient(circle at 40% 34%, rgba(255, 255, 255, 0.22), transparent 24%),
    radial-gradient(circle at 50% 50%, rgba(85, 214, 255, 0.18), rgba(255, 255, 255, 0.04) 58%, rgba(255, 255, 255, 0.1)),
    rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 34px rgba(85, 214, 255, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 18px 46px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(14px) saturate(130%);
}

.move-joystick {
  left: max(28px, env(safe-area-inset-left));
}

.look-joystick {
  right: max(28px, env(safe-area-inset-right));
}

.joystick-label {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  color: rgba(238, 246, 255, 0.72);
  font-size: 11px;
  font-weight: 900;
}

.joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 58px;
  height: 58px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff, #9decff 32%, #2877af 70%, #102d57);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.34), 0 0 34px rgba(85, 214, 255, 0.28), inset 0 -8px 16px rgba(3, 6, 12, 0.22);
}

#actionHints {
  position: absolute;
  z-index: 4;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(280px, calc(env(safe-area-inset-bottom) + 280px));
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: flex-end;
  pointer-events: none;
}

@keyframes pulseAlarm {
  50% {
    background: #860020;
    color: #ffd6df;
  }
}

@media (orientation: portrait) {
  #gameShell::after {
    content: "Rotate your iPad to landscape";
    position: absolute;
    z-index: 20;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 28px;
    background: #050911;
    color: var(--ink);
    font-size: 24px;
    font-weight: 900;
    text-align: center;
  }
}

@media (max-width: 720px) {
  #hud {
    align-items: stretch;
    gap: 8px;
  }

  .brand,
  .stats {
    min-height: 42px;
    padding: 8px 10px;
  }

  .stats {
    gap: 8px;
    font-size: 15px;
  }

  .joystick {
    width: 112px;
    height: 112px;
  }

  .joystick-knob {
    width: 50px;
    height: 50px;
  }

  #actionHints {
    bottom: max(240px, calc(env(safe-area-inset-bottom) + 240px));
  }

  .panel {
    padding: 18px;
  }
}
