:root {
  --ink: #27160f;
  --paper: #fffaf0;
  --red: #d6452f;
  --gold: #f5bc35;
  --teal: #147d79;
  --shadow: 0 16px 32px rgba(37, 18, 6, 0.22);
}

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

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: var(--ink);
  background: #251206;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: manipulation;
  user-select: none;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.game-shell {
  display: grid;
  width: 100vw;
  height: 100dvh;
  min-height: 520px;
  place-items: center;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

.stage {
  position: relative;
  width: min(100%, 480px);
  height: 100%;
  max-height: 920px;
  overflow: hidden;
  border: 3px solid rgba(255, 250, 240, 0.72);
  border-radius: 24px;
  background: #f3dcc1 url("./assets/background.png") center / cover no-repeat;
  box-shadow: var(--shadow);
  isolation: isolate;
}

.stage::after {
  position: absolute;
  inset: 0;
  z-index: -1;
  content: "";
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(52, 22, 8, 0.18)),
    linear-gradient(0deg, rgba(255, 244, 214, 0.38), transparent 42%);
}

.stage.fever {
  animation: feverGlow 900ms ease-in-out infinite alternate;
}

.stage.fever::after {
  background:
    radial-gradient(circle at 50% 38%, rgba(255, 241, 138, 0.38), transparent 38%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(214, 69, 47, 0.18)),
    linear-gradient(0deg, rgba(255, 244, 214, 0.46), transparent 42%);
}

.stage.danger-flash {
  animation: dangerFlash 220ms ease-out;
}

.hud {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.hud-item,
.timing-panel,
.result-box {
  border: 2px solid rgba(255, 255, 255, 0.78);
  background: rgba(255, 250, 240, 0.88);
  box-shadow: 0 8px 20px rgba(55, 25, 8, 0.18);
  backdrop-filter: blur(8px);
}

.hud-item {
  min-width: 0;
  border-radius: 8px;
  padding: 8px 6px;
  text-align: center;
}

.hud-item span {
  display: block;
  color: #7d392b;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
}

.hud-item strong {
  display: block;
  min-height: 24px;
  margin-top: 3px;
  font-size: 21px;
  font-weight: 950;
  line-height: 1.05;
}

.fever-badge {
  position: absolute;
  top: 76px;
  left: 50%;
  z-index: 7;
  min-width: 118px;
  padding: 7px 12px;
  border: 2px solid #fffaf0;
  border-radius: 999px;
  color: #27160f;
  background: linear-gradient(180deg, #fff7b5, var(--gold));
  box-shadow: 0 7px 0 #b45718, 0 16px 24px rgba(39, 22, 15, 0.25);
  font-size: 14px;
  font-weight: 950;
  line-height: 1;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, -12px) scale(0.86);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.fever-badge.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.playfield {
  position: absolute;
  inset: 72px 0 172px;
  overflow: hidden;
}

.hero {
  position: absolute;
  right: clamp(-28px, -6vw, -8px);
  bottom: clamp(28px, 6vh, 58px);
  z-index: 3;
  width: min(70%, 320px);
  aspect-ratio: 362 / 724;
  background: url("./assets/oni-swing-sheet.png") 0 50% / 600% 100% no-repeat;
  filter: drop-shadow(0 16px 18px rgba(39, 22, 15, 0.25));
  transform-origin: 48% 82%;
  will-change: transform;
}

.speech {
  position: absolute;
  right: clamp(88px, 28vw, 145px);
  bottom: clamp(260px, 48vh, 410px);
  z-index: 8;
  max-width: min(58%, 230px);
  padding: 9px 12px;
  border: 2px solid rgba(39, 22, 15, 0.82);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.94);
  box-shadow: 0 8px 18px rgba(39, 22, 15, 0.18);
  font-size: 15px;
  font-weight: 950;
  line-height: 1.2;
  opacity: 0;
  transform: translateY(6px) scale(0.96);
  transition: opacity 160ms ease, transform 160ms ease;
}

.speech::after {
  position: absolute;
  right: 20px;
  bottom: -9px;
  width: 14px;
  height: 14px;
  border-right: 2px solid rgba(39, 22, 15, 0.82);
  border-bottom: 2px solid rgba(39, 22, 15, 0.82);
  background: rgba(255, 250, 240, 0.94);
  content: "";
  transform: rotate(45deg);
}

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

.hero.swing {
  filter: drop-shadow(0 16px 18px rgba(39, 22, 15, 0.25)) brightness(1.06);
}

.mortar-wrap {
  position: absolute;
  left: clamp(-2px, 2vw, 14px);
  bottom: 0;
  z-index: 2;
  width: min(66%, 292px);
  aspect-ratio: 1 / 1;
  transform-origin: 50% 82%;
}

.mortar-wrap.bump {
  animation: bump 160ms ease-out;
}

.usu {
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 0;
  z-index: 3;
  width: 92%;
  filter: drop-shadow(0 14px 14px rgba(39, 22, 15, 0.28));
}

.mochi {
  position: absolute;
  left: 30%;
  bottom: 50%;
  z-index: 4;
  width: 40%;
  transform-origin: 50% 72%;
  filter: drop-shadow(0 5px 5px rgba(39, 22, 15, 0.16));
}

.mochi.squash {
  animation: squash 180ms ease-out;
}

.impact {
  position: absolute;
  left: 12%;
  bottom: 46%;
  z-index: 5;
  width: 76%;
  opacity: 0;
  transform: scale(0.6);
  pointer-events: none;
}

.impact.show {
  animation: impact 280ms ease-out;
}

.water-splash {
  position: absolute;
  left: 30%;
  bottom: 53%;
  z-index: 6;
  width: 40%;
  aspect-ratio: 1 / 0.72;
  opacity: 0;
  pointer-events: none;
}

.water-splash::before,
.water-splash::after {
  position: absolute;
  inset: 0;
  content: "";
  background:
    radial-gradient(circle at 22% 56%, rgba(145, 230, 255, 0.95) 0 7%, transparent 8%),
    radial-gradient(circle at 42% 28%, rgba(145, 230, 255, 0.92) 0 8%, transparent 9%),
    radial-gradient(circle at 62% 50%, rgba(145, 230, 255, 0.9) 0 6%, transparent 7%),
    radial-gradient(circle at 78% 22%, rgba(255, 255, 255, 0.94) 0 5%, transparent 6%),
    radial-gradient(ellipse at 50% 72%, rgba(80, 190, 230, 0.72) 0 34%, transparent 36%);
}

.water-splash::after {
  filter: blur(2px);
  opacity: 0.75;
}

.water-splash.show {
  animation: waterSplash 520ms ease-out;
}

.float-text {
  position: absolute;
  left: 30%;
  bottom: 49%;
  z-index: 6;
  min-width: 120px;
  color: #fffaf0;
  font-size: 28px;
  font-weight: 950;
  line-height: 1;
  text-align: center;
  text-shadow: 0 3px 0 #7c2118, 0 8px 16px rgba(39, 22, 15, 0.3);
  opacity: 0;
  transform: translate(-50%, 10px) scale(0.88);
}

.float-text.show {
  animation: floatScore 700ms ease-out;
}

.timing-panel {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 98px;
  z-index: 6;
  border-radius: 8px;
  padding: 9px 10px 11px;
}

.timing-labels {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 7px;
  color: #7d392b;
  font-size: 10px;
  font-weight: 900;
}

.timing-labels strong {
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0;
}

.timing-labels span:last-child {
  text-align: right;
}

.timing-bar {
  position: relative;
  height: 18px;
  overflow: hidden;
  border: 2px solid rgba(39, 22, 15, 0.74);
  border-radius: 999px;
  background: linear-gradient(90deg, #d6452f, #f5bc35 30%, #79d7e8 50%, #f5bc35 70%, #d6452f);
}

.zone {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}

.zone.ok {
  width: 34%;
  background: rgba(255, 250, 240, 0.3);
}

.zone.perfect {
  width: 13%;
  background: rgba(255, 255, 255, 0.88);
}

.needle {
  position: absolute;
  top: -5px;
  left: 0;
  width: 7px;
  height: 28px;
  border-radius: 999px;
  background: var(--ink);
  box-shadow: 0 0 0 2px #fffaf0;
  transform: translateX(-50%);
}

.hit-button,
.start-button {
  border-radius: 8px;
  color: #fffaf0;
  font-weight: 950;
  box-shadow: 0 10px 0 #8d2218, 0 18px 28px rgba(39, 22, 15, 0.32);
}

.hit-button {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 18px;
  z-index: 6;
  min-height: 66px;
  background: linear-gradient(180deg, #34c6dc, var(--teal));
  font-size: 28px;
}

.hit-button:active,
.hit-button.pressed {
  transform: translateY(6px);
  box-shadow: 0 4px 0 #8d2218, 0 10px 18px rgba(39, 22, 15, 0.26);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(39, 22, 15, 0.24);
}

.overlay.hidden {
  display: none;
}

.result-box {
  width: min(100%, 340px);
  border-radius: 8px;
  padding: 24px 18px 20px;
  text-align: center;
}

.kicker {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 950;
}

h1 {
  margin: 0;
  font-size: clamp(32px, 11vw, 48px);
  line-height: 1.05;
}

.result-score {
  margin: 10px 0 18px;
  color: #7d392b;
  font-size: 16px;
  font-weight: 900;
}

.start-button {
  width: 100%;
  min-height: 56px;
  background: linear-gradient(180deg, #26a69a, var(--teal));
  font-size: 22px;
  box-shadow: 0 9px 0 #0b4d49, 0 16px 26px rgba(39, 22, 15, 0.28);
}

@keyframes bump {
  50% {
    transform: translateY(7px) scale(1.04, 0.96);
  }
}

@keyframes squash {
  50% {
    transform: scale(1.2, 0.74);
  }
}

@keyframes impact {
  0% {
    opacity: 0;
    transform: scale(0.58) rotate(-4deg);
  }
  30% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(1.08) rotate(2deg);
  }
}

@keyframes waterSplash {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.7);
  }
  24% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-30px) scale(1.16);
  }
}

@keyframes floatScore {
  0% {
    opacity: 0;
    transform: translate(-50%, 12px) scale(0.86);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -44px) scale(1.06);
  }
}

@keyframes feverGlow {
  0% {
    box-shadow: var(--shadow), 0 0 0 rgba(245, 188, 53, 0);
  }
  100% {
    box-shadow: var(--shadow), 0 0 34px rgba(245, 188, 53, 0.78);
  }
}

@keyframes dangerFlash {
  0%,
  100% {
    filter: none;
  }
  45% {
    filter: saturate(1.35) sepia(0.35) hue-rotate(-30deg);
  }
}

@media (max-width: 360px) {
  .game-shell {
    min-height: 500px;
    padding: 4px;
  }

  .stage {
    border-width: 2px;
    border-radius: 18px;
  }

  .hud {
    top: 8px;
    left: 8px;
    right: 8px;
    gap: 5px;
  }

  .hud-item {
    padding: 7px 3px;
  }

  .hud-item strong {
    font-size: 18px;
  }

  .playfield {
    inset: 62px 0 162px;
  }

  .fever-badge {
    top: 66px;
    min-width: 108px;
    font-size: 12px;
  }

  .hero {
    width: 72%;
  }

  .speech {
    right: 82px;
    bottom: clamp(228px, 45vh, 360px);
    max-width: 190px;
    padding: 8px 10px;
    font-size: 13px;
  }

  .mortar-wrap {
    width: 64%;
  }

  .timing-panel {
    left: 8px;
    right: 8px;
    bottom: 88px;
  }

  .hit-button {
    left: 8px;
    right: 8px;
    bottom: 12px;
    min-height: 62px;
    font-size: 27px;
  }
}

@media (min-width: 760px) {
  .game-shell {
    padding: 18px;
  }

  .stage {
    max-height: 860px;
  }
}
