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

:root {
  --orange: #FF8A3D;
  --orange-deep: #E8691D;
  --orange-soft: #FFB067;
  --orange-pale: #FFE2C3;
  --ink: #412B1D;
  --ink-soft: #6E523D;
  --muted: #9A806A;
  --cream: #FFFBF3;
  --cream-deep: #FFF3DF;
  --mint: #8FD5B0;
  --mint-deep: #4E9E7C;
  --mint-pale: #DFF5E9;
  --red: #EF5B45;
  --frame-a: #FFD9A9;
  --frame-b: #F0B474;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(255, 182, 112, 0.28) 0%, rgba(255, 182, 112, 0) 55%),
    linear-gradient(180deg, #DDF3E7 0%, #EDF8EE 36%, #FFF2DE 100%);
  color: var(--ink);
  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;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  box-shadow: inset 0 0 90px rgba(126, 80, 34, 0.07);
}

/* ---------- background scenery ---------- */
.bg-decor {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.sun-glow {
  position: absolute;
  top: -150px;
  right: -110px;
  width: 360px;
  height: 360px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 190, 116, 0.55) 0%, rgba(255, 195, 128, 0.18) 45%, rgba(255, 200, 140, 0) 70%);
}

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

.blob-a {
  left: -110px;
  top: 22%;
  width: 260px;
  height: 260px;
  background: radial-gradient(circle at 60% 40%, rgba(153, 219, 183, 0.55), rgba(153, 219, 183, 0) 68%);
}

.blob-b {
  right: -130px;
  bottom: -40px;
  width: 320px;
  height: 320px;
  background: radial-gradient(circle at 40% 40%, rgba(255, 181, 108, 0.4), rgba(255, 181, 108, 0) 70%);
}

.dot-grid {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(116, 158, 130, 0.22) 1.3px, transparent 1.3px);
  background-size: 26px 26px;
  -webkit-mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.8), transparent 68%);
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.8), transparent 68%);
  opacity: 0.55;
}

.deco-leaf {
  position: absolute;
  width: 76px;
  height: 76px;
  opacity: 0.9;
  animation: leafFloat 7s ease-in-out infinite;
}

.deco-leaf svg {
  display: block;
  width: 100%;
  height: 100%;
}

.leaf-a {
  left: -18px;
  bottom: 12%;
  transform: rotate(-18deg);
}

.leaf-b {
  right: -22px;
  top: 15%;
  width: 64px;
  height: 64px;
  transform: rotate(22deg);
  animation-delay: -2.6s;
  opacity: 0.7;
}

.deco-spark {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #F7BF7B;
  clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%);
  opacity: 0.8;
  animation: sparkle 3.6s ease-in-out infinite;
}

.spark-a {
  left: 9%;
  top: 14%;
}

.spark-b {
  right: 12%;
  top: 42%;
  width: 7px;
  height: 7px;
  animation-delay: -1.4s;
  background: #93D6B1;
}

.spark-c {
  left: 16%;
  bottom: 24%;
  width: 6px;
  height: 6px;
  animation-delay: -2.4s;
}

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

/* ---------- HUD ---------- */
.hud {
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.hud-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: 9px 13px;
  border-radius: 20px;
  background: rgba(255, 251, 243, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.92);
  box-shadow:
    0 10px 22px -12px rgba(126, 79, 31, 0.34),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.score-card {
  flex: 1.35;
}

.best-card {
  flex: 0.9;
  background: rgba(255, 251, 243, 0.64);
}

.hud-orb,
.best-orb {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #FFFDF8;
  background: linear-gradient(155deg, #FFB168 0%, #FF8A3D 55%, #F06F24 100%);
  box-shadow:
    0 4px 0 rgba(210, 94, 26, 0.35),
    0 7px 12px -5px rgba(226, 102, 30, 0.58),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.best-orb {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  color: #8C6A2C;
  background: linear-gradient(155deg, #FFF4C8, #FFE39A);
  box-shadow:
    0 3px 0 rgba(196, 154, 66, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

.hud-orb .mp-icon {
  width: 21px;
  height: 21px;
}

.best-orb .mp-icon {
  width: 17px;
  height: 17px;
}

.hud-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  line-height: 1;
}

.hud-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.hud-value {
  margin-top: 3px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  transform-origin: left center;
}

.hud-value-sm {
  font-size: 20px;
  color: #7A5B36;
}

.hud-value.is-bump {
  animation: scoreBump 0.34s cubic-bezier(0.2, 0.9, 0.3, 1.35);
}

/* ---------- game stage ---------- */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-frame {
  position: relative;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 12 / 20;
  max-height: 100%;
  padding: 6px;
  border-radius: 31px;
  touch-action: none;
  background: linear-gradient(150deg, var(--frame-a) 0%, #F8C58B 45%, var(--frame-b) 100%);
  box-shadow:
    0 26px 42px -18px rgba(143, 72, 21, 0.55),
    0 10px 0 -3px rgba(196, 112, 45, 0.30),
    inset 0 2px 0 rgba(255, 255, 255, 0.75),
    inset 0 -2px 0 rgba(172, 94, 33, 0.22);
  will-change: transform;
}

.board-frame.shake {
  animation: boardShake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 25px;
  background: #FFF7E6;
  touch-action: none;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.6),
    inset 0 12px 28px rgba(199, 140, 64, 0.12);
}

.board-gloss {
  position: absolute;
  inset: 6px;
  z-index: 2;
  border-radius: 25px;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.4) 0%,
    rgba(255, 255, 255, 0.06) 15%,
    rgba(255, 255, 255, 0) 48%,
    rgba(151, 91, 32, 0.05) 100%
  );
}

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 6px;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border-radius: 25px;
  background: rgba(66, 41, 22, 0.24);
  -webkit-backdrop-filter: blur(4px) saturate(1.05);
  backdrop-filter: blur(4px) saturate(1.05);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.22s ease, visibility 0.22s ease;
  touch-action: none;
}

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

.start-card {
  width: min(88%, 306px);
  padding: 0 18px 16px;
  border-radius: 28px;
  text-align: center;
  background: linear-gradient(180deg, #FFFDF8 0%, #FFF5E6 100%);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow:
    0 26px 46px -18px rgba(75, 40, 12, 0.62),
    0 0 0 5px rgba(255, 255, 255, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.95);
  transform-origin: 50% 70%;
}

.start-overlay {
  background: rgba(66, 41, 22, 0.18);
  -webkit-backdrop-filter: blur(2.5px) saturate(1.04);
  backdrop-filter: blur(2.5px) saturate(1.04);
}

.start-overlay.is-show .start-card {
  animation: cardIn 0.46s cubic-bezier(0.2, 0.9, 0.28, 1.24) both;
}

.mascot {
  width: 92px;
  height: 92px;
  margin: -40px auto 1px;
  filter: drop-shadow(0 10px 12px rgba(160, 82, 24, 0.26));
  animation: mascotBob 3.4s ease-in-out infinite;
}

.mascot svg {
  display: block;
  width: 100%;
  height: 100%;
}

.game-title {
  margin: 4px 0 0;
  font-size: 25px;
  line-height: 1.2;
  font-weight: 900;
  letter-spacing: 0.02em;
  color: #4A301F;
}

.game-sub {
  margin: 6px 0 14px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
  font-weight: 500;
}

.btn {
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 16px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #FFFDF8;
  cursor: pointer;
  background: linear-gradient(180deg, #FFA45C 0%, #FF8A3D 48%, #F27625 100%);
  box-shadow:
    0 5px 0 #D65F19,
    0 12px 20px -8px rgba(231, 105, 29, 0.62),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.1s ease;
  touch-action: manipulation;
}

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

.btn:active {
  transform: translateY(4px);
  filter: saturate(1.06);
  box-shadow:
    0 1px 0 #D65F19,
    0 5px 10px -6px rgba(231, 105, 29, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.btn:focus-visible {
  outline: 3px solid rgba(62, 139, 102, 0.55);
  outline-offset: 3px;
}

.gesture-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin: 12px 0 0;
  font-size: 11px;
  font-weight: 600;
  color: #B08E70;
}

.gesture-line .mp-icon {
  width: 15px;
  height: 15px;
  color: #D99A62;
}

/* game over */
.over-overlay {
  background: rgba(58, 34, 17, 0.34);
}

.over-card {
  width: min(86%, 286px);
  padding: 20px 20px 18px;
  border-radius: 28px;
  text-align: center;
  background: linear-gradient(180deg, #FFFDF8 0%, #FFF4E3 100%);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow:
    0 28px 48px -18px rgba(65, 33, 9, 0.66),
    0 0 0 5px rgba(255, 255, 255, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.95);
  transform-origin: 50% 70%;
}

.over-overlay.is-show .over-card {
  animation: cardIn 0.42s cubic-bezier(0.2, 0.9, 0.28, 1.24) both;
}

.over-badge {
  width: 52px;
  height: 52px;
  margin: 0 auto 8px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: #E8682F;
  background: linear-gradient(160deg, #FFE9CD, #FFD9AE);
  box-shadow:
    0 5px 0 rgba(209, 137, 76, 0.26),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.over-badge .mp-icon {
  width: 28px;
  height: 28px;
}

.over-title {
  margin: 0;
  font-size: 23px;
  font-weight: 900;
  letter-spacing: 0.03em;
  color: #4A301F;
}

.over-reason {
  margin: 4px 0 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.final-score-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 9px;
  padding: 11px 10px 9px;
  border-radius: 17px;
  background: rgba(255, 235, 208, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.7);
}

.final-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #9B7754;
}

.final-value {
  font-size: 40px;
  line-height: 0.9;
  font-weight: 900;
  letter-spacing: -0.04em;
  color: var(--orange-deep);
  font-variant-numeric: tabular-nums;
}

.best-line {
  margin: 9px 0 15px;
  font-size: 11.5px;
  font-weight: 600;
  color: #A98B6E;
}

.best-line.is-record {
  color: #D96A1F;
  font-weight: 800;
  animation: recordPulse 1.2s ease-in-out 2;
}

/* ---------- bottom dock ---------- */
.dock {
  flex: 0 0 auto;
}

.tip-card {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 60px;
  padding: 9px 13px;
  border-radius: 19px;
  background: rgba(255, 251, 243, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.88);
  box-shadow:
    0 10px 22px -14px rgba(120, 75, 31, 0.36),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.tip-orb {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #3D8C67;
  background: linear-gradient(160deg, #C6EFD8, #92D8B2);
  box-shadow:
    0 4px 0 rgba(92, 157, 120, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.tip-orb .mp-icon {
  width: 22px;
  height: 22px;
}

.tip-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.tip-copy strong {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.tip-copy span {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.key-hint {
  display: none;
  flex: 0 0 auto;
  margin-left: auto;
  width: 46px;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 0;
  color: #B79A7C;
  opacity: 0.72;
}

.key-hint .mp-icon {
  width: 15px;
  height: 15px;
}

.key-hint .mp-icon:nth-child(1) {
  grid-column: 2;
  grid-row: 1;
}

.key-hint .mp-icon:nth-child(2) {
  grid-column: 1;
  grid-row: 2;
}

.key-hint .mp-icon:nth-child(3) {
  grid-column: 2;
  grid-row: 2;
}

.key-hint .mp-icon:nth-child(4) {
  grid-column: 3;
  grid-row: 2;
}

/* ---------- animations ---------- */
@keyframes scoreBump {
  0% { transform: scale(1); }
  38% { transform: scale(1.22); }
  100% { transform: scale(1); }
}

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

@keyframes mascotBob {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-5px) rotate(1.5deg); }
}

@keyframes leafFloat {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -12px; }
}

@keyframes sparkle {
  0%, 100% { opacity: 0.25; transform: scale(0.72) rotate(0deg); }
  50% { opacity: 0.9; transform: scale(1.08) rotate(22deg); }
}

@keyframes boardShake {
  10%, 90% { transform: translate3d(-2px, 0, 0) rotate(-0.25deg); }
  20%, 80% { transform: translate3d(4px, 0, 0) rotate(0.35deg); }
  30%, 50%, 70% { transform: translate3d(-6px, 1px, 0) rotate(-0.5deg); }
  40%, 60% { transform: translate3d(6px, -1px, 0) rotate(0.5deg); }
}

@keyframes recordPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* ---------- responsive tweaks ---------- */
@media (hover: hover) and (pointer: fine) {
  .key-hint {
    display: grid;
  }
}

@media (max-width: 350px) {
  .app {
    padding-left: 12px;
    padding-right: 12px;
  }

  .hud-card {
    padding: 8px 10px;
    gap: 8px;
  }

  .hud-orb {
    width: 36px;
    height: 36px;
  }

  .hud-value {
    font-size: 23px;
  }

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

  .tip-copy span {
    font-size: 10px;
  }

  .start-card {
    padding-left: 14px;
    padding-right: 14px;
  }
}

@media (max-height: 640px) {
  .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 {
    min-height: 52px;
  }

  .hud-orb {
    width: 34px;
    height: 34px;
  }

  .tip-card {
    min-height: 52px;
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .tip-orb {
    width: 34px;
    height: 34px;
  }

  .mascot {
    width: 76px;
    height: 76px;
    margin-top: -34px;
  }

  .game-title {
    font-size: 22px;
  }

  .game-sub {
    margin-bottom: 11px;
  }

  .gesture-line {
    margin-top: 9px;
  }
}

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