:root {
  --orange: #FF8A3D;
  --orange-deep: #E96312;
  --orange-light: #FFB36B;
  --gold: #FFC63D;
  --ink: #37281D;
  --muted: #9B7A5C;
  --cream: #FFF8EC;
  --cream-deep: #FFEFD8;
  --line: #F0D8B8;
}

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #0B2233;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

#app {
  position: relative;
  width: 100vw;
  max-width: 62vh;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #8FD8FB;
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.5);
  isolation: isolate;
}

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

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

.hud {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 0;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.hud.show {
  opacity: 1;
  transform: translateY(0);
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(17, 52, 78, 0.48));
  color: #fff;
  box-shadow: 0 5px 14px rgba(12, 44, 68, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: auto;
  transition: transform 0.12s ease;
}

.hud-btn:active {
  transform: scale(0.92);
}

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

.chip {
  height: 40px;
  padding: 0 14px 0 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  border: 1.5px solid rgba(255, 255, 255, 0.6);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.3), rgba(15, 50, 76, 0.46));
  box-shadow: 0 5px 14px rgba(12, 44, 68, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-shadow: 0 2px 4px rgba(13, 42, 64, 0.4);
}

.chip .mp-icon {
  width: 23px;
  height: 23px;
  flex: none;
}

.score-chip .mp-icon {
  color: #FFD24A;
}

.coin-chip .mp-icon {
  color: #FFB020;
}

.coin-chip {
  margin-top: 2px;
}

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

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  font-family: inherit;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
  -webkit-appearance: none;
  appearance: none;
}

.btn .mp-icon {
  width: 24px;
  height: 24px;
  flex: none;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(180deg, #FFB346 0%, #FF8A3D 46%, #FF7617 100%);
  border: 2px solid rgba(255, 255, 255, 0.58);
  box-shadow: 0 6px 0 #D4580B, 0 14px 28px rgba(212, 88, 11, 0.36),
    inset 0 2px 0 rgba(255, 255, 255, 0.5);
  text-shadow: 0 2px 0 rgba(190, 74, 6, 0.36);
  overflow: hidden;
}

.btn-primary::after {
  content: "";
  position: absolute;
  top: -60%;
  left: -30%;
  width: 36%;
  height: 220%;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0));
  transform: rotate(18deg);
  animation: sheen 3.4s ease-in-out infinite;
  pointer-events: none;
}

.btn-primary:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #D4580B, 0 6px 14px rgba(212, 88, 11, 0.3),
    inset 0 2px 0 rgba(255, 255, 255, 0.45);
}

.btn-ghost {
  color: #8A6746;
  background: #FFFDF8;
  border: 1.5px solid #EED7B8;
  box-shadow: 0 3px 0 #EBD6B9, 0 6px 14px rgba(120, 82, 42, 0.12);
  font-size: 15px;
  min-height: 46px;
  padding: 0 14px;
}

.btn-ghost:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #EBD6B9;
}

.btn-ghost .mp-icon {
  width: 20px;
  height: 20px;
  color: #C08A50;
}

.btn-wide {
  width: 100%;
}

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

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(22px + env(safe-area-inset-bottom));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.screen.show {
  opacity: 1;
}

.start-screen {
  background: linear-gradient(
    180deg,
    rgba(12, 62, 96, 0.18) 0%,
    rgba(12, 62, 96, 0) 34%,
    rgba(9, 42, 64, 0.52) 100%
  );
  justify-content: space-between;
}

.start-screen .btn,
.start-screen .best-pill {
  pointer-events: auto;
}

.brand {
  padding-top: 8vh;
  text-align: center;
  animation: rise 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
}

.brand-kicker {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px 6px 11px;
  border-radius: 999px;
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  background: linear-gradient(180deg, #FFAE4E, #FF801F);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.16em;
  box-shadow: 0 6px 16px rgba(198, 78, 8, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.45);
  text-shadow: 0 1px 0 rgba(180, 70, 5, 0.35);
}

.brand-kicker .mp-icon {
  width: 17px;
  height: 17px;
  color: #FFF4B8;
}

.brand h1 {
  margin: 16px 0 10px;
  font-size: clamp(42px, 13vw, 58px);
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.03em;
  filter: drop-shadow(0 6px 0 rgba(145, 70, 14, 0.22)) drop-shadow(0 14px 26px rgba(10, 50, 76, 0.3));
}

.brand-white {
  color: #fff;
}

.brand-orange {
  color: #FFC24B;
}

.brand-sub {
  display: inline-block;
  margin: 0;
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(12, 48, 72, 0.34);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: rgba(255, 255, 255, 0.95);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.start-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 13px;
  padding-bottom: 1vh;
  animation: rise 0.7s 0.08s cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
}

.best-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 16px 0 12px;
  border-radius: 999px;
  background: rgba(255, 250, 240, 0.92);
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 6px 16px rgba(20, 50, 70, 0.22);
  color: #8A6746;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.best-pill .mp-icon {
  width: 20px;
  height: 20px;
  color: #FFAE2B;
}

.best-pill b {
  color: #3A2B20;
  font-size: 18px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.btn-start {
  width: 100%;
  max-width: 330px;
  height: 64px;
  font-size: 21px;
  letter-spacing: 0.06em;
  animation: breathe 2.8s ease-in-out infinite;
}

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

.hint-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.hint-row span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  background: rgba(9, 40, 60, 0.36);
  border: 1px solid rgba(255, 255, 255, 0.24);
  color: rgba(255, 255, 255, 0.88);
  font-size: 11.5px;
  font-weight: 700;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

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

/* ---------------- Overlay / result ---------------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(7, 32, 50, 0.46);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  opacity: 0;
  pointer-events: none;
  overflow-y: auto;
  transition: opacity 0.25s ease;
}

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

.result-card {
  position: relative;
  width: 100%;
  max-width: 342px;
  padding: 46px 18px 16px;
  border-radius: 28px;
  background: linear-gradient(180deg, #FFFDF8 0%, #FFF6E9 62%, #FFEFD8 100%);
  border: 1.5px solid #FFE6C4;
  box-shadow: 0 26px 60px rgba(4, 28, 46, 0.46), inset 0 2px 0 #FFFFFF;
  transform: translateY(18px) scale(0.96);
  transition: transform 0.34s cubic-bezier(0.2, 0.9, 0.28, 1.18);
  text-align: center;
}

.overlay.show .result-card {
  transform: translateY(0) scale(1);
}

.ribbon {
  position: absolute;
  top: -17px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 34px;
  background: linear-gradient(180deg, #FFAD45 0%, #FF8A3D 52%, #FA6D12 100%);
  color: #fff;
  font-size: 19px;
  font-weight: 900;
  letter-spacing: 0.1em;
  white-space: nowrap;
  clip-path: polygon(0 0, 100% 0, 93% 50%, 100% 100%, 0 100%, 7% 50%);
  filter: drop-shadow(0 6px 12px rgba(198, 78, 8, 0.35));
  text-shadow: 0 2px 0 rgba(180, 68, 4, 0.32);
}

.result-face {
  width: 74px;
  height: 74px;
  margin: 0 auto 4px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #F07A1E;
  background: radial-gradient(circle at 50% 32%, #FFF4E2, #FFE0B8);
  border: 2px dashed rgba(240, 122, 30, 0.38);
  box-shadow: inset 0 -6px 12px rgba(240, 122, 30, 0.12);
}

.result-face .mp-icon {
  width: 42px;
  height: 42px;
}

.result-tip {
  margin: 8px 0 4px;
  color: #A08363;
  font-size: 13px;
  font-weight: 700;
}

.score-big span {
  display: block;
  color: #B89773;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.score-big b {
  display: block;
  color: #332519;
  font-size: 46px;
  font-weight: 900;
  line-height: 1.08;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.result-stats {
  display: flex;
  align-items: stretch;
  margin: 12px 0 15px;
  padding: 9px 4px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid #F5E3CA;
}

.result-stats > div {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: relative;
}

.result-stats > div + div::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 1px;
  background: #F2DFC5;
}

.result-stats span {
  color: #AD8D6B;
  font-size: 11px;
  font-weight: 700;
}

.result-stats b {
  color: #4A3624;
  font-size: 16px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.btn-ad {
  width: 100%;
  height: 58px;
  font-size: 18px;
  letter-spacing: 0.04em;
}

.result-actions {
  display: flex;
  gap: 9px;
  margin-top: 12px;
}

.result-actions .btn {
  flex: 1;
  padding: 0 8px;
  font-size: 13.5px;
  min-height: 44px;
  gap: 5px;
}

.result-actions .btn .mp-icon {
  width: 18px;
  height: 18px;
}

/* ---------------- Pause ---------------- */

.pause-card {
  width: 100%;
  max-width: 312px;
  padding: 26px 20px 18px;
  border-radius: 26px;
  background: linear-gradient(180deg, #FFFDF8, #FFF3E0);
  border: 1.5px solid #FFE6C4;
  box-shadow: 0 22px 56px rgba(4, 28, 46, 0.45), inset 0 2px 0 #FFFFFF;
  text-align: center;
  transform: translateY(14px) scale(0.97);
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.28, 1.18);
}

.overlay.show .pause-card {
  transform: translateY(0) scale(1);
}

.pause-badge {
  width: 64px;
  height: 64px;
  margin: 0 auto 10px;
  display: grid;
  place-items: center;
  border-radius: 22px;
  color: #fff;
  background: linear-gradient(180deg, #FFAF46, #FF7A18);
  box-shadow: 0 8px 0 #D4580B, 0 12px 22px rgba(212, 88, 11, 0.3);
}

.pause-badge .mp-icon {
  width: 32px;
  height: 32px;
}

.pause-card h2 {
  margin: 4px 0 4px;
  color: #37281D;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0.06em;
}

.pause-tip {
  margin: 0 0 14px;
  color: #A08363;
  font-size: 13px;
  font-weight: 600;
}

.pause-score {
  margin-bottom: 16px;
  padding: 11px;
  border-radius: 14px;
  background: #FFF9F0;
  border: 1px dashed #EAD2B2;
  color: #A08363;
  font-size: 13px;
  font-weight: 700;
}

.pause-score b {
  color: #FF7A18;
  font-size: 22px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  vertical-align: -2px;
}

.pause-card .btn-primary {
  width: 100%;
  margin-bottom: 10px;
}

/* ---------------- Ad simulation ---------------- */

.ad-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(3, 16, 27, 0.94);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

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

.ad-card {
  width: 100%;
  max-width: 316px;
  padding: 22px 22px 20px;
  border-radius: 24px;
  background: linear-gradient(180deg, #1A3348, #122535);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 26px 60px rgba(0, 0, 0, 0.5);
  text-align: center;
  color: #fff;
}

.ad-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 18px;
}

.ad-tag {
  padding: 2px 6px;
  border-radius: 5px;
  background: #FFC63D;
  color: #4A3200;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.ad-label {
  color: rgba(255, 255, 255, 0.62);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2em;
}

.ad-reel {
  position: relative;
  width: 96px;
  height: 96px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  color: #FFC63D;
}

.ad-reel .mp-icon {
  width: 50px;
  height: 50px;
}

.ad-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px dashed rgba(255, 198, 61, 0.42);
  animation: spin 7s linear infinite;
}

.ad-reel::before {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 198, 61, 0.18), rgba(255, 198, 61, 0));
}

.ad-card h3 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.ad-card p {
  margin: 0 0 18px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 12px;
  line-height: 1.6;
}

.ad-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.ad-bar i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #FFB346, #FF7A18);
  transition: width 0.1s linear;
}

.ad-count {
  margin-top: 9px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}

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

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: 78%;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(9, 34, 52, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #FFF7E8;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

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

/* ---------------- Animations ---------------- */

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes breathe {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.025);
  }
}

@keyframes sheen {
  0%,
  55% {
    left: -45%;
  }
  85%,
  100% {
    left: 125%;
  }
}

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

@media (max-height: 700px) {
  .brand {
    padding-top: 4vh;
  }
  .brand h1 {
    font-size: clamp(36px, 11vw, 48px);
    margin: 12px 0 8px;
  }
  .btn-start {
    height: 58px;
    font-size: 19px;
  }
  .start-panel {
    gap: 10px;
  }
  .result-card {
    padding: 40px 16px 14px;
  }
  .score-big b {
    font-size: 40px;
  }
  .result-face {
    width: 62px;
    height: 62px;
  }
  .result-face .mp-icon {
    width: 34px;
    height: 34px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn-primary::after,
  .btn-start,
  .brand,
  .start-panel,
  .ad-ring {
    animation: none !important;
  }
}
