/* 像素方块 · 像素风俄罗斯方块 */
:root {
  color-scheme: dark;
  --bg: #070B17;
  --panel: #151D38;
  --panel-hi: #1D2749;
  --line: #2E3A64;
  --line-hi: #3B4A7C;
  --text: #F5F2FF;
  --muted: #8D96BC;
  --dim: #5E6789;
  --accent: #FF8A3D;
  --accent-hi: #FFB474;
  --accent-deep: #A94B12;
  --green: #6EE07A;
  --red: #FF5F7A;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: ui-monospace, "SF Mono", "Menlo", "Consolas", "Courier New", monospace;
}

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

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

/* ---------- 背景 ---------- */
.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background:
    radial-gradient(130% 72% at 50% -12%, #1C2A52 0%, #0B1122 52%, #060A15 100%);
}

.bg-grid {
  position: absolute;
  inset: -2px;
  background-image:
    linear-gradient(rgba(128, 152, 224, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(128, 152, 224, 0.055) 1px, transparent 1px);
  background-size: 30px 30px;
  mask-image: radial-gradient(90% 70% at 50% 40%, #000 10%, transparent 88%);
  -webkit-mask-image: radial-gradient(90% 70% at 50% 40%, #000 10%, transparent 88%);
}

.bg-glow {
  position: absolute;
  display: block;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.42;
  pointer-events: none;
}

.bg-glow-a {
  width: 300px;
  height: 300px;
  left: -120px;
  top: 8%;
  background: #FF8A3D;
  opacity: 0.2;
}

.bg-glow-b {
  width: 320px;
  height: 320px;
  right: -140px;
  bottom: 4%;
  background: #5B6CFF;
  opacity: 0.24;
}

.bg-stars { position: absolute; inset: 0; }

.bg-stars i {
  position: absolute;
  display: block;
  width: 3px;
  height: 3px;
  background: #CFD9FF;
  opacity: 0.22;
  animation: twinkle 3.6s ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.1; transform: scale(0.8); }
  50% { opacity: 0.5; transform: scale(1); }
}

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

/* ---------- 顶部状态 ---------- */
.hud {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) 78px;
  gap: 8px;
  flex: 0 0 auto;
}

.hud-card {
  position: relative;
  padding: 7px 9px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #1C2647 0%, #121831 100%);
  box-shadow:
    0 4px 0 #04070E,
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.hud-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 10%;
  width: 80%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.22), transparent);
}

.hud-label {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--muted);
  line-height: 1.2;
}

.hud-level {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  border-color: #60401F;
  background: linear-gradient(180deg, #37230F 0%, #1D150C 100%);
}

.hud-level::after {
  background: linear-gradient(90deg, transparent, rgba(255, 170, 90, 0.55), transparent);
}

.hud-level .hud-label { color: #D8A36E; }

.hud-big {
  display: flex;
  align-items: baseline;
  gap: 2px;
  line-height: 1;
}

.hud-big b {
  font-family: var(--mono);
  font-size: 25px;
  font-weight: 900;
  color: var(--accent-hi);
  text-shadow: 0 2px 0 #7C3608, 0 0 14px rgba(255, 138, 61, 0.55);
}

.hud-big em {
  font-style: normal;
  font-size: 9px;
  font-weight: 700;
  color: #C79467;
}

.hud-score { display: flex; flex-direction: column; justify-content: center; }

.hud-score-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

.score-num {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
  color: #FFFFFF;
  letter-spacing: 0.01em;
  text-shadow: 0 0 14px rgba(255, 138, 61, 0.38);
  white-space: nowrap;
}

.goal-bar {
  position: relative;
  height: 9px;
  margin-top: 5px;
  border: 1px solid #283254;
  border-radius: 99px;
  background: #090E1C;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}

.goal-bar i {
  position: relative;
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #F0741F 0%, #FF8A3D 46%, #FFD08A 100%);
  box-shadow: 0 0 10px rgba(255, 138, 61, 0.8);
  transition: width 0.3s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.goal-bar i::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 4px;
  right: 4px;
  height: 2px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.32);
}

.goal-line {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  margin-top: 4px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--muted);
  white-space: nowrap;
}

.goal-line b {
  font-family: var(--mono);
  color: var(--accent-hi);
  font-weight: 800;
}

.goal-line #goalProgress {
  color: #C7D1F6;
  font-weight: 700;
}

.goal-line #goalProgress b { color: var(--accent-hi); }

.hud-best {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}

.best-num {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
  color: #DCE2FF;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- 场地 ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}

.board-shell {
  position: relative;
  flex: 0 0 auto;
  border: 2px solid var(--line-hi);
  border-radius: 13px;
  background: #0A1021;
  box-shadow:
    0 6px 0 #04070E,
    0 0 0 3px #0B1224,
    0 0 34px rgba(255, 138, 61, 0.12);
  overflow: hidden;
  touch-action: none;
  isolation: isolate;
}

.board-shell.shaking { animation: board-shake 0.22s steps(2, end) 1; }

@keyframes board-shake {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-3px, 2px); }
  50% { transform: translate(2px, -2px); }
  75% { transform: translate(-2px, -1px); }
  100% { transform: translate(0, 0); }
}

#board {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.board-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.045) 0,
    rgba(255, 255, 255, 0.045) 1px,
    transparent 1px,
    transparent 3px
  );
  opacity: 0.26;
}

/* 侧栏 */
.side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 84px;
  flex: 0 0 auto;
}

.panel {
  border: 2px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #19213D 0%, #111730 100%);
  box-shadow:
    0 4px 0 #04070E,
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
  padding: 6px;
}

.panel-title {
  margin-bottom: 5px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--muted);
  text-align: center;
}

.next-box {
  padding: 3px;
  border: 1px solid #293254;
  border-radius: 8px;
  background: #090E1D;
  box-shadow: inset 0 2px 7px rgba(0, 0, 0, 0.6);
}

#next {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
}

.stat-panel {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px;
}

.stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px;
  font-size: 9.5px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.stat span { white-space: nowrap; }

.stat b {
  font-family: var(--mono);
  font-size: 13.5px;
  letter-spacing: -0.02em;
  font-weight: 900;
  color: var(--text);
}

/* ---------- 操作 ---------- */
.controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
  flex: 0 0 auto;
  padding-top: 2px;
}

.ctrl {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 70px;
  border: 2px solid #394671;
  border-radius: 14px;
  background: linear-gradient(180deg, #242F55 0%, #161D38 100%);
  box-shadow:
    0 5px 0 #04070E,
    inset 0 2px 0 rgba(255, 255, 255, 0.09);
  color: var(--text);
  touch-action: none;
  transition: transform 0.06s ease, box-shadow 0.06s ease, filter 0.12s ease;
}

.ctrl .mp-icon {
  width: 27px;
  height: 27px;
  color: #EDF0FF;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.42));
}

.ctrl span {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.ctrl.is-down {
  transform: translateY(3px);
  box-shadow:
    0 2px 0 #04070E,
    inset 0 2px 0 rgba(255, 255, 255, 0.04);
  filter: brightness(1.14);
}

.ctrl-rotate {
  border-color: #FFC08A;
  background: linear-gradient(180deg, #FFA45F 0%, #EF701C 100%);
  box-shadow:
    0 5px 0 #8A3A0C,
    inset 0 2px 0 rgba(255, 255, 255, 0.38);
}

.ctrl-rotate .mp-icon { color: #341404; }

.ctrl-rotate span { color: #5E2B08; }

.ctrl-rotate.is-down {
  transform: translateY(3px);
  box-shadow:
    0 2px 0 #8A3A0C,
    inset 0 2px 0 rgba(255, 255, 255, 0.2);
}

.tips {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  flex: 0 0 auto;
  margin: 0;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--dim);
  white-space: nowrap;
}

.tips .brand {
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.18em;
  color: #C98A56;
}

.tip-dot {
  width: 2px;
  height: 2px;
  background: #4B5478;
}

/* ---------- 分数浮字 ---------- */
.float-score {
  position: absolute;
  left: 50%;
  top: 36%;
  z-index: 3;
  transform: translate(-50%, 0);
  pointer-events: none;
  font-family: var(--mono);
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 0.02em;
  color: #FFDCAE;
  text-shadow:
    0 3px 0 #8A3A0C,
    0 0 20px rgba(255, 138, 61, 0.85);
  opacity: 0;
  white-space: nowrap;
}

.float-score.run { animation: float-up 0.9s cubic-bezier(0.2, 0.7, 0.3, 1) forwards; }

.float-score.level {
  font-size: 22px;
  color: #FFFFFF;
  letter-spacing: 0.14em;
  text-shadow: 0 3px 0 #8A3A0C, 0 0 18px rgba(255, 138, 61, 0.8);
}

@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, 12px) scale(0.7); }
  18% { opacity: 1; transform: translate(-50%, 0) scale(1.12); }
  62% { opacity: 1; transform: translate(-50%, -8px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -46px) scale(0.98); }
}

/* ---------- 遮罩 / 结算 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 14px;
  background: rgba(5, 9, 19, 0.78);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  opacity: 0;
  pointer-events: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  transition: opacity 0.22s ease;
}

.overlay.show { opacity: 1; pointer-events: auto; }

.overlay-inner {
  width: 100%;
  max-width: 260px;
  margin: auto 0;
  pointer-events: none;
  text-align: center;
  transform: translateY(10px) scale(0.97);
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

.overlay.show .overlay-inner { transform: none; pointer-events: auto; }

.ov-badge {
  display: inline-block;
  margin-bottom: 9px;
  padding: 4px 10px;
  border: 1px solid rgba(255, 138, 61, 0.5);
  border-radius: 99px;
  background: rgba(255, 138, 61, 0.14);
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: #FFD9A8;
}

.ov-badge.danger {
  border-color: rgba(255, 95, 122, 0.55);
  background: rgba(255, 95, 122, 0.14);
  color: #FFC9D2;
}

.ov-title {
  margin: 0 0 6px;
  font-size: 32px;
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: 0;
  color: #FFF6EA;
  text-shadow:
    0 3px 0 #A94B12,
    0 0 22px rgba(255, 138, 61, 0.45);
}

.ov-title.small { font-size: 25px; }

.ov-sub {
  margin: 0 0 13px;
  font-size: 11px;
  line-height: 1.55;
  color: var(--muted);
}

.ov-sub b { color: var(--accent-hi); font-family: var(--mono); }

.ov-stats {
  display: flex;
  gap: 6px;
  margin: 0 0 10px;
}

.ov-stats > div {
  flex: 1;
  min-width: 0;
  padding: 7px 3px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.045);
}

.ov-stats span {
  display: block;
  margin-bottom: 2px;
  font-size: 8px;
  color: var(--muted);
}

.ov-stats b {
  display: block;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 900;
  color: #FFFFFF;
  white-space: nowrap;
}

.ov-next-goal {
  margin: 0 0 13px;
  font-size: 10px;
  color: var(--muted);
}

.ov-next-goal b {
  font-family: var(--mono);
  color: var(--accent-hi);
}

.ov-best {
  margin: 0 0 12px;
  font-size: 10px;
  color: var(--muted);
}

.ov-best b {
  font-family: var(--mono);
  font-size: 13px;
  color: #FFE2BB;
}

.ov-best em {
  display: inline-block;
  margin-left: 5px;
  padding: 2px 6px;
  border-radius: 99px;
  background: rgba(110, 224, 122, 0.16);
  border: 1px solid rgba(110, 224, 122, 0.5);
  font-style: normal;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #9CF0A5;
}

.ov-btn {
  display: block;
  width: 100%;
  height: 48px;
  border: 2px solid #FFC08A;
  border-radius: 12px;
  background: linear-gradient(180deg, #FFA45F 0%, #EF701C 100%);
  box-shadow:
    0 4px 0 #8A3A0C,
    inset 0 2px 0 rgba(255, 255, 255, 0.38);
  color: #351404;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.08em;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
  touch-action: none;
}

.ov-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #8A3A0C;
}

.ov-btn.ghost {
  height: 42px;
  margin-top: 8px;
  border-color: #394671;
  background: linear-gradient(180deg, #242F55 0%, #161D38 100%);
  box-shadow: 0 4px 0 #04070E;
  color: var(--text);
  font-size: 13px;
}

.ov-btn.ghost:active { box-shadow: 0 1px 0 #04070E; }

.ov-auto {
  height: 4px;
  margin-top: 11px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.ov-auto i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #F0741F, #FFD08A);
  transform-origin: left center;
  animation: auto-bar 2.2s linear forwards;
}

@keyframes auto-bar {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

/* ---------- 短屏适配 ---------- */
@media (max-height: 720px) {
  .app {
    gap: 8px;
    padding-top: calc(env(safe-area-inset-top, 0px) + 8px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  }

  .hud-card { padding: 5px 8px; }
  .hud-big b { font-size: 22px; }
  .score-num { font-size: 20px; }
  .goal-line { margin-top: 3px; }
  .ctrl { height: 60px; border-radius: 12px; }
  .ctrl .mp-icon { width: 23px; height: 23px; }
  .side { width: 76px; gap: 7px; }
  .panel { padding: 5px; }
  .stat-panel { padding: 7px; }
  .tips { font-size: 9px; }
  .ov-title { font-size: 28px; }
}

@media (max-width: 350px) {
  .app { padding-left: 12px; padding-right: 12px; gap: 8px; }
  .hud { grid-template-columns: 64px minmax(0, 1fr) 70px; gap: 6px; }
  .controls { gap: 6px; }
  .side { width: 70px; }
  .stat-panel { padding: 6px; }
  .stat { font-size: 9px; }
  .stat b { font-size: 12.5px; }
  .ctrl span { font-size: 8px; }
}

@media (min-width: 700px) and (min-height: 760px) {
  .app { max-width: 430px; }
  .board-shell { box-shadow: 0 8px 0 #04070E, 0 0 0 3px #0B1224, 0 0 60px rgba(255, 138, 61, 0.16); }
}

@media (prefers-reduced-motion: reduce) {
  .bg-stars i { animation: none; }
  .board-shell.shaking { animation: none; }
  .float-score.run { animation-duration: 0.4s; }
  .overlay, .overlay-inner, .goal-bar i { transition: none; }
}
