:root {
  --orange: #FF8A3D;
  --orange-deep: #F2741E;
  --orange-dark: #C9560D;
  --cream: #FFF7E8;
  --paper: #FFFCF6;
  --ink: #4A2E1C;
  --ink-soft: #7A5734;
  --muted: #A3794F;
  --sun: #FFC94D;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #8FD8E8;
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  width: 100%;
}

.app {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

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

/* ---------------- HUD ---------------- */
.hud {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 560px;
  padding: 0 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  z-index: 10;
}

.score-card {
  position: relative;
  min-width: 118px;
  padding: 8px 15px 9px;
  border-radius: 18px;
  background: rgba(255, 252, 246, 0.93);
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 8px 20px rgba(105, 66, 20, 0.13), inset 0 -2px 0 rgba(242, 155, 78, 0.16);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.score-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.score-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.score-value {
  display: inline-block;
  min-width: 34px;
  color: var(--orange-deep);
  font-size: 25px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  transform-origin: left center;
}

.score-value.bump {
  animation: score-bump 0.22s ease-out;
}

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

.best-row {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-top: 3px;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
}

.best-row .mp-icon {
  width: 12px;
  height: 12px;
  color: #F5B23E;
}

.best-row b {
  color: var(--ink-soft);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.next-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 6px 9px 7px;
  border-radius: 18px;
  background: rgba(255, 252, 246, 0.93);
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 8px 20px rgba(105, 66, 20, 0.13), inset 0 -2px 0 rgba(242, 155, 78, 0.16);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

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

#next-canvas {
  display: block;
  width: 46px;
  height: 46px;
  margin-top: -1px;
}

.combo {
  position: absolute;
  left: 16px;
  top: 76px;
  padding: 4px 12px 5px;
  border-radius: 999px;
  background: linear-gradient(180deg, #FFB25B, #FF8A3D);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
  box-shadow: 0 6px 14px rgba(242, 116, 30, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.45);
  opacity: 0;
  transform: translateY(-4px) scale(0.85);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.combo b { font-size: 14px; }

.combo.show {
  opacity: 1;
  transform: none;
}

/* ---------------- Hint ---------------- */
.hint {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 38px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 15px;
  border-radius: 999px;
  background: rgba(63, 38, 20, 0.74);
  color: #FFF6E8;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  pointer-events: none;
  z-index: 9;
  box-shadow: 0 8px 20px rgba(63, 38, 20, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.14);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: opacity 0.45s ease, transform 0.45s ease;
}

.hint .mp-icon {
  width: 16px;
  height: 16px;
  color: #FFD08A;
}

.hint.hide {
  opacity: 0;
  transform: translate(-50%, 8px);
}

/* ---------------- Game over ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(58, 36, 18, 0.42);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

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

.over-card {
  width: min(340px, 100%);
  padding: 24px 22px 20px;
  border-radius: 28px;
  background: linear-gradient(180deg, #FFFDF8 0%, #FFF4E2 100%);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 26px 60px rgba(46, 25, 8, 0.36), inset 0 -4px 0 rgba(242, 155, 78, 0.14);
  text-align: center;
  transform: translateY(14px) scale(0.86);
  transition: transform 0.34s cubic-bezier(0.2, 1.35, 0.4, 1);
}

.overlay.show .over-card {
  transform: none;
}

.melon-badge {
  position: relative;
  width: 78px;
  height: 78px;
  margin: 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 26%, rgba(194, 240, 168, 0.9) 0 10%, rgba(194, 240, 168, 0) 38%),
    repeating-linear-gradient(102deg, #3E9E45 0 8px, #63BE56 8px 17px);
  box-shadow: inset -7px -9px 0 rgba(26, 94, 40, 0.16), 0 10px 18px rgba(48, 110, 52, 0.26);
}

.melon-badge::before {
  content: "";
  position: absolute;
  left: 54%;
  top: -9px;
  width: 25px;
  height: 13px;
  border-radius: 100% 0 100% 0;
  background: #6DB24E;
  transform: rotate(-20deg);
  box-shadow: inset 0 -2px 0 rgba(40, 90, 30, 0.22);
}

.melon-badge::after {
  content: "";
  position: absolute;
  left: 20%;
  top: 15%;
  width: 28%;
  height: 17%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.62);
  transform: rotate(-28deg);
  filter: blur(0.5px);
}

.melon-face {
  position: absolute;
  left: 50%;
  top: 54%;
  width: 5px;
  height: 7px;
  border-radius: 50%;
  background: #29572A;
  transform: translateX(-50%);
  box-shadow: -13px 0 0 #29572A, 13px 0 0 #29572A;
}

.melon-face::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 12px;
  width: 14px;
  height: 7px;
  border: 2px solid #29572A;
  border-top: 0;
  border-radius: 0 0 12px 12px;
  transform: translateX(-50%);
}

.over-card h2 {
  margin: 15px 0 5px;
  color: var(--ink);
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0.01em;
}

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

.result-row {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}

.result {
  flex: 1;
  padding: 10px 6px 11px;
  border-radius: 16px;
  background: #FFF0D9;
  border: 1px solid rgba(242, 155, 78, 0.22);
  box-shadow: inset 0 -2px 0 rgba(242, 155, 78, 0.12);
}

.result span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.result strong {
  display: block;
  color: var(--orange-deep);
  font-size: 24px;
  line-height: 1;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.primary-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  height: 52px;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, #FFA14F 0%, #F2741E 100%);
  color: #fff;
  font-family: inherit;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 8px 0 #C9560D, 0 12px 24px rgba(242, 116, 30, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.45);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  -webkit-tap-highlight-color: transparent;
}

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

.primary-btn:active {
  transform: translateY(5px);
  box-shadow: 0 3px 0 #C9560D, 0 6px 12px rgba(242, 116, 30, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

/* ---------------- Safe area probes ---------------- */
.safe-probe {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  visibility: hidden;
  pointer-events: none;
}

#safe-top { padding-top: env(safe-area-inset-top, 0px); }
#safe-bottom { padding-bottom: env(safe-area-inset-bottom, 0px); }

@media (max-height: 640px) {
  .hud { top: calc(env(safe-area-inset-top, 0px) + 8px); }
  .score-card { padding: 6px 13px 7px; }
  .score-value { font-size: 22px; }
  .next-card { padding: 5px 8px 6px; }
  #next-canvas { width: 40px; height: 40px; }
  .over-card { padding: 18px 18px 16px; }
  .melon-badge { width: 64px; height: 64px; }
  .over-card h2 { margin-top: 11px; font-size: 21px; }
  .result-row { margin-bottom: 14px; }
  .primary-btn { height: 48px; }
}
