:root {
  --brand: #ff8a3d;
  --brand-deep: #f86f1d;
  --brand-dark: #b0480d;
  --ink: #4a2a10;
  --cream: #fff6e3;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #2a190d;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

body {
  background: radial-gradient(120% 80% at 50% 12%, #503019 0%, #2a190d 55%, #140c06 100%);
}

.stage {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
  background: #f3d9b6;
  touch-action: none;
  isolation: isolate;
  box-shadow: 0 0 70px rgba(0, 0, 0, .45);
}

.game {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

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

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 6;
  display: flex;
  align-items: flex-start;
  padding: calc(env(safe-area-inset-top, 0px) + 11px) 12px 0;
  pointer-events: none;
}

.score-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 94px;
  max-width: 152px;
  height: 46px;
  padding: 0 13px 0 7px;
  border-radius: 15px;
  border: 2px solid #8b4a1d;
  background: linear-gradient(180deg, rgba(255, 252, 240, .95) 0%, rgba(255, 243, 216, .95) 38%, rgba(243, 205, 148, .97) 100%);
  box-shadow: 0 3px 0 #71370f, 0 7px 15px rgba(65, 31, 8, .32), inset 0 2px 0 rgba(255, 255, 255, .9), inset 0 -2px 0 rgba(164, 92, 35, .25);
  overflow: hidden;
}

.score-card::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 11px;
  border: 1px solid rgba(255, 255, 255, .35);
  pointer-events: none;
}

.crown {
  flex: 0 0 auto;
  width: 31px;
  height: 31px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #7a3b08;
  background: radial-gradient(circle at 34% 28%, #fff6c7 0%, #ffd05e 38%, #f7a51d 72%, #d98106 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .85), inset 0 -2px 2px rgba(146, 76, 4, .35), 0 1px 3px rgba(93, 43, 4, .35);
}

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

.score-num {
  position: relative;
  z-index: 1;
  font-size: 21px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: .01em;
  font-variant-numeric: tabular-nums;
  color: #4a280e;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .7);
  transform-origin: 50% 55%;
  white-space: nowrap;
}

.score-num.bump { animation: score-bump .27s ease-out; }
@keyframes score-bump {
  0% { transform: scale(1); }
  34% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.next-card {
  margin-left: auto;
  width: 66px;
  padding: 4px 4px 5px;
  border-radius: 14px;
  border: 2px solid #8b4a1d;
  background: linear-gradient(180deg, rgba(255, 251, 237, .95) 0%, rgba(254, 239, 208, .95) 42%, rgba(240, 198, 137, .97) 100%);
  box-shadow: 0 3px 0 #71370f, 0 7px 14px rgba(65, 31, 8, .3), inset 0 2px 0 rgba(255, 255, 255, .85);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.next-label {
  font-size: 9px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: .08em;
  color: #85501f;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .6);
}

#nextPreview {
  width: 44px;
  height: 44px;
  margin: 1px auto 0;
  display: block;
  filter: drop-shadow(0 3px 3px rgba(92, 45, 12, .28));
}

.pause-btn {
  flex: 0 0 auto;
  margin-left: 8px;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 13px;
  border: 2px solid #8b4a1d;
  display: grid;
  place-items: center;
  color: #6b350b;
  background: linear-gradient(180deg, #fff3d6 0%, #f7d69c 45%, #eab167 100%);
  box-shadow: 0 3px 0 #71370f, 0 7px 14px rgba(65, 31, 8, .3), inset 0 2px 0 rgba(255, 255, 255, .9);
  pointer-events: auto;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .08s ease;
  -webkit-appearance: none;
  appearance: none;
}

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

.pause-btn:active {
  transform: translateY(3px) scale(.97);
  box-shadow: 0 0 0 #71370f, 0 2px 5px rgba(65, 31, 8, .25), inset 0 2px 0 rgba(255, 255, 255, .8);
}

/* ---------------- hint ---------------- */

.hint {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 86px);
  z-index: 6;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 244, 220, .22);
  background: rgba(77, 40, 14, .54);
  box-shadow: 0 6px 18px rgba(40, 18, 5, .22);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  color: #fff2d8;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  white-space: nowrap;
  pointer-events: none;
  opacity: 1;
  transition: opacity .35s ease, transform .35s ease;
  animation: hint-in .55s .25s both;
}

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

.hint-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffd88e;
  box-shadow: 0 0 0 0 rgba(255, 216, 142, .55);
  animation: hint-pulse 1.8s ease-out infinite;
}

@keyframes hint-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 216, 142, .55); }
  70% { box-shadow: 0 0 0 9px rgba(255, 216, 142, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 216, 142, 0); }
}

@keyframes hint-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------------- modal ---------------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 22px calc(env(safe-area-inset-bottom, 0px) + 28px);
  background: rgba(48, 24, 8, .44);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  animation: overlay-in .22s ease-out both;
}

.overlay[hidden] { display: none; }
@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  position: relative;
  width: 100%;
  max-width: 326px;
  padding: 24px 20px 20px;
  border-radius: 25px;
  border: 2px solid #8b4a1d;
  background: radial-gradient(120% 80% at 50% 0%, #fffdf5 0%, #fff6e3 38%, #fbe8c6 100%);
  box-shadow: 0 8px 0 #6c340e, 0 24px 55px rgba(38, 17, 4, .42), inset 0 2px 0 rgba(255, 255, 255, .95);
  text-align: center;
  animation: modal-in .3s cubic-bezier(.2, 1.25, .4, 1) both;
}

.modal::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 19px;
  border: 1px dashed rgba(168, 111, 58, .34);
  pointer-events: none;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(14px) scale(.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-badge {
  width: 58px;
  height: 58px;
  margin: -6px auto 8px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #7b3a06;
  background: radial-gradient(circle at 32% 26%, #fffbe0 0%, #ffe08a 32%, #ffb42e 68%, #e88a00 100%);
  border: 2px solid rgba(139, 74, 29, .75);
  box-shadow: 0 3px 0 rgba(139, 74, 29, .55), inset 0 2px 0 rgba(255, 255, 255, .8);
}

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

.modal-title {
  margin: 0;
  font-size: 23px;
  line-height: 1.25;
  font-weight: 900;
  letter-spacing: .01em;
  color: #4b2a10;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .7);
}

.modal-sub {
  margin: 5px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  font-weight: 600;
  color: #98683a;
}

.result-row {
  display: flex;
  gap: 9px;
  margin: 17px 0 18px;
}

.result-box {
  flex: 1;
  padding: 10px 8px 9px;
  border-radius: 14px;
  border: 1px solid rgba(170, 111, 56, .30);
  background: linear-gradient(180deg, rgba(255, 252, 242, .8), rgba(244, 220, 180, .55));
  box-shadow: inset 0 1px 3px rgba(140, 88, 40, .12);
}

.result-box span {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .08em;
  color: #a4794d;
}

.result-box strong {
  display: block;
  margin-top: 2px;
  font-size: 26px;
  line-height: 1.15;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: #4b2a10;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .8);
}

.primary-btn,
.ghost-btn {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 51px;
  border-radius: 16px;
  font-family: inherit;
  font-size: 16.5px;
  font-weight: 900;
  letter-spacing: .06em;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: transform .08s ease, box-shadow .08s ease;
}

.primary-btn {
  border: 2px solid var(--brand-dark);
  color: #fff9ee;
  background: linear-gradient(180deg, #ffab61 0%, var(--brand) 48%, var(--brand-deep) 100%);
  box-shadow: 0 4px 0 #a33f07, 0 10px 20px rgba(143, 58, 8, .28), inset 0 2px 0 rgba(255, 255, 255, .45);
  text-shadow: 0 1px 2px rgba(129, 48, 3, .38);
}

.primary-btn:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 #a33f07, 0 3px 8px rgba(143, 58, 8, .22), inset 0 2px 0 rgba(255, 255, 255, .35);
}

.ghost-btn {
  margin-top: 9px;
  height: 44px;
  border: 1.5px dashed rgba(150, 94, 44, .48);
  color: #8d5a2c;
  background: rgba(255, 255, 255, .25);
  font-size: 13.5px;
}

.ghost-btn:active {
  transform: translateY(2px);
  background: rgba(255, 255, 255, .45);
}

/* ---------------- boot ---------------- */

.boot {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: radial-gradient(90% 60% at 50% 42%, #f6dfbf 0%, #e8c9a1 58%, #d8b183 100%);
  transition: opacity .45s ease;
}

.boot.hide {
  opacity: 0;
  pointer-events: none;
}

.boot-steam {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid rgba(151, 94, 44, .22);
  border-top-color: #b46a2b;
  box-shadow: 0 4px 12px rgba(120, 65, 22, .12);
  animation: boot-spin .9s linear infinite;
}

.boot-text {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  color: #8d5b2f;
}

@keyframes boot-spin {
  to { transform: rotate(360deg); }
}

@media (max-height: 690px) {
  .hud { padding-top: calc(env(safe-area-inset-top, 0px) + 7px); }
  .hint {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 72px);
    font-size: 11px;
    padding: 8px 14px;
  }
  .modal { padding: 20px 18px 16px; }
  .modal-badge { width: 50px; height: 50px; margin-bottom: 6px; }
  .modal-badge .mp-icon { width: 27px; height: 27px; }
  .result-row { margin: 13px 0 14px; }
}

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

/* ---------------- 等级配色图例 ---------------- */

.tier-legend {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  z-index: 6;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 244, 220, .22);
  background: rgba(77, 40, 14, .42);
  box-shadow: 0 5px 14px rgba(40, 18, 5, .18);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
  white-space: nowrap;
}

.tier-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: .02em;
  color: #fff2d8;
}

.tier-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, .55);
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, .18);
}

.tier-dot.t1 { background: linear-gradient(180deg, #fffdf6, #e2d3b8); }
.tier-dot.t2 { background: linear-gradient(180deg, #fff6d8, #e8c96f); }
.tier-dot.t3 { background: linear-gradient(180deg, #ffe9a8, #e0a52c); }
.tier-dot.t4 { background: linear-gradient(180deg, #a9713f, #4e2a10); box-shadow: 0 0 7px rgba(255, 170, 60, .85); }

@media (max-height: 690px) {
  .tier-legend { bottom: calc(env(safe-area-inset-bottom, 0px) + 8px); padding: 5px 8px; }
  .tier-chip { font-size: 9px; }
  .tier-dot { width: 10px; height: 10px; }
}

/* ---------------- 分数跳动 ---------------- */

.score-num.bump { animation: score-bump .27s ease-out; }
@keyframes score-bump {
  0% { transform: scale(1); }
  34% { transform: scale(1.22); }
  100% { transform: scale(1); }
}
