:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  --ink: #34444b;
  --coral: #ed5b78;
  --coral-dark: #b73755;
  --cream: #ffffff;
  --mint: #42a9c7;
  --yellow: #ffd45c;
}

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #c8eefa;
  color: var(--ink);
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
}

button {
  font: inherit;
}

#game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  isolation: isolate;
}

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

.hud {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 0;
  width: 100%;
  min-height: 96px;
  padding: max(24px, env(safe-area-inset-top)) 20px 10px;
  display: grid;
  grid-template-columns: 1fr;
  align-items: start;
  pointer-events: none;
}

.stat {
  display: grid;
  align-content: start;
  justify-items: center;
  min-width: 64px;
  text-shadow: 0 1px 8px rgba(255, 252, 237, 0.75);
}

.stat-right {
  display: none;
}

.stat-label {
  display: none;
  color: rgba(255, 255, 255, 0.86);
  font-size: 11px;
  font-weight: 700;
}

.stat strong {
  color: #ffffff;
  font-size: 52px;
  line-height: 1;
  -webkit-text-stroke: 2px rgba(49, 70, 80, 0.72);
  text-shadow: 0 3px 0 rgba(49, 70, 80, 0.32);
  font-variant-numeric: tabular-nums;
}

.brand-mark {
  display: none;
  align-items: center;
  gap: 6px;
  padding-top: 3px;
  font-size: 15px;
  font-weight: 900;
  color: #432f31;
}

.brand-crown {
  position: relative;
  width: 19px;
  height: 14px;
  border-radius: 3px 3px 6px 6px;
  background: linear-gradient(180deg, #f1d087, #b97b2f);
  clip-path: polygon(0 25%, 27% 58%, 50% 0, 73% 58%, 100% 25%, 87% 100%, 13% 100%);
}

.screen {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(max(24px, env(safe-area-inset-top)) + 48px) 24px calc(max(28px, env(safe-area-inset-bottom)) + 24px);
}

.screen[hidden] {
  display: none;
}

.screen-start {
  justify-content: space-between;
  padding-top: max(18vh, 126px);
  background: rgba(142, 216, 244, 0.18);
}

.title-lockup {
  display: grid;
  justify-items: center;
  text-align: center;
  filter: drop-shadow(0 2px 10px rgba(255, 248, 223, 0.8));
}

.title-lockup h1 {
  margin: 12px 0 6px;
  color: #34444b;
  font-size: clamp(34px, 10vw, 50px);
  line-height: 1.05;
  letter-spacing: 0;
}

.title-lockup p {
  margin: 0;
  color: #4d6771;
  font-size: 15px;
  font-weight: 700;
}

.mini-cake {
  display: grid;
  gap: 2px;
  justify-items: center;
  width: 74px;
  height: 54px;
  align-content: end;
}

.mini-cake i {
  display: block;
  height: 13px;
  border-radius: 6px 6px 3px 3px;
  border: 1px solid rgba(62, 31, 35, 0.34);
  border-bottom-width: 3px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.38), 0 3px 7px rgba(49, 27, 29, 0.16);
}

.mini-cake i:nth-child(1) {
  width: 37px;
  background: #d9a955;
}

.mini-cake i:nth-child(2) {
  width: 54px;
  background: #287e76;
}

.mini-cake i:nth-child(3) {
  width: 70px;
  background: #a92f45;
}

.primary-button {
  min-width: 176px;
  min-height: 54px;
  padding: 0 28px;
  border: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  border: 3px solid #8d6333;
  background: linear-gradient(180deg, #fff2a0, #f3d76c);
  color: #e44f68;
  box-shadow: 0 5px 0 #9b6c34, 0 12px 26px rgba(55, 79, 88, 0.22), inset 0 2px 0 rgba(255,255,255,0.65);
  font-size: 28px;
  font-weight: 900;
  cursor: pointer;
  transform: translateY(-6px);
}

.primary-button:active {
  transform: translateY(0);
  box-shadow: 0 1px 0 var(--coral-dark), 0 7px 14px rgba(101, 56, 68, 0.18);
}

.primary-button:focus-visible {
  outline: 4px solid rgba(255, 209, 102, 0.85);
  outline-offset: 4px;
}

.play-icon {
  display: none;
}

.retry-icon {
  width: 16px;
  height: 16px;
  border: 3px solid white;
  border-left-color: transparent;
  border-radius: 50%;
  position: relative;
}

.retry-icon::after {
  content: "";
  position: absolute;
  left: -5px;
  top: -3px;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-right: 6px solid white;
  transform: rotate(24deg);
}

.screen-over {
  background: rgba(35, 24, 25, 0.52);
  backdrop-filter: blur(7px) saturate(0.85);
}

.result-panel {
  width: min(100%, 320px);
  padding: 28px 24px 26px;
  border: 1px solid rgba(112, 76, 51, 0.28);
  border-radius: 8px;
  display: grid;
  justify-items: center;
  background: rgba(255, 248, 231, 0.97);
  box-shadow: 0 20px 60px rgba(31, 19, 19, 0.42);
  text-align: center;
}

.result-label {
  font-size: 14px;
  color: #86636c;
  font-weight: 800;
}

.result-score {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin: 2px 0;
}

.result-score strong {
  color: #d94f5c;
  font-size: 72px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.result-score span {
  font-size: 20px;
  font-weight: 900;
}

.result-panel p {
  margin: 5px 0 14px;
  color: #765961;
  font-size: 15px;
  font-weight: 700;
}

.result-panel .result-player-id {
  margin: 0 0 24px;
  color: #86636c;
  font-size: 13px;
}

.result-player-id strong {
  color: #4d4145;
  font-variant-numeric: tabular-nums;
}

.perfect-toast {
  position: absolute;
  z-index: 4;
  top: 29%;
  left: 50%;
  color: #fff4b5;
  filter: drop-shadow(0 3px 0 #9b5c28) drop-shadow(0 7px 12px rgba(63, 39, 30, 0.34));
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  text-shadow: 0 0 12px rgba(255, 211, 78, 0.72);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px) scale(0.84);
}

.perfect-toast.show {
  animation: toast-pop 750ms ease-out;
}

.game-player-id {
  position: absolute;
  z-index: 4;
  left: max(10px, env(safe-area-inset-left));
  bottom: max(8px, env(safe-area-inset-bottom));
  color: rgba(52, 68, 75, 0.48);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes toast-pop {
  0% { opacity: 0; transform: translate(-50%, 14px) scale(0.56); }
  18% { opacity: 1; transform: translate(-50%, -2px) scale(1.14); }
  34% { opacity: 1; transform: translate(-50%, 0) scale(0.98); }
  72% { opacity: 1; transform: translate(-50%, -4px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -22px) scale(0.94); }
}

@media (min-width: 680px) {
  body {
    display: grid;
    place-items: center;
    background: #c8eefa;
  }

  #game-shell {
    width: min(100vw, 540px);
    height: min(100dvh, 960px);
    box-shadow: 0 0 70px rgba(57, 42, 39, 0.28);
  }
}

@media (max-height: 620px) {
  .screen-start {
    padding-top: 105px;
  }

  .title-lockup h1 {
    font-size: 34px;
  }

  .mini-cake {
    transform: scale(0.82);
  }
}

@media (prefers-reduced-motion: reduce) {
  .perfect-toast.show {
    animation-duration: 1ms;
  }
}
