:root {
  --orange: #FF8A3D;
  --orange-deep: #E9651A;
  --cream: #FFF8EC;
  --cream-2: #FFF1DC;
  --ink: #4A2A18;
  --muted: #936B4F;
  --wood: #7A4322;
  --hud-shadow: 0 4px 0 rgba(186, 118, 66, .20), 0 10px 24px rgba(105, 51, 14, .16);
}

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

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #FFB66B;
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  outline: none;
}

.ui {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

/* ---------------- HUD ---------------- */
.hud {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 50%;
  width: 100%;
  max-width: 540px;
  padding: 0 14px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.pill {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 42px;
  padding: 0 13px;
  border-radius: 999px;
  background: rgba(255, 250, 240, .95);
  border: 1.5px solid rgba(255, 255, 255, .82);
  box-shadow: var(--hud-shadow), inset 0 -2px 0 rgba(222, 174, 120, .22);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--ink);
}

.pill strong {
  font-size: 18px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -.01em;
}

.pill-k {
  font-size: 11px;
  font-weight: 700;
  color: #A57250;
  letter-spacing: .04em;
}

.pill-sub {
  font-size: 11px;
  font-weight: 700;
  color: #B58B6C;
}

.candy-dot {
  position: relative;
  width: 18px;
  height: 18px;
  margin-right: 1px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #FFB1AE 0%, #F65A60 44%, #C9252E 100%);
  box-shadow: 0 0 0 3px #FFE6C9, inset -2px -2px 0 rgba(112, 13, 20, .18);
}

.candy-dot::before,
.candy-dot::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 7px;
  height: 9px;
  margin-top: -4.5px;
  background: #FFC94A;
  z-index: -1;
}

.candy-dot::before {
  left: -4px;
  clip-path: polygon(100% 0, 100% 100%, 0 66%, 24% 50%, 0 34%);
}

.candy-dot::after {
  right: -4px;
  clip-path: polygon(0 0, 0 100%, 100% 66%, 76% 50%, 100% 34%);
}

.star-pill {
  gap: 4px;
  padding-left: 11px;
}

.star-pill .mp-icon {
  width: 20px;
  height: 20px;
  color: #FFB020;
  filter: drop-shadow(0 1px 0 #FFF3D0);
}

.star-pill.bump {
  animation: bump .32s cubic-bezier(.2, 1.4, .4, 1);
}

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

.round-btn {
  pointer-events: auto;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, .82);
  background: rgba(255, 250, 240, .95);
  box-shadow: var(--hud-shadow), inset 0 -2px 0 rgba(222, 174, 120, .22);
  color: #B06A34;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
  padding: 0;
}

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

.round-btn:active {
  transform: translateY(2px) scale(.94);
  box-shadow: 0 2px 0 rgba(186, 118, 66, .20), 0 5px 12px rgba(105, 51, 14, .14);
}

/* ---------------- bottom ---------------- */
.bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 15px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
}

.tip {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 16px;
  border-radius: 999px;
  background: rgba(255, 249, 239, .94);
  border: 1.5px solid rgba(255, 255, 255, .7);
  box-shadow: 0 4px 0 rgba(186, 118, 66, .16), 0 8px 20px rgba(82, 42, 13, .18);
  font-size: 13px;
  font-weight: 700;
  color: #7A4A2A;
  letter-spacing: .01em;
  transition: opacity .35s ease, transform .35s ease;
}

.tip .mp-icon {
  width: 19px;
  height: 19px;
  color: var(--orange);
}

.tip.gone {
  opacity: 0;
  transform: translateY(10px);
}

.dots {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 12px;
}

.dot {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 248, 236, .52);
  box-shadow: inset 0 1px 0 rgba(78, 40, 12, .10);
  transition: width .28s ease, background .28s ease;
}

.dot.done {
  background: #FFD37A;
}

.dot.active {
  width: 22px;
  background: #FFF8EC;
  box-shadow: 0 2px 6px rgba(78, 40, 12, .22);
}

/* ---------------- overlay ---------------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px 24px;
  background: rgba(73, 36, 14, .40);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .26s ease;
}

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

.modal {
  position: relative;
  width: min(340px, 100%);
  padding: 30px 22px 16px;
  border-radius: 30px;
  background: linear-gradient(180deg, #FFFDF8 0%, #FFF3E2 100%);
  border: 1.5px solid rgba(255, 255, 255, .9);
  box-shadow: 0 24px 60px rgba(58, 26, 8, .34), inset 0 2px 0 #FFFFFF, inset 0 -4px 0 rgba(226, 187, 141, .22);
  text-align: center;
  transform: translateY(16px) scale(.95);
  transition: transform .34s cubic-bezier(.2, .95, .3, 1.12);
}

.overlay.show .modal {
  transform: none;
}

.modal::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -54px;
  width: 250px;
  height: 130px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(255, 172, 84, .42) 0%, rgba(255, 172, 84, 0) 70%);
  pointer-events: none;
}

.modal-badge {
  position: relative;
  width: 76px;
  height: 76px;
  margin: -59px auto 10px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #FFF9EF;
  background: linear-gradient(180deg, #FFB65F 0%, #FF7A26 100%);
  border: 4px solid #FFF9EF;
  box-shadow: 0 7px 0 rgba(208, 89, 19, .26), 0 16px 28px rgba(93, 40, 8, .24);
}

.modal-badge.fail {
  background: linear-gradient(180deg, #FF9A8A 0%, #EE5A5F 100%);
  box-shadow: 0 7px 0 rgba(178, 49, 54, .24), 0 16px 28px rgba(93, 28, 20, .22);
}

.modal-badge .mp-icon {
  width: 36px;
  height: 36px;
}

.modal h2 {
  margin: 4px 0 6px;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 900;
  letter-spacing: .01em;
  color: var(--ink);
}

.modal-sub {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  font-weight: 600;
  color: var(--muted);
}

.modal-stars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 15px 0 19px;
}

.mstar {
  display: block;
  width: 44px;
  height: 44px;
  color: #E5D5C0;
  transform: scale(.9);
}

.mstar .mp-icon {
  width: 100%;
  height: 100%;
}

.mstar.on {
  color: #FFC12E;
  filter: drop-shadow(0 3px 0 rgba(204, 133, 9, .24));
  animation: starPop .46s cubic-bezier(.2, 1.45, .4, 1) both;
}

@keyframes starPop {
  0% { transform: scale(.2) rotate(-18deg); opacity: 0; }
  70% { transform: scale(1.13) rotate(4deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.modal-actions {
  margin-top: 2px;
}

.btn {
  pointer-events: auto;
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: .03em;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}

.btn-primary {
  color: #FFFBF3;
  background: linear-gradient(180deg, #FFA95F 0%, #FF7A26 100%);
  box-shadow: 0 5px 0 #D65B12, 0 14px 24px rgba(214, 91, 18, .28);
  text-shadow: 0 1px 0 rgba(140, 53, 7, .22);
}

.btn-primary:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #D65B12, 0 5px 10px rgba(214, 91, 18, .20);
}

.btn-ghost {
  margin-top: 8px;
  height: 42px;
  background: transparent;
  color: #A27454;
  font-size: 14px;
  font-weight: 700;
  box-shadow: none;
}

.btn-ghost:active {
  transform: scale(.97);
}

/* ---------------- small screens ---------------- */
@media (max-width: 360px) {
  .hud {
    padding: 0 10px;
  }

  .pill {
    height: 38px;
    padding: 0 10px;
  }

  .pill strong {
    font-size: 16px;
  }

  .round-btn {
    width: 38px;
    height: 38px;
  }

  .hud-group {
    gap: 6px;
  }

  .candy-dot {
    width: 16px;
    height: 16px;
  }

  .modal {
    padding-left: 18px;
    padding-right: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .star-pill.bump,
  .mstar.on {
    animation: none;
  }

  .overlay,
  .modal,
  .tip {
    transition: none;
  }
}
