:root {
  --app-bg: #050807;
  --surface: rgba(12, 22, 18, 0.82);
  --surface-strong: rgba(18, 31, 26, 0.94);
  --line: rgba(150, 255, 197, 0.13);
  --line-strong: rgba(150, 255, 197, 0.28);
  --text: #ecfff5;
  --muted: #8ca99b;
  --accent: #72ff9e;
  --accent-strong: #a8ffbd;
  --danger: #ff7979;
  --shadow: rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--app-bg);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 0%, rgba(114, 255, 158, 0.16), transparent 34%),
    radial-gradient(circle at 88% 18%, rgba(76, 144, 255, 0.12), transparent 30%),
    linear-gradient(180deg, #08110d 0%, #050807 60%, #030504 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.app-shell {
  width: min(100%, 480px);
  min-height: 100dvh;
  display: grid;
  align-items: center;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.app-card {
  position: relative;
  display: grid;
  gap: 18px;
  width: 100%;
  padding: clamp(18px, 4vw, 24px);
  border: 1px solid var(--line);
  border-radius: 32px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 30%),
    var(--surface);
  box-shadow:
    0 24px 70px var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(24px);
}

.app-card::before {
  content: "";
  position: absolute;
  inset: 1px;
  z-index: -1;
  border-radius: inherit;
  background: linear-gradient(140deg, rgba(114, 255, 158, 0.34), transparent 38%, rgba(255, 255, 255, 0.12));
  filter: blur(18px);
  opacity: 0.28;
}

.app-header,
.scoreboard {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2.3rem, 11vw, 4.1rem);
  line-height: 0.88;
  letter-spacing: -0.04em;
}

h2 {
  font-size: clamp(2rem, 9vw, 3.4rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

p {
  color: var(--muted);
  line-height: 1.5;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 86px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

.status-pill span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(114, 255, 158, 0.85);
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.score-card {
  min-height: 78px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
}

.score-card span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.score-card strong {
  display: block;
  color: var(--text);
  font-size: clamp(2rem, 9vw, 3rem);
  line-height: 1;
  letter-spacing: -0.05em;
  transition: transform 180ms ease, color 180ms ease, text-shadow 180ms ease;
}

.score-card-muted strong {
  color: var(--accent-strong);
}

.score-pop {
  color: var(--accent) !important;
  transform: translateY(-2px) scale(1.06);
  text-shadow: 0 0 18px rgba(114, 255, 158, 0.55);
}

.game-stage {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 28px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.08), transparent 26%),
    #09110e;
  box-shadow:
    inset 0 0 30px rgba(114, 255, 158, 0.08),
    0 18px 42px rgba(0, 0, 0, 0.34);
}

canvas {
  display: block;
  width: min(100%, 360px);
  height: auto;
  margin: 0 auto;
  aspect-ratio: 1;
  image-rendering: pixelated;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 22px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 30%, rgba(114, 255, 158, 0.16), transparent 34%),
    rgba(5, 8, 7, 0.78);
  backdrop-filter: blur(12px);
  opacity: 1;
  transition: opacity 220ms ease, transform 220ms ease;
}

.overlay-panel {
  display: grid;
  justify-items: center;
  gap: 14px;
  max-width: 290px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: rgba(13, 24, 20, 0.86);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
  animation: floatIn 420ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

.overlay-panel p:not(.eyebrow) {
  max-width: 230px;
}

.hidden {
  display: none;
}

.primary-action,
.touch-button {
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.primary-action {
  min-width: 154px;
  padding: 13px 20px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), #d4ff9c);
  color: #061008;
  font-weight: 900;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-transform: uppercase;
  box-shadow:
    0 0 26px rgba(114, 255, 158, 0.28),
    0 12px 28px rgba(0, 0, 0, 0.32);
  transition: transform 160ms ease, box-shadow 160ms ease, filter 160ms ease;
}

.primary-action:hover,
.primary-action:focus-visible {
  outline: none;
  filter: brightness(1.04);
  transform: translateY(-1px);
  box-shadow:
    0 0 34px rgba(114, 255, 158, 0.42),
    0 15px 32px rgba(0, 0, 0, 0.36);
}

.keypad {
  width: min(286px, 88%);
  margin: 2px auto 0;
  display: grid;
  grid-template-columns: repeat(3, 76px);
  grid-template-rows: repeat(3, 54px);
  justify-content: center;
  gap: 8px;
}

.touch-button {
  width: 76px;
  min-height: 54px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.025));
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
  user-select: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 10px 24px rgba(0, 0, 0, 0.22);
  transition: transform 130ms ease, border-color 130ms ease, background 130ms ease, box-shadow 130ms ease;
}

.touch-button:hover,
.touch-button:focus-visible {
  outline: none;
  border-color: rgba(114, 255, 158, 0.45);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 0 22px rgba(114, 255, 158, 0.12),
    0 10px 24px rgba(0, 0, 0, 0.22);
}

.touch-button:active {
  transform: translateY(2px) scale(0.98);
  background: rgba(114, 255, 158, 0.14);
}

.touch-button.up {
  grid-column: 2;
  grid-row: 1;
}

.touch-button.left {
  grid-column: 1;
  grid-row: 2;
}

.touch-button.center {
  grid-column: 2;
  grid-row: 2;
  pointer-events: none;
  opacity: 0.45;
  border-radius: 999px;
}

.touch-button.right {
  grid-column: 3;
  grid-row: 2;
}

.touch-button.down {
  grid-column: 2;
  grid-row: 3;
}

@keyframes floatIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 520px) {
  body {
    place-items: stretch;
  }

  .app-shell {
    align-items: stretch;
    padding: max(10px, env(safe-area-inset-top)) 10px max(12px, env(safe-area-inset-bottom));
  }

  .app-card {
    min-height: calc(100dvh - max(10px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom)));
    align-content: space-between;
    border-radius: 28px;
  }

  .app-header {
    align-items: flex-start;
  }

  .status-pill {
    min-width: auto;
    padding-inline: 9px;
  }

  .game-stage {
    border-radius: 24px;
  }

  canvas {
    width: min(100%, calc(100dvw - 70px));
  }

  .keypad {
    grid-template-columns: repeat(3, minmax(58px, 70px));
    grid-template-rows: repeat(3, 48px);
    gap: 7px;
  }

  .touch-button {
    width: 100%;
    min-height: 48px;
    font-size: 1.05rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
