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

html, body {
  height: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, #ffe9f0, #fff6e5);
  font-family: 'Hiragino Maru Gothic ProN', 'ヒラギノ丸ゴ ProN', 'BIZ UDGothic', sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

/* ---- HUD ---- */
#hud {
  width: min(100vw, 520px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px 6px;
  font-weight: bold;
  color: #7a5230;
}
#hud-left { flex: 1; }
.hud-label { font-size: 16px; }
#bar {
  margin-top: 4px;
  height: 14px;
  background: #e8d7c5;
  border-radius: 7px;
  overflow: hidden;
}
#bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffd54f, #4fc3f7, #66eea0);
  border-radius: 7px;
  transition: width 0.25s;
}
#hud-right { font-size: 18px; white-space: nowrap; }

/* ---- ステージ ---- */
#stage {
  position: relative;
  width: min(100vw - 8px, calc((100dvh - 178px) * 0.75), 520px);
  aspect-ratio: 3 / 4;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 6px 24px rgba(120, 80, 40, 0.25);
  touch-action: none;
}
#stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#dirtLight, #dirtHard { transition: opacity 0.5s; }
#fx { pointer-events: none; }

#hint-ring {
  position: absolute;
  width: 90px;
  height: 90px;
  margin: -45px 0 0 -45px;
  border: 5px solid #fff176;
  border-radius: 50%;
  pointer-events: none;
  animation: hintPulse 0.9s infinite;
  box-shadow: 0 0 14px rgba(255, 241, 118, 0.9);
}
@keyframes hintPulse {
  0%   { transform: scale(0.7); opacity: 1; }
  100% { transform: scale(1.25); opacity: 0; }
}

#msg {
  margin-top: 8px;
  font-size: 17px;
  font-weight: bold;
  color: #a06a3a;
  transition: opacity 0.6s;
}

/* ---- ステージえらび ---- */
#stage-bar {
  display: flex;
  gap: 12px;
  margin-top: 6px;
}
#stage-bar button {
  font-family: inherit;
  font-size: 24px;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(120, 80, 40, 0.25);
  cursor: pointer;
}
#stage-bar button.active {
  outline: 3px solid #ffb300;
  transform: scale(1.1);
}
#stage-bar button:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ---- ぴっかーん演出 ---- */
#flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 40;
}
#flash.on { animation: flashAnim 0.7s ease-out; }
@keyframes flashAnim {
  0% { opacity: 0; }
  15% { opacity: 1; }
  100% { opacity: 0; }
}

#boom-word {
  position: fixed;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.2);
  font-size: min(15vw, 78px);
  font-weight: 900;
  color: #ffb300;
  -webkit-text-stroke: 3px #fff;
  text-shadow: 0 4px 0 #e65100, 0 0 30px #fff59d;
  z-index: 50;
  pointer-events: none;
  white-space: nowrap;
}
#boom-word.on { animation: boomWord 1.2s ease-out forwards; }
@keyframes boomWord {
  0%   { transform: translate(-50%, -50%) scale(0.2); opacity: 0; }
  25%  { transform: translate(-50%, -50%) scale(1.25); opacity: 1; }
  40%  { transform: translate(-50%, -50%) scale(1.0); }
  85%  { transform: translate(-50%, -50%) scale(1.05); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.1); opacity: 0; }
}

body.shake #stage { animation: stageShake 0.5s; }
@keyframes stageShake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-8px, 5px); }
  40% { transform: translate(7px, -6px); }
  60% { transform: translate(-6px, 4px); }
  80% { transform: translate(5px, -3px); }
}

/* ---- クリア画面 ---- */
#clear-screen {
  position: fixed;
  inset: 0;
  background: rgba(255, 250, 235, 0.96);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  text-align: center;
}
#clear-title { font-size: 24px; font-weight: 900; color: #ef6c00; }
#clear-time { font-size: 34px; font-weight: 900; color: #5d4037; }
#clear-best { font-size: 17px; font-weight: bold; color: #43a047; min-height: 22px; }
#ba {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ba-box {
  background: #fff;
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 3px 12px rgba(120, 80, 40, 0.2);
}
.ba-label { font-weight: bold; color: #8d6e63; margin-bottom: 4px; }
.ba-box canvas {
  width: min(34vw, 150px);
  height: auto;
  border-radius: 8px;
  display: block;
}
.ba-arrow { font-size: 26px; }
#next {
  margin-top: 8px;
  font-family: inherit;
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(180deg, #81c784, #43a047);
  border: none;
  border-radius: 999px;
  padding: 14px 36px;
  box-shadow: 0 4px 0 #2e7031;
  cursor: pointer;
}
#next:active { transform: translateY(3px); box-shadow: 0 1px 0 #2e7031; }

#retry {
  margin-top: 2px;
  font-family: inherit;
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(180deg, #ffb74d, #f57c00);
  border: none;
  border-radius: 999px;
  padding: 14px 36px;
  box-shadow: 0 4px 0 #bf5f00;
  cursor: pointer;
}
#retry:active { transform: translateY(3px); box-shadow: 0 1px 0 #bf5f00; }

.hidden { display: none !important; }
