:root {
  color-scheme: dark;
  --ink: #f7f0d8;
  --red: #ff2b2b;
  --gold: #ffd35a;
  --blue: #38d4ff;
  --black: #110711;
  --stone: #52445f;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100svh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 43, 43, 0.22), transparent 30%),
    linear-gradient(180deg, #180b22 0%, #09070e 60%, #030205 100%);
  color: var(--ink);
  font-family: "Trebuchet MS", Arial, sans-serif;
  overflow-x: hidden;
  overscroll-behavior: none;
}

.game-shell {
  width: min(96vw, 960px);
  display: grid;
  align-content: start;
  gap: 10px;
}

.topbar,
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: #171020;
  border: 4px solid #39294e;
  box-shadow: 0 0 0 4px #050308, 0 0 24px rgba(255, 43, 43, 0.18);
}

.brand {
  width: clamp(116px, 18vw, 178px);
  line-height: 0;
}

.brand img {
  width: 100%;
  height: auto;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.status,
.controls {
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
}

.status {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 14px;
  color: var(--gold);
}

#game {
  width: 100%;
  aspect-ratio: var(--game-aspect, 16 / 9);
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #10152f;
  border: 6px solid #0b0710;
  outline: 4px solid #6b496e;
  box-shadow:
    0 0 0 8px #050308,
    0 0 28px rgba(255, 43, 43, 0.2),
    0 18px 42px rgba(0, 0, 0, 0.58);
  touch-action: none;
  user-select: none;
}

.controls {
  flex-wrap: wrap;
  color: #aeeeff;
}

button {
  min-height: 34px;
  padding: 6px 12px;
  border: 3px solid #ffd35a;
  background: #2b1b34;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.touch-controls {
  display: none;
  justify-content: space-between;
  gap: 18px;
  padding: 4px 2px env(safe-area-inset-bottom);
}

.touch-pad,
.touch-actions {
  display: flex;
  gap: 12px;
}

.touch-button {
  width: clamp(52px, 15vw, 78px);
  height: clamp(52px, 15vw, 78px);
  padding: 0;
  border-radius: 50%;
  border: 4px solid #6b496e;
  background: linear-gradient(180deg, #372244, #140b1c);
  color: #f7f0d8;
  font-family: Impact, Haettenschweiler, "Arial Black", sans-serif;
  font-size: clamp(24px, 7vw, 38px);
  line-height: 1;
  box-shadow: 0 6px 0 #050308, inset 0 0 18px rgba(255, 211, 90, 0.12);
}

.touch-button.action {
  border-color: #ff2b2b;
  color: #ffd35a;
}

.touch-button.is-down {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #050308, inset 0 0 24px rgba(56, 212, 255, 0.28);
}

#music-toggle[data-playing="true"] {
  border-color: #38d4ff;
  color: #aeeeff;
  box-shadow: 0 0 14px rgba(56, 212, 255, 0.32);
}

button:hover,
button:focus-visible {
  background: #472655;
  outline: none;
}

@media (max-width: 640px) {
  body {
    align-items: start;
    padding: 8px;
  }

  .game-shell {
    width: 100%;
    gap: 8px;
  }

  .topbar {
    align-items: start;
    padding: 8px;
  }

  .brand {
    width: clamp(104px, 32vw, 132px);
  }

  .status,
  .controls {
    font-size: 12px;
  }

  .controls span {
    display: none;
  }

  .controls {
    justify-content: center;
    padding: 8px;
  }

  .touch-controls {
    display: flex;
  }
}

@media (max-width: 700px) and (orientation: portrait) {
  body {
    display: block;
    min-height: 100svh;
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
    overflow-y: auto;
  }

  .game-shell {
    width: 100%;
    max-width: none;
    min-height: calc(100svh - 16px);
    gap: 8px;
  }

  .topbar {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px;
    align-items: center;
    padding: 7px;
    border-width: 3px;
    box-shadow: 0 0 0 3px #050308, 0 0 18px rgba(255, 43, 43, 0.16);
  }

  .brand {
    font-size: clamp(17px, 5vw, 23px);
  }

  .status {
    gap: 5px 10px;
    font-size: clamp(10px, 3vw, 12px);
    line-height: 1.25;
  }

  #game {
    width: 100%;
    max-height: calc(100svh - 214px);
    border-width: 4px;
    outline-width: 3px;
    box-shadow:
      0 0 0 5px #050308,
      0 0 20px rgba(255, 43, 43, 0.18),
      0 10px 28px rgba(0, 0, 0, 0.52);
  }

  .controls {
    justify-content: center;
    padding: 7px;
    border-width: 3px;
  }

  .touch-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: end;
    position: sticky;
    bottom: 0;
    padding: 8px 0 max(8px, env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(3, 2, 5, 0), rgba(3, 2, 5, 0.95) 24%);
  }

  .touch-pad,
  .touch-actions {
    gap: 8px;
  }

  .touch-actions {
    justify-content: end;
  }

  .touch-button {
    width: clamp(52px, 17vw, 72px);
    height: clamp(52px, 17vw, 72px);
    font-size: clamp(24px, 7vw, 34px);
  }
}

.is-mobile.is-portrait body {
  display: block;
  place-items: start center;
  padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
}

.is-mobile.is-portrait .game-shell {
  width: 100%;
  max-width: none;
}

.is-mobile.is-portrait #game {
  width: 100%;
  max-height: calc(100svh - 214px);
}

.is-mobile.is-portrait .touch-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  position: sticky;
  bottom: 0;
  align-items: end;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(3, 2, 5, 0), rgba(3, 2, 5, 0.92) 22%);
}

.is-mobile.is-landscape body {
  overflow: hidden;
}

@media (max-width: 900px) and (orientation: landscape) {
  body {
    padding: 6px;
    place-items: start center;
  }

  .game-shell {
    width: min(100%, 980px);
    grid-template-columns: 1fr 178px;
    gap: 8px;
  }

  .topbar,
  #game {
    grid-column: 1;
  }

  .controls {
    grid-column: 2;
    grid-row: 1;
    align-content: start;
    justify-content: center;
    padding: 8px;
  }

  .controls span {
    display: none;
  }

  .touch-controls {
    grid-column: 2;
    grid-row: 2;
    display: grid;
    align-content: end;
    gap: 14px;
  }

  .touch-pad,
  .touch-actions {
    justify-content: center;
  }

  .touch-button {
    width: 66px;
    height: 66px;
    font-size: 28px;
  }
}
