:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --theme: #FF8A3D;
  --theme-deep: #E4681F;
  --ink: #4A2B16;
  --muted: #A0795A;
  --line: #F3C69C;
  --card: #FFFCF5;
}

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

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: linear-gradient(180deg, #FFF9EE 0%, #FFF1DC 55%, #FFE2C4 100%);
}

body {
  position: fixed;
  inset: 0;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

#stage {
  position: fixed;
  inset: 0;
  z-index: 0;
}

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

/* ---------- top HUD ---------- */
.hud {
  position: fixed;
  top: calc(var(--sat) + 10px);
  left: 0;
  right: 0;
  width: min(calc(100% - 32px), 540px);
  margin: 0 auto;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  animation: hudIn .45s cubic-bezier(.2, .9, .3, 1.15) both;
}

@keyframes hudIn {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 42px;
  padding: 0 13px 0 9px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: rgba(255, 252, 245, .95);
  box-shadow: 0 5px 14px rgba(190, 105, 40, .13), inset 0 2px 0 rgba(255, 255, 255, .9);
}

.pill svg {
  flex: none;
  width: 23px;
  height: 23px;
  margin-right: 5px;
}

.pill .num {
  font-size: 21px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.pill .unit {
  margin: 2px 0 0 3px;
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
}

.pill .num.pop {
  animation: numPop .3s cubic-bezier(.2, .9, .3, 1.6);
}

@keyframes numPop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.32); color: #F06B1D; }
  100% { transform: scale(1); }
}

.best-pill {
  padding-right: 14px;
  background: rgba(255, 247, 232, .93);
}

.best-pill .ico-crown {
  width: 21px;
  height: 21px;
  margin-right: 5px;
}

.best-pill .best-label {
  margin-right: 5px;
  font-size: 11px;
  font-weight: 800;
  color: #B07E52;
  letter-spacing: .04em;
}

.best-pill .num {
  font-size: 17px;
  color: #A95E22;
}

/* ---------- swipe hint ---------- */
.hint {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sab) + 18px);
  z-index: 4;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 7px;
  height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: rgba(255, 249, 238, .95);
  box-shadow: 0 7px 18px rgba(185, 100, 35, .14), inset 0 2px 0 #fff;
  color: #8A5A33;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .01em;
  white-space: nowrap;
  transition: opacity .32s ease, transform .32s ease;
  pointer-events: none;
}

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

.hint .ico-swipe {
  width: 21px;
  height: 21px;
  color: var(--theme);
  animation: swipeNudge 1.7s ease-in-out infinite;
}

@keyframes swipeNudge {
  0%, 100% { transform: translateX(-2px); }
  50%      { transform: translateX(2px); }
}

/* ---------- game over ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 26px;
  background: radial-gradient(circle at 50% 44%, rgba(96, 49, 17, .16), rgba(80, 40, 15, .44));
  opacity: 0;
  visibility: hidden;
  transition: opacity .24s ease, visibility .24s ease;
}

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

.panel {
  position: relative;
  width: min(330px, 88vw);
  padding: 20px 20px 20px;
  border-radius: 28px;
  border: 3px solid #F6C592;
  background: linear-gradient(180deg, #FFFDF7 0%, #FFF4E2 100%);
  box-shadow: 0 22px 46px rgba(140, 68, 18, .3), inset 0 2px 0 #fff;
  text-align: center;
  transform: translateY(16px) scale(.92);
  opacity: 0;
  transition: transform .34s cubic-bezier(.2, 1.25, .35, 1), opacity .22s ease;
}

.overlay.show .panel {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.ov-face {
  width: 82px;
  height: 82px;
  margin: -56px auto 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 3px solid #F6C592;
  background: #FFF8EB;
  box-shadow: 0 8px 18px rgba(170, 85, 25, .18), inset 0 2px 0 #fff;
}

.ov-face svg {
  width: 66px;
  height: 66px;
  display: block;
}

.ov-eyebrow {
  margin: 2px 0 3px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .18em;
  color: #B58A67;
}

#ovTitle {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -.01em;
  color: var(--ink);
}

.ov-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 5px;
  margin-top: 10px;
  line-height: 1;
}

#finalScore {
  font-size: 50px;
  font-weight: 900;
  letter-spacing: -.04em;
  color: var(--theme);
  text-shadow: 0 3px 0 #FFDCC0;
  font-variant-numeric: tabular-nums;
}

.ov-unit {
  font-size: 14px;
  font-weight: 800;
  color: #A86F45;
}

.ov-best {
  margin: 7px 0 18px;
  font-size: 13px;
  font-weight: 700;
  color: #A9815E;
}

.ov-best b {
  color: #9A5A24;
  font-weight: 900;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 54px;
  border: 0;
  border-radius: 18px;
  background: linear-gradient(180deg, #FFA758 0%, #FF7C2A 100%);
  color: #fff;
  font-family: inherit;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: .02em;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 7px 0 #E4681F, 0 12px 22px rgba(228, 104, 31, .28),
    inset 0 2px 0 rgba(255, 255, 255, .4);
  transition: transform .08s ease, box-shadow .08s ease;
}

.btn svg {
  width: 21px;
  height: 21px;
}

.btn:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 #E4681F, 0 6px 12px rgba(228, 104, 31, .24),
    inset 0 2px 0 rgba(255, 255, 255, .32);
}

.btn:focus-visible {
  outline: 3px solid rgba(255, 138, 61, .45);
  outline-offset: 3px;
}

@media (max-height: 600px) {
  .ov-face { width: 70px; height: 70px; margin-top: -48px; }
  .ov-face svg { width: 56px; height: 56px; }
  #finalScore { font-size: 42px; }
  .ov-best { margin-bottom: 13px; }
  .btn { height: 50px; }
}

@media (prefers-reduced-motion: reduce) {
  .hud, .hint .ico-swipe, .pill .num.pop { animation: none; }
  .overlay, .panel, .hint { transition-duration: .01s; }
}
