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

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

body {
  display: flex;
  justify-content: center;
  overflow: hidden;
  overscroll-behavior: none;
  background: radial-gradient(circle at 50% 18%, #4A2C1C 0%, #2A1811 55%, #1B0F0B 100%);
  color: #3A2314;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

#game {
  position: relative;
  width: 100%;
  max-width: 520px;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  touch-action: none;
  background: #FFB067;
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.45);
}

#stage {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------------- HUD ---------------- */

.hud {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 14px 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

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

.hud-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
}

.score-box {
  min-width: 106px;
  padding: 8px 13px 7px;
  border-radius: 15px;
  background: rgba(255, 248, 236, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 6px 16px rgba(92, 40, 10, 0.22);
}

.score-line {
  display: flex;
  align-items: baseline;
  gap: 2px;
  color: #3A2314;
}

#scoreNum {
  font-size: 28px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.score-unit {
  font-size: 11px;
  font-weight: 800;
  color: #C06A32;
}

.score-best {
  margin-top: 3px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.09em;
  color: #A08468;
}

.score-best b {
  color: #D9702A;
  font-weight: 800;
}

.bamboo-box {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  padding: 0 10px 0 8px;
  border-radius: 999px;
  background: rgba(47, 42, 30, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #FFF6E6;
  font-size: 12px;
  font-weight: 700;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.bamboo-box .mp-icon {
  width: 15px;
  height: 15px;
  color: #BDEB8A;
}

.bamboo-num {
  font-size: 14px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.bamboo-label {
  font-size: 9px;
  opacity: 0.75;
  letter-spacing: 0.06em;
}

.bamboo-box.bump {
  animation: bump 0.3s ease;
}

@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.hud-right {
  display: flex;
  gap: 7px;
  pointer-events: auto;
}

.hud-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  background: rgba(52, 28, 14, 0.34);
  color: #FFF6E6;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(80, 34, 8, 0.18);
  cursor: pointer;
  transition: transform 0.1s ease, background 0.1s ease;
}

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

.hud-btn:active {
  transform: scale(0.9);
  background: rgba(52, 28, 14, 0.55);
}

/* ---------------- Slide button ---------------- */

.slide-btn {
  position: absolute;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  z-index: 4;
  width: 70px;
  height: 70px;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 246, 226, 0.65);
  background: rgba(52, 28, 14, 0.36);
  color: #FFF6E6;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 22px rgba(60, 25, 8, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  opacity: 0;
  visibility: hidden;
  transform: scale(0.8);
  pointer-events: none;
  cursor: pointer;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease, background 0.1s ease;
}

.slide-btn.show {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
  pointer-events: auto;
}

.slide-btn .mp-icon {
  width: 27px;
  height: 27px;
  margin-top: 2px;
}

.slide-btn span {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  opacity: 0.9;
}

.slide-btn:active {
  transform: scale(0.9);
  background: rgba(52, 28, 14, 0.55);
}

/* ---------------- Toast ---------------- */

.toast {
  position: absolute;
  left: 50%;
  top: 19%;
  z-index: 7;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(52, 28, 14, 0.78);
  border: 1px solid rgba(255, 236, 208, 0.3);
  color: #FFF3DA;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.05em;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, -8px) scale(0.94);
  pointer-events: none;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 20px rgba(40, 20, 8, 0.28);
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s ease;
}

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

/* ---------------- Screens ---------------- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.26s ease, visibility 0.26s ease;
}

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

.screen.overlay {
  z-index: 8;
  align-items: center;
  justify-content: center;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  background: rgba(40, 22, 12, 0.62);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
}

/* ---------------- Start screen ---------------- */

.start-screen {
  padding-top: calc(env(safe-area-inset-top, 0px) + 22px);
}

.start-top {
  padding: 0 22px;
  text-align: center;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid rgba(255, 244, 222, 0.4);
  background: rgba(58, 29, 10, 0.28);
  color: #FFF4DE;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.eyebrow .mp-icon {
  width: 14px;
  height: 14px;
  color: #FFD9A0;
}

.game-title {
  margin: 10px 0 0;
  font-size: clamp(46px, 14vw, 70px);
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0.02em;
  color: #FFF7E8;
  text-shadow: 0 3px 0 #C05A1A, 0 6px 0 rgba(122, 52, 12, 0.42), 0 14px 26px rgba(80, 34, 8, 0.36);
}

.game-sub {
  margin: 12px 0 0;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: #FFF0D8;
  text-shadow: 0 2px 10px rgba(110, 45, 10, 0.55);
}

.start-bottom {
  padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
}

.start-card {
  position: relative;
  padding: 16px 16px 14px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.85);
  background: linear-gradient(180deg, #FFF8EC 0%, #FFECD4 100%);
  box-shadow: 0 18px 40px rgba(82, 36, 10, 0.35), inset 0 1px 0 #FFFFFF;
}

.best-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 0 4px;
  color: #8A6A50;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.best-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.best-label .mp-icon {
  width: 16px;
  height: 16px;
  color: #E2A13A;
}

.best-value {
  color: #7A4A28;
  font-weight: 600;
}

.best-value b {
  margin-right: 2px;
  font-size: 22px;
  font-weight: 900;
  color: #E2631C;
  font-variant-numeric: tabular-nums;
}

/* ---------------- Buttons ---------------- */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  height: 54px;
  padding: 0 18px;
  border: 0;
  border-radius: 17px;
  font-family: inherit;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

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

.btn-primary {
  background: linear-gradient(180deg, #FFA85F 0%, #FF7A24 100%);
  color: #FFFDF8;
  text-shadow: 0 1px 2px rgba(150, 55, 0, 0.3);
  box-shadow: 0 5px 0 #C9540F, 0 12px 22px rgba(198, 80, 20, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.btn-primary:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #C9540F, 0 5px 10px rgba(198, 80, 20, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.btn-ghost {
  margin-top: 9px;
  height: 50px;
  background: #FFF3E1;
  color: #8A4B22;
  border: 1.5px solid #F1CFA5;
  box-shadow: 0 3px 0 rgba(190, 120, 60, 0.14);
  font-size: 15px;
}

.btn-ghost:active {
  transform: translateY(2px);
  background: #FFEAD2;
  box-shadow: none;
}

.btn-text {
  margin-top: 6px;
  height: 44px;
  background: transparent;
  color: #9A7A5F;
  font-size: 14px;
  font-weight: 700;
}

.btn-text:active {
  opacity: 0.65;
}

.hint-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 12px;
  padding: 0 4px;
}

.hint {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #9A7A5F;
  font-size: 11px;
  line-height: 1.45;
  letter-spacing: 0.02em;
}

.hint .mp-icon {
  flex: 0 0 14px;
  width: 14px;
  height: 14px;
  color: #C9824A;
}

/* ---------------- Sheets ---------------- */

.sheet {
  position: relative;
  width: 100%;
  max-width: 350px;
  padding: 22px 20px 16px;
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.85);
  background: linear-gradient(180deg, #FFF8EC 0%, #FFE9CF 100%);
  box-shadow: 0 26px 60px rgba(25, 12, 5, 0.45), inset 0 1px 0 #FFFFFF;
  text-align: center;
}

.screen.show .sheet {
  animation: sheetIn 0.34s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

@keyframes sheetIn {
  0% { opacity: 0; transform: translateY(22px) scale(0.96); }
  100% { opacity: 1; transform: none; }
}

.sheet-badge {
  width: 58px;
  height: 58px;
  margin: -48px auto 10px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 4px solid #FFF6E7;
  background: linear-gradient(180deg, #FFB067 0%, #FF822E 100%);
  color: #FFFDF8;
  box-shadow: 0 10px 22px rgba(200, 85, 20, 0.35);
}

.sheet-badge .mp-icon {
  width: 26px;
  height: 26px;
}

.sheet-badge.trophy {
  background: linear-gradient(180deg, #FFD37A 0%, #F5A623 100%);
  color: #7A4210;
}

.sheet h2 {
  margin: 2px 0 0;
  color: #3A2314;
  font-size: 23px;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.sheet-desc {
  margin: 6px 0 0;
  color: #9A7A5F;
  font-size: 12px;
  letter-spacing: 0.06em;
}

.new-best {
  display: none;
  width: fit-content;
  margin: 0 auto 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: #FF8A3D;
  color: #FFF9EF;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
  box-shadow: 0 4px 10px rgba(200, 85, 20, 0.3);
}

.new-best.show {
  display: block;
  animation: bump 0.4s ease;
}

.final-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  margin: 9px 0 4px;
  color: #E2631C;
}

.final-score span:first-child {
  font-size: 56px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.final-score .unit {
  font-size: 15px;
  font-weight: 800;
  color: #A56233;
}

.final-stats {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 12px 0 16px;
}

.stat {
  flex: 1;
  max-width: 135px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border-radius: 13px;
  border: 1px solid #F3D6B4;
  background: #FFF2E0;
  color: #8A5A36;
  font-size: 11px;
  font-weight: 700;
}

.stat .mp-icon {
  width: 16px;
  height: 16px;
  color: #C9824A;
}

.stat b {
  color: #5B351C;
  font-size: 16px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.stat span {
  opacity: 0.8;
}

.mini-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin: 14px 0 18px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid #F3D6B4;
  background: #FFF2E0;
}

.mini-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mini-stat b {
  color: #E2631C;
  font-size: 24px;
  line-height: 1;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.mini-stat span {
  color: #A08468;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.mini-divider {
  width: 1px;
  height: 26px;
  background: #EBCBA7;
}

.over-sheet {
  padding-top: 24px;
}

/* ---------------- Responsive ---------------- */

@media (max-height: 680px) {
  .start-screen {
    padding-top: calc(env(safe-area-inset-top, 0px) + 14px);
  }
  .game-title {
    font-size: clamp(40px, 12vw, 54px);
  }
  .game-sub {
    font-size: 12px;
  }
  .start-card {
    padding: 13px 14px 11px;
    border-radius: 21px;
  }
  .best-row {
    margin-bottom: 9px;
  }
  .btn {
    height: 50px;
    font-size: 16px;
  }
  .hint-row {
    margin-top: 9px;
    gap: 3px;
  }
  .sheet {
    padding: 18px 18px 12px;
  }
  .sheet-badge {
    width: 50px;
    height: 50px;
    margin-top: -42px;
  }
  .final-score span:first-child {
    font-size: 46px;
  }
  .final-stats {
    margin: 10px 0 13px;
  }
}

@media (min-width: 560px) {
  #game {
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
  }
}

button:focus-visible {
  outline: 3px solid rgba(255, 180, 90, 0.9);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001s !important;
    transition-duration: 0.001s !important;
  }
}
