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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #2b2440;
  font-family: "Hiragino Maru Gothic ProN", "Rounded Mplus 1c", "Yu Gothic", sans-serif;
  touch-action: none;
}

#gameContainer {
  position: relative;
  width: 100%;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: linear-gradient(180deg, #ffd9ec 0%, #fff3c4 100%);
  overflow: hidden;
  box-shadow: 0 0 40px rgba(0,0,0,0.4);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hidden { display: none !important; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background: linear-gradient(180deg, rgba(255,217,236,0.97) 0%, rgba(255,243,196,0.97) 100%);
  z-index: 10;
}

#bearLogo, #resultBear {
  width: 140px;
  height: auto;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.15));
  margin-bottom: 8px;
}

.overlay h1 {
  font-size: 26px;
  color: #7a4a6b;
  margin: 4px 0 12px;
  line-height: 1.3;
  text-shadow: 1px 1px 0 #fff;
}

/* ---------- Result screen: dramatic theming ---------- */
#resultScreen {
  transition: background 0.3s;
  overflow: hidden;
}

#resultParticles {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

#resultParticles span {
  position: absolute;
  top: -12%;
  font-size: 22px;
  will-change: transform, top, opacity;
}

#resultContent {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

#resultBear {
  animation: bearPop 0.7s cubic-bezier(.34,1.56,.64,1) both;
}

@keyframes bearPop {
  0%   { transform: scale(0) rotate(-20deg); opacity: 0; }
  60%  { transform: scale(1.2) rotate(6deg);  opacity: 1; }
  100% { transform: scale(1) rotate(0deg); }
}

#resultTitle {
  animation: titlePop 0.5s ease-out both;
}

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

@keyframes particleFall {
  0%   { top: -12%; opacity: 0; transform: rotate(0deg); }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { top: 112%; opacity: 0; transform: rotate(360deg); }
}

@keyframes particleDrift {
  0%   { top: -12%; opacity: 0; }
  15%  { opacity: 0.8; }
  85%  { opacity: 0.8; }
  100% { top: 112%; opacity: 0; }
}

/* Clear (success): vibrant, celebratory */
.result-clear {
  background: linear-gradient(160deg, #fff6c9 0%, #ffd6ec 45%, #ffe9a8 100%);
}
.result-clear #resultParticles span {
  animation-name: particleFall;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}
.result-clear #resultTitle {
  background: linear-gradient(90deg, #ff6fa5, #ffb347, #06d6a0, #4cc9f0, #ff6fa5);
  background-size: 300% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 2px 3px rgba(122, 74, 107, 0.45));
  animation: titlePop 0.5s ease-out both, rainbowShift 2.5s linear infinite;
}
@keyframes rainbowShift {
  to { background-position: 300% center; }
}

/* Game over: muted, gentle rain */
.result-gameover {
  background: linear-gradient(180deg, #cfd9e8 0%, #aab8d0 100%);
}
.result-gameover #resultParticles span {
  animation-name: particleDrift;
  animation-timing-function: ease-in;
  animation-iteration-count: infinite;
  filter: grayscale(0.2);
}
.result-gameover #resultTitle {
  color: #55647f;
  animation: titleShake 0.5s ease-out both;
}
@keyframes titleShake {
  0%   { transform: translateX(0); }
  20%  { transform: translateX(-8px); }
  40%  { transform: translateX(8px); }
  60%  { transform: translateX(-5px); }
  80%  { transform: translateX(5px); }
  100% { transform: translateX(0); }
}
.result-gameover .rank { color: #6b7ba0; }
.result-gameover #resultStats { color: #55647f; }
.result-gameover .btn {
  background: linear-gradient(180deg, #9fb3d1 0%, #7d94bf 100%);
  box-shadow: 0 4px 0 #5f76a0, 0 6px 10px rgba(0,0,0,0.2);
}

#itemBreakdown {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 320px;
  margin: 4px 0 14px;
}

.item-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.75);
  border-radius: 14px;
  padding: 6px 10px;
  font-size: 14px;
  font-weight: bold;
  color: #7a4a6b;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}
.item-chip.zero {
  opacity: 0.4;
}
.item-chip .count {
  color: #ff6fa5;
}
.result-gameover .item-chip {
  color: #55647f;
}
.result-gameover .item-chip .count {
  color: #5f76a0;
}

.desc {
  font-size: 14px;
  color: #7a4a6b;
  max-width: 320px;
  margin: 0 0 14px;
}

.controls-guide {
  background: rgba(255,255,255,0.6);
  border-radius: 14px;
  padding: 10px 14px;
  margin-bottom: 18px;
  max-width: 340px;
}

.controls-guide p {
  font-size: 12.5px;
  color: #6b4a5a;
  margin: 4px 0;
  text-align: left;
}

.btn {
  font-size: 18px;
  font-weight: bold;
  color: #fff;
  background: linear-gradient(180deg, #ff9ec7 0%, #ff6fa5 100%);
  border: none;
  border-radius: 30px;
  padding: 14px 42px;
  box-shadow: 0 4px 0 #d1487f, 0 6px 10px rgba(0,0,0,0.2);
  cursor: pointer;
  transition: transform 0.1s;
}
.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #d1487f, 0 2px 6px rgba(0,0,0,0.2);
}

.rank {
  font-size: 20px;
  font-weight: bold;
  color: #ff6fa5;
  margin: 6px 0;
}

#resultStats {
  font-size: 15px;
  color: #7a4a6b;
  margin-bottom: 18px;
  white-space: pre-line;
  line-height: 1.6;
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  z-index: 5;
  pointer-events: none;
}

#lives {
  font-size: 20px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}

#progressWrap {
  flex: 1;
  margin: 0 10px;
}

#progressBar {
  position: relative;
  height: 14px;
  background: rgba(255,255,255,0.5);
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.8);
  overflow: visible;
}

#progressFill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffb6d5, #ff6fa5);
  border-radius: 6px;
  transition: width 0.15s linear;
}

#progressIcon {
  position: absolute;
  top: -13px;
  left: 0%;
  transform: translateX(-50%);
  font-size: 16px;
  transition: left 0.15s linear;
}

#itemCount {
  font-size: 15px;
  font-weight: bold;
  color: #7a4a6b;
  background: rgba(255,255,255,0.6);
  padding: 3px 10px;
  border-radius: 12px;
  white-space: nowrap;
}

#touchButtons {
  position: absolute;
  bottom: 14px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 12px;
  z-index: 5;
}

.tbtn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.55);
  color: #7a4a6b;
  font-size: 20px;
  box-shadow: 0 3px 6px rgba(0,0,0,0.2);
}
.tbtn:active {
  background: rgba(255,255,255,0.85);
}
