:root {
  --orange: #FF8A3D;
  --orange-deep: #F2711C;
  --ink: #4B2A12;
  --ink-soft: #9A7456;
  --cream: #FFF9EF;
}

* { box-sizing: border-box; }

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

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 75% at 8% -5%, #FFF4E3 0%, rgba(255, 244, 227, 0) 55%),
    radial-gradient(110% 70% at 100% 8%, #FFD9B0 0%, rgba(255, 217, 176, 0) 52%),
    linear-gradient(178deg, #FFE9D2 0%, #FFDDB8 55%, #FFD1A4 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.stage {
  position: absolute;
  inset: 0;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1;
}

/* ---------- soft background decoration ---------- */
.ambient {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
  border-radius: 32px;
}

.ambient-dot {
  position: absolute;
  border-radius: 50%;
}

.a1 {
  width: 160px;
  height: 160px;
  left: -62px;
  top: 8%;
  background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, .72), rgba(255, 255, 255, 0) 70%);
}

.a2 {
  width: 130px;
  height: 130px;
  right: -44px;
  top: 32%;
  background: radial-gradient(circle at 40% 40%, rgba(255, 170, 96, .32), rgba(255, 170, 96, 0) 70%);
}

.a3 {
  width: 230px;
  height: 230px;
  right: -90px;
  bottom: 3%;
  background: radial-gradient(circle at 45% 45%, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 70%);
}

.ambient-leaf {
  position: absolute;
  width: 46px;
  height: 26px;
  border-radius: 0 100% 0 100%;
  background: rgba(141, 190, 112, .22);
}

.l1 { left: -12px; top: 32%; transform: rotate(24deg); }
.l2 { right: -10px; bottom: 24%; transform: rotate(-32deg) scale(.8); }

/* ---------- top hud ---------- */
.hud {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  display: flex;
  gap: 9px;
}

.pill {
  height: 46px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 15px;
  background: linear-gradient(180deg, rgba(255, 253, 247, .97), rgba(255, 241, 224, .97));
  border: 1.5px solid rgba(255, 255, 255, .95);
  box-shadow: 0 4px 0 rgba(224, 154, 88, .16), 0 9px 18px rgba(166, 104, 44, .11), inset 0 1px 0 #FFF;
}

.score-pill { flex: 1.35; }
.best-pill { flex: 1; }

.pill-label {
  font-size: 12px;
  font-weight: 700;
  color: #A97A55;
  letter-spacing: .04em;
}

.pill-value {
  margin-left: auto;
  min-width: 22px;
  text-align: right;
  font-size: 21px;
  line-height: 1;
  font-weight: 900;
  color: var(--orange-deep);
  letter-spacing: -.02em;
  display: inline-block;
}

.best-pill .pill-value { color: #8A5A33; }
.best-pill .mp-icon { width: 20px; height: 20px; color: #FFB020; }

.fruit-mark {
  position: relative;
  flex: 0 0 auto;
  width: 19px;
  height: 19px;
  border-radius: 52% 52% 46% 46%;
  background: radial-gradient(circle at 34% 28%, #FF9E9E, #F04A4A 60%, #D62F3C);
  box-shadow: inset -1px -2px 0 rgba(150, 20, 30, .18), 0 1px 2px rgba(160, 40, 40, .2);
}

.fruit-mark::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 4px;
  width: 5px;
  height: 3px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .65);
  transform: rotate(-25deg);
}

.fruit-leaf {
  position: absolute;
  right: -2px;
  top: -4px;
  width: 10px;
  height: 6px;
  border-radius: 10px 0 10px 0;
  background: linear-gradient(135deg, #8ED26C, #5CA83F);
  transform: rotate(-22deg);
}

@keyframes scorePop {
  0% { transform: scale(1); }
  35% { transform: scale(1.38); }
  70% { transform: scale(.94); }
  100% { transform: scale(1); }
}

.pill-value.bump { animation: scorePop .34s cubic-bezier(.2, .8, .3, 1.4); }

/* ---------- game board ---------- */
.board-shell {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-frame {
  position: relative;
  padding: 6px;
  border-radius: 26px;
  background: linear-gradient(160deg, #FFFDF7 0%, #FFE8CC 55%, #FFD7AE 100%);
  border: 2px solid rgba(255, 255, 255, .95);
  box-shadow: 0 6px 0 rgba(209, 138, 74, .18), 0 18px 34px rgba(150, 88, 36, .18), inset 0 1px 0 #fff;
}

#game {
  display: block;
  border-radius: 19px;
  background: #C7E9B4;
  touch-action: none;
}

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 16px;
  border-radius: 26px;
  background: rgba(84, 47, 20, .26);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 1;
  visibility: visible;
  transition: opacity .24s ease, visibility .24s ease;
}


.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.panel {
  width: min(324px, 100%);
  max-height: 100%;
  overflow-y: auto;
  scrollbar-width: none;
  padding: 20px 20px 17px;
  border-radius: 27px;
  background: linear-gradient(180deg, #FFFDF8 0%, #FFF6E8 52%, #FFEFD9 100%);
  border: 2px solid #FFF;
  box-shadow: 0 12px 0 rgba(151, 86, 34, .12), 0 26px 48px rgba(112, 58, 20, .28);
  text-align: center;
  transform: translateY(0) scale(1);
  transition: transform .24s cubic-bezier(.2, .9, .3, 1.2);
}

.panel::-webkit-scrollbar { display: none; }
.overlay.hidden .panel { transform: translateY(10px) scale(.95); }

.mascot {
  width: 150px;
  height: 92px;
  margin: -4px auto 2px;
  filter: drop-shadow(0 8px 8px rgba(196, 116, 56, .18));
  animation: mascotFloat 3.2s ease-in-out infinite;
}

@keyframes mascotFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

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

.panel-title {
  margin: 0;
  font-size: 27px;
  line-height: 1.15;
  font-weight: 900;
  letter-spacing: .06em;
  color: #4B2A12;
  text-shadow: 0 2px 0 #fff;
}

.panel-sub {
  margin: 8px 0 0;
  font-size: 13.5px;
  line-height: 1.65;
  font-weight: 500;
  color: #A87C5B;
}

.btn-primary {
  width: 100%;
  height: 54px;
  margin-top: 16px;
  border: 0;
  border-radius: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: linear-gradient(180deg, #FFAE63 0%, #FF8A3D 46%, #F97A28 100%);
  color: #fff;
  font-family: inherit;
  font-size: 17.5px;
  font-weight: 900;
  letter-spacing: .08em;
  cursor: pointer;
  box-shadow: 0 5px 0 #DE661D, 0 12px 22px rgba(244, 118, 42, .35), inset 0 1px 0 rgba(255, 255, 255, .55);
  text-shadow: 0 1px 0 rgba(180, 70, 10, .25);
  transition: transform .09s ease, box-shadow .09s ease, filter .09s ease;
}

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

.btn-primary:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #DE661D, 0 5px 10px rgba(244, 118, 42, .3), inset 0 2px 4px rgba(160, 60, 10, .2);
  filter: brightness(.98);
}

.btn-primary:focus-visible {
  outline: 3px solid #FFD9AE;
  outline-offset: 3px;
}

.panel-hint {
  margin: 12px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .03em;
  color: #B58D6D;
}

.panel-hint .mp-icon { width: 15px; height: 15px; color: #D2A47D; }

.over-badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 12px;
  margin-bottom: 6px;
  border-radius: 999px;
  background: #FFE4C2;
  color: #C55F1E;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .1em;
}

.over-badge.record {
  background: linear-gradient(180deg, #FFE9A8, #FFD469);
  color: #A55A00;
  box-shadow: 0 2px 0 rgba(196, 126, 20, .18);
}

.result-row {
  display: flex;
  align-items: center;
  margin-top: 14px;
  padding: 12px 8px;
  border-radius: 18px;
  background: linear-gradient(180deg, #FFF3DE, #FFE9C9);
  border: 1.5px solid rgba(255, 255, 255, .9);
  box-shadow: inset 0 2px 5px rgba(194, 126, 64, .08);
}

.result-cell {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.result-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .08em;
  color: #B08462;
}

.result-cell strong {
  font-size: 28px;
  line-height: 1.1;
  font-weight: 900;
  letter-spacing: -.02em;
  color: var(--orange-deep);
}

.result-divider {
  width: 1.5px;
  height: 34px;
  border-radius: 2px;
  background: rgba(220, 164, 112, .35);
}

/* ---------- pause ---------- */
.pause-screen {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 26px;
  background: rgba(74, 42, 18, .38);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  transition: opacity .2s ease, visibility .2s ease;
}

.pause-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 20px 30px;
  border-radius: 22px;
  background: linear-gradient(180deg, #FFFDF7, #FFF1DC);
  border: 2px solid #fff;
  box-shadow: 0 18px 36px rgba(90, 50, 20, .28);
}

.pause-card .mp-icon {
  width: 30px;
  height: 30px;
  color: var(--orange);
  margin-bottom: 4px;
}

.pause-card strong { font-size: 18px; color: #5B3418; }
.pause-card span { font-size: 12px; color: #B18460; }

/* ---------- direction pad ---------- */
.pad {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  width: min(196px, 46vw);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 5px;
  padding: 8px;
  border-radius: 30px;
  background: linear-gradient(180deg, rgba(255, 252, 245, .95), rgba(255, 234, 209, .9));
  border: 1.5px solid rgba(255, 255, 255, .95);
  box-shadow: 0 6px 0 rgba(215, 143, 80, .14), 0 16px 28px rgba(158, 94, 38, .14), inset 0 1px 0 #fff;
}

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

.pad-btn {
  border: 0;
  border-radius: 17px;
  background: linear-gradient(180deg, #FFFEFB, #FFEAD2);
  color: #F0742C;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 3px 0 #EDC29A, inset 0 1px 0 #fff;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform .08s ease, box-shadow .08s ease, background .08s ease;
}

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

.pad-btn:active,
.pad-btn.pressed {
  transform: translateY(3px) scale(.97);
  background: linear-gradient(180deg, #FFE9CE, #FFDBB4);
  box-shadow: 0 0 0 #EDC29A, inset 0 2px 5px rgba(206, 130, 64, .22);
}

.pad-btn:focus-visible {
  outline: 3px solid #FFD9AE;
  outline-offset: 2px;
}

.pad-center {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(214, 150, 96, .4);
}

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

/* ---------- compact heights ---------- */
@media (max-height: 720px) {
  .stage {
    padding-top: calc(7px + env(safe-area-inset-top));
    padding-bottom: calc(9px + env(safe-area-inset-bottom));
    gap: 8px;
  }

  .hud { gap: 8px; }
  .pill { height: 42px; padding: 0 13px; }
  .pill-value { font-size: 19px; }

  .pad {
    width: min(174px, 44vw);
    padding: 7px;
    gap: 4px;
    border-radius: 26px;
  }

  .pad-btn { border-radius: 15px; }
  .pad-btn .mp-icon { width: 29px; height: 29px; }

  .mascot { width: 126px; height: 76px; }
  .panel { padding: 17px 18px 15px; }
  .panel-title { font-size: 24px; }
  .panel-sub { font-size: 12.5px; line-height: 1.55; }
  .btn-primary { height: 50px; margin-top: 13px; font-size: 16px; }
  .panel-hint { margin-top: 10px; font-size: 11px; }
  .result-row { margin-top: 11px; padding: 10px 6px; }
  .result-cell strong { font-size: 25px; }
}

@media (max-height: 620px) {
  .mascot { width: 108px; height: 62px; margin-bottom: 0; }
  .panel { padding: 14px 16px 12px; border-radius: 22px; }
  .panel-title { font-size: 21px; }
  .panel-sub { font-size: 11.5px; margin-top: 5px; }
  .btn-primary { height: 46px; margin-top: 10px; font-size: 15px; border-radius: 16px; }
  .panel-hint { margin-top: 8px; }
  .over-badge { height: 20px; margin-bottom: 4px; }
  .result-row { margin-top: 9px; padding: 8px 6px; }
  .result-cell strong { font-size: 23px; }
  .result-divider { height: 28px; }
  .pad { width: min(152px, 46vw); }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
