:root {
  color-scheme: dark;
  --bg: #050b1a;
  --ink: #e6fff1;
  --muted: #8fb5a4;
  --accent: #2ee58a;
  --danger: #ff4757;
  --panel: rgba(8, 18, 38, 0.72);
  font-family:
    ui-rounded,
    system-ui,
    -apple-system,
    'Segoe UI',
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg) url('./assets/backdrop.webp') center / cover fixed no-repeat;
  color: var(--ink);
}

.app {
  display: grid;
  gap: 12px;
  justify-items: center;
  max-width: 640px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  align-content: start;
}

.back {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 2px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.back:hover {
  color: var(--ink);
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: 0.04em;
  text-shadow: 0 0 18px rgba(46, 229, 138, 0.55);
}

.brand img {
  border-radius: 8px;
}

.scores {
  display: flex;
  gap: 18px;
  margin: 0;
}

.scores div {
  text-align: right;
}

.scores dt {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.scores dd {
  margin: 0;
  font-size: 1.4rem;
  font-variant-numeric: tabular-nums;
}

.stage {
  position: relative;
  width: min(100%, 72dvh, 600px);
  aspect-ratio: 1;
  border-radius: 14px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(46, 229, 138, 0.25),
    0 20px 60px rgba(0, 0, 0, 0.55),
    0 0 40px rgba(46, 229, 138, 0.12);
  touch-action: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

canvas:focus-visible,
.back:focus-visible,
.btn:focus-visible,
.toggle:focus-within {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  background: radial-gradient(circle at 50% 40%, rgba(5, 11, 26, 0.55), rgba(5, 11, 26, 0.9));
  backdrop-filter: blur(3px);
}

.overlay[hidden] {
  display: none;
}

.overlay h2 {
  margin: 0;
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  text-shadow: 0 0 22px rgba(46, 229, 138, 0.6);
}

.overlay p {
  margin: 0;
  color: var(--muted);
}

.overlay-art {
  width: clamp(96px, 28%, 160px);
  height: auto;
  border-radius: 22%;
  filter: drop-shadow(0 0 24px rgba(46, 229, 138, 0.35));
}

.hint {
  font-size: 0.8rem;
}

.btn {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid rgba(46, 229, 138, 0.35);
  border-radius: 999px;
  padding: 10px 22px;
  cursor: pointer;
  min-height: 44px;
}

.btn.primary {
  background: linear-gradient(180deg, #34f29a, #11a866);
  color: #02140b;
  border: 0;
  padding-inline: 32px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.controls {
  display: flex;
  gap: 16px;
  align-items: center;
}

.toggle {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
  padding: 0 6px;
}

.toggle input {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
}

.pad {
  display: none;
  grid-template-areas:
    '. up .'
    'left . right'
    '. down .';
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(3, 56px);
  gap: 6px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.pad button {
  font-size: 1.3rem;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid rgba(46, 229, 138, 0.3);
  border-radius: 14px;
}

.pad button:active {
  background: rgba(46, 229, 138, 0.25);
}

.pad .up {
  grid-area: up;
}
.pad .down {
  grid-area: down;
}
.pad .left {
  grid-area: left;
}
.pad .right {
  grid-area: right;
}

@media (pointer: coarse) {
  .pad {
    display: grid;
  }
  .stage {
    width: min(100%, 56dvh, 600px);
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
  .overlay {
    backdrop-filter: none;
  }
}
