* {
  box-sizing: border-box;
}

:root {
  --ui-top-space: 0px;
  --ui-bottom-space: 0px;
  --game-area-h: calc(100dvh - var(--ui-top-space) - var(--ui-bottom-space));
  --game-w: min(100vw, calc(var(--game-area-h) * 1.77777));
  --game-h: min(56.25vw, var(--game-area-h));
  --game-left: calc((100vw - var(--game-w)) / 2);
  --game-top: calc(var(--ui-top-space) + (var(--game-area-h) - var(--game-h)) / 2);
}

@font-face {
  font-family: "GuchioCute";
  src: url("assets/GuchioCuteFont.ttf") format("truetype");
  font-weight: 100 900;
  font-display: block;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: #10151f;
  font-family: "GuchioCute", "Noto Sans JP", "Yu Gothic", "Meiryo", sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.shell {
  display: grid;
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  place-items: center;
  background:
    radial-gradient(circle at 50% 35%, rgba(78, 182, 255, 0.18), transparent 34%),
    linear-gradient(180deg, #182133 0%, #090c12 100%);
}

canvas {
  display: block;
  width: var(--game-w);
  height: var(--game-h);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #0d8df0;
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.45);
  touch-action: none;
}

.touch-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding:
    0
    calc(var(--game-left) + clamp(14px, 2.8vw, 34px))
    0
    calc(var(--game-left) + clamp(14px, 2.8vw, 34px));
  pointer-events: none;
}

.touch-actions {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  z-index: 11;
  display: flex;
  gap: clamp(8px, 2.2vw, 18px);
  align-items: center;
  justify-content: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.touch-action-button {
  width: clamp(92px, 14vw, 150px);
  height: clamp(34px, 5.2vw, 54px);
  padding: 0;
  border: 0;
  background: transparent;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  opacity: 0.92;
}

.touch-action-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}

.touch-action-button.is-pressed {
  transform: scale(0.96);
  opacity: 1;
}

.touch-move {
  display: flex;
  gap: clamp(10px, 2.8vw, 22px);
}

.touch-button {
  width: clamp(64px, 9vw, 104px);
  height: clamp(58px, 8vw, 92px);
  padding: 0;
  border: 0;
  background: transparent;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  opacity: 0.86;
}

.touch-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.touch-button.is-pressed {
  transform: scale(0.94);
  opacity: 1;
}

.touch-jump {
  width: clamp(74px, 10vw, 116px);
  height: clamp(86px, 11.8vw, 136px);
}

.orientation-message {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: rgba(9, 12, 18, 0.72);
  pointer-events: none;
}

.orientation-panel {
  display: grid;
  gap: 10px;
  max-width: 420px;
  padding: 24px 28px;
  border: 5px solid #ffffff;
  border-radius: 18px;
  background: rgba(255, 244, 180, 0.96);
  color: #5b3300;
  text-align: center;
  box-shadow: 0 12px 44px rgba(0, 0, 0, 0.38);
}

.orientation-panel strong {
  font-size: clamp(28px, 8vw, 48px);
  line-height: 1.1;
}

.orientation-panel span {
  font-size: clamp(18px, 5vw, 28px);
  line-height: 1.25;
}

@media (hover: hover) and (pointer: fine) and (min-width: 901px) {
  .touch-controls,
  .touch-actions {
    display: none;
  }
}

@media (orientation: landscape) and (pointer: coarse) {
  :root {
    --ui-top-space: 0px;
    --ui-bottom-space: 0px;
  }

  canvas {
    box-shadow: 0 10px 36px rgba(0, 0, 0, 0.42);
  }

  .touch-actions {
    display: none;
  }

  .touch-controls {
    bottom: calc(var(--game-top) + clamp(14px, 3dvh, 26px));
    padding:
      0
      max(8px, env(safe-area-inset-right))
      0
      max(8px, env(safe-area-inset-left));
  }

  .touch-move {
    gap: clamp(8px, 1.6vw, 18px);
  }

  .touch-button {
    position: relative;
    width: clamp(58px, 7.2vw, 88px);
    height: clamp(52px, 6.6vw, 80px);
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    opacity: 0.72;
  }

  .touch-button img {
    opacity: 1;
  }

  .touch-jump {
    width: clamp(76px, 9.4vw, 112px);
    height: clamp(88px, 10.8vw, 130px);
    margin-right: 0;
    background: transparent;
  }

  .touch-button.is-pressed {
    transform: scale(0.9);
    opacity: 0.95;
  }
}

@media (orientation: portrait) and (pointer: coarse) {
  .orientation-message {
    display: flex;
  }
}
