:root {
  color-scheme: dark;
  --surface: #140d22;
  --letterbox: #080611;
  --gold: #f7c765;
  --gold-dark: #9a5c2f;
  --mint: #8fe8c2;
  --pink: #ff7eb6;
  --danger: #e5504f;
  --control-size: clamp(58px, 15.5vw, 78px);
  --app-width: 100dvw;
  --app-height: 100dvh;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --game-width: calc(var(--app-width) - var(--safe-left) - var(--safe-right));
  --game-height: calc(var(--app-height) - var(--safe-top) - var(--safe-bottom));
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
}

html,
body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  min-width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--letterbox);
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

@supports (-webkit-touch-callout: none) {
  html,
  body {
    height: -webkit-fill-available;
  }
}

body {
  font-family:
    "Courier New",
    ui-monospace,
    SFMono-Regular,
    Menlo,
    Consolas,
    monospace;
}

#game-root {
  position: fixed;
  inset: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  width: var(--app-width);
  height: var(--app-height);
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  background:
    linear-gradient(180deg, #080611 0%, #140d22 48%, #080611 100%);
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#game-canvas {
  display: block;
  width: var(--game-width);
  height: var(--game-height);
  aspect-ratio: auto;
  max-width: 100%;
  max-height: 100%;
  outline: none;
  background: var(--surface);
  border: 0;
  contain: strict;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  box-shadow:
    0 0 0 2px rgb(247 199 101 / 0.5),
    0 18px 52px rgb(0 0 0 / 0.42);
}

.touch-controls {
  position: absolute;
  left: 50%;
  top: 50%;
  display: none;
  width: var(--game-width);
  height: var(--game-height);
  transform: translate(-50%, -50%);
  pointer-events: none;
  padding:
    max(14px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
}

.touch-cluster {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  gap: clamp(7px, 2.4vw, 12px);
  pointer-events: auto;
}

.touch-cluster-left {
  left: max(10px, env(safe-area-inset-left));
}

.touch-cluster-right {
  right: max(10px, env(safe-area-inset-right));
}

.touch-button {
  position: relative;
  width: var(--control-size);
  aspect-ratio: 1;
  border: 3px solid rgb(247 199 101 / 0.88);
  border-radius: 50%;
  background:
    linear-gradient(180deg, rgb(43 23 53 / 0.74), rgb(22 13 35 / 0.68));
  box-shadow:
    inset 0 0 0 2px rgb(255 229 164 / 0.12),
    0 8px 22px rgb(0 0 0 / 0.28);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

.touch-button::before,
.touch-button::after {
  position: absolute;
  inset: 0;
  margin: auto;
  content: "";
}

.touch-left::before,
.touch-right::before {
  width: 0;
  height: 0;
  border-top: 13px solid transparent;
  border-bottom: 13px solid transparent;
}

.touch-left::before {
  border-right: 20px solid var(--mint);
  transform: translateX(-4px);
}

.touch-right::before {
  border-left: 20px solid var(--mint);
  transform: translateX(4px);
}

.touch-attack::before {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #59c7ff;
  box-shadow:
    8px -8px 0 -9px transparent,
    inset -5px -4px 0 rgb(24 83 126 / 0.45);
}

.touch-attack {
  background:
    linear-gradient(180deg, rgb(43 23 53 / 0.74), rgb(22 13 35 / 0.68));
}

.touch-attack::after {
  display: none;
}

.touch-jump::before {
  width: 0;
  height: 0;
  border-left: 15px solid transparent;
  border-right: 15px solid transparent;
  border-bottom: 28px solid var(--gold);
  transform: translateY(-3px);
}

.touch-button:active,
.touch-button.is-down {
  transform: translateY(2px) scale(0.97);
  background: rgb(247 199 101 / 0.2);
}

.orientation-lock {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 30%, rgb(78 52 70 / 0.92), rgb(8 6 17 / 0.98));
  color: #ffe5a4;
  text-align: center;
  pointer-events: auto;
}

.orientation-lock-panel {
  width: min(360px, 92vw);
  padding: 22px 20px;
  border: 3px solid var(--gold);
  background: rgb(21 13 35 / 0.94);
  box-shadow:
    inset 0 0 0 2px rgb(255 229 164 / 0.12),
    0 18px 42px rgb(0 0 0 / 0.48);
}

.orientation-lock strong,
.orientation-lock span {
  display: block;
}

.orientation-lock strong {
  margin-bottom: 10px;
  font-size: 22px;
}

.orientation-lock span {
  font-size: 14px;
  color: var(--mint);
}

@media (pointer: coarse), (max-width: 860px) {
  .touch-controls {
    display: block;
  }
}

@media (max-width: 380px), (max-height: 680px) {
  :root {
    --control-size: clamp(44px, 13vw, 56px);
  }

  .touch-cluster {
    bottom: max(12px, env(safe-area-inset-bottom));
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  .orientation-lock {
    display: flex;
  }

  #touch-controls {
    display: none;
  }
}

@media (min-width: 900px) and (pointer: fine) {
  :root {
    --game-width: 100dvw;
    --game-height: 100dvh;
  }

  #game-root {
    padding: 0;
    background: #140d22;
  }

  #game-canvas {
    width: var(--game-width);
    height: var(--game-height);
    aspect-ratio: auto;
    box-shadow: none;
  }

  .touch-controls {
    display: none;
  }
}
