:root {
  --orange: #FF8A3D;
  --orange-deep: #E96F1E;
  --orange-soft: #FFE3CB;
  --ink: #3C2A21;
  --ink-soft: #6F5647;
  --muted: #9B806D;
  --cream: #FFF8EF;
  --cream-deep: #FFF0DE;
  --mint: #4FC79A;
  --mint-soft: #DDF6EC;
  --yellow: #FFC94D;
  --plum: #2D2042;
  --card-shadow: 0 8px 20px rgba(176, 104, 54, 0.13);
  --card-border: 1px solid rgba(255, 255, 255, 0.92);
}

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

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

body {
  position: relative;
  overflow: hidden;
  color: var(--ink);
  background: #FFF3E3;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 12% 4%, #FFE0BF 0, rgba(255, 224, 191, 0) 42%),
    radial-gradient(circle at 92% 12%, #CFF1E6 0, rgba(207, 241, 230, 0) 38%),
    radial-gradient(circle at 82% 92%, #FFDCB5 0, rgba(255, 220, 181, 0) 46%),
    linear-gradient(180deg, #FFF9F1 0%, #FFF1DF 58%, #FFE8CF 100%);
  z-index: -2;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(rgba(255, 138, 61, 0.13) 1.4px, transparent 1.4px);
  background-size: 22px 22px;
  opacity: 0.5;
  pointer-events: none;
  z-index: -1;
}

/* ---------- background decoration ---------- */

.bg-deco {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(2px);
  opacity: 0.55;
}

.blob-a {
  width: 150px;
  height: 150px;
  left: -64px;
  top: 26%;
  background: radial-gradient(circle at 35% 30%, #FFE7C8, #FFD1A4);
}

.blob-b {
  width: 120px;
  height: 120px;
  right: -52px;
  top: 8%;
  background: radial-gradient(circle at 35% 30%, #E2FAF1, #B4E9D8);
}

.blob-c {
  width: 170px;
  height: 170px;
  right: -76px;
  bottom: -38px;
  background: radial-gradient(circle at 35% 30%, #FFEFD8, #FFD9AE);
}

.deco-block {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  opacity: 0.32;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.45);
}

.deco-1 {
  left: 18px;
  top: 21%;
  background: #FFC94D;
  transform: rotate(-16deg);
}

.deco-2 {
  right: 22px;
  top: 34%;
  background: #8FDBBE;
  transform: rotate(22deg);
}

.deco-3 {
  left: 30px;
  bottom: 24%;
  background: #FFAD7B;
  transform: rotate(12deg);
}

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

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

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 249, 241, 0.94));
  border: var(--card-border);
  box-shadow: var(--card-shadow), inset 0 1px 0 #fff;
}

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

.hud {
  flex: 0 0 auto;
  height: 68px;
  display: flex;
  align-items: stretch;
  gap: 9px;
}

.score-card {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 15px 7px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.65);
  background: linear-gradient(155deg, #FFA867 0%, #FF8937 48%, #FF7624 100%);
  box-shadow: 0 10px 22px rgba(233, 111, 30, 0.3), inset 0 2px 0 rgba(255, 255, 255, 0.38);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.score-card::after {
  content: "";
  position: absolute;
  width: 92px;
  height: 92px;
  right: -28px;
  top: -42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  pointer-events: none;
}

.score-label {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: rgba(255, 255, 255, 0.86);
}

.score-label .mp-icon {
  width: 14px;
  height: 14px;
}

.score-value {
  position: relative;
  z-index: 1;
  margin-top: 1px;
  font-size: clamp(25px, 7.4vw, 32px);
  font-weight: 900;
  line-height: 1.02;
  letter-spacing: 0.01em;
  color: #fff;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(180, 70, 10, 0.22);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.score-value.bump {
  animation: score-bump 0.34s cubic-bezier(0.2, 1.6, 0.4, 1);
}

@keyframes score-bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

.next-card {
  flex: 0 0 90px;
  width: 90px;
  border-radius: 18px;
  padding: 6px 6px 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}

.next-label {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--muted);
}

#nextCanvas {
  display: block;
  width: 62px;
  height: 34px;
}

.pause-btn {
  flex: 0 0 48px;
  width: 48px;
  padding: 0;
  border-radius: 18px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

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

.pause-btn:active {
  transform: scale(0.94);
  box-shadow: 0 2px 6px rgba(176, 104, 54, 0.12);
}

/* ---------- stats ---------- */

.stats {
  flex: 0 0 auto;
  height: 30px;
  display: flex;
  align-items: stretch;
  gap: 7px;
}

.stat {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 7px rgba(176, 104, 54, 0.07);
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
}

.stat .mp-icon {
  width: 13px;
  height: 13px;
  color: var(--orange);
  flex: 0 0 auto;
}

.stat b {
  font-size: 12.5px;
  font-weight: 900;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* ---------- board ---------- */

.play-area {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1px 0;
}

.board-shell {
  position: relative;
  flex: 0 0 auto;
  padding: 6px;
  border-radius: 24px;
  border: 2px solid rgba(255, 255, 255, 0.24);
  background: linear-gradient(160deg, #5B4374 0%, #35264D 46%, #211736 100%);
  box-shadow:
    0 20px 36px rgba(71, 38, 92, 0.32),
    0 4px 0 rgba(255, 255, 255, 0.05) inset,
    0 0 0 1px rgba(45, 32, 66, 0.25);
}

#board {
  display: block;
  border-radius: 18px;
  background: #241A36;
  touch-action: none;
  cursor: pointer;
}

.board-shell.bump {
  animation: board-bump 0.16s ease-out;
}

.board-shell.shake {
  animation: board-shake 0.26s ease-out;
}

@keyframes board-bump {
  0% { transform: translateY(0) scale(1); }
  40% { transform: translateY(3px) scale(0.995); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes board-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

.score-pop {
  position: absolute;
  left: 50%;
  top: 13%;
  z-index: 4;
  transform: translate(-50%, 0);
  font-size: 21px;
  font-weight: 900;
  color: #FFD166;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 0 rgba(30, 18, 48, 0.55), 0 0 16px rgba(255, 209, 102, 0.45);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

.score-pop.show {
  animation: score-pop 0.85s ease-out forwards;
}

@keyframes score-pop {
  0% { opacity: 0; transform: translate(-50%, 12px) scale(0.8); }
  22% { opacity: 1; transform: translate(-50%, 0) scale(1.08); }
  60% { opacity: 1; transform: translate(-50%, -10px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -34px) scale(0.96); }
}

.spark {
  position: absolute;
  z-index: 4;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  pointer-events: none;
  animation: spark-fly 0.68s ease-out forwards;
}

@keyframes spark-fly {
  0% { transform: translate(0, 0) rotate(0deg) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(190deg) scale(0.4); opacity: 0; }
}

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

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 9px;
  border-radius: 22px;
  background: rgba(28, 19, 46, 0.66);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  overflow-y: auto;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

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

.ov-card {
  width: 100%;
  max-width: 258px;
  margin: auto;
  padding: 15px 14px 13px;
  border-radius: 22px;
  border: 1px solid #FFE3C7;
  background: linear-gradient(180deg, #FFFDF9 0%, #FFF4E6 100%);
  box-shadow: 0 18px 34px rgba(20, 10, 35, 0.38), inset 0 1px 0 #fff;
  text-align: center;
  transform: translateY(10px) scale(0.96);
  transition: transform 0.28s cubic-bezier(0.2, 1.3, 0.36, 1);
}

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

.ov-card h1 {
  margin: 0;
  font-size: clamp(23px, 6.8vw, 28px);
  font-weight: 900;
  letter-spacing: 0.03em;
  color: var(--ink);
}

[hidden] {
  display: none !important;
}

.logo-art {
  position: relative;
  width: 72px;
  height: 48px;
  margin: 0 auto 7px;
  animation: logo-float 3.2s ease-in-out infinite;
}

.lb {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.35), 0 3px 6px rgba(80, 45, 20, 0.15);
}

.lb::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 4px;
  width: 7px;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.55);
}

.lb-a {
  left: 0;
  top: 25px;
  background: #FF8A3D;
}

.lb-b {
  left: 23px;
  top: 25px;
  background: #FFC94D;
}

.lb-c {
  left: 23px;
  top: 2px;
  background: #B98BFF;
}

.lb-d {
  left: 46px;
  top: 2px;
  background: #4FC79A;
}

@keyframes logo-float {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-4px) rotate(1deg); }
}

.ov-sub {
  margin: 5px 0 11px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
}

.ov-title {
  font-size: 20px;
  font-weight: 900;
  color: var(--ink);
}

.ov-badge {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.ov-big {
  margin: 2px 0 3px;
  font-size: clamp(32px, 10vw, 42px);
  font-weight: 900;
  line-height: 1;
  color: var(--orange-deep);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.8);
}

.ov-meta {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 12px;
}

.ov-meta b {
  color: var(--ink);
  font-weight: 900;
}

.ov-tip {
  margin: 9px 0 0;
  font-size: 10.5px;
  font-weight: 600;
  color: #B49A85;
}

.btn {
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.02em;
  border-radius: 15px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

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

.btn-primary {
  width: 100%;
  height: 46px;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.42);
  background: linear-gradient(180deg, #FFA45E 0%, #FF8937 55%, #FF7926 100%);
  box-shadow: 0 5px 0 #D96118, 0 9px 18px rgba(255, 121, 38, 0.3), inset 0 2px 0 rgba(255, 255, 255, 0.35);
}

.btn-primary:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #D96118, 0 3px 8px rgba(255, 121, 38, 0.22);
}

.btn-ghost {
  width: 100%;
  height: 46px;
  color: var(--ink-soft);
  background: linear-gradient(180deg, #FFFDF8, #FFF1DF);
  border: 1px solid #F0DCC4;
  box-shadow: 0 4px 0 #EBD4BA;
}

.btn-ghost:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #EBD4BA;
}

.tips {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 9px;
}

.tips span {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid #F3E1CB;
  background: #FFF8EE;
  font-size: 9.5px;
  font-weight: 700;
  color: #A88C76;
  white-space: nowrap;
}

.tips .mp-icon {
  width: 11px;
  height: 11px;
  color: #C49A78;
}

.ov-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.ov-row .btn {
  flex: 1 1 0;
  min-width: 0;
  height: 44px;
  font-size: 14px;
}

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

.controls {
  flex: 0 0 auto;
  padding: 9px 14px 10px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.92);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(255, 246, 235, 0.92));
  box-shadow: 0 12px 26px rgba(176, 104, 54, 0.14), inset 0 1px 0 #fff;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pad-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
}

.pad-btn {
  width: clamp(50px, 15vw, 60px);
  height: clamp(46px, 13.5vw, 54px);
  padding: 0;
  border-radius: 17px;
  border: 1px solid #F2DDC4;
  background: linear-gradient(180deg, #FFFDF8, #FFEFDC);
  box-shadow: 0 4px 0 #EBD1B5, 0 6px 12px rgba(176, 104, 54, 0.1), inset 0 1px 0 #fff;
  color: #7A563C;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;
  transition: transform 0.09s ease, box-shadow 0.09s ease;
}

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

.pad-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #EBD1B5, 0 2px 4px rgba(176, 104, 54, 0.1);
}

.pad-btn.rotate {
  width: clamp(54px, 16vw, 64px);
  height: clamp(54px, 16vw, 64px);
  border-radius: 50%;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: linear-gradient(180deg, #FFA55F 0%, #FF8937 55%, #FF7A26 100%);
  box-shadow: 0 5px 0 #D9621C, 0 10px 18px rgba(255, 127, 49, 0.28), inset 0 2px 0 rgba(255, 255, 255, 0.38);
}

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

.pad-btn.rotate:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #D9621C, 0 3px 8px rgba(255, 127, 49, 0.22);
}

.drop-row {
  display: flex;
  gap: 10px;
}

.drop-btn {
  flex: 1 1 0;
  height: clamp(40px, 11.5vw, 46px);
  padding: 0;
  border-radius: 15px;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.03em;
  cursor: pointer;
  touch-action: none;
  transition: transform 0.09s ease, box-shadow 0.09s ease;
}

.drop-btn .mp-icon {
  width: 20px;
  height: 20px;
}

.drop-btn.soft {
  color: #2E7D60;
  border-color: #B9E6D4;
  background: linear-gradient(180deg, #E9FBF3, #CFF1E3);
  box-shadow: 0 4px 0 #ACDCC8, inset 0 1px 0 #fff;
}

.drop-btn.soft:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #ACDCC8;
}

.drop-btn.hard {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.16);
  background: linear-gradient(180deg, #4E3C69 0%, #382A50 55%, #2C2042 100%);
  box-shadow: 0 4px 0 #1E1530, 0 8px 16px rgba(45, 32, 66, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.drop-btn.hard:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #1E1530, 0 3px 8px rgba(45, 32, 66, 0.2);
}

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

@media (max-height: 720px) {
  .app {
    gap: 7px;
    padding-top: calc(7px + env(safe-area-inset-top));
    padding-bottom: calc(7px + env(safe-area-inset-bottom));
  }

  .hud {
    height: 62px;
  }

  .stats {
    height: 27px;
  }

  .stat {
    font-size: 10.5px;
  }

  .stat b {
    font-size: 12px;
  }

  .controls {
    padding: 7px 12px 8px;
    gap: 6px;
  }

  .pad-btn {
    height: clamp(42px, 12vw, 48px);
  }

  .pad-btn.rotate {
    width: clamp(50px, 15vw, 58px);
    height: clamp(50px, 15vw, 58px);
  }

  .drop-btn {
    height: 39px;
  }
}

@media (max-height: 610px) {
  .stats {
    display: none;
  }

  .hud {
    height: 56px;
  }

  .controls {
    padding: 6px 10px 7px;
  }

  .pad-row {
    padding: 0 6px;
  }

  .drop-btn {
    height: 36px;
    font-size: 13px;
  }

  .pad-btn {
    height: 40px;
  }

  .pad-btn.rotate {
    width: 46px;
    height: 46px;
  }
}

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