:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --accent-2: #8a6bff;
  --secondary: #2a2b3d;
  --text: #fff;
  --muted: #aaadbe;
  --lime: #b6ff5c;
  --teal: #16c9b4;
  --hud-h: 52px;
  --help-h: 26px;
  --dpad-h: 0px;
  font-family:
    "Nunito",
    ui-rounded,
    "SF Pro Rounded",
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  font-weight: 800;
}
* {
  box-sizing: border-box;
}
html,
body {
  width: 100%;
  min-width: 0;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
body {
  padding: 10px;
  background:
    radial-gradient(120% 70% at 50% 0%, #1d1b44 0%, rgba(15, 16, 32, 0) 60%),
    var(--bg);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
:focus-visible {
  outline: 3px solid #ffd84a;
  outline-offset: 2px;
}

.shell {
  width: min(760px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* HUD */
.hud {
  width: 100%;
  min-height: var(--hud-h);
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}
.brand-icon {
  width: 34px;
  height: 34px;
  filter: drop-shadow(0 3px 6px rgba(22, 201, 180, 0.35));
}
.brand h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #e5ffb8, var(--lime) 55%, #6fd83a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.chips {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}
.chip {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  padding: 7px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #26273b, var(--panel));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 3px 0 #0a0b16;
}
.chip span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.chip strong {
  font-size: 18px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.chip-score strong {
  color: var(--lime);
}
.chip.pop strong {
  animation: pop 0.28s cubic-bezier(0.3, 1.8, 0.5, 1);
}
@keyframes pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.35);
  }
  100% {
    transform: scale(1);
  }
}

/* Pills */
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  font-weight: 900;
  font-size: 16px;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    filter 0.12s ease,
    box-shadow 0.12s ease;
}
.pill:active:not(:disabled) {
  transform: translateY(2px) scale(0.98);
}
.pill:disabled {
  opacity: 0.45;
  cursor: default;
}
.pill-primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.25),
    0 4px 0 #3f22b8,
    0 10px 24px rgba(104, 66, 255, 0.4);
}
.pill-primary:hover {
  filter: brightness(1.08);
}
.pill-secondary {
  background: var(--secondary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 3px 0 #15162a;
}
.pill-secondary:hover:not(:disabled) {
  background: #34354b;
}
.pill-big {
  min-height: 54px;
  min-width: 180px;
  font-size: 22px;
  letter-spacing: 0.01em;
}
.pause-button {
  flex: 0 0 auto;
  padding: 0 14px;
}
.pause-button svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* Board */
.stage {
  width: 100%;
  display: flex;
  justify-content: center;
}
.board {
  position: relative;
  width: min(
    100%,
    max(
      260px,
      calc(100svh - 20px - var(--hud-h) - var(--help-h) - var(--dpad-h) - 24px)
    )
  );
  aspect-ratio: 1;
  border-radius: 22px;
  padding: 8px;
  background: linear-gradient(180deg, #2c2d52, #1b1c34);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.1),
    0 6px 0 #0b0c1a,
    0 18px 40px rgba(0, 0, 0, 0.45);
}
.board.shake {
  animation: shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}
@keyframes shake {
  10%,
  90% {
    transform: translateX(-2px);
  }
  20%,
  80% {
    transform: translateX(4px);
  }
  30%,
  50%,
  70% {
    transform: translateX(-7px);
  }
  40%,
  60% {
    transform: translateX(7px);
  }
}
canvas:focus-visible {
  outline: 2px solid rgba(138, 107, 255, 0.7);
  outline-offset: 3px;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 15px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Overlay */
.overlay {
  position: absolute;
  inset: 8px;
  display: grid;
  place-items: center;
  padding: 12px;
  border-radius: 15px;
  background: rgba(12, 12, 30, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  transition: opacity 0.2s ease;
}
.overlay[hidden] {
  display: none;
}
.card {
  width: min(360px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 18px 18px 20px;
  border-radius: 22px;
  text-align: center;
  background: linear-gradient(180deg, #25264a, var(--panel));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.1),
    0 8px 0 #0b0c1a,
    0 24px 50px rgba(0, 0, 0, 0.5);
  animation: card-in 0.35s cubic-bezier(0.3, 1.5, 0.5, 1);
}
@keyframes card-in {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
}
.card-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.card-title {
  margin: 2px 0 4px;
  font-size: clamp(34px, 9vw, 48px);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #f1ffd6, var(--lime) 50%, #4fcf3a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 #1a5b2a);
}
.card.lost .card-title {
  background-image: linear-gradient(180deg, #ffe0e6, #ff6b8a 55%, #e2335a);
  filter: drop-shadow(0 3px 0 #6b1530);
}
.card.paused .card-title {
  background-image: linear-gradient(180deg, #fff, #c8b8ff 55%, #8a6bff);
  filter: drop-shadow(0 3px 0 #2d1a7a);
}
.card-copy {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
}
.final {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 0 12px;
}
.final[hidden] {
  display: none;
}
.final-label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.final-score {
  font-size: 52px;
  font-weight: 900;
  line-height: 1;
  color: #fff;
  text-shadow: 0 4px 0 #3f22b8;
  font-variant-numeric: tabular-nums;
}
.badge {
  margin-top: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe066, #ffb020);
  color: #3b2400;
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 3px 0 #b36b00;
  animation: badge 0.9s ease-in-out infinite alternate;
}
.badge[hidden] {
  display: none;
}
@keyframes badge {
  to {
    transform: scale(1.08) rotate(-2deg);
  }
}
.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.mode {
  min-height: 52px;
  padding: 6px 8px;
  border: 2px solid transparent;
  border-radius: 16px;
  background: var(--secondary);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.15;
  box-shadow: 0 3px 0 #15162a;
  transition:
    border-color 0.15s,
    background 0.15s;
}
.mode strong {
  font-size: 16px;
  font-weight: 900;
}
.mode small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.mode[aria-pressed="true"] {
  border-color: var(--accent-2);
  background: linear-gradient(180deg, #3a2f7a, #2a2458);
}
.mode[aria-pressed="true"] small {
  color: #d8ceff;
}
.card-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.card-actions [hidden] {
  display: none;
}
.pill-reward {
  flex-basis: 100%;
  max-width: 280px;
  font-size: 15px;
}
.pill-reward:disabled {
  cursor: progress;
}
.ad-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.ad-note[hidden] {
  display: none;
}

/* D-pad: shown on touch devices */
.dpad {
  display: none;
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(3, 50px);
  gap: 4px;
  touch-action: none;
}
.dpad-btn {
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, #34355a, #25263f);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.12),
    0 4px 0 #0b0c1a;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.dpad-btn svg {
  width: 26px;
  height: 26px;
  fill: #d9dbef;
}
.dpad-btn.pressed,
.dpad-btn:active {
  transform: translateY(3px);
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  box-shadow: 0 1px 0 #0b0c1a;
}
.dpad-btn.pressed svg,
.dpad-btn:active svg {
  fill: #fff;
}
.dpad-up {
  grid-area: 1 / 2;
}
.dpad-left {
  grid-area: 2 / 1;
}
.dpad-right {
  grid-area: 2 / 3;
}
.dpad-down {
  grid-area: 3 / 2;
}
@media (pointer: coarse) {
  :root {
    --dpad-h: 170px;
  }
  .dpad {
    display: grid;
  }
}

.help {
  margin: 0;
  min-height: var(--help-h);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}
kbd {
  display: inline-block;
  min-width: 20px;
  margin: 0 1px;
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--secondary);
  box-shadow: 0 2px 0 #0b0c1a;
  color: #fff;
  font: inherit;
  font-size: 11px;
}
@media (pointer: coarse) {
  .help {
    display: none;
  }
  :root {
    --help-h: 0px;
  }
}

@media (max-width: 520px) {
  body {
    padding: 8px;
  }
  .brand h1 {
    display: none;
  }
  .chips {
    justify-content: flex-start;
    gap: 4px;
  }
  .chip {
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 5px 10px;
    border-radius: 14px;
  }
  .chip span {
    font-size: 9px;
  }
  .pause-text {
    display: none;
  }
  .pause-button {
    width: 44px;
    padding: 0;
  }
}
@media (max-width: 360px) {
  .chip {
    padding: 5px 7px;
  }
  .chip strong {
    font-size: 16px;
  }
  .chip-length {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

.modes[hidden] {
  display: none;
}
.board {
  container-type: inline-size;
}
@container (max-width: 400px) {
  .overlay {
    padding: 8px;
  }
  .card {
    padding: 10px 12px 12px;
    border-radius: 18px;
  }
  .card-kicker {
    font-size: 10px;
  }
  .card-title {
    font-size: 32px;
    margin: 0 0 2px;
  }
  .card-copy {
    font-size: 13px;
    margin-bottom: 8px;
  }
  .final {
    margin-bottom: 8px;
  }
  .final-score {
    font-size: 36px;
  }
  .badge {
    margin-top: 4px;
    font-size: 11px;
  }
  .modes {
    margin-bottom: 10px;
    gap: 6px;
  }
  .mode {
    min-height: 44px;
    border-radius: 13px;
  }
  .mode small {
    font-size: 10px;
  }
  .pill-big {
    min-height: 46px;
    min-width: 140px;
    font-size: 19px;
  }
}
@container (max-width: 320px) {
  .mode small {
    display: none;
  }
  .card-copy {
    display: none;
  }
}
