:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#game-root {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: #05070a;
  color: #f7f4dd;
}

#game-root {
  position: relative;
  isolation: isolate;
}

canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

#level,
#help-button {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  z-index: 2;
  margin: 0;
  border: 1px solid rgb(255 255 255 / 28%);
  border-radius: 999px;
  background: rgb(5 7 10 / 72%);
  color: #ffe26e;
  box-shadow: 0 8px 28px rgb(0 0 0 / 28%);
  backdrop-filter: blur(8px);
}

#level {
  left: max(12px, env(safe-area-inset-left));
  padding: 8px 13px;
  font-size: 0.875rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

#help-button {
  right: max(12px, env(safe-area-inset-right));
  padding: 8px 13px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

#help-button:focus-visible,
.touch-controls button:focus-visible {
  outline: 3px solid #68e7ff;
  outline-offset: 3px;
}

#instructions {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 3;
  width: min(440px, calc(100% - 32px));
  padding: clamp(22px, 5vw, 36px);
  border: 1px solid rgb(255 255 255 / 30%);
  border-radius: 24px;
  background: rgb(5 7 10 / 88%);
  box-shadow: 0 24px 80px rgb(0 0 0 / 48%);
  text-align: center;
  transform: translate(-50%, -50%);
  backdrop-filter: blur(14px);
}

#instructions[hidden] {
  display: none;
}

#instructions h1 {
  margin: 0 0 14px;
  color: #ffe26e;
  font-size: clamp(2rem, 8vw, 3.5rem);
  letter-spacing: -0.05em;
}

#instructions p {
  margin: 10px 0 0;
  line-height: 1.55;
}

.desktop-hint {
  color: #9eefff;
  font-size: 0.86rem;
}

.touch-controls {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 2;
  display: none;
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(2, 58px);
  gap: 8px;
  touch-action: none;
}

.touch-controls button {
  border: 1px solid rgb(255 255 255 / 35%);
  border-radius: 18px;
  background: rgb(5 7 10 / 70%);
  color: white;
  font: 800 1.45rem/1 system-ui, sans-serif;
  box-shadow: 0 8px 24px rgb(0 0 0 / 30%);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  backdrop-filter: blur(8px);
}

.touch-controls button[data-direction="up"] {
  grid-column: 2;
}

.touch-controls button[data-direction="left"] {
  grid-row: 2;
  grid-column: 1;
}

.touch-controls button[data-direction="down"] {
  grid-row: 2;
  grid-column: 2;
}

.touch-controls button[data-direction="right"] {
  grid-row: 2;
  grid-column: 3;
}

.touch-controls button.is-active {
  border-color: #ffe26e;
  background: rgb(255 226 110 / 30%);
  transform: translateY(1px) scale(0.97);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (hover: none), (pointer: coarse) {
  .touch-controls {
    display: grid;
  }

  .desktop-hint {
    display: none;
  }
}

@media (max-height: 520px) {
  .touch-controls {
    grid-template-columns: repeat(3, 50px);
    grid-template-rows: repeat(2, 50px);
  }

  #instructions {
    padding: 18px 24px;
  }
}
