:root {
  color-scheme: light;
  --ink: #17222d;
  --paper: #fff9ec;
  --accent: #e9382f;
  --accent-2: #f2b938;
  --leaf: #37a44b;
  --water: #1b8bb8;
  --soil: #6a3b21;
  --shadow: 0 14px 34px rgba(21, 35, 45, 0.2);
  font-family: "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #123c4d;
  color: var(--ink);
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  min-height: 100svh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: linear-gradient(180deg, #a6e5ff 0%, #f8e38c 100%);
  touch-action: manipulation;
  user-select: none;
}

.hud {
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(78px, 1fr) auto minmax(78px, 1fr);
  align-items: center;
  gap: 8px;
  width: min(760px, 100%);
  margin: 0 auto 8px;
}

.meter,
.score-panel > div {
  min-width: 0;
  border: 2px solid rgba(23, 34, 45, 0.18);
  border-radius: 8px;
  background: rgba(255, 249, 236, 0.88);
  box-shadow: 0 8px 18px rgba(45, 53, 36, 0.12);
  text-align: center;
}

.meter {
  padding: 8px 6px;
}

.meter span,
.score-panel span {
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  color: rgba(23, 34, 45, 0.7);
}

.meter strong {
  display: block;
  font-size: clamp(19px, 5.6vw, 34px);
  line-height: 1;
}

.title-lockup {
  min-width: 118px;
  text-align: center;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.24), 0 8px 20px rgba(0, 0, 0, 0.22);
}

.kagoshima {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent);
  font-size: 11px;
  font-weight: 900;
}

h1 {
  margin: 2px 0 0;
  font-size: clamp(21px, 6.2vw, 42px);
  line-height: 1.05;
}

.stage {
  position: relative;
  z-index: 1;
  overflow: hidden;
  width: min(760px, 100%);
  min-height: 0;
  margin: 0 auto;
  border-radius: 8px;
  outline: none;
  background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.02), rgba(0, 0, 0, 0.12)), url("./assets/sakurajima-bg.png");
  background-size: cover;
  background-position: center bottom;
  box-shadow: var(--shadow);
  isolation: isolate;
}

.stage:focus-visible {
  box-shadow: 0 0 0 4px #fff, 0 0 0 8px var(--accent), var(--shadow);
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0) 38%, rgba(0, 0, 0, 0.12) 100%);
  pointer-events: none;
}

.sky-shine {
  position: absolute;
  z-index: 1;
  top: -14%;
  right: -24%;
  width: 62%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 244, 173, 0.88) 0%, rgba(255, 236, 117, 0.44) 36%, rgba(255, 255, 255, 0) 70%);
  pointer-events: none;
}

.rare-badge {
  position: absolute;
  z-index: 3;
  top: 78px;
  left: 50%;
  transform: translateX(-50%) rotate(-2deg);
  max-width: calc(100% - 24px);
  padding: 8px 12px;
  border: 2px solid #fff6bf;
  border-radius: 8px;
  background: linear-gradient(135deg, #7c4300, #ffd54b 42%, #fff4b0 52%, #d48a00);
  color: #341d00;
  box-shadow: 0 10px 26px rgba(44, 24, 0, 0.28);
  font-weight: 900;
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

.progress-wrap {
  position: absolute;
  z-index: 3;
  top: 14px;
  left: 14px;
  right: 14px;
  display: grid;
  grid-template-columns: 1fr 46px;
  align-items: center;
  gap: 8px;
}

.progress-track {
  overflow: hidden;
  height: 17px;
  border: 2px solid rgba(23, 34, 45, 0.32);
  border-radius: 999px;
  background: rgba(255, 249, 236, 0.82);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--leaf), #f0d747, var(--accent));
  transition: width 90ms ease-out;
}

#progressText {
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  text-align: right;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.34);
}

.pull-rig {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: clamp(22px, 6.5svh, 58px);
  width: min(92%, 520px);
  transform: translate(-50%, var(--pull-y, 28%)) rotate(var(--tilt, 0deg)) scale(var(--scale, 0.84));
  transform-origin: 52% 78%;
  transition: transform 80ms ease-out;
  filter: drop-shadow(0 18px 18px rgba(38, 24, 12, 0.28));
}

.pull-rig.success {
  animation: victory-pop 620ms cubic-bezier(0.18, 0.9, 0.25, 1.18) both;
}

.onikin {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.soil-front {
  position: absolute;
  z-index: 3;
  left: 0;
  right: 0;
  bottom: 0;
  height: clamp(104px, 21svh, 174px);
  background:
    radial-gradient(circle at 12% 38%, rgba(96, 53, 28, 0.72) 0 8px, transparent 9px),
    radial-gradient(circle at 72% 28%, rgba(124, 72, 38, 0.74) 0 10px, transparent 11px),
    linear-gradient(180deg, #8b512b 0%, #5d351f 84%);
  box-shadow: inset 0 20px 26px rgba(255, 222, 141, 0.18);
}

.soil-lip {
  position: absolute;
  left: -4%;
  right: -4%;
  top: -26px;
  height: 58px;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, #9a5d35 0%, #754224 56%, rgba(79, 39, 20, 0) 70%);
}

.tap-prompt {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: min(92%, 360px);
  padding: 10px 14px;
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  background: rgba(233, 56, 47, 0.9);
  color: #fff;
  font-size: clamp(17px, 5vw, 25px);
  font-weight: 950;
  text-align: center;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
  box-shadow: 0 10px 18px rgba(44, 20, 12, 0.24);
}

.burst-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  overflow: hidden;
  pointer-events: none;
}

.pop {
  position: absolute;
  left: var(--x);
  top: var(--y);
  transform: translate(-50%, -50%);
  color: #fff;
  font-weight: 950;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.34);
  animation: pop-rise 640ms ease-out forwards;
}

.clod {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  background: #6c3f22;
  animation: clod 540ms ease-out forwards;
}

.score-panel {
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(760px, 100%);
  margin: 8px auto 0;
}

.score-panel > div {
  padding: 8px 4px;
}

.score-panel strong {
  display: block;
  overflow: hidden;
  min-height: 24px;
  font-size: clamp(18px, 5.2vw, 32px);
  line-height: 1.05;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(18px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: rgba(11, 27, 38, 0.36);
  backdrop-filter: blur(5px);
}

.modal.active {
  display: flex;
}

.modal-card {
  width: min(430px, 100%);
  max-height: min(700px, 92svh);
  overflow: auto;
  border: 3px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 18px;
  text-align: center;
}

.reward {
  width: min(64%, 250px);
  aspect-ratio: 1;
  object-fit: contain;
  margin: -2px auto 4px;
  filter: drop-shadow(0 14px 12px rgba(67, 45, 15, 0.2));
}

.modal-kicker {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 950;
}

.modal h2 {
  margin: 0;
  font-size: clamp(27px, 8vw, 40px);
  line-height: 1.05;
}

.modal p {
  margin: 12px 0 16px;
  color: rgba(23, 34, 45, 0.78);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.55;
}

.primary-button {
  width: 100%;
  min-height: 54px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffdb59, #f08a22);
  color: #2a1700;
  box-shadow: 0 7px 0 #a64e18, 0 16px 24px rgba(79, 39, 20, 0.22);
  font-size: 20px;
  font-weight: 950;
  cursor: pointer;
}

.primary-button:active {
  transform: translateY(3px);
  box-shadow: 0 4px 0 #a64e18, 0 10px 18px rgba(79, 39, 20, 0.22);
}

.shake {
  animation: screen-shake 120ms linear;
}

@keyframes pop-rise {
  0% {
    opacity: 0;
    transform: translate(-50%, -20%) scale(0.76);
  }
  25% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -160%) scale(1.18);
  }
}

@keyframes clod {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.8);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.4);
  }
}

@keyframes victory-pop {
  0% {
    transform: translate(-50%, -2%) rotate(-3deg) scale(0.96);
  }
  48% {
    transform: translate(-50%, -25%) rotate(4deg) scale(1.04);
  }
  100% {
    transform: translate(-50%, -18%) rotate(0deg) scale(1);
  }
}

@keyframes screen-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  30% {
    transform: translateX(-4px);
  }
  65% {
    transform: translateX(4px);
  }
}

@media (min-width: 760px) {
  body {
    overflow: auto;
  }

  .game-shell {
    min-height: 100vh;
  }
}

@media (max-height: 680px) {
  .hud {
    margin-bottom: 5px;
  }

  .meter,
  .score-panel > div {
    padding-top: 5px;
    padding-bottom: 5px;
  }

  .soil-front {
    height: 100px;
  }

  .tap-prompt {
    bottom: 8px;
    padding: 7px 10px;
  }
}
