* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: #05070E;
  color: #E9F1FF;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

button {
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- ambient background ---------- */

.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(72px);
  pointer-events: none;
  z-index: 0;
}

.bg-glow-a {
  width: 330px;
  height: 330px;
  left: -130px;
  top: -100px;
  background: rgba(53, 224, 255, 0.13);
}

.bg-glow-b {
  width: 380px;
  height: 380px;
  right: -160px;
  bottom: 4%;
  background: rgba(155, 107, 255, 0.12);
}

.bg-grid {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(120, 170, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 170, 255, 0.035) 1px, transparent 1px);
  background-size: 34px 34px;
  -webkit-mask-image: radial-gradient(circle at 50% 32%, #000 0%, transparent 74%);
  mask-image: radial-gradient(circle at 50% 32%, #000 0%, transparent 74%);
}

/* ---------- layout ---------- */

.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 520px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-top: calc(env(safe-area-inset-top, 0px) + 10px);
  padding-right: 16px;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  padding-left: 16px;
}

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

.hud {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px 10px;
}

.hud-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.24em;
  color: #7E92B5;
}

.hud-label::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #35E0FF;
  box-shadow: 0 0 9px rgba(53, 224, 255, 0.9);
}

.score-value {
  margin-top: 5px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: clamp(30px, 9.4vw, 40px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #FFFFFF 16%, #A8EDFF 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 16px rgba(53, 224, 255, 0.25));
  transform-origin: left center;
}

.score-value.bump {
  animation: scoreBump 0.26s ease-out;
}

.best-line {
  margin-top: 6px;
  font-size: 10px;
  letter-spacing: 0.1em;
  color: #5F7396;
}

.best-line b {
  margin-left: 3px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 600;
  color: #A8BDDC;
}

.stats {
  display: flex;
  gap: 8px;
  padding-bottom: 2px;
}

.stat-chip {
  min-width: 56px;
  padding: 7px 10px 6px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.022));
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.stat-chip span {
  display: block;
  font-size: 9px;
  line-height: 1;
  letter-spacing: 0.12em;
  color: #7286A6;
}

.stat-chip b {
  display: block;
  margin-top: 4px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  color: #F0F7FF;
  font-variant-numeric: tabular-nums;
  transform-origin: left center;
}

.stat-chip b.bump {
  animation: scoreBump 0.3s ease-out;
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.board-frame {
  position: relative;
  flex: 0 0 auto;
  border-radius: 16px;
  overflow: hidden;
  background: #080B14;
  border: 1px solid rgba(96, 180, 255, 0.22);
  box-shadow:
    0 0 0 3px rgba(53, 224, 255, 0.035),
    0 0 26px rgba(53, 224, 255, 0.09),
    0 18px 42px rgba(0, 0, 0, 0.52),
    inset 0 0 0 1px rgba(255, 255, 255, 0.025);
  touch-action: none;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.board-frame::after {
  content: "";
  position: absolute;
  top: 0;
  left: 14%;
  right: 14%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(53, 224, 255, 0.55), transparent);
  pointer-events: none;
}

.board-frame.danger {
  border-color: rgba(255, 77, 109, 0.5);
  box-shadow:
    0 0 0 3px rgba(255, 77, 109, 0.05),
    0 0 30px rgba(255, 77, 109, 0.18),
    0 18px 42px rgba(0, 0, 0, 0.52),
    inset 0 0 0 1px rgba(255, 77, 109, 0.08);
}

.board-frame.danger::after {
  background: linear-gradient(90deg, transparent, rgba(255, 77, 109, 0.7), transparent);
}

.board-frame.shake {
  animation: boardShake 0.3s ease-out;
}

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

/* ---------- right rail ---------- */

.rail {
  flex: 0 0 62px;
  width: 62px;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.next-card {
  width: 100%;
  padding: 8px 5px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 10px 22px rgba(0, 0, 0, 0.24);
}

.rail-label {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 8px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.2em;
  color: #7FA2CC;
}

.next-canvas {
  display: block;
  width: 50px;
  height: 50px;
}

.pause-btn {
  width: 46px;
  height: 46px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 15px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  color: #9FB6D8;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: transform 0.08s ease, color 0.15s ease, background 0.15s ease;
}

.pause-btn .mp-icon {
  width: 22px;
  height: 22px;
}

.pause-btn:active {
  transform: scale(0.92);
  color: #DFF7FF;
  background: rgba(53, 224, 255, 0.14);
}

/* ---------- hint ---------- */

.hint {
  flex: 0 0 auto;
  padding: 8px 0 2px;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: #5E7191;
  white-space: nowrap;
}

/* ---------- controls ---------- */

.controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(20, 27, 47, 0.92), rgba(9, 12, 23, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    0 16px 34px rgba(0, 0, 0, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.09);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.pad {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.ctrl {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.085), rgba(255, 255, 255, 0.02));
  color: #D7E6FF;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  touch-action: none;
  transition: transform 0.08s ease, background 0.1s ease, border-color 0.1s ease, color 0.1s ease;
}

.ctrl .mp-icon {
  width: 27px;
  height: 27px;
}

.ctrl:active,
.ctrl.is-down {
  transform: scale(0.93);
  background: linear-gradient(180deg, rgba(53, 224, 255, 0.22), rgba(53, 224, 255, 0.06));
  border-color: rgba(53, 224, 255, 0.4);
  color: #FFFFFF;
}

.ctrl-rotate {
  flex: 0 0 58px;
  width: 58px;
  height: 58px;
  border-radius: 18px;
  border: 0;
  background: linear-gradient(140deg, #7BEAFF 0%, #35D6FF 45%, #4C8DFF 100%);
  color: #04121F;
  box-shadow:
    0 10px 24px rgba(53, 214, 255, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.65),
    inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

.ctrl-rotate .mp-icon {
  width: 29px;
  height: 29px;
}

.ctrl-rotate:active,
.ctrl-rotate.is-down {
  transform: scale(0.93);
  filter: brightness(1.08);
  background: linear-gradient(140deg, #7BEAFF 0%, #35D6FF 45%, #4C8DFF 100%);
  border-color: transparent;
  color: #04121F;
}

/* ---------- overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(4, 7, 14, 0.72);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  position: relative;
  width: min(340px, 100%);
  padding: 24px 20px 20px;
  overflow: hidden;
  border-radius: 26px;
  text-align: center;
  background: linear-gradient(165deg, rgba(30, 38, 62, 0.98), rgba(10, 14, 26, 0.99));
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    0 32px 80px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.overlay-card::before {
  content: "";
  position: absolute;
  top: -68px;
  left: 50%;
  width: 220px;
  height: 150px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(53, 224, 255, 0.24), transparent 70%);
  pointer-events: none;
}

.overlay.show .overlay-card {
  animation: cardIn 0.34s cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
}

.overlay.mode-over .overlay-card::before {
  background: radial-gradient(circle, rgba(255, 77, 109, 0.2), transparent 70%);
}

.ov-kicker {
  position: relative;
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.24em;
  color: #7DE7FF;
  background: rgba(53, 224, 255, 0.1);
  border: 1px solid rgba(53, 224, 255, 0.25);
}

.overlay.mode-over .ov-kicker {
  color: #FF9DB1;
  background: rgba(255, 77, 109, 0.12);
  border-color: rgba(255, 77, 109, 0.3);
}

.overlay-card h2 {
  position: relative;
  margin: 12px 0 6px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #F4FAFF;
}

.ov-note {
  position: relative;
  margin: 0 0 18px;
  font-size: 12px;
  line-height: 1.6;
  color: #8CA1C2;
}

.ov-stats {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.ov-stat {
  padding: 12px 8px 10px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.ov-stat span {
  display: block;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: #7E92B5;
}

.ov-stat strong {
  display: block;
  margin-top: 6px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
  color: #EAF6FF;
  font-variant-numeric: tabular-nums;
}

.ov-stat:first-child strong {
  color: #7DE7FF;
  text-shadow: 0 0 18px rgba(53, 224, 255, 0.35);
}

.overlay.mode-over .ov-stat:first-child strong {
  color: #FF9DB1;
  text-shadow: 0 0 18px rgba(255, 77, 109, 0.32);
}

.ov-actions {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.btn {
  height: 50px;
  border-radius: 16px;
  border: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  touch-action: manipulation;
  transition: transform 0.1s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn[hidden] {
  display: none;
}

.btn-primary {
  background: linear-gradient(135deg, #7BEAFF, #35D6FF 45%, #4C8DFF);
  color: #05121F;
  box-shadow:
    0 10px 26px rgba(53, 214, 255, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #B9CCE8;
}

/* ---------- animations ---------- */

@keyframes scoreBump {
  0% { transform: scale(1); }
  35% { transform: scale(1.07); }
  100% { transform: scale(1); }
}

@keyframes boardShake {
  0%, 100% { transform: translate(0, 0); }
  18% { transform: translate(-3px, 2px); }
  36% { transform: translate(3px, -2px); }
  54% { transform: translate(-2px, -1px); }
  72% { transform: translate(2px, 1px); }
}

@keyframes cardIn {
  0% { opacity: 0; transform: translateY(18px) scale(0.95); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- short screens ---------- */

@media (max-height: 720px) {
  .hint { display: none; }
  .hud { padding-bottom: 8px; }
  .score-value { font-size: clamp(28px, 8.6vw, 34px); }
  .controls { padding: 6px; }
  .ctrl { height: 50px; }
  .ctrl-rotate { width: 54px; height: 54px; flex-basis: 54px; }
  .next-canvas { width: 44px; height: 44px; }
}

@media (max-height: 620px) {
  .best-line { display: none; }
  .stat-chip { padding: 6px 9px 5px; }
  .ctrl { height: 46px; }
  .ctrl-rotate { width: 50px; height: 50px; flex-basis: 50px; }
}

@media (prefers-reduced-motion: reduce) {
  .score-value.bump,
  .stat-chip b.bump,
  .board-frame.shake,
  .overlay.show .overlay-card {
    animation: none;
  }
}
