:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --accent-2: #8a6bff;
  --secondary: #2a2b3d;
  --text: #fff;
  --muted: #aaadbe;
  --lime: #8ff05a;
  --hud-h: 48px;
  --help-h: 22px;
  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%, #1c2a3f 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;
}
kbd {
  display: inline-block;
  min-width: 20px;
  margin: 0 1px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--secondary);
  box-shadow: 0 2px 0 #0b0c1a;
  color: #fff;
  font: inherit;
  font-size: 0.9em;
  text-align: center;
}

.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: 36px;
  height: 36px;
  overflow: visible;
  filter: drop-shadow(0 3px 6px rgba(120, 230, 80, 0.35));
}
.brand h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: -0.02em;
  white-space: nowrap;
  background: linear-gradient(180deg, #f1ffc9, var(--lime) 55%, #38b94a);
  -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 {
  display: inline-block;
  min-width: 1.2ch;
  font-size: 18px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.chip-score strong {
  color: var(--lime);
}
.chip-best strong {
  color: #ffd36b;
}
.chip.pop strong {
  animation: pop 0.32s cubic-bezier(0.3, 1.8, 0.5, 1);
}
@keyframes pop {
  50% {
    transform: scale(1.35);
  }
}
.hud-actions {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--secondary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 3px 0 #15162a;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.icon-btn:hover:not(:disabled) {
  background: #34354b;
}
.icon-btn:active:not(:disabled) {
  transform: translateY(2px);
}
.icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
.icon-btn .icon-off,
.icon-btn[aria-pressed="true"] .icon-on {
  display: none;
}
.icon-btn[aria-pressed="true"] .icon-off {
  display: block;
}

/* Pills */
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  font-weight: 900;
  font-size: 16px;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    filter 0.12s ease;
}
.pill svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}
.pill:active:not(:disabled) {
  transform: translateY(2px) scale(0.98);
}
.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,
.pill-secondary:hover {
  filter: brightness(1.1);
}
.pill-secondary {
  margin-top: 10px;
  background: var(--secondary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 4px 0 #111224;
}
.pill-big {
  min-height: 56px;
  min-width: 190px;
  font-size: 22px;
}

/* Board */
.stage {
  width: 100%;
  display: flex;
  justify-content: center;
}
.board {
  --board-h: calc(100svh - 20px - var(--hud-h) - var(--help-h) - 24px);
  position: relative;
  width: min(100%, max(250px, calc(var(--board-h) * 2 / 3)));
  aspect-ratio: 2 / 3;
  max-height: var(--board-h);
  border-radius: 22px;
  padding: 6px;
  background: linear-gradient(180deg, #2a3b5a, #1b1c34);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.12),
    0 6px 0 #0b0c1a,
    0 18px 40px rgba(0, 0, 0, 0.45);
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 17px;
  background: #fbe9dc;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
}
canvas:focus-visible {
  outline: 2px solid rgba(80, 60, 160, 0.5);
  outline-offset: -3px;
}

/* On-screen steering (touch helpers) */
.steer {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.steer[hidden] {
  display: none;
}
.steer-btn {
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  background: rgba(64, 52, 140, 0.28);
  box-shadow: 0 4px 10px rgba(40, 30, 90, 0.2);
  cursor: pointer;
  touch-action: none;
  transition:
    transform 0.1s ease,
    background 0.1s ease;
}
.steer-btn svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: #fff;
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.steer-btn.is-down {
  transform: scale(0.9);
  background: rgba(104, 66, 255, 0.6);
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 6px;
  display: grid;
  place-items: center;
  padding: 12px;
  border-radius: 17px;
  background: rgba(30, 22, 70, 0.38);
  backdrop-filter: blur(1.5px);
  -webkit-backdrop-filter: blur(1.5px);
}
.overlay[hidden],
.card[hidden] {
  display: none;
}
.card {
  width: min(320px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 16px 14px 18px;
  border-radius: 24px;
  text-align: center;
  background: linear-gradient(180deg, #2b2c55, var(--panel));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.12),
    0 8px 0 #0b0c1a,
    0 24px 50px rgba(0, 0, 0, 0.5);
  animation: card-in 0.42s cubic-bezier(0.3, 1.5, 0.5, 1);
}
#card-pause {
  display: flex;
  flex-direction: column;
  align-items: center;
}
#card-pause[hidden] {
  display: none;
}
@keyframes card-in {
  from {
    transform: translateY(24px) scale(0.85);
    opacity: 0;
  }
}
.kicker {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.logo,
.card-title {
  margin: 2px 0 6px;
  font-size: clamp(40px, 12vw, 54px);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #f4ffd0, #8ff05a 50%, #2fae43);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 0 #1d5e22)
    drop-shadow(0 8px 14px rgba(0, 0, 0, 0.35));
}
.logo {
  animation: logo-bounce 1.1s cubic-bezier(0.3, 0, 0.4, 1) infinite alternate;
}
@keyframes logo-bounce {
  to {
    transform: translateY(-5px) scaleY(1.03);
  }
}
.card-title {
  font-size: clamp(34px, 10vw, 44px);
}
.over-title {
  background-image: linear-gradient(180deg, #ffe0e6, #ff6b8a 55%, #e2335a);
  filter: drop-shadow(0 4px 0 #6b1530);
}
.over-title.is-best {
  background-image: linear-gradient(180deg, #fffbd0, #ffd21f 48%, #ff8a00);
  filter: drop-shadow(0 4px 0 #9c4a00);
}
#card-pause .card-title {
  background-image: linear-gradient(180deg, #fff, #c8b8ff 55%, #8a6bff);
  filter: drop-shadow(0 4px 0 #2d1a7a);
}
.copy {
  margin: 0 auto 10px;
  max-width: 270px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
}
.legend {
  display: grid;
  grid-template-columns: repeat(2, auto);
  justify-content: center;
  gap: 6px 14px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
  color: #dfe1f0;
  font-size: 13px;
}
.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
  text-align: left;
}
.sw {
  display: inline-block;
  width: 30px;
  height: 10px;
  border-radius: 999px;
  border: 2px solid rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.55);
}
.sw-normal {
  background: linear-gradient(180deg, #a6f27a, #3fb24a);
}
.sw-moving {
  background: linear-gradient(180deg, #8fdcff, #2c8fe6);
}
.sw-breaking {
  background: linear-gradient(180deg, #e2b07c, #9a5f2e);
}
.sw-vanish {
  background: linear-gradient(180deg, #fff, #dfe4ff);
}
.start-best {
  margin: -2px 0 12px;
  color: var(--muted);
  font-size: 14px;
}
.start-best strong {
  color: #ffd36b;
  font-size: 18px;
}
.start-best[hidden] {
  display: none;
}

/* Result panel */
.result {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 22px;
  margin: 6px 0 8px;
  padding: 12px 12px 14px;
  border-radius: 18px;
  background: var(--panel-2);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.35);
}
.score-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.05;
}
.score-row span {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.score-row strong {
  font-size: 24px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: #ffd36b;
  text-shadow: 0 2px 0 #7a4a00;
}
.score-main strong {
  font-size: 40px;
  color: var(--lime);
  text-shadow: 0 3px 0 #1d5e22;
}
.badge {
  position: absolute;
  top: -12px;
  right: -6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe066, #ffb020);
  color: #3b2400;
  font-size: 12px;
  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(-4deg);
  }
}
.run-stats {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.run-stats:empty {
  display: none;
}

.help {
  margin: 0;
  min-height: var(--help-h);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

@media (max-width: 600px) and (orientation: portrait) {
  .board {
    width: 100%;
    aspect-ratio: auto;
    height: min(var(--board-h), calc((100vw - 20px) * 1.9));
    min-height: calc((100vw - 20px) * 1.35);
    max-height: none;
  }
}
@media (max-width: 480px) {
  .brand h1 {
    display: none;
  }
  .chip {
    padding: 7px 10px;
  }
}
@media (max-width: 340px) {
  .chip span {
    display: none;
  }
}
@media (pointer: coarse) {
  .help {
    display: none;
  }
}
@media (pointer: fine) {
  .steer-btn {
    opacity: 0.55;
  }
}

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