:root {
  --orange: #FF8A3D;
  --orange-hi: #FFAC66;
  --orange-deep: #D95E1B;
  --cream: #FFFBF2;
  --cream-2: #FFF3DD;
  --ink: #4C3320;
  --ink-soft: #6B4B33;
  --muted: #9C7C60;
  --line: #F0D9B6;
  --green: #64C46A;
  --green-deep: #2F8E48;
  --shadow-card: 0 6px 18px rgba(30, 88, 62, 0.14);
}

* {
  box-sizing: border-box;
}

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

html {
  background: #8ED7B2;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

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

button:focus-visible {
  outline: 3px solid rgba(255, 138, 61, 0.55);
  outline-offset: 3px;
}

/* ---------- painted garden backdrop ---------- */
.scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #D9F7EF 0%, #A9E8D8 42%, #8AD4A6 100%);
  pointer-events: none;
}

.scene-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%;
}

.cloud {
  position: absolute;
  display: block;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  filter: blur(1px);
  animation: cloudDrift 16s ease-in-out infinite alternate;
}

.cloud-a {
  top: 7%;
  left: 6%;
  width: 74px;
  height: 22px;
  box-shadow: 30px -9px 0 -2px rgba(255, 255, 255, 0.45);
}

.cloud-b {
  top: 16%;
  right: 4%;
  width: 58px;
  height: 18px;
  opacity: 0.68;
  animation-delay: -7s;
  box-shadow: -24px -7px 0 -3px rgba(255, 255, 255, 0.4);
}

@keyframes cloudDrift {
  from { transform: translate3d(-6px, 0, 0); }
  to { transform: translate3d(10px, 3px, 0); }
}

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

/* ---------- score bar (not a page header) ---------- */
.hud {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  margin-bottom: 10px;
}

.pill {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 0;
  min-width: 0;
  height: 48px;
  padding: 0 12px 0 8px;
  border-radius: 999px;
  border: 1.5px solid rgba(255, 255, 255, 0.92);
  background: rgba(255, 251, 242, 0.94);
  box-shadow:
    0 3px 0 rgba(176, 132, 86, 0.22),
    0 9px 20px rgba(31, 92, 67, 0.12);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

.pill-icon {
  display: grid;
  place-items: center;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #EF7A28;
  background: linear-gradient(160deg, #FFEAC9, #FFD29A);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.85);
}

.pill-icon.best {
  color: #B97A15;
  background: linear-gradient(160deg, #FFF3C9, #FFDE8E);
}

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

.pill-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1;
}

.pill-text em {
  font-style: normal;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: #A68567;
}

.pill-text strong {
  margin-top: 3px;
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  color: #573A22;
  font-variant-numeric: tabular-nums;
}

.pill-text strong.pop {
  animation: scorePop 0.32s ease;
}

@keyframes scorePop {
  0% { transform: scale(1); }
  45% { transform: scale(1.32); color: var(--orange); }
  100% { transform: scale(1); }
}

.pause-btn {
  display: grid;
  place-items: center;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.92);
  background: rgba(255, 251, 242, 0.94);
  color: #EF7A28;
  box-shadow:
    0 3px 0 rgba(176, 132, 86, 0.22),
    0 9px 20px rgba(31, 92, 67, 0.12);
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

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

.pause-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(176, 132, 86, 0.22);
}

/* ---------- stage / board ---------- */
.stage {
  position: relative;
  touch-action: none;
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.board {
  position: relative;
  box-sizing: border-box;
  padding: 7px;
  border-radius: 32px;
  background:
    linear-gradient(150deg, #FFFDF6 0%, #FFF4DF 55%, #FFE7C4 100%);
  box-shadow:
    0 7px 0 #D9AE79,
    0 20px 36px rgba(23, 78, 53, 0.28),
    inset 0 0 0 1.5px rgba(255, 255, 255, 0.92);
}

.board::after {
  content: "";
  position: absolute;
  inset: 3px;
  z-index: 4;
  border-radius: 29px;
  border: 2px solid rgba(255, 138, 61, 0.22);
  pointer-events: none;
}

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

@keyframes boardShake {
  0%, 100% { transform: translate3d(0, 0, 0); }
  16% { transform: translate3d(-5px, 2px, 0) rotate(-0.5deg); }
  34% { transform: translate3d(5px, -2px, 0) rotate(0.5deg); }
  52% { transform: translate3d(-4px, 1px, 0) rotate(-0.35deg); }
  72% { transform: translate3d(3px, -1px, 0) rotate(0.25deg); }
  88% { transform: translate3d(-1px, 1px, 0); }
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 25px;
  background: #7FCC60;
  box-shadow:
    inset 0 2px 8px rgba(30, 86, 44, 0.22),
    inset 0 -3px 10px rgba(30, 86, 44, 0.12);
  touch-action: none;
  cursor: pointer;
}

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 7px;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  border-radius: 25px;
  background:
    radial-gradient(120% 95% at 50% 10%, rgba(36, 92, 58, 0.08), rgba(24, 67, 43, 0.5));
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 1;
  transform: scale(1);
  transition: opacity 0.26s ease, transform 0.26s ease;
}

.overlay.hidden {
  opacity: 0;
  transform: scale(1.025);
  pointer-events: none;
}

.panel {
  position: relative;
  width: 100%;
  max-width: 306px;
  padding: 16px 20px 18px;
  overflow: hidden;
  text-align: center;
  border-radius: 28px;
  border: 2px solid rgba(255, 255, 255, 0.96);
  background:
    linear-gradient(180deg, #FFFDF7 0%, #FFF9EC 55%, #FFF2DC 100%);
  box-shadow:
    0 8px 0 rgba(166, 116, 66, 0.28),
    0 22px 42px rgba(23, 72, 48, 0.32);
}

.overlay:not(.hidden) .panel {
  animation: panelIn 0.34s cubic-bezier(0.22, 1.4, 0.36, 1) both;
}

.panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 7px;
  background: repeating-linear-gradient(
    90deg,
    #FFB067 0 15px,
    #FFD8A8 15px 30px,
    #9BDD84 30px 45px,
    #C9EEA9 45px 60px
  );
  opacity: 0.9;
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(10px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.mascot-wrap {
  display: flex;
  justify-content: center;
  margin: -4px auto -2px;
  filter: drop-shadow(0 6px 8px rgba(48, 112, 62, 0.14));
}

.mascot {
  display: block;
  width: 200px;
  max-width: 100%;
  height: 136px;
  overflow: visible;
  animation: mascotBob 3.4s ease-in-out infinite;
}

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

.mascot-tongue {
  transform-origin: 17px 14px;
  animation: tongueFlick 3.2s ease-in-out infinite;
}

@keyframes tongueFlick {
  0%, 8%, 16%, 100% { transform: scaleX(1); opacity: 1; }
  4%, 12% { transform: scaleX(1.06); opacity: 1; }
  84% { transform: scaleX(1); opacity: 1; }
}

.game-title {
  margin: 2px 0 6px;
  font-size: 30px;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 0.12em;
  text-indent: 0.12em;
  color: #4A2F1C;
  text-shadow:
    0 2px 0 rgba(255, 255, 255, 0.9),
    0 5px 0 rgba(255, 138, 61, 0.18);
}

.game-sub {
  margin: 0 auto 14px;
  max-width: 230px;
  font-size: 12.5px;
  line-height: 1.65;
  color: #8D6E53;
}

.cta {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  height: 52px;
  padding: 0 18px;
  overflow: hidden;
  border: 0;
  border-radius: 26px;
  color: #FFFFFF;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.08em;
  background: linear-gradient(180deg, #FFAC62 0%, #FF8A3D 45%, #FB7428 100%);
  box-shadow:
    0 5px 0 #D55E1B,
    0 10px 20px rgba(215, 93, 27, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.42);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.cta::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 8px;
  right: 8px;
  height: 15px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0));
  pointer-events: none;
}

.cta span,
.cta .mp-icon {
  position: relative;
  z-index: 1;
}

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

.cta:active {
  transform: translateY(3px);
  box-shadow:
    0 2px 0 #D55E1B,
    0 4px 10px rgba(215, 93, 27, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.42);
}

.micro-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin: 12px 0 0;
  font-size: 11px;
  line-height: 1;
  color: #A3886C;
}

.micro-hint .mp-icon {
  width: 15px;
  height: 15px;
  color: #E68A45;
}

/* game over panel */
.over-panel,
.pause-panel {
  padding-top: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  color: #D7843E;
}

.panel-title {
  margin: 0 0 14px;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #4A2F1C;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.85);
}

.result-card {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 7px;
  margin: 0 0 12px;
  padding: 12px 10px 13px;
  border-radius: 18px;
  border: 1.5px dashed rgba(255, 138, 61, 0.42);
  background: rgba(255, 244, 224, 0.75);
  color: #8A6A4F;
  font-size: 12.5px;
}

.result-card strong {
  font-size: 34px;
  font-weight: 900;
  line-height: 0.9;
  color: var(--orange);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 #FFFFFF;
}

.new-best {
  display: inline-block;
  margin: 0 0 12px;
  padding: 5px 14px;
  border-radius: 999px;
  color: #FFFFFF;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  background: linear-gradient(180deg, #FFB44F, #F58B25);
  box-shadow: 0 3px 0 #CE6C13;
  animation: bestPop 0.5s cubic-bezier(0.22, 1.5, 0.36, 1) both;
}

.new-best.hidden {
  display: none;
}

@keyframes bestPop {
  from { opacity: 0; transform: scale(0.7) rotate(-5deg); }
  to { opacity: 1; transform: scale(1) rotate(-2deg); }
}

.pause-badge {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin: 2px auto 12px;
  border-radius: 50%;
  color: #EF7A28;
  background: linear-gradient(160deg, #FFEAC9, #FFD29A);
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.7),
    0 5px 0 rgba(196, 143, 88, 0.28);
}

.pause-badge .mp-icon {
  width: 32px;
  height: 32px;
}

/* ---------- bottom controls ---------- */
.controls {
  --btn: 44px;
  --gap: 3px;
  --dock-pad: 5px;
  --dock: calc(var(--btn) * 3 + var(--gap) * 2 + var(--dock-pad) * 2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
  padding-top: 10px;
}

.hint-card {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  height: var(--dock);
  padding: 8px 10px;
  text-align: center;
  border-radius: 24px;
  border: 1.5px solid rgba(255, 255, 255, 0.88);
  background: rgba(255, 251, 242, 0.9);
  box-shadow:
    0 4px 0 rgba(176, 132, 86, 0.2),
    0 10px 22px rgba(31, 92, 67, 0.1);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.swipe-art {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  color: #EE7A28;
  background: linear-gradient(160deg, #FFEAC9, #FFD29A);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.7);
}

.swipe-art .mp-icon {
  width: 27px;
  height: 27px;
  animation: swipeHint 2.6s ease-in-out infinite;
}

@keyframes swipeHint {
  0%, 100% { transform: translateX(-3px); }
  50% { transform: translateX(4px); }
}

.hint-card strong {
  font-size: 13.5px;
  line-height: 1.1;
  color: #5B3D27;
}

.hint-card > span:last-child {
  font-size: 10.5px;
  line-height: 1.45;
  color: #9A7B60;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, var(--btn));
  grid-template-rows: repeat(3, var(--btn));
  gap: var(--gap);
  flex: 0 0 auto;
  padding: var(--dock-pad);
  border-radius: 24px;
  border: 1.5px solid rgba(255, 255, 255, 0.88);
  background: rgba(255, 251, 242, 0.9);
  box-shadow:
    0 4px 0 rgba(176, 132, 86, 0.2),
    0 10px 22px rgba(31, 92, 67, 0.1);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.d-btn {
  display: grid;
  place-items: center;
  width: var(--btn);
  height: var(--btn);
  padding: 0;
  border: 2px solid #F4D8B3;
  border-radius: 15px;
  color: #F07B28;
  background: linear-gradient(180deg, #FFFDF6, #FFF0D6);
  box-shadow: 0 3px 0 #E2C29B;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.07s ease, box-shadow 0.07s ease, background 0.07s ease;
}

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

.d-btn:active,
.d-btn.pressed {
  transform: translateY(2px);
  background: linear-gradient(180deg, #FFE4C2, #FFD3A2);
  box-shadow: 0 1px 0 #E2C29B;
}

.up { grid-area: 1 / 2; }
.left { grid-area: 2 / 1; }
.right { grid-area: 2 / 3; }
.down { grid-area: 3 / 2; }

.d-center {
  grid-area: 2 / 2;
  display: grid;
  place-items: center;
  align-self: stretch;
  justify-self: stretch;
  border-radius: 15px;
  color: #F3FFE3;
  background: linear-gradient(160deg, #9BE07E, #5CBE62);
  box-shadow:
    inset 0 -3px 0 rgba(42, 110, 50, 0.24),
    inset 0 2px 0 rgba(255, 255, 255, 0.34);
  pointer-events: none;
}

.d-center .mp-icon {
  width: 23px;
  height: 23px;
}

/* ---------- short screens / narrow screens ---------- */
@media (max-height: 720px) {
  .app {
    padding-top: calc(env(safe-area-inset-top, 0px) + 8px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  }

  .hud {
    margin-bottom: 7px;
  }

  .pill,
  .pause-btn {
    height: 44px;
  }

  .pause-btn {
    flex-basis: 44px;
    width: 44px;
  }

  .pill-icon {
    flex-basis: 29px;
    width: 29px;
    height: 29px;
  }

  .pill-text strong {
    font-size: 18px;
  }

  .controls {
    --btn: 39px;
    padding-top: 7px;
  }

  .hint-card {
    gap: 3px;
    padding: 6px 8px;
  }

  .swipe-art {
    width: 40px;
    height: 40px;
  }

  .swipe-art .mp-icon {
    width: 23px;
    height: 23px;
  }

  .hint-card strong {
    font-size: 12.5px;
  }

  .hint-card > span:last-child {
    font-size: 10px;
  }

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

  .mascot {
    width: 170px;
    height: 116px;
  }

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

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

  .panel {
    padding: 13px 18px 15px;
  }

  .cta {
    height: 48px;
    font-size: 17px;
  }

  .over-panel,
  .pause-panel {
    padding-top: 19px;
  }

  .result-card {
    padding: 9px 8px 10px;
    margin-bottom: 10px;
  }
}

@media (max-width: 365px) {
  .app {
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }

  .controls {
    --btn: 40px;
    gap: 8px;
  }

  .pill {
    padding-right: 9px;
  }

  .panel {
    padding-left: 15px;
    padding-right: 15px;
  }

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

  .hint-card > span:last-child {
    display: none;
  }
}

@media (max-width: 330px) {
  .controls {
    --btn: 37px;
  }

  .hint-card {
    padding: 6px;
  }

  .swipe-art {
    width: 38px;
    height: 38px;
  }

  .hint-card strong {
    font-size: 12px;
  }
}

@media (max-height: 600px) {
  .mascot {
    width: 142px;
    height: 97px;
  }

  .game-sub {
    display: none;
  }

  .game-title {
    margin-top: 0;
    font-size: 25px;
  }

  .micro-hint {
    margin-top: 8px;
  }

  .panel {
    padding-top: 12px;
    padding-bottom: 12px;
  }
}

/* graceful landscape fallback: controls move beside the board */
@media (orientation: landscape) and (max-height: 520px) {
  .app {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
    column-gap: 12px;
    max-width: 920px;
    padding-top: calc(env(safe-area-inset-top, 0px) + 7px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 7px);
  }

  .hud {
    grid-column: 1 / -1;
    grid-row: 1;
    margin-bottom: 6px;
  }

  .hud .pill {
    max-width: 190px;
  }

  .hud .pause-btn {
    margin-left: auto;
  }

  .stage {
    grid-column: 1;
    grid-row: 2;
  }

  .controls {
    grid-column: 2;
    grid-row: 2;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    padding-top: 0;
    align-self: center;
  }

  .hint-card {
    display: none;
  }

  .dpad {
    --btn: 42px;
  }

  .panel {
    max-width: 290px;
    padding: 10px 14px 12px;
  }

  .mascot {
    width: 118px;
    height: 80px;
  }

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

  .game-sub,
  .micro-hint {
    display: none;
  }

  .cta {
    height: 42px;
    font-size: 15px;
  }

  .over-panel,
  .pause-panel {
    padding-top: 15px;
  }

  .pause-badge {
    width: 48px;
    height: 48px;
    margin-bottom: 8px;
  }

  .panel-title {
    margin-bottom: 10px;
    font-size: 21px;
  }

  .result-card {
    padding: 7px 8px 8px;
    margin-bottom: 8px;
  }
}

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