:root {
  --bg: #04060f;
  --cyan: #38e8ff;
  --cyan-soft: #8ff4ff;
  --purple: #a35bff;
  --pink: #ff3dd8;
  --orange: #ff8a3d;
  --orange-hi: #ffb066;
  --ink: #ecfbff;
  --muted: #7d93c4;
  --panel: rgba(7, 13, 32, 0.86);
  --bevel: polygon(10px 0, calc(100% - 10px) 0, 100% 10px, 100% calc(100% - 10px), calc(100% - 10px) 100%, 10px 100%, 0 calc(100% - 10px), 0 10px);
  --mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}

body {
  position: fixed;
  inset: 0;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- cyberpunk city backdrop (generated art) ---------- */

.bg,
.bg-veil {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.bg {
  background: #04060f url("images/gen/gptimg_1795347245_look.png") center / cover no-repeat;
  filter: blur(1.2px) brightness(0.84) saturate(1.32);
  transform: scale(1.02);
  opacity: 1;
}

@media (max-aspect-ratio: 3/4) {
  .bg {
    background-size: auto 280%;
    background-position: 0% 8%;
  }
}

/* wide / desktop preview: crop to the city side of the key art so the
   painted HUD in the artwork never doubles up behind the real HUD */
@media (min-aspect-ratio: 4/5) {
  .bg {
    background-size: cover;
    background-position: center;
    filter: blur(14px) brightness(0.5) saturate(1.35);
    transform: scale(1.12);
  }
}

.bg-veil {
  background:
    radial-gradient(78% 42% at 50% -4%, rgba(56, 232, 255, 0.18), transparent 62%),
    radial-gradient(62% 38% at 98% 50%, rgba(255, 61, 216, 0.14), transparent 68%),
    radial-gradient(70% 42% at 0% 100%, rgba(255, 138, 61, 0.16), transparent 70%),
    linear-gradient(180deg, rgba(3, 5, 15, 0.12), rgba(3, 5, 15, 0.46) 42%, rgba(3, 5, 15, 0.84));
}

.bg-veil::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 3px);
  opacity: 0.42;
  mix-blend-mode: overlay;
}

/* ---------- app shell ---------- */

.app {
  position: relative;
  z-index: 2;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px calc(env(safe-area-inset-bottom, 0px) + 8px);
  display: flex;
  flex-direction: column;
  gap: 7px;
  touch-action: none;
}

/* ---------- HUD ---------- */

.hud {
  flex: 0 0 auto;
  height: 62px;
  display: flex;
  align-items: stretch;
  gap: 7px;
  padding: 0 1px;
}

.hud-card {
  position: relative;
  background: linear-gradient(155deg, rgba(14, 25, 56, 0.86), rgba(4, 8, 21, 0.78));
  border: 1px solid rgba(56, 232, 255, 0.42);
  -webkit-backdrop-filter: blur(7px) saturate(1.2);
  backdrop-filter: blur(7px) saturate(1.2);
  clip-path: var(--bevel);
  box-shadow: inset 0 0 16px rgba(56, 232, 255, 0.1), 0 0 14px rgba(56, 232, 255, 0.1);
}

.score-card {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 14px 7px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
}

.score-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 2px;
  background: linear-gradient(180deg, var(--orange), rgba(255, 138, 61, 0));
  box-shadow: 0 0 9px var(--orange);
}

.label {
  display: block;
  font-family: var(--mono);
  font-size: 8.5px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.24em;
  color: #7fdcff;
  text-shadow: 0 0 8px rgba(56, 232, 255, 0.55);
}

.value {
  display: block;
  font-family: var(--mono);
  font-size: 23px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  text-shadow: 0 0 12px rgba(56, 232, 255, 0.55);
}

.value.pop {
  animation: valuePop 0.26s ease-out;
}

@keyframes valuePop {
  0% { transform: scale(1); }
  38% { transform: scale(1.14); color: #fff; }
  100% { transform: scale(1); }
}

.stats-card {
  flex: 0 0 108px;
  width: 108px;
  display: flex;
  align-items: center;
  padding: 7px 5px;
  border-color: rgba(163, 91, 255, 0.46);
  box-shadow: inset 0 0 16px rgba(163, 91, 255, 0.12), 0 0 14px rgba(163, 91, 255, 0.1);
}

.stats-card::after {
  content: "";
  position: absolute;
  right: 0;
  top: 10px;
  bottom: 10px;
  width: 2px;
  background: linear-gradient(180deg, var(--purple), rgba(163, 91, 255, 0));
  box-shadow: 0 0 9px var(--purple);
}

.stat {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.stat + .stat {
  border-left: 1px solid rgba(163, 91, 255, 0.24);
}

.stat .label {
  font-size: 7.5px;
  letter-spacing: 0.14em;
  color: #cbaaff;
  text-shadow: 0 0 8px rgba(163, 91, 255, 0.6);
}

.stat .value {
  font-size: 19px;
  text-shadow: 0 0 11px rgba(163, 91, 255, 0.6);
}

.pause-btn {
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  align-self: center;
  padding: 0;
  display: grid;
  place-items: center;
  color: var(--cyan-soft);
  background: linear-gradient(160deg, #0b1430, #050914);
  border: 1px solid rgba(56, 232, 255, 0.72);
  clip-path: var(--bevel);
  box-shadow: 0 0 15px rgba(56, 232, 255, 0.34), inset 0 0 14px rgba(56, 232, 255, 0.18);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
}

.pause-btn .mp-icon {
  width: 19px;
  height: 19px;
  filter: drop-shadow(0 0 6px rgba(56, 232, 255, 0.9));
}

.pause-btn:active {
  transform: scale(0.92);
  box-shadow: 0 0 22px rgba(56, 232, 255, 0.5), inset 0 0 18px rgba(56, 232, 255, 0.32);
}

/* ---------- play field ---------- */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding-top: 2px;
}

.board-col {
  flex: 0 0 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-shell {
  position: relative;
  padding: 3px;
  background: linear-gradient(145deg, #55f6ff 0%, #4f6bff 26%, #a35bff 50%, #ff3dd8 72%, #ffb066 100%);
  clip-path: polygon(12px 0, calc(100% - 12px) 0, 100% 12px, 100% calc(100% - 12px), calc(100% - 12px) 100%, 12px 100%, 0 calc(100% - 12px), 0 12px);
  filter: drop-shadow(0 0 10px rgba(56, 232, 255, 0.45)) drop-shadow(0 0 26px rgba(163, 91, 255, 0.26));
}

.board-inner {
  position: relative;
  width: 100%;
  height: 100%;
  background: #040817;
  overflow: hidden;
  clip-path: polygon(9px 0, calc(100% - 9px) 0, 100% 9px, 100% calc(100% - 9px), calc(100% - 9px) 100%, 9px 100%, 0 calc(100% - 9px), 0 9px);
  box-shadow: inset 0 0 30px rgba(56, 232, 255, 0.14);
}

.board-inner::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(56, 232, 255, 0.18), inset 0 0 46px rgba(56, 232, 255, 0.09);
}

#board {
  display: block;
  width: 100%;
  height: 100%;
}

.board-scan {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.24) 0 1px, transparent 1px 4px);
  opacity: 0.3;
}

.combo {
  position: absolute;
  left: 50%;
  top: 42%;
  z-index: 3;
  transform: translate(-50%, -50%) scale(0.86);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

.combo.show {
  animation: comboPop 0.92s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.combo b {
  font-family: var(--mono);
  font-size: 27px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #fff;
  text-shadow: 0 0 10px var(--orange), 0 0 26px rgba(255, 138, 61, 0.85), 0 2px 0 rgba(0, 0, 0, 0.4);
}

.combo span {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.24em;
  color: var(--orange-hi);
  text-shadow: 0 0 12px rgba(255, 138, 61, 0.9);
}

@keyframes comboPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  30% { transform: translate(-50%, -50%) scale(1); }
  72% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -58%) scale(1.02); }
}

/* ---------- next queue ---------- */

.side {
  flex: 0 0 60px;
  width: 60px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.next-shell {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 9px 5px 8px;
  background: linear-gradient(160deg, rgba(12, 21, 47, 0.86), rgba(4, 8, 19, 0.8));
  border: 1px solid rgba(163, 91, 255, 0.52);
  -webkit-backdrop-filter: blur(7px) saturate(1.2);
  backdrop-filter: blur(7px) saturate(1.2);
  clip-path: var(--bevel);
  box-shadow: inset 0 0 18px rgba(163, 91, 255, 0.14), 0 0 16px rgba(163, 91, 255, 0.16);
}

.next-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(163, 91, 255, 0.22);
  font-family: var(--mono);
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: #ddc8ff;
  text-shadow: 0 0 9px rgba(163, 91, 255, 0.8);
}

.next-head .dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 7px var(--orange);
}

#next {
  flex: 1 1 auto;
  display: block;
  width: 100%;
  min-height: 0;
}

/* ---------- hint + controls ---------- */

.hint {
  flex: 0 0 auto;
  height: 13px;
  text-align: center;
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.16em;
  color: #7184b3;
  white-space: nowrap;
  opacity: 1;
  transition: opacity 0.6s ease;
}

.hint.gone {
  opacity: 0;
}

.pad {
  flex: 0 0 auto;
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 1px 5px 0;
}

.pad-btn {
  width: 58px;
  height: 58px;
  padding: 0;
  display: grid;
  place-items: center;
  color: var(--cyan-soft);
  background: linear-gradient(160deg, rgba(16, 30, 64, 0.96), rgba(5, 9, 20, 0.96));
  border: 1px solid rgba(56, 232, 255, 0.5);
  clip-path: var(--bevel);
  box-shadow: inset 0 0 16px rgba(56, 232, 255, 0.12), 0 0 13px rgba(56, 232, 255, 0.12);
  cursor: pointer;
  transition: transform 0.07s ease, box-shadow 0.14s ease, filter 0.14s ease;
}

.pad-btn .mp-icon {
  width: 27px;
  height: 27px;
  filter: drop-shadow(0 0 6px rgba(56, 232, 255, 0.6));
}

.pad-btn.press {
  transform: scale(0.92);
  box-shadow: 0 0 22px rgba(56, 232, 255, 0.45), inset 0 0 20px rgba(56, 232, 255, 0.3);
}

.pad-btn.rotate {
  width: 64px;
  height: 64px;
  color: #241000;
  border-color: rgba(255, 176, 102, 0.95);
  background: linear-gradient(150deg, #ffd0a0 0%, #ffb066 28%, #ff8a3d 58%, #d34f00 100%);
  box-shadow: 0 0 24px rgba(255, 138, 61, 0.55), inset 0 0 18px rgba(255, 255, 255, 0.38);
}

.pad-btn.rotate .mp-icon {
  width: 30px;
  height: 30px;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.25));
}

.pad-btn.rotate.press {
  filter: brightness(1.16);
  box-shadow: 0 0 30px rgba(255, 138, 61, 0.8), inset 0 0 24px rgba(255, 255, 255, 0.45);
}

.pad-btn.drop {
  color: var(--orange-hi);
  border-color: rgba(255, 138, 61, 0.56);
  box-shadow: inset 0 0 16px rgba(255, 138, 61, 0.1), 0 0 13px rgba(255, 138, 61, 0.12);
}

.pad-btn.drop .mp-icon {
  filter: drop-shadow(0 0 6px rgba(255, 138, 61, 0.7));
}

/* ---------- pause / game over dialog ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(62% 52% at 50% 50%, rgba(12, 18, 44, 0.62), rgba(2, 4, 12, 0.9));
  -webkit-backdrop-filter: blur(7px) saturate(0.9);
  backdrop-filter: blur(7px) saturate(0.9);
  animation: overlayIn 0.24s ease-out;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.dialog {
  position: relative;
  width: min(320px, 86vw);
  padding: 26px 22px 22px;
  text-align: center;
  background: linear-gradient(160deg, rgba(15, 27, 60, 0.98), rgba(4, 8, 20, 0.98));
  border: 1px solid rgba(56, 232, 255, 0.5);
  clip-path: polygon(14px 0, calc(100% - 14px) 0, 100% 14px, 100% calc(100% - 14px), calc(100% - 14px) 100%, 14px 100%, 0 calc(100% - 14px), 0 14px);
  box-shadow: 0 0 44px rgba(56, 232, 255, 0.16), inset 0 0 30px rgba(56, 232, 255, 0.06);
  animation: dialogIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes dialogIn {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.dialog::before {
  content: "";
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--orange), transparent);
  box-shadow: 0 0 14px var(--orange);
}

.dialog-kicker {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.28em;
  color: var(--cyan);
  text-shadow: 0 0 9px rgba(56, 232, 255, 0.7);
}

.dialog h2 {
  margin: 9px 0 0;
  font-size: 27px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 0 0 18px rgba(56, 232, 255, 0.45);
}

.dialog-score {
  margin-top: 14px;
}

.dialog-score span {
  display: block;
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.24em;
  color: #7fdcff;
}

.dialog-score b {
  display: block;
  margin-top: 5px;
  font-family: var(--mono);
  font-size: 38px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 0 10px var(--orange), 0 0 30px rgba(255, 138, 61, 0.65);
}

.dialog-sub {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.7;
  color: #9db0d8;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.act-btn {
  flex: 1 1 0;
  min-width: 0;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--cyan-soft);
  background: linear-gradient(160deg, rgba(17, 32, 70, 0.98), rgba(5, 10, 24, 0.98));
  border: 1px solid rgba(56, 232, 255, 0.5);
  clip-path: var(--bevel);
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
}

.act-btn .mp-icon {
  width: 19px;
  height: 19px;
}

.act-btn.primary {
  color: #241000;
  border-color: rgba(255, 176, 102, 0.95);
  background: linear-gradient(150deg, #ffd0a0, #ff8a3d 58%, #e06000);
  box-shadow: 0 0 22px rgba(255, 138, 61, 0.4), inset 0 0 16px rgba(255, 255, 255, 0.32);
}

.act-btn:active {
  transform: scale(0.95);
  filter: brightness(1.12);
}

/* ---------- small screens ---------- */

@media (max-height: 700px) {
  .app { gap: 5px; }
  .hud { height: 56px; }
  .score-card { padding: 6px 12px; }
  .value { font-size: 21px; }
  .stat .value { font-size: 17px; }
  .pause-btn { width: 42px; height: 42px; flex-basis: 42px; }
  .pad-btn { width: 52px; height: 52px; }
  .pad-btn.rotate { width: 58px; height: 58px; }
  .hint { display: none; }
}

@media (min-width: 560px) {
  .app { max-width: 440px; }
}
