* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  min-height: 100%;
  background: #0b0d1a;
  color: #eee;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#game-wrap {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}
#game-wrap canvas {
  display: block;
  touch-action: none;
}
#hint {
  position: fixed;
  bottom: 12px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 13px;
  color: #888;
  pointer-events: none;
  user-select: none;
}

#touch-controls {
  --touch-cluster-gap: 10px;
  --touch-action-gap: 12px;
  --touch-button-size: 86px;
  --touch-button-radius: 14px;
  --touch-button-font-size: 18px;
  --touch-button-shadow-y: 6px;
  --touch-direction-font-size: 36px;
  --touch-small-size: 64px;
  --touch-small-font-size: 28px;
  --touch-action-size: 96px;
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: flex-end;
  justify-content: space-between;
  padding:
    0
    max(16px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  pointer-events: none;
  touch-action: none;
}

.touch-cluster {
  display: flex;
  align-items: flex-end;
  gap: var(--touch-cluster-gap);
  pointer-events: auto;
}

.touch-cluster-move {
  align-items: center;
}

.touch-cluster-action {
  gap: var(--touch-action-gap);
}

.touch-column {
  display: flex;
  align-items: center;
  justify-content: center;
}

.touch-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-button-size);
  height: var(--touch-button-size);
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: var(--touch-button-radius);
  background: rgba(20, 20, 40, 0.48);
  color: #ffffff;
  font: 700 var(--touch-button-font-size)/1 "Courier New", monospace;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.55);
  box-shadow: 0 var(--touch-button-shadow-y) 0 rgba(0, 0, 0, 0.28);
  appearance: none;
  -webkit-appearance: none;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.touch-button-direction {
  font-size: var(--touch-direction-font-size);
}

.touch-button-small {
  width: var(--touch-small-size);
  height: var(--touch-small-size);
  font-size: var(--touch-small-font-size);
}

.touch-button-action {
  width: var(--touch-action-size);
  height: var(--touch-action-size);
}

.touch-button.is-active {
  transform: translateY(4px);
  background: rgba(255, 200, 30, 0.58);
  border-color: rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.24);
}

#rotate-hint {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  z-index: 40;
  display: none;
  width: min(460px, calc(100vw - 32px));
  padding: 11px 16px;
  transform: translateX(-50%);
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 12px;
  background: rgba(11, 13, 26, 0.82);
  color: #ffffff;
  font: 700 16px/1.3 "Courier New", monospace;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.34);
  pointer-events: none;
  touch-action: none;
}

@media (any-pointer: coarse) {
  body.show-touch-controls #touch-controls {
    display: flex;
  }
}

@media (any-pointer: coarse) and (orientation: portrait) {
  #touch-controls {
    --touch-cluster-gap: 6px;
    --touch-action-gap: 8px;
    --touch-button-size: 62px;
    --touch-button-radius: 11px;
    --touch-button-font-size: 13px;
    --touch-button-shadow-y: 4px;
    --touch-direction-font-size: 28px;
    --touch-small-size: 48px;
    --touch-small-font-size: 22px;
    --touch-action-size: 68px;
  }

  #rotate-hint {
    display: block;
  }

  body.show-touch-controls #touch-controls {
    display: flex;
    align-items: flex-end;
    padding:
      0
      max(8px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }
}

@media (any-pointer: coarse) and (max-height: 520px) {
  #touch-controls {
    --touch-cluster-gap: 8px;
    --touch-action-gap: 10px;
    --touch-button-size: 74px;
    --touch-button-radius: 12px;
    --touch-button-font-size: 16px;
    --touch-direction-font-size: 32px;
    --touch-small-size: 56px;
    --touch-small-font-size: 25px;
    --touch-action-size: 84px;
    padding:
      0
      max(12px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }
}
