/* ============================================================
   俄罗斯方块 · 卡通糖果风
   主色 #FF8A3D / 奶油底 / 深紫棋盘
   ============================================================ */

:root {
  --orange: #FF8A3D;
  --orange-deep: #E56F24;
  --orange-dark: #C85F1D;
  --orange-soft: #FFB273;
  --cream: #FFFDF8;
  --cream-2: #FFF3E3;
  --ink: #4A2C1A;
  --muted: #8F5F3B;
  --line: #F1D2AC;
  --board: #2A2344;
  --board-deep: #241D3C;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #FFE6C7;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

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

/* ---------------- 背景 ---------------- */

.scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% -10%, #FFF7E8 0%, #FFE9CC 38%, #FFDCB4 72%, #FFD2A2 100%);
}

.sun {
  position: absolute;
  top: -72px;
  right: -42px;
  width: 196px;
  height: 196px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #FFE79A 0%, #FFD275 52%, #FFB44F 72%, rgba(255, 180, 79, 0) 73%);
  opacity: .9;
}

.sun::after {
  content: "";
  position: absolute;
  inset: -34px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 204, 104, .26) 0%, rgba(255, 204, 104, 0) 68%);
}

.cloud {
  position: absolute;
  width: 58px;
  height: 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .82);
  filter: blur(.2px);
  box-shadow: 0 8px 18px rgba(255, 159, 82, .10);
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  background: inherit;
  border-radius: 50%;
}

.cloud::before {
  width: 30px;
  height: 30px;
  left: 9px;
  top: -15px;
}

.cloud::after {
  width: 20px;
  height: 20px;
  right: 7px;
  top: -10px;
}

.cloud-a { top: 13%; left: -26px; transform: scale(.9); animation: drift 15s ease-in-out infinite; }
.cloud-b { top: 26%; right: -34px; transform: scale(1.18); opacity: .72; animation: drift 19s ease-in-out infinite reverse; }
.cloud-c { top: 47%; left: -40px; transform: scale(.72); opacity: .55; animation: drift 23s ease-in-out infinite; }

@keyframes drift {
  0%, 100% { margin-left: 0; }
  50% { margin-left: 24px; }
}

.hill {
  position: absolute;
  bottom: -108px;
  border-radius: 50%;
  opacity: .62;
}

.hill-a {
  left: -34%;
  width: 112%;
  height: 246px;
  background: linear-gradient(180deg, #FFC98F, #FFB572);
}

.hill-b {
  right: -42%;
  bottom: -128px;
  width: 100%;
  height: 230px;
  background: linear-gradient(180deg, #FFBE7D, #FFA95F);
  opacity: .45;
}

.tet {
  position: absolute;
  width: 17px;
  height: 17px;
  border-radius: 5px;
  background: currentColor;
  color: rgba(255, 138, 61, .22);
  opacity: .8;
}

.tet::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: currentColor;
  box-shadow:
    20px 0 0 currentColor,
    40px 0 0 currentColor,
    20px -20px 0 currentColor;
}

.tet-a { top: 17%; left: -14px; transform: rotate(-14deg); }
.tet-b {
  right: -22px;
  bottom: 22%;
  transform: rotate(18deg) scale(.9);
  color: rgba(255, 255, 255, .35);
}

.spark {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #FFF4D6;
  box-shadow: 0 0 12px rgba(255, 244, 214, .9);
  opacity: .75;
}

.spark-a { top: 33%; left: 9%; }
.spark-b { top: 21%; right: 13%; width: 5px; height: 5px; }
.spark-c { top: 58%; right: 7%; width: 6px; height: 6px; }

/* ---------------- 页面骨架 ---------------- */

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

/* ---------------- 顶部数据条 ---------------- */

.hud {
  display: grid;
  grid-template-columns: 1.32fr .78fr 1.12fr;
  gap: 8px;
  flex: none;
}

.hud-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  height: 64px;
  padding: 7px 10px 8px;
  border: 2px solid var(--line);
  border-radius: 17px;
  background: linear-gradient(180deg, #FFFDF9 0%, #FFF5E7 100%);
  box-shadow:
    0 3px 0 #EBC79B,
    0 8px 16px rgba(186, 105, 40, .10);
}

.hud-label {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  line-height: 1;
  white-space: nowrap;
}

.hud-label .mp-icon {
  width: 13px;
  height: 13px;
}

.hud-value {
  color: var(--ink);
  font-size: 21px;
  font-weight: 900;
  letter-spacing: .01em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.hud-score {
  border-color: #FFB77C;
  background: linear-gradient(160deg, #FFA75F 0%, #FF8A3D 58%, #F87B30 100%);
  box-shadow:
    0 3px 0 var(--orange-dark),
    0 9px 18px rgba(226, 111, 41, .28);
}

.hud-score::after {
  content: "";
  position: absolute;
  top: 5px;
  left: 9px;
  right: 9px;
  height: 42%;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .22), rgba(255, 255, 255, 0));
  pointer-events: none;
}

.hud-score .hud-label { color: rgba(255, 255, 255, .9); }
.hud-score .hud-value {
  color: #FFFDF8;
  text-shadow: 0 2px 0 rgba(185, 76, 9, .28);
}

.hud-level {
  padding-left: 8px;
  padding-right: 8px;
  border-color: #FFD98C;
  background: linear-gradient(180deg, #FFF9E3 0%, #FFEDBC 100%);
  box-shadow:
    0 3px 0 #E8BE6E,
    0 8px 16px rgba(186, 130, 40, .10);
}

.level-row {
  display: flex;
  align-items: baseline;
  gap: 3px;
  min-width: 0;
}

.hud-level .hud-value {
  color: #A6600B;
  font-size: 22px;
}

.hud-lines {
  display: inline-block;
  color: #A6600B;
  font-size: 9px;
  font-weight: 800;
  opacity: .8;
  white-space: nowrap;
}

.hud-lines b {
  font-size: 11px;
  font-weight: 900;
}

.hud-best .hud-value { font-size: 18px; }

/* ---------------- 棋盘中场 ---------------- */

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

.board-shell {
  position: relative;
  flex: none;
  padding: 6px;
  border-radius: 21px;
  background: linear-gradient(180deg, #FFB273 0%, #FF8A3D 46%, #F97B2D 100%);
  box-shadow:
    0 7px 0 var(--orange-dark),
    0 17px 28px rgba(171, 82, 20, .28),
    inset 0 1px 0 rgba(255, 255, 255, .42);
  opacity: 0;
  transition: opacity .2s ease;
}

.board-shell.ready { opacity: 1; }

.board-shell::after {
  content: "";
  position: absolute;
  top: 6px;
  left: 6px;
  right: 6px;
  height: 26px;
  border-radius: 14px 14px 8px 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .20), rgba(255, 255, 255, 0));
  pointer-events: none;
  z-index: 2;
}

#board {
  display: block;
  width: 220px;
  height: 440px;
  border-radius: 14px;
  background: var(--board);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, .07),
    inset 0 14px 24px rgba(0, 0, 0, .20);
  touch-action: none;
}

.board-shell.shake { animation: boardShake .18s ease-in-out; }

@keyframes boardShake {
  0%, 100% { transform: translate3d(0, 0, 0); }
  25% { transform: translate3d(-2px, 1px, 0); }
  50% { transform: translate3d(2px, -1px, 0); }
  75% { transform: translate3d(-1px, 1px, 0); }
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 13px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: calc(100% - 24px);
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(29, 21, 45, .64);
  color: rgba(255, 255, 255, .92);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .02em;
  line-height: 1;
  white-space: nowrap;
  transform: translateX(-50%);
  opacity: 1;
  transition: opacity .45s ease;
  pointer-events: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.hint .mp-icon { width: 13px; height: 13px; }
.hint.hide { opacity: 0; }

.toast {
  position: absolute;
  top: 36%;
  left: 50%;
  z-index: 4;
  padding: 9px 16px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, .45);
  background: linear-gradient(180deg, #FFB273, #FF8A3D);
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: .02em;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, -50%) scale(.7);
  box-shadow: 0 5px 0 rgba(180, 76, 10, .45), 0 12px 24px rgba(70, 30, 0, .25);
  pointer-events: none;
}

.toast.show { animation: toastPop .95s cubic-bezier(.2, .8, .3, 1) both; }

@keyframes toastPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.55); }
  16% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  30% { transform: translate(-50%, -50%) scale(1); }
  72% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -118%) scale(.98); }
}

/* ---------------- 右侧信息 ---------------- */

.side {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 10px;
  align-self: center;
  width: clamp(68px, 20vw, 86px);
}

.next-card,
.progress-card {
  padding: 7px 5px 8px;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #FFFDF9, #FFF4E5);
  text-align: center;
  box-shadow:
    0 3px 0 #EBC79B,
    0 9px 16px rgba(186, 105, 40, .10);
}

.side-label {
  display: block;
  color: #9A6238;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .16em;
  line-height: 1;
}

#next {
  display: block;
  width: 100%;
  height: 58px;
  margin-top: 2px;
}

.progress-card { padding-top: 8px; padding-bottom: 9px; }

.progress-track {
  height: 7px;
  margin: 7px 3px 0;
  overflow: hidden;
  border-radius: 999px;
  background: #F2E3D0;
  box-shadow: inset 0 1px 2px rgba(150, 100, 60, .16);
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #FFC46B, #FF8A3D);
  box-shadow: 0 0 6px rgba(255, 138, 61, .55);
  transition: width .3s ease;
}

.progress-text {
  display: block;
  margin-top: 5px;
  color: #8B5B38;
  font-size: 9px;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
}

/* ---------------- 底部操作 ---------------- */

.dock {
  flex: none;
  padding: 9px 9px 10px;
  border: 2px solid #F2D2AB;
  border-radius: 22px;
  background: linear-gradient(180deg, #FFFDF9 0%, #FFF0DD 100%);
  box-shadow:
    0 4px 0 #E5BE92,
    0 12px 22px rgba(180, 100, 40, .12);
}

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

.pad-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 62px;
  padding: 0;
  border: 0;
  border-radius: 15px;
  background: linear-gradient(180deg, #FFFDFA 0%, #FFEBD5 100%);
  color: #98582A;
  box-shadow:
    inset 0 0 0 2px #F0C99F,
    0 4px 0 #DFAE7E;
  cursor: pointer;
  touch-action: none;
  transition: transform .06s ease, box-shadow .06s ease, filter .06s ease;
}

.pad-btn .mp-icon {
  width: 25px;
  height: 25px;
}

.pad-text {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .03em;
  line-height: 1;
}

.pad-rotate {
  background: linear-gradient(180deg, #FFE59A 0%, #FFC94F 100%);
  color: #7C4C00;
  box-shadow:
    inset 0 0 0 2px #FFD166,
    0 4px 0 #D89B20;
}

.pad-drop {
  background: linear-gradient(180deg, #FFA965 0%, #FF7F30 100%);
  color: #FFFDF8;
  box-shadow:
    inset 0 0 0 2px #FFB77C,
    0 4px 0 var(--orange-dark);
}

.pad-drop .mp-icon { filter: drop-shadow(0 1px 0 rgba(160, 66, 5, .35)); }

.pad-btn.is-down,
.pad-btn:active {
  transform: translateY(3px);
  box-shadow:
    inset 0 0 0 2px #F0C99F,
    0 1px 0 #DFAE7E;
  filter: brightness(.995);
}

.pad-rotate.is-down,
.pad-rotate:active {
  box-shadow:
    inset 0 0 0 2px #FFD166,
    0 1px 0 #D89B20;
}

.pad-drop.is-down,
.pad-drop:active {
  box-shadow:
    inset 0 0 0 2px #FFB77C,
    0 1px 0 var(--orange-dark);
}

/* ---------------- 结束 / 暂停浮层 ---------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(48, 29, 59, .56);
  opacity: 0;
  visibility: hidden;
  transition: opacity .22s ease, visibility .22s ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.overlay.show {
  opacity: 1;
  visibility: visible;
}

.pause-overlay { z-index: 25; }

.overlay-card {
  position: relative;
  width: 100%;
  max-width: 332px;
  padding: 26px 20px 20px;
  border: 3px solid #FFDBB6;
  border-radius: 28px;
  background: linear-gradient(180deg, #FFFDF9 0%, #FFF2E1 100%);
  text-align: center;
  box-shadow:
    0 10px 0 #DCAE80,
    0 32px 60px rgba(45, 20, 0, .34);
  transform: translateY(14px) scale(.96);
  transition: transform .26s cubic-bezier(.2, .9, .3, 1.2);
}

.overlay.show .overlay-card { transform: translateY(0) scale(1); }

.overlay-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  margin: -52px auto 10px;
  border: 3px solid #FFF3D6;
  border-radius: 50%;
  background: linear-gradient(180deg, #FFC95A, #FF8A3D);
  color: #FFFDF8;
  box-shadow:
    0 5px 0 #C85F1D,
    0 10px 20px rgba(150, 70, 10, .3);
}

.overlay-badge .mp-icon { width: 28px; height: 28px; }
.pause-badge { background: linear-gradient(180deg, #9D8BE8, #6F5BD6); box-shadow: 0 5px 0 #4A38A8, 0 10px 20px rgba(60, 40, 150, .3); }

.record-badge {
  display: none;
  width: fit-content;
  margin: 0 auto 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #FFE08A, #FFC94F);
  color: #8A5300;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .12em;
  box-shadow: 0 2px 0 #D89B20;
}

.record-badge.show { display: block; }

.overlay-card h2 {
  margin: 0;
  color: var(--ink);
  font-size: 24px;
  font-weight: 900;
  letter-spacing: .02em;
}

.overlay-sub {
  margin: 6px 0 16px;
  color: #8F5F3B;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.final-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-bottom: 18px;
}

.final-item {
  padding: 10px 4px 9px;
  border: 2px solid #F3D9B9;
  border-radius: 14px;
  background: #FFFCF7;
  box-shadow: inset 0 -2px 0 rgba(224, 185, 140, .24);
}

.final-item span {
  display: block;
  margin-bottom: 4px;
  color: #8F5F3B;
  font-size: 9px;
  font-weight: 700;
  white-space: nowrap;
}

.final-item strong {
  display: block;
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.final-item:first-child strong { color: var(--orange-deep); }

.restart-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  height: 54px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, #FFA75F 0%, #FF8A3D 56%, #F87B30 100%);
  color: #FFFDF8;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: .06em;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .32),
    0 5px 0 var(--orange-dark),
    0 12px 20px rgba(220, 100, 25, .3);
  cursor: pointer;
  transition: transform .07s ease, box-shadow .07s ease;
}

.restart-btn .mp-icon { width: 21px; height: 21px; }

.restart-btn:active {
  transform: translateY(4px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, .24),
    0 1px 0 var(--orange-dark);
}

.pause-card { max-width: 300px; }

/* ---------------- 矮屏 / 窄屏适配 ---------------- */

@media (max-height: 700px) {
  .game { gap: 8px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .hud-card { height: 56px; padding: 5px 8px 6px; border-radius: 15px; }
  .hud-value { font-size: 18px; }
  .hud-level .hud-value { font-size: 19px; }
  .hud-best .hud-value { font-size: 16px; }
  .hud-label { font-size: 9px; }
  .side { gap: 8px; }
  .next-card, .progress-card { padding: 5px 4px 6px; }
  #next { height: 46px; }
  .dock { padding: 7px 7px 8px; border-radius: 19px; }
  .pad-row { gap: 6px; }
  .pad-btn { height: 54px; border-radius: 13px; }
  .pad-btn .mp-icon { width: 22px; height: 22px; }
  .pad-text { font-size: 9px; }
  .hint { bottom: 10px; font-size: 8px; padding: 5px 8px; }
}

@media (max-width: 349px) {
  .game { padding-left: 12px; padding-right: 12px; }
  .hud { gap: 6px; }
  .hud-card { padding-left: 7px; padding-right: 7px; }
  .hud-value { font-size: 17px; }
  .hud-best .hud-value { font-size: 15px; }
  .pad-row { gap: 5px; }
  .pad-text { display: none; }
  .side { width: 66px; }
  .hint span { font-size: 8px; }
}

@media (min-height: 900px) {
  .game { gap: 12px; padding-top: calc(14px + env(safe-area-inset-top)); }
  .hud-card { height: 70px; }
  .hud-value { font-size: 23px; }
  .pad-btn { height: 68px; }
  #next { height: 68px; }
}

/* 动效减弱偏好 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* 得分跳动 */
.hud-score.score-bump {
  animation: scoreBump .4s cubic-bezier(.2, .9, .3, 1.4);
}

@keyframes scoreBump {
  0% { transform: scale(1); }
  32% { transform: scale(1.055) rotate(-.5deg); }
  68% { transform: scale(.995) rotate(.2deg); }
  100% { transform: scale(1); }
}
