* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #fff7e6;
  color: #333;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

body {
  position: fixed;
  inset: 0;
}

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  background: linear-gradient(#bfe6ff 0%, #e8f6ff 55%, #fff7e6 100%);
  overflow: hidden;
}

/* ---------- HUD ---------- */
.hud {
  flex: none;
  padding: 8px 12px 4px;
  text-align: center;
}

.title {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: #e4572e;
  text-shadow: 2px 2px 0 #fff;
}

.hud-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.hud-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 0;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08);
}

.hud-main {
  flex: 1.4;
}

.hud-label {
  font-size: 11px;
  color: #777;
  font-weight: 700;
}

.hud-value {
  font-size: 22px;
  font-weight: 900;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.hud-main .hud-value {
  color: #e4572e;
}

.hud-value small {
  font-size: 12px;
  margin-left: 1px;
}

.hud-value.danger {
  color: #e00;
  animation: pulse 0.5s ease-in-out infinite alternate;
}

.hud-value.bump {
  animation: bump 0.25s ease;
}

@keyframes pulse {
  to {
    transform: scale(1.15);
  }
}

@keyframes bump {
  50% {
    transform: scale(1.25);
  }
}

/* ---------- Stage ---------- */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 14px;
  background: repeating-linear-gradient(90deg, #8bc34a 0 12px, #7cb342 12px 24px);
  border-top: 2px solid #689f38;
}

.balance {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  padding: 2px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  background: #43a047;
  transition: background-color 0.2s;
}

.balance.tilt {
  background: #f9a825;
}

.balance.danger {
  background: #e53935;
  animation: pulse 0.3s ease-in-out infinite alternate;
}

/* World: width 0 anchor at horizontal center, scaled from bottom center */
.world {
  position: absolute;
  left: 50%;
  bottom: 14px;
  width: 0;
  height: 0;
  transform-origin: 0 100%;
  transform: scale(var(--world-scale, 1));
  transition: transform 0.3s ease;
}

.stack {
  position: absolute;
  bottom: 0;
  width: 56px;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
}

.stack-left {
  left: -64px;
}

.stack-right {
  left: 8px;
}

.item {
  position: relative;
  width: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 2px solid rgba(0, 0, 0, 0.18);
  line-height: 1;
  overflow: visible;
  animation: pop-in 0.25s ease-out;
  transition: transform 0.9s cubic-bezier(0.2, 0.7, 0.3, 1), opacity 0.9s ease;
}

.item span {
  display: block;
  line-height: 1;
}

@keyframes pop-in {
  from {
    transform: translateY(40px) scale(0.6);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.world.scatter .item {
  animation: none;
  transform: translate(var(--sx), var(--sy)) rotate(var(--sr));
  opacity: 0.85;
}

/* ---------- Character ---------- */
.character {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 0;
}

.character.hop {
  animation: hop 0.25s ease-out;
}

@keyframes hop {
  40% {
    transform: translateY(-14px);
  }
}

.leg {
  position: absolute;
  width: 7px;
  margin-left: -3.5px;
  background: #333;
  border-radius: 4px;
  transform-origin: 50% 100%;
  transition: bottom 0.2s ease, height 0.2s ease, transform 0.2s ease, left 0.2s ease;
}

.shoe {
  position: absolute;
  width: 40px;
  margin-left: -20px;
  font-size: 30px;
  line-height: 1;
  text-align: center;
  transition: bottom 0.2s ease;
}

.shoe-left {
  transform: scaleX(-1);
}

.upper {
  --tilt-angle: 0deg;
  position: absolute;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  transform: rotate(var(--tilt-angle));
  transition: transform 0.2s ease, bottom 0.2s ease;
}

.upper-inner {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 0;
}

.upper-inner.shake {
  animation: shake 0.12s linear infinite;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0) rotate(0);
  }
  25% {
    transform: translateX(-3px) rotate(-2deg);
  }
  75% {
    transform: translateX(3px) rotate(2deg);
  }
}

.torso {
  position: absolute;
  left: -4px;
  bottom: -2px;
  width: 8px;
  height: 116px;
  background: #333;
  border-radius: 4px;
}

/* Arms hang from the shoulder (100px above the hip), pivoting at their top end */
.arm {
  position: absolute;
  left: -3.5px;
  bottom: 22px;
  width: 7px;
  height: 78px;
  background: #333;
  border-radius: 4px;
  transform-origin: 50% 0;
  transition: transform 0.2s ease;
}

.arm-left {
  transform: rotate(35deg);
}

.arm-right {
  transform: rotate(-35deg);
}

.character.danger .arm-left {
  transform: rotate(130deg);
}

.character.danger .arm-right {
  transform: rotate(-130deg);
}

.head {
  position: absolute;
  left: -30px;
  bottom: 108px;
  width: 60px;
  font-size: 54px;
  line-height: 1;
  text-align: center;
}

.character.falling .upper {
  transition: transform 0.6s cubic-bezier(0.5, 0, 0.9, 0.5);
}

.character.falling .upper-inner {
  animation: none;
}

/* ---------- Info ---------- */
.info {
  flex: none;
  padding: 6px 12px 0;
  background: #fff7e6;
}

.next {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 6px 12px;
  background: #fff;
  border: 3px dashed #f4a261;
  border-radius: 14px;
}

.next-label {
  font-size: 13px;
  font-weight: 800;
  color: #a0522d;
  writing-mode: horizontal-tb;
}

.next-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.next-item.change {
  animation: next-in 0.2s ease-out;
}

@keyframes next-in {
  from {
    transform: scale(0.4) rotate(-20deg);
    opacity: 0;
  }
}

.next-emoji {
  font-size: 44px;
  line-height: 1;
}

.next-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.next-name {
  font-size: 13px;
  color: #666;
  font-weight: 700;
}

.next-height {
  font-size: 22px;
  font-weight: 900;
  color: #e4572e;
}

.side-heights {
  display: flex;
  justify-content: space-around;
  padding: 6px 0 2px;
  font-size: 14px;
  font-weight: 700;
  color: #555;
}

.side-heights b {
  font-size: 18px;
  color: #222;
  font-variant-numeric: tabular-nums;
}

/* ---------- Controls ---------- */
.controls {
  flex: none;
  display: flex;
  gap: 10px;
  padding: 6px 12px 12px;
  background: #fff7e6;
}

.btn {
  font-family: inherit;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
}

.controls .btn {
  flex: 1;
  height: 84px;
  border-radius: 18px;
  font-size: 20px;
  font-weight: 900;
  line-height: 1.25;
  color: #fff;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.05s, box-shadow 0.05s, opacity 0.2s;
}

.btn-left {
  background: #2a9d8f;
}

.btn-right {
  background: #e76f51;
}

.controls .btn:active:not(:disabled) {
  transform: translateY(5px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

.controls .btn:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.45);
  animation: fade-in 0.25s ease;
}

.overlay.hidden,
.hidden {
  display: none;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.panel {
  width: 100%;
  max-width: 340px;
  padding: 24px 20px;
  text-align: center;
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  animation: panel-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes panel-in {
  from {
    transform: scale(0.7);
    opacity: 0;
  }
}

.panel h2 {
  font-size: 24px;
  font-weight: 900;
  color: #e4572e;
  margin-bottom: 12px;
}

.panel-emoji {
  font-size: 54px;
  margin-bottom: 4px;
}

.rules {
  font-size: 15px;
  line-height: 1.8;
  margin-bottom: 20px;
}

.warn {
  color: #e53935;
  font-weight: 800;
}

.btn-primary {
  width: 100%;
  padding: 16px;
  border-radius: 16px;
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  background: #e4572e;
  box-shadow: 0 6px 0 #a63d1f;
}

.btn-primary:active {
  transform: translateY(5px);
  box-shadow: 0 1px 0 #a63d1f;
}

.result .fell-message {
  font-size: 20px;
  font-weight: 900;
  color: #e53935;
  margin-bottom: 8px;
}

.result-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 6px 0;
}

.result-label {
  font-size: 13px;
  color: #777;
  font-weight: 700;
}

.result-value {
  font-size: 24px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.result-value.big {
  font-size: 40px;
  color: #e4572e;
}

.rank {
  display: inline-block;
  margin: 10px 0 6px;
  padding: 6px 18px;
  font-size: 22px;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(135deg, #f4a261, #e76f51);
  border-radius: 999px;
}

.new-record {
  font-size: 16px;
  font-weight: 900;
  color: #f9a825;
  animation: pulse 0.5s ease-in-out infinite alternate;
}

.result .btn-primary {
  margin-top: 16px;
}

/* ---------- Small screens ---------- */
@media (max-height: 640px) {
  .title {
    font-size: 15px;
  }
  .hud-value {
    font-size: 18px;
  }
  .next-emoji {
    font-size: 34px;
  }
  .controls .btn {
    height: 68px;
    font-size: 17px;
  }
}
