* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior-y: none; /* Idle refresh is handled by the game. */
  background: #ffeef6;
  font-family: "PingFang TC", "Microsoft JhengHei", "Nunito", system-ui, -apple-system, sans-serif;
  touch-action: manipulation;
}

#game-wrapper {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  background: linear-gradient(180deg, #ffd6ea 0%, #fff4fa 65%, #e6f4ff 100%);
}

/* Fill the installed app viewport, including the iOS home-indicator area. */
@media (display-mode: standalone) {
  html { background: linear-gradient(#ffeef6 75%, #f591a9 75%); }
  body { background: transparent; }
  #game-wrapper:not([hidden]) { position: fixed; inset: 0; width: auto; height: auto; }
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none; /* 手機點擊遊戲畫面立即跳躍 */
}

/* HUD 頂部資訊列 */
#hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 20;
  pointer-events: none;
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.badge-title {
  background: rgba(255, 255, 255, 0.85);
  border: 2px solid #ff7eb9;
  color: #d62872;
  font-weight: 800;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: 0 3px 0 #ff9ecb;
}

.icon-btn {
  background: #ffffff;
  border: 2px solid #1d5cff;
  color: #1d5cff;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 3px 0 #1d5cff;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

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

.score-box {
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid #ff9ecb;
  padding: 5px 12px;
  border-radius: 12px;
  font-family: "Courier New", monospace;
  font-weight: 900;
  font-size: 16px;
  color: #9e5c7c;
  display: flex;
  gap: 6px;
  align-items: center;
}

.score-box.current {
  border-color: #1d5cff;
  color: #1d5cff;
}

.score-box .label {
  font-size: 11px;
  opacity: 0.8;
}

/* UI 面板 */
.ui-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 30;
  pointer-events: none;
}

.panel {
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.94);
  border: 4px solid #ff66ad;
  border-radius: 28px;
  padding: 26px 34px;
  text-align: center;
  max-width: 90vw;
  box-shadow: 0 10px 0 #ff9ecb, 0 18px 30px rgba(214, 40, 114, 0.2);
}

.panel.hidden {
  display: none;
}

.panel h1 {
  color: #e0217b;
  font-size: clamp(22px, 4vw, 34px);
  margin-bottom: 8px;
  text-shadow: 2px 2px 0 #ffd1e6;
}

.subtitle {
  color: #6b4c5b;
  font-size: clamp(13px, 2vw, 16px);
  margin-bottom: 16px;
}

.controls-hint {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #fff3f8;
  border: 2px dashed #ff9ecb;
  border-radius: 16px;
  padding: 10px 16px;
  margin-bottom: 20px;
  font-size: 13px;
  color: #553b47;
}

.gameover-title {
  color: #e0217b;
  font-size: 28px;
  margin-bottom: 10px;
}

.final-score-text {
  font-size: 20px;
  font-weight: 800;
  color: #1d5cff;
  margin-bottom: 8px;
}

.new-record {
  display: inline-block;
  background: #ffd426;
  color: #b81d48;
  font-weight: 800;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  margin-bottom: 14px;
}

.new-record.hidden {
  display: none;
}

.btn-primary {
  background: linear-gradient(180deg, #ff5ca8 0%, #e0217b 100%);
  color: #fff;
  border: 3px solid #ffffff;
  outline: 3px solid #e0217b;
  font-size: 18px;
  font-weight: 800;
  padding: 12px 32px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 6px 0 #a81057;
  transition: transform 0.1s;
}

.btn-primary:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #a81057;
}

.pulse {
  animation: pulseAnim 1.5s infinite;
}

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

/* 手機橫向提示遮罩 */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 224, 240, 0.96);
  z-index: 999;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.overlay.hidden {
  display: none;
}

.rotate-card {
  background: #fff;
  border: 4px solid #1d5cff;
  border-radius: 24px;
  padding: 28px;
  text-align: center;
  box-shadow: 0 8px 0 #1d5cff;
}

.phone-icon {
  font-size: 48px;
  margin-bottom: 12px;
  display: inline-block;
  animation: rotatePhone 1.8s ease-in-out infinite;
}

@keyframes rotatePhone {
  0%, 20% { transform: rotate(0deg); }
  50%, 80% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}

.rotate-card h2 {
  color: #1d5cff;
  margin-bottom: 8px;
}

.rotate-card p {
  color: #555;
  margin-bottom: 18px;
  font-size: 14px;
}

@media (max-height: 460px) {
  .badge-title {
    display: none;
  }
  .panel {
    padding: 16px 24px;
  }
  .controls-hint {
    margin-bottom: 12px;
    padding: 6px 12px;
  }
}

/* Pinky Jump — simple modern child-friendly UI */
.badge-title{display:inline-flex;align-items:center;gap:7px;border-color:#f7a6cb;background:rgba(255,255,255,.87);color:#b82467;box-shadow:0 3px 0 #ffd1e6}
.badge-title img{width:24px;height:24px;border-radius:6px}
.icon-btn{border-color:#da9dc4;color:#a02f6a;box-shadow:0 3px 0 #d6a5c1}
.score-box.current{border-color:#f48ab7;color:#bb326c}
.start-mascot{width:80px;height:80px;border-radius:19px;object-fit:cover;margin:0 auto 9px;display:block}
.panel{max-height:calc(100dvh - 75px);overflow:auto;border:3px solid #f790bc;box-shadow:0 7px 0 #ffc0d8,0 12px 26px rgba(173,50,115,.17)}
.panel h1{color:#be3471;text-shadow:none}
.btn-primary{background:linear-gradient(180deg,#ff84b6,#e35395);outline-color:#e35395;box-shadow:0 5px 0 #af376e}
@media(max-width:600px){#hud{top:max(6px,env(safe-area-inset-top));left:7px;right:7px;gap:3px}.hud-left,.hud-right{gap:4px}.badge-title{padding:4px 7px;font-size:11px}.badge-title img{width:19px;height:19px}.icon-btn{padding:4px 6px;font-size:11px}.score-box{padding:4px 6px;font-size:12px;gap:3px}.score-box .label{font-size:9px}.panel{padding:14px 19px}.controls-hint{padding:8px;font-size:11px}}

/* Installation button: keep game score controls usable on small phones. */
@media (max-width:600px) {
  #hud .badge-title { display:none !important; }
  #hud .hud-left, #hud .hud-right { gap:3px; }
}

#game-wrapper[hidden] { display: none; }

/* Shield icon bounce when a shield is used up. */
.shield-box.shield-hit { animation: shield-hit .6s ease-out; }
@keyframes shield-hit {
  0% { transform: scale(1); }
  20% { transform: scale(1.45) rotate(-8deg); background: #ff6b9d; color: #fff; }
  45% { transform: scale(.9) rotate(6deg); }
  70% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* Heart slots (replaces the shield counter). */
#shield-hearts { display: inline-flex; gap: 2px; font-family: system-ui, sans-serif; line-height: 1; }
#shield-hearts i { font-style: normal; color: #f2a9c8; font-size: 18px; }
#shield-hearts i.on { color: #ff2d6f; }
/* Same height as the neighbouring HUD boxes. */
.score-box.shield-box { display: inline-flex; align-items: center; }
@media (max-width: 900px) { #shield-hearts i { font-size: 15px; } #shield-hearts { gap: 0; } }
.score-box { white-space: nowrap; }

/* 手機橫向（矮螢幕）：面板不出捲軸、不蓋住上方 HUD */
@media (orientation: landscape) and (max-height: 500px) {
  .ui-overlay { padding: 50px 12px 8px; box-sizing: border-box; }
  .panel { max-height: calc(100dvh - 60px); padding: 10px 22px 14px; border-radius: 22px; }
  #start-panel h1 { margin: 0; font-size: 26px; }
  #start-panel .subtitle { margin: 6px 0 8px; font-size: 13px; }
  #start-panel .controls-hint { margin: 0 0 10px; padding: 5px 12px; font-size: 12px; }
  .pinky-pick-panel .btn-primary { padding-top: 8px; padding-bottom: 8px; }
}

.shield-box{touch-action:none;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent}

/* ===== 選角舞台（開始＋死亡畫面）：角色大、無外框、站在影子上 ===== */
.pinky-pick-panel:not(.hidden) { display: flex; flex-direction: column; align-items: center; }
.pinky-pick-panel .pinky-panel-info { display: contents; }
.pinky-pick-panel .pinky-panel-info > * { max-width: 100%; }
#gameover-panel .gameover-title { order: -3; }
#gameover-panel .final-score-text { order: -2; }
#gameover-panel .new-record { order: -1; }
.pinky-char-pick { display: grid; justify-items: center; margin: 0 auto 4px; }
.pinky-char-stage { display: flex; align-items: center; gap: 6px; }
.pinky-char-figure { padding: 0; border: 0; background: none; cursor: pointer; touch-action: pan-y; -webkit-tap-highlight-color: transparent; border-radius: 24px; }
.pinky-char-figure canvas { display: block; width: clamp(120px, 26dvh, 200px); height: clamp(120px, 26dvh, 200px); }
.pinky-char-figure:focus-visible { outline: 3px solid #e35395; outline-offset: 2px; }
.pinky-char-arrow {
  flex: none; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%;
  background: rgba(255,255,255,.85); color: #bc317a; font-size: 18px; line-height: 1; cursor: pointer;
  box-shadow: 0 2px 6px rgba(173,50,115,.22); -webkit-tap-highlight-color: transparent;
}
.pinky-char-arrow:active { transform: scale(.92); }
.pinky-char-name { margin: 0; font-size: 22px; font-weight: 900; line-height: 1.15; }
.pinky-char-dots { display: flex; gap: 6px; justify-content: center; min-height: 8px; margin: 5px 0 8px; }
.pinky-char-dots i { width: 8px; height: 8px; border-radius: 50%; background: #f7c3dc; }
.pinky-char-dots i.on { background: #bc317a; }
.pinky-char-dialog { text-align: center; }
.pinky-char-dialog canvas { display: block; width: 150px; height: 150px; margin: 0 auto; }
/* 橫向：角色在左、文字與按鈕在右 */
@media (orientation: landscape) {
  .pinky-pick-panel:not(.hidden) { flex-direction: row; justify-content: center; gap: 14px; text-align: center; }
  .pinky-pick-panel .pinky-panel-info { display: flex; flex-direction: column; align-items: center; min-width: 0; flex: 1 1 auto; }
  .pinky-pick-panel .pinky-char-pick { flex: none; margin: 0; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .pinky-char-figure canvas { width: clamp(96px, 34dvh, 140px); height: clamp(96px, 34dvh, 140px); }
  .pinky-char-name { font-size: 18px; }
  .pinky-char-dots { margin: 3px 0 0; }
  .pinky-char-arrow { width: 38px; height: 38px; font-size: 15px; }
}
/* 手機橫向：角色說明卡改左右排（角色在左、文字在右），不用捲動 */
@media (orientation: landscape) and (max-height: 500px) {
  .pinky-char-dialog[open] {
    display: grid; grid-template-columns: 130px 1fr; grid-template-areas: "pic title" "pic desc" "pic hint" "pic act";
    align-items: center; column-gap: 16px; text-align: left; width: min(560px, calc(100vw - 32px)); padding: 14px 18px;
  }
  .pinky-char-dialog h2 { grid-area: title; margin: 0 0 4px; }
  .pinky-char-dialog canvas { grid-area: pic; width: 130px; height: 130px; }
  .pinky-char-dialog #pinky-char-desc { grid-area: desc; margin-bottom: 6px; }
  .pinky-char-dialog .pinky-install-hint { grid-area: hint; margin-bottom: 0; }
  .pinky-char-dialog .pinky-install-actions { grid-area: act; margin-top: 8px; }
}
