:root {
  color-scheme: dark;
  font-family:
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui,
    sans-serif;
  --page: #050d0b;
  --surface: #0b1815;
  --surface-raised: #10231d;
  --line: rgba(189, 239, 214, 0.12);
  --muted: #86a397;
  --text: #f1fff8;
  --mint: #74f2ad;
  --mint-deep: #1caa67;
  --red: #ff6269;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--page);
  color: var(--text);
  font-synthesis: none;
  -webkit-tap-highlight-color: transparent;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-width: 300px;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 14% 8%, rgba(41, 166, 106, 0.14), transparent 27rem),
    radial-gradient(circle at 90% 80%, rgba(255, 98, 105, 0.08), transparent 24rem),
    linear-gradient(145deg, #07130f 0%, #040a09 55%, #08100e 100%);
  -webkit-user-select: none;
  user-select: none;
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: 0.18;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.023) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.023) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(to bottom, black, transparent 75%);
}

button,
select {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
select:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 3px;
}

.app {
  position: relative;
  width: min(100%, 480px);
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    calc(18px + var(--safe-top))
    18px
    calc(16px + var(--safe-bottom));
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  position: relative;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(116, 242, 173, 0.38);
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(116, 242, 173, 0.16), rgba(116, 242, 173, 0.03));
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.08);
}

.brand-mark span {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--mint);
  box-shadow: 0 0 10px rgba(116, 242, 173, 0.4);
}

.brand-mark span:nth-child(1) {
  transform: translate(-7px, -5px);
}

.brand-mark span:nth-child(2) {
  transform: translate(0, 0);
}

.brand-mark span:nth-child(3) {
  transform: translate(7px, 5px);
}

.eyebrow {
  margin: 0;
  color: var(--mint);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.2em;
  line-height: 1.25;
  text-transform: uppercase;
}

h1 {
  margin: 1px 0 0;
  font-size: 23px;
  font-weight: 800;
  letter-spacing: 0.03em;
  line-height: 1.1;
}

.scoreboard {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(13, 29, 24, 0.72);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.035);
}

.score-main,
.best-score {
  display: flex;
  flex-direction: column;
}

.scoreboard span {
  color: var(--muted);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.scoreboard strong {
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.score-main strong {
  color: var(--mint);
  font-size: 24px;
  transform-origin: left center;
}

.score-main strong.is-popping {
  animation: score-pop 300ms ease-out;
}

.best-score {
  padding-left: 12px;
  border-left: 1px solid var(--line);
}

.best-meta {
  display: flex;
  align-items: center;
  gap: 5px;
}

.best-meta small {
  padding: 1px 4px;
  border-radius: 4px;
  color: var(--mint);
  font-size: 8px;
  font-weight: 700;
  line-height: 1.3;
  background: rgba(116, 242, 173, 0.1);
}

.best-score strong {
  font-size: 15px;
  transform-origin: left center;
}

.best-score strong.is-popping {
  animation: best-pop 360ms ease-out;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 15px 1px 9px;
}

.status-pill,
.speed-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 9px rgba(116, 242, 173, 0.7);
}

[data-status="paused"] .live-dot {
  background: #ffca66;
  box-shadow: 0 0 9px rgba(255, 202, 102, 0.6);
}

[data-status="gameover"] .live-dot {
  background: var(--red);
  box-shadow: 0 0 9px rgba(255, 98, 105, 0.7);
}

.speed-pill {
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--surface);
}

.speed-pill strong {
  color: #d7f8e6;
}

.board-shell {
  position: relative;
  width: 100%;
  overflow: hidden;
  aspect-ratio: 1;
  border: 1px solid rgba(139, 223, 183, 0.18);
  border-radius: 24px;
  background: #0c1b18;
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.34),
    0 0 0 5px rgba(116, 242, 173, 0.025),
    inset 0 0 0 1px rgba(255, 255, 255, 0.025);
  isolation: isolate;
}

.board-shell::after {
  position: absolute;
  z-index: 2;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  content: "";
  box-shadow:
    inset 0 0 40px rgba(0, 0, 0, 0.25),
    inset 0 1px rgba(255, 255, 255, 0.07);
}

.board-glow {
  position: absolute;
  z-index: -1;
  top: -20%;
  left: 15%;
  width: 70%;
  height: 50%;
  border-radius: 50%;
  background: rgba(88, 235, 164, 0.1);
  filter: blur(40px);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.game-overlay {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 26px;
  background: rgba(3, 12, 9, 0.5);
  backdrop-filter: blur(4px);
  transition: opacity 180ms ease;
}

.game-overlay[hidden] {
  display: none;
}

.overlay-card {
  width: min(100%, 240px);
  padding: 23px 21px 20px;
  border: 1px solid rgba(184, 242, 214, 0.19);
  border-radius: 19px;
  text-align: center;
  background:
    linear-gradient(145deg, rgba(21, 50, 40, 0.96), rgba(9, 25, 20, 0.97));
  box-shadow:
    0 20px 44px rgba(0, 0, 0, 0.35),
    inset 0 1px rgba(255, 255, 255, 0.07);
}

.overlay-card h2 {
  margin: 7px 0 8px;
  font-size: 27px;
  line-height: 1.2;
}

.overlay-card > p:not(.eyebrow) {
  margin: 0 0 17px;
  color: #abc4b8;
  font-size: 12px;
  line-height: 1.65;
}

.primary-button {
  width: 100%;
  min-height: 43px;
  border: 0;
  border-radius: 12px;
  color: #052216;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  background: linear-gradient(180deg, #8bfabb, #5fe49e);
  box-shadow: 0 6px 16px rgba(28, 170, 103, 0.3);
}

.primary-button:active {
  transform: translateY(1px);
  filter: brightness(0.92);
}

.control-panel {
  display: grid;
  grid-template-columns: 72px 126px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

.difficulty-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.difficulty-wrap label {
  padding-left: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.select-shell {
  position: relative;
}

.select-shell::after {
  position: absolute;
  top: 50%;
  right: 10px;
  width: 5px;
  height: 5px;
  border-right: 1.5px solid var(--mint);
  border-bottom: 1.5px solid var(--mint);
  content: "";
  pointer-events: none;
  transform: translateY(-70%) rotate(45deg);
}

select {
  width: 100%;
  height: 42px;
  padding: 0 28px 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: #e9fff4;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  appearance: none;
  background: var(--surface-raised);
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 38px);
  grid-template-rows: repeat(3, 33px);
  gap: 3px;
  justify-content: center;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(11, 25, 21, 0.74);
}

.direction-button {
  display: grid;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(167, 227, 195, 0.13);
  border-radius: 9px;
  color: #d8f2e5;
  font-size: 18px;
  font-weight: 500;
  cursor: pointer;
  touch-action: none;
  background: linear-gradient(180deg, #19352b, #12271f);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.055);
}

.direction-button:active,
.direction-button.is-queued {
  color: var(--mint);
  border-color: rgba(116, 242, 173, 0.5);
  background: #1a3d2e;
  transform: scale(0.94);
}

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

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

.dpad-center {
  display: grid;
  grid-column: 2;
  grid-row: 2;
  place-items: center;
}

.dpad-center span {
  width: 7px;
  height: 7px;
  border-radius: 3px;
  background: rgba(116, 242, 173, 0.35);
}

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

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

.actions {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 7px;
}

.utility-button {
  display: flex;
  min-width: 0;
  height: 34px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: #b8cfc4;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  background: #10211c;
}

.utility-button.accent {
  color: var(--mint);
  border-color: rgba(116, 242, 173, 0.27);
  background: rgba(36, 115, 78, 0.19);
}

.utility-button.reverse {
  color: #ffd888;
  border-color: rgba(255, 209, 116, 0.28);
  background: rgba(103, 76, 26, 0.18);
}

.utility-button.reverse.is-used {
  animation: reverse-flash 320ms ease-out;
}

.utility-button:disabled {
  cursor: default;
  opacity: 0.42;
}

.utility-button:not(:disabled):active {
  transform: translateY(1px);
  filter: brightness(1.16);
}

.pause-icon {
  display: inline-block;
  width: 8px;
  height: 9px;
  border-right: 2px solid currentColor;
  border-left: 2px solid currentColor;
}

.play-icon {
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 6px solid currentColor;
}

.tip {
  margin: 12px 0 0;
  color: #617a6f;
  font-size: 10px;
  line-height: 1.5;
  text-align: center;
}

@keyframes score-pop {
  0% {
    transform: scale(1);
  }
  35% {
    color: #fff;
    transform: scale(1.3);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes reverse-flash {
  0% {
    color: #fff;
    background: rgba(255, 206, 105, 0.42);
    transform: scale(1);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes best-pop {
  0% {
    color: var(--mint);
    transform: scale(1);
  }
  40% {
    color: #fff4bd;
    transform: scale(1.35);
  }
  100% {
    transform: scale(1);
  }
}

@media (max-width: 390px) {
  .app {
    padding-right: 13px;
    padding-left: 13px;
  }

  .control-panel {
    grid-template-columns: 64px 118px minmax(0, 1fr);
    gap: 8px;
  }

  .dpad {
    grid-template-columns: repeat(3, 35px);
    grid-template-rows: repeat(3, 31px);
  }

  .actions {
    gap: 5px;
  }

  .utility-button {
    height: 31px;
    font-size: 9px;
  }
}

@media (min-width: 720px) {
  .app {
    width: min(100%, 680px);
    padding-right: 28px;
    padding-left: 28px;
  }

  .topbar {
    margin-top: 10px;
  }

  .board-shell {
    width: min(100%, 560px);
    margin: 0 auto;
  }

  .status-row {
    width: min(100%, 560px);
    margin-right: auto;
    margin-left: auto;
  }

  .control-panel {
    grid-template-columns: 86px 142px minmax(0, 1fr);
    gap: 18px;
    width: min(100%, 560px);
    margin-right: auto;
    margin-left: auto;
  }

  .dpad {
    grid-template-columns: repeat(3, 43px);
    grid-template-rows: repeat(3, 36px);
  }

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

  .actions .accent {
    grid-column: 1 / -1;
  }
}

@media (max-height: 760px) and (max-width: 719px) {
  .app {
    padding-top: calc(10px + var(--safe-top));
  }

  .status-row {
    margin-top: 9px;
    margin-bottom: 6px;
  }

  .scoreboard {
    padding-top: 5px;
    padding-bottom: 5px;
  }

  .control-panel {
    margin-top: 10px;
  }

  .tip {
    display: none;
  }
}

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