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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0b1020;
  color: #e8ecff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
}

#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(10, 14, 26, 0.9);
  border-bottom: 1px solid #232a4a;
  z-index: 5;
}

#hud-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#hud-actions {
  display: flex;
  gap: 8px;
}

.pill {
  background: #151b33;
  border: 1px solid #2a3357;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 14px;
  white-space: nowrap;
}

.pill b {
  color: #ffd166;
  font-weight: 700;
}

.hud-btn {
  background: #232c4f;
  color: #e8ecff;
  border: 1px solid #3b4a7a;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  min-height: 40px;
}

.hud-btn:active,
.hud-btn.active {
  background: #33406e;
}

#canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
  padding: 6px;
}

#game {
  display: block;
  background: #0d1428;
  border-radius: 8px;
  box-shadow: 0 0 40px rgba(50, 90, 255, 0.15);
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
}

#dpad {
  display: grid;
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(3, 58px);
  gap: 6px;
  justify-content: center;
  padding: 10px 0 14px;
}

.dbtn {
  border: 1px solid #33406e;
  border-radius: 12px;
  background: #1c2440;
  color: #cfe0ff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
}

.dbtn:active,
.dbtn.active {
  background: #3a4b86;
}

#d-up {
  grid-area: 1 / 2;
}

#d-left {
  grid-area: 2 / 1;
}

#d-down {
  grid-area: 2 / 2;
}

#d-right {
  grid-area: 2 / 3;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(6, 9, 20, 0.78);
  border-radius: 8px;
  text-align: center;
  padding: 20px;
  z-index: 10;
}

.overlay[hidden] {
  display: none;
}

.overlay h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0.5px;
  color: #ffffff;
}

.overlay p {
  margin: 0;
  max-width: 430px;
  font-size: 14px;
  line-height: 1.5;
  color: #b9c4e6;
}

.overlay img {
  width: 92px;
  height: 92px;
}

.big-btn {
  background: linear-gradient(180deg, #3f6dff, #2a4bd0);
  color: #ffffff;
  border: none;
  border-radius: 14px;
  padding: 14px 36px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  min-height: 52px;
  box-shadow: 0 6px 0 #1c35a0;
}

.big-btn:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #1c35a0;
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%) translateY(8px);
  background: #ff3b4e;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 20;
  max-width: 92%;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-height: 520px) {
  #dpad {
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(3, 48px);
    gap: 5px;
    padding: 6px 0 8px;
  }
  .overlay h1 {
    font-size: 20px;
  }
  .overlay img {
    width: 56px;
    height: 56px;
  }
  .big-btn {
    padding: 10px 26px;
    font-size: 15px;
    min-height: 44px;
  }
  .pill {
    font-size: 12px;
    padding: 3px 9px;
  }
}
