:root {
  --orange: #FF8A3D;
  --orange-deep: #EF6A1E;
  --orange-soft: #FFB45F;
  --cream: #FFF8EC;
  --cream-deep: #FFEFD8;
  --ink: #61351B;
  --ink-soft: #A06A45;
  --shadow: rgba(164, 76, 15, .24);
}

* { box-sizing: border-box; }

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background: #FF9A46;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

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

button:focus-visible {
  outline: 3px solid rgba(255, 255, 255, .9);
  outline-offset: 3px;
}

.game {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 560px;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px calc(env(safe-area-inset-bottom, 0px) + 10px);
  overflow: hidden;
  background:
    radial-gradient(120% 52% at 50% 0%, #FFC87E 0%, rgba(255, 200, 126, 0) 62%),
    linear-gradient(180deg, #FFB15C 0%, #FF9946 46%, #FFAE5B 100%);
}

.sun-glow {
  position: absolute;
  top: -120px;
  left: 50%;
  width: 460px;
  height: 360px;
  transform: translateX(-50%);
  background: radial-gradient(circle, rgba(255, 238, 178, .62) 0%, rgba(255, 238, 178, 0) 68%);
  pointer-events: none;
}

.bush {
  position: absolute;
  bottom: -34px;
  width: 200px;
  height: 126px;
  border-radius: 52% 52% 0 0 / 100% 100% 0 0;
  pointer-events: none;
  z-index: 0;
  filter: saturate(1.02);
}

.bush-left {
  left: -58px;
  background: linear-gradient(165deg, #9ADB6C 0%, #6DBB4C 58%, #56A640 100%);
  box-shadow: 24px -8px 0 -14px rgba(125, 196, 84, .75);
}

.bush-right {
  right: -66px;
  background: linear-gradient(200deg, #A7E276 0%, #71BE50 56%, #56A43F 100%);
  box-shadow: -26px -10px 0 -16px rgba(139, 208, 99, .72);
}

.float-star {
  position: absolute;
  width: 17px;
  height: 17px;
  background: #FFE37D;
  opacity: .55;
  clip-path: polygon(50% 0%, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0% 50%, 39% 39%);
  animation: star-drift 5.5s ease-in-out infinite;
  pointer-events: none;
}

.star-a { top: 17%; left: 5%; }
.star-b { top: 47%; right: 4%; width: 12px; height: 12px; animation-delay: -2.6s; }

@keyframes star-drift {
  0%, 100% { transform: translateY(0) rotate(0deg); opacity: .3; }
  50% { transform: translateY(-10px) rotate(22deg); opacity: .8; }
}

.hud {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 440px;
  width: min(100%, calc(100vh - 252px), 440px);
  width: min(100%, calc(100dvh - 252px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)), 440px);
  flex: 0 0 auto;
  padding: 1px 2px 0;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  padding: 0 16px;
  border-radius: 26px;
  border: 1px solid rgba(255, 255, 255, .9);
  background: linear-gradient(180deg, #FFFDF7 0%, #FFF5E6 100%);
  box-shadow: 0 4px 0 rgba(183, 90, 23, .22), 0 7px 16px rgba(146, 64, 8, .12), inset 0 1px 0 #fff;
  color: #63351C;
  font-size: 21px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: .01em;
  font-variant-numeric: tabular-nums;
}

.best-pill .mp-icon {
  width: 27px;
  height: 27px;
  color: #FFB300;
  filter: drop-shadow(0 2px 0 rgba(183, 106, 0, .16));
}

.apple-mini {
  display: block;
  width: 24px;
  height: 24px;
  filter: drop-shadow(0 2px 0 rgba(160, 32, 32, .14));
}

.score-pill.is-bump {
  animation: score-bump .32s cubic-bezier(.34, 1.56, .64, 1);
}

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

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .9);
  border-radius: 50%;
  background: linear-gradient(180deg, #FFFDF7 0%, #FFF1DE 100%);
  color: #B4662A;
  box-shadow: 0 4px 0 rgba(183, 90, 23, .22), inset 0 1px 0 #fff;
  cursor: pointer;
  transition: opacity .2s ease, transform .2s ease;
}

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

.icon-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(183, 90, 23, .22), inset 0 1px 0 #fff;
}

.pause-btn {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(.82);
}

.game[data-state="playing"] .pause-btn {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: scale(1);
}

.stage {
  position: relative;
  z-index: 2;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 0;
  padding-top: 7px;
}

.board-frame {
  width: 100%;
  max-width: 440px;
  width: min(100%, calc(100vh - 252px), 440px);
  width: min(100%, calc(100dvh - 252px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)), 440px);
  aspect-ratio: 1 / 1;
  flex: 0 0 auto;
  padding: clamp(6px, 2.1vw, 10px);
  border-radius: clamp(24px, 7.2vw, 32px);
  background: linear-gradient(155deg, #FFFDF6 0%, #FFF2DD 56%, #FFE2BC 100%);
  box-shadow:
    0 9px 0 rgba(190, 97, 29, .22),
    0 18px 34px rgba(150, 62, 8, .22),
    inset 0 2px 0 rgba(255, 255, 255, .95);
}

.board-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  border-radius: clamp(18px, 5.6vw, 23px);
  background: #FFF8EC;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, .7),
    inset 0 5px 16px rgba(196, 126, 66, .12);
}

.board-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, .55),
    inset 0 10px 26px rgba(196, 126, 66, .08);
  pointer-events: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.bottom {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 440px;
  width: min(100%, calc(100vh - 252px), 440px);
  width: min(100%, calc(100dvh - 252px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)), 440px);
  min-height: 150px;
  flex: 0 0 auto;
}

.panel {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.game[data-state="ready"] .panel-ready,
.game[data-state="playing"] .panel-play,
.game[data-state="paused"] .panel-pause,
.game[data-state="over"] .panel-over {
  display: flex;
  animation: panel-in .24s ease both;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}

.ready-tip {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 11px;
  padding: 7px 14px;
  border: 1px solid rgba(255, 255, 255, .4);
  border-radius: 999px;
  background: rgba(255, 249, 237, .28);
  color: #6E3612;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .01em;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.ready-tip .mp-icon {
  width: 17px;
  height: 17px;
  color: #7A3D16;
}

.start-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
}

.cta {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-width: 238px;
  height: 66px;
  padding: 0 30px;
  border: 0;
  border-radius: 36px;
  background: linear-gradient(180deg, #FFB750 0%, #FF8A3D 52%, #FF7528 100%);
  color: #FFFDF8;
  font-size: 23px;
  font-weight: 900;
  letter-spacing: .05em;
  cursor: pointer;
  box-shadow:
    0 7px 0 #D75E18,
    0 13px 24px rgba(160, 63, 4, .34),
    inset 0 2px 0 rgba(255, 255, 255, .58);
  text-shadow: 0 2px 2px rgba(170, 70, 0, .24);
  transition: transform .08s ease, box-shadow .08s ease;
}

.cta .mp-icon {
  width: 30px;
  height: 30px;
  color: #fff;
  filter: drop-shadow(0 2px 1px rgba(160, 60, 0, .2));
}

.cta:active {
  transform: translateY(5px);
  box-shadow:
    0 2px 0 #D75E18,
    0 4px 10px rgba(160, 63, 4, .26),
    inset 0 2px 0 rgba(255, 255, 255, .4);
}

.cta-small {
  min-width: 208px;
  height: 56px;
  border-radius: 30px;
  font-size: 20px;
}

.cta-small .mp-icon {
  width: 26px;
  height: 26px;
}

.twinkle {
  position: absolute;
  width: 19px;
  height: 19px;
  color: #FFE47A;
  filter: drop-shadow(0 0 7px rgba(255, 226, 110, .85));
  animation: twinkle 1.9s ease-in-out infinite;
  pointer-events: none;
}

.twinkle-1 { left: -14px; top: -17px; }
.twinkle-2 { left: -25px; top: 6px; width: 13px; height: 13px; animation-delay: -.6s; }
.twinkle-3 { right: -15px; top: -13px; width: 15px; height: 15px; animation-delay: -1.2s; }

@keyframes twinkle {
  0%, 100% { opacity: .4; transform: scale(.78) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.14) rotate(24deg); }
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 48px);
  grid-template-areas:
    ". up ."
    "left center right"
    ". down .";
  gap: 4px;
}

.dbtn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .9);
  border-radius: 16px;
  background: linear-gradient(180deg, #FFFDF7 0%, #FFEBD2 100%);
  color: #E37327;
  box-shadow: 0 4px 0 rgba(181, 87, 20, .24), inset 0 1px 0 #fff;
  cursor: pointer;
  transition: transform .07s ease, box-shadow .07s ease, background .12s ease;
}

.dbtn .mp-icon {
  width: 33px;
  height: 33px;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, .7));
}

.dbtn.is-pressed,
.dbtn:active {
  transform: translateY(3px);
  background: linear-gradient(180deg, #FFE5C5 0%, #FFD1A0 100%);
  box-shadow: 0 1px 0 rgba(181, 87, 20, .24), inset 0 2px 4px rgba(180, 90, 20, .12);
}

.dbtn-up { grid-area: up; }
.dbtn-left { grid-area: left; }
.dbtn-right { grid-area: right; }
.dbtn-down { grid-area: down; }

.dpad-center {
  display: flex;
  align-items: center;
  justify-content: center;
  grid-area: center;
  color: rgba(221, 112, 38, .3);
}

.dpad-center .mp-icon {
  width: 25px;
  height: 25px;
}

.ghost-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  margin-top: 2px;
  padding: 0 18px;
  border: 0;
  border-radius: 20px;
  background: transparent;
  color: rgba(99, 53, 27, .74);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s ease, transform .08s ease;
}

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

.ghost-btn:active {
  background: rgba(255, 255, 255, .24);
  transform: translateY(1px);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(118, 55, 16, .24);
  opacity: 0;
  visibility: hidden;
  transition: opacity .22s ease, visibility .22s ease;
}

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

.overlay-card {
  width: 100%;
  max-width: 292px;
  padding: 17px 18px 19px;
  border-radius: 26px;
  background: linear-gradient(180deg, #FFFDF8 0%, #FFF0DA 100%);
  box-shadow:
    0 10px 0 rgba(158, 74, 16, .18),
    0 20px 40px rgba(108, 43, 5, .3),
    inset 0 2px 0 #fff;
  text-align: center;
  transform: translateY(14px) scale(.94);
  transition: transform .32s cubic-bezier(.34, 1.56, .64, 1);
}

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

.overlay-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  margin: 0 auto 4px;
  border-radius: 50%;
  background: linear-gradient(180deg, #FFE5B1 0%, #FFC66A 100%);
  color: #C37613;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .9), 0 4px 9px rgba(188, 118, 28, .22);
}

.overlay-badge .mp-icon {
  width: 29px;
  height: 29px;
}

.overlay-title {
  margin: 1px 0 0;
  color: #6A3517;
  font-size: 21px;
  font-weight: 900;
  letter-spacing: .02em;
}

.overlay-score {
  margin: 1px 0 0;
  color: #FF7A2F;
  font-size: 46px;
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: .01em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 3px 0 rgba(255, 255, 255, .85);
}

.overlay-sub {
  margin: 2px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
}

.record-badge {
  display: inline-block;
  margin: 5px 0 0;
  padding: 4px 11px;
  border-radius: 999px;
  background: linear-gradient(180deg, #FFF7C9 0%, #FFE894 100%);
  color: #B46B00;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .04em;
  box-shadow: 0 2px 0 rgba(190, 133, 24, .16);
}

.toast {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 72px);
  left: 50%;
  z-index: 12;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(92, 45, 15, .84);
  color: #FFF6E8;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
  transition: opacity .2s ease, transform .2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 360px) {
  .pill {
    height: 42px;
    padding: 0 12px;
    gap: 6px;
    font-size: 18px;
  }
  .best-pill .mp-icon { width: 23px; height: 23px; }
  .apple-mini { width: 21px; height: 21px; }
  .icon-btn { width: 42px; height: 42px; }
  .ready-tip { font-size: 12px; padding: 6px 12px; }
  .cta { min-width: 218px; height: 60px; font-size: 21px; }
  .cta-small { height: 52px; min-width: 196px; }
}

@media (min-width: 600px) {
  body { background: #F0A05A; }
  .game { box-shadow: 0 0 70px rgba(110, 46, 2, .2); }
}

@media (max-height: 630px) {
  .game { padding-top: calc(env(safe-area-inset-top, 0px) + 6px); padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 6px); }
  .hud { padding-top: 0; }
  .pill, .icon-btn { height: 42px; }
  .pill { font-size: 19px; padding: 0 14px; }
  .bottom { min-height: 140px; }
  .cta { height: 58px; min-width: 218px; font-size: 21px; }
  .cta-small { height: 52px; }
  .dpad { grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 44px); }
  .board-frame {
    width: 100%;
    max-width: 440px;
    width: min(100%, calc(100vh - 236px), 440px);
    width: min(100%, calc(100dvh - 236px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)), 440px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .float-star, .twinkle { animation: none; }
  .panel { animation: none; }
  .overlay-card { transition: none; }
}
