* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

:root {
  --bg: #17212b;
  --panel: #223142;
  --accent: #f2c94c;
  --text: #f7f9fb;
  --danger: #e85d5d;
  --ok: #52c878;
}

html, body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  user-select: none;
  cursor: pointer;
}

#app {
  width: 100vw;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 160px;
  background:
    radial-gradient(circle at top, rgba(255,255,255,.05), transparent 35%),
    var(--bg);
}

.hud {
  min-height: 52px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 8px;
  align-items: center;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  background: rgba(10, 17, 24, .92);
  font-size: 14px;
  z-index: 3;
}

.hud > div {
  background: var(--panel);
  border-radius: 10px;
  padding: 8px 10px;
  white-space: nowrap;
  text-align: center;
}

.small-btn {
  width: 42px;
  height: 36px;
  border-radius: 10px;
  background: #394b5e;
}

.game-wrap {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #111a22;
}

canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.message {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 24px;
  text-align: center;
  background: rgba(8, 13, 18, .75);
  backdrop-filter: blur(5px);
  z-index: 4;
}

.message.hidden {
  display: none;
}

.message h1 {
  margin: 0 0 8px;
  font-size: clamp(28px, 7vw, 54px);
}

.message p {
  max-width: 520px;
  margin: 0 0 18px;
  line-height: 1.5;
}

.message button {
  min-width: 160px;
  padding: 13px 24px;
  border-radius: 14px;
  background: var(--accent);
  color: #1d2430;
  font-weight: 800;
}

.controls {
  position: relative;
  display: grid;
  grid-template-columns: 140px 1fr 140px;
  align-items: center;
  gap: 10px;
  padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  background: rgba(10, 17, 24, .97);
}

.dpad {
  position: relative;
  width: 132px;
  height: 132px;
}

.dpad button {
  position: absolute;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: #33475a;
  box-shadow: inset 0 -3px rgba(0,0,0,.22);
  font-size: 20px;
}

.dpad button:active,
.dpad button.active {
  transform: scale(.94);
  background: #506a82;
}

.dpad .up { top: 0; left: 43px; }
.dpad .left { top: 43px; left: 0; }
.dpad .down { bottom: 0; left: 43px; }
.dpad .right { top: 43px; right: 0; }

.actions {
  display: grid;
  place-items: center;
}

.flute-btn {
  width: min(190px, 100%);
  min-height: 74px;
  border-radius: 999px;
  background: var(--accent);
  color: #202530;
  font-weight: 900;
  box-shadow: 0 8px 0 #a77d12;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.flute-btn:active,
.flute-btn.active {
  transform: translateY(5px);
  box-shadow: 0 3px 0 #a77d12;
}

.flute-btn .icon {
  font-size: 32px;
}

.joystick {
  position: relative;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: rgba(70, 92, 113, .55);
  border: 3px solid rgba(255,255,255,.12);
  box-shadow: inset 0 0 25px rgba(0,0,0,.28);
}

.stick {
  position: absolute;
  width: 58px;
  height: 58px;
  left: 34px;
  top: 34px;
  border-radius: 50%;
  background: #90a6b8;
  box-shadow: 0 5px 12px rgba(0,0,0,.35);
  transform: translate(0, 0);
}

@media (max-width: 650px) {
  #app {
    grid-template-rows: auto minmax(0, 1fr) 146px;
  }

  .controls {
    grid-template-columns: 118px 1fr 118px;
    padding-inline: 7px;
  }

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

  .dpad button {
    width: 40px;
    height: 40px;
  }

  .dpad .up { left: 36px; }
  .dpad .left { top: 36px; }
  .dpad .down { left: 36px; }
  .dpad .right { top: 36px; }

  .stick {
    width: 50px;
    height: 50px;
    left: 28px;
    top: 28px;
  }

  .flute-btn {
    min-height: 66px;
    font-size: 14px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  #app {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .controls {
    position: absolute;
    inset: 52px 0 0;
    background: transparent;
    pointer-events: none;
    grid-template-columns: 140px 1fr 140px;
    align-items: end;
    padding-bottom: 12px;
    z-index: 3;
  }

  .controls > * {
    pointer-events: auto;
  }

  .actions {
    align-self: end;
  }

  .flute-btn {
    width: 120px;
    min-height: 58px;
  }
}
