* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  color: #f5f0ff;
  font-family: "Segoe UI", Arial, sans-serif;
  background:
    radial-gradient(circle at 16% 16%, rgba(230, 255, 172, 0.86), transparent 8%),
    radial-gradient(circle at 78% 22%, rgba(154, 76, 255, 0.42), transparent 24%),
    linear-gradient(135deg, #101428 0%, #1b1834 48%, #0b2b27 100%);
}

canvas,
button {
  touch-action: none;
  user-select: none;
}

button {
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: #8f3dff;
  box-shadow: 0 6px 0 #4b188c, 0 14px 24px rgba(0, 0, 0, 0.32);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

button:active,
button.is-down {
  translate: 0 4px;
  box-shadow: 0 2px 0 #4b188c, 0 8px 16px rgba(0, 0, 0, 0.26);
}

.game-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100%;
  gap: 12px;
  padding: 14px;
}

.topbar,
.controls {
  width: min(1120px, 100%);
  margin: 0 auto;
  border: 3px solid rgba(222, 255, 166, 0.22);
  border-radius: 8px;
  background: rgba(13, 17, 35, 0.78);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.24);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
}

.topbar strong {
  display: block;
  font-size: 24px;
}

.topbar span,
.controls p {
  margin: 0;
  color: #b8c4db;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.stats b {
  min-width: 92px;
  padding: 9px 12px;
  border-radius: 8px;
  text-align: center;
  color: #dfff8f;
  background: rgba(255, 255, 255, 0.08);
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  touch-action: none;
}

canvas {
  display: block;
  width: min(1120px, 100%);
  max-height: calc(100vh - 178px);
  aspect-ratio: 16 / 9;
  border: 5px solid #dfff8f;
  border-radius: 8px;
  background: #11162c;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  touch-action: none;
}

.message {
  position: absolute;
  display: grid;
  gap: 12px;
  justify-items: center;
  width: min(430px, calc(100% - 36px));
  padding: 24px;
  border: 4px solid #dfff8f;
  border-radius: 8px;
  text-align: center;
  background: rgba(12, 15, 31, 0.94);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.38);
}

.message.is-hidden {
  display: none;
}

.message h1 {
  margin: 0;
  font-size: clamp(32px, 7vw, 60px);
  line-height: 0.95;
  color: #dfff8f;
  text-shadow: 3px 3px 0 #8f3dff;
}

.message p {
  margin: 0;
  color: #c9d3e8;
}

.message button {
  min-width: 160px;
  padding: 13px 22px;
  font-size: 20px;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
}

.touch {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.touch button {
  min-width: 76px;
  padding: 10px 12px;
  background: #213f9d;
  box-shadow: 0 5px 0 #10225e, 0 10px 16px rgba(0, 0, 0, 0.22);
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .game-shell {
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100dvh;
    padding: 8px;
    gap: 8px;
  }

  .topbar,
  .controls {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    gap: 8px;
    padding: 9px;
  }

  .topbar strong {
    font-size: 18px;
  }

  .topbar span {
    font-size: 12px;
  }

  .stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .stats b {
    min-width: 0;
    padding: 7px 5px;
    font-size: 12px;
  }

  canvas {
    width: 100%;
    height: 100%;
    max-height: none;
    object-fit: contain;
  }

  .message {
    width: min(360px, calc(100% - 22px));
    padding: 16px;
  }

  .message h1 {
    font-size: 38px;
  }

  .controls {
    padding: 8px;
  }

  .controls p {
    display: none;
  }

  .touch {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
  }

  .touch button {
    min-width: 0;
    min-height: 48px;
    padding: 11px 6px;
    font-size: 13px;
  }
}

@media (max-width: 760px) and (orientation: portrait) {
  canvas {
    aspect-ratio: 9 / 12;
  }

  .stage {
    min-height: 0;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .topbar span,
  .controls p {
    display: none;
  }

  .game-shell {
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100dvh;
  }

  .topbar,
  .controls {
    padding: 6px 8px;
  }

  .touch button {
    min-height: 38px;
  }
}
