:root{
  --brown:#d4a373;
  --brown-dk:#ab8361;
  --blue:#7a9ab5;
  --blue-dk:#4a6a85;
  --green:#8ab5a0;
  --green-dk:#5a8a75;
  --bg:#fafaf8;
  --sky:#8ecfee;
  --grass:#95d976;
  --dirt:#a67026;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  margin: 0; padding: 8px 12px 10px; background: var(--bg);
  font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  display: flex; flex-direction: column; align-items: center;
  touch-action: none;
}
.header {
  position: relative;
  width: 100%; max-width: 500px; display: flex; justify-content: space-between; align-items: center;
  color: var(--brown-dk); font-size: 1.05rem; font-weight: bold; padding: 6px 4px 10px;
}
.hp-outer {
  width: 130px; height: 16px; background: #f2e9d8; border-radius: 8px; overflow: hidden;
  border: 2px solid var(--brown-dk); flex-shrink: 0;
}
.hp-inner {
  height: 100%; width: 0%;
  background: #f0ac6c;
  transition: width 0.25s ease;
}
.score-delta {
  position: absolute; right: 4px; top: 2px;
  font-size: 0.95rem; font-weight: bold;
  opacity: 0; transform: translateY(0);
  transition: opacity 0.5s ease, transform 0.5s ease;
  pointer-events: none;
}
.score-delta.show { opacity: 1; transform: translateY(-16px); }
.loading-msg {
  font-size: 1.1rem; color: var(--brown-dk); padding: 60px 0; text-align: center;
  width: 100%; max-width: 500px;
}
#canvasWrap {
  position: relative; border-radius: 12px 12px 3px 3px; overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15); display: none;
}
#gameCanvas { display: block; }
.speaker-indicator {
  position: absolute; top: 10px; right: 10px; z-index: 50;
  width: 34px; height: 34px;
  color: var(--blue);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem;
}
.speaker-indicator .wave {
  position: absolute; top: 50%; left: 50%; width: 34px; height: 34px;
  margin: -17px 0 0 -17px; border-radius: 50%; border: 2px solid var(--blue);
  opacity: 0; pointer-events: none;
}
.speaker-indicator.playing .wave1 { animation: speakerWave 1s ease-out; }
.speaker-indicator.playing .wave2 { animation: speakerWave 1s ease-out 0.25s; }
@keyframes speakerWave {
  0% { transform: scale(0.6); opacity: 0.6; }
  100% { transform: scale(1.9); opacity: 0; }
}
.interval-btn {
  position: absolute; top: 10px; right: 50px; z-index: 50;
  min-width: 34px; height: 34px; padding: 0 4px;
  border: none; background: none;
  color: var(--blue); display: flex; align-items: center; gap: 6px;
  font-size: 1.2rem; font-weight: bold;
}
.interval-icon { width: 24px; height: 24px; }
.interval-hint { font-size: 0.85rem; color: var(--brown-dk); margin: -6px 0 16px; }
.interval-adjust {
  display: flex; align-items: center; justify-content: center; gap: 24px;
  margin-bottom: 16px;
}
.interval-step-btn {
  width: 54px; height: 54px; border-radius: 50%; border: none;
  background: var(--blue); color: #fff; font-size: 1.8rem; font-weight: bold;
}
.interval-step-btn:disabled { background: #d8cfc2; color: #fff; }
.interval-value { font-size: 2.2rem; font-weight: bold; color: var(--brown-dk); min-width: 50px; }
#controls {
  width: 100%; max-width: 500px; display: none;
  justify-content: space-between; align-items: center;
  padding: 14px 18px 10px;
}
#controls.show { display: flex; }
.move-btns { display: flex; gap: 16px; }
.ctrl-btn {
  border: none; border-radius: 50%; color: #fff; font-size: 1.4rem;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.1s ease, filter 0.1s ease;position: relative;
}
.ctrl-btn.is-active { transform: scale(0.98); filter: brightness(0.9); }
.move-btn { width: 54px; height: 54px; background: var(--blue); top: 10px;}
.jump-btn { width: 66px; height: 66px; background: var(--green); font-size: 1rem; font-weight: bold; top: 10px;}
.jump-btn::after {
  content: '';
  position: absolute;
  top: -12px; left: -12px; right: -12px; bottom: -12px;
}


#msgBox {
  position: fixed; left: 50%; top: 40%; transform: translate(-50%,-50%);
  background: rgba(0,0,0,0.6); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 1.05rem; opacity: 0; pointer-events: none; transition: opacity 0.15s; z-index: 600;
  max-width: 85%; text-align: center;
}
.bottom-btns {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%);
  display: flex; gap: 10px; width: 100%; max-width: 500px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg); z-index: 100;
}
.bottom-btns button {
  flex: 1; padding: 10px 0; border: none; border-radius: 10px;
  background: #eee2d0; color: var(--brown-dk); font-size: 0.9rem; font-weight: bold;
  transition: transform 0.1s ease, background 0.1s ease;
}
.bottom-btns button.reset-btn { background: var(--blue); color: #fff; }
.bottom-btns button.listen-btn { background: var(--green); color: #fff; }
.bottom-btns button.is-active { transform: scale(0.97); }
.finish-score { font-size: 2rem; font-weight: bold; color: #d85a30; margin-bottom: 6px; }
.finish-sub { color: var(--brown-dk); font-size: 0.85rem; margin-bottom: 16px; }
.stamp-overlay {
  display: flex; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.3); z-index: 999; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 0.15s ease, visibility 0.15s ease;
}
.stamp-overlay.show { opacity: 1; visibility: visible; pointer-events: auto; }
.finish-box {
  background: #fff; border-radius: 16px; padding: 32px 26px; text-align: center;
  width: 85%; max-width: 320px;
  max-height: 80vh; overflow-y: auto; /* 內容太長時框內自己捲動，不會撐爆整個畫面、
                                          把關閉按鈕擠到螢幕外面碰不到 */
}
.finish-emoji { font-size: 2.75rem; margin-bottom: 8px; }
.finish-title { font-size: 1.125rem; font-weight: bold; color: var(--brown-dk); margin-bottom: 6px; }
.help-title { font-size: 1.3rem; margin-bottom: 16px; }
.help-text {
  text-align: left; color: #777; font-size: 1.1rem; line-height: 33px;
  margin-bottom: 16px;
}
.help-text p { margin: 0 0 12px; }
.help-text p:last-child { margin-bottom: 0; }
.help-box {
  width: 88vw; max-width: 460px; height: 70vh; max-height: 70vh;
  display: flex; flex-direction: column; padding: 24px 24px;
}
.help-scroll-area {
  flex: 1;
  overflow-y: auto;
  margin: 0 0 16px;
}
.finish-btn {
  display: block; width: 100%; padding: 12px 0; margin-bottom: 10px; border: none;
  border-radius: 10px; background: var(--green); color: #fff; font-size: 1rem; font-weight: bold;
}
.header-status { display: flex; gap: 8px; align-items: center; }

.finish-btn-secondary {
    display: block; width: 100%; padding: 12px 0; margin-bottom: 10px; border: none;
    border-radius: 10px; background: #eee2d0; color: var(--brown-dk); font-size: 1rem; font-weight: bold;
  }
  .finish-btn-secondary:last-child { margin-bottom: 0; }
