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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1f6fa8;
  font-family: "Comic Sans MS", "Marker Felt", "Microsoft JhengHei", "PingFang TC", sans-serif;
  touch-action: manipulation;
  overscroll-behavior: none;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: none;
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 14px 12px;
  padding-top: max(14px, env(safe-area-inset-top));
  display: flex;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  z-index: 5;
  opacity: 1;
  transition: opacity 0.25s ease;
}

#hud.hidden-during-menu { opacity: 0; }

.hud-pill {
  background: rgba(255, 255, 255, 0.92);
  color: #2a3a5e;
  font-size: clamp(18px, 4.5vw, 26px);
  font-weight: bold;
  padding: 6px 14px;
  border-radius: 999px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15);
  white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}

#score-pill.target-reached {
  background: linear-gradient(180deg, #b6f0a3 0%, #6ddc52 100%);
  color: #1a5010;
  animation: scoreReady 0.6s ease-in-out infinite alternate;
}

@keyframes scoreReady {
  from { box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15); }
  to   { box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15), 0 0 14px rgba(110, 220, 80, 0.7); }
}

/* Cute SVG cat sitting on dock at horizon (~36% from top) */
#cat-container {
  position: absolute;
  left: 50%;
  bottom: 64vh;
  bottom: 64dvh;
  transform: translateX(-50%);
  width: min(38vw, 220px);
  pointer-events: none;
  z-index: 2;
  display: flex;
  justify-content: center;
}

#cat {
  width: 100%;
  height: auto;
  transform-origin: 50% 100%;
  animation: catBob 3.2s ease-in-out infinite;
  filter: drop-shadow(0 6px 4px rgba(0, 0, 0, 0.25));
}

@keyframes catBob {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50%      { transform: translateY(-4px) rotate(1.5deg); }
}

#cat .eyes-happy { display: none; }
#cat.happy { animation: catHappyBounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }
#cat.happy .eyes-open  { display: none; }
#cat.happy .eyes-happy { display: inline; }

@keyframes catHappyBounce {
  0%, 100% { transform: translateY(0)    scale(1, 1); }
  25%      { transform: translateY(-22px) scale(1.06, 0.94); }
  60%      { transform: translateY(0)    scale(0.96, 1.04); }
  85%      { transform: translateY(-4px) scale(1.02, 0.98); }
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 60, 110, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  animation: fadeIn 0.3s ease;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  background: linear-gradient(180deg, #fffbe6 0%, #ffe9a8 100%);
  border-radius: 32px;
  padding: 36px 32px;
  text-align: center;
  box-shadow: 0 12px 0 rgba(0, 0, 0, 0.18), 0 0 0 6px #fff inset;
  max-width: 90vw;
  width: 380px;
  animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.big-emoji {
  font-size: 80px;
  line-height: 1;
  margin-bottom: 8px;
  animation: wiggle 1.6s ease-in-out infinite;
}

h1 {
  font-size: 42px;
  color: #d24a2a;
  margin-bottom: 12px;
  text-shadow: 3px 3px 0 #fff, 4px 4px 0 rgba(0, 0, 0, 0.1);
  letter-spacing: 2px;
}

.tagline, .result, .best, .tip {
  font-size: 22px;
  color: #5a3a1a;
  margin: 10px 0;
}

.result span, .best span {
  font-size: 32px;
  font-weight: bold;
  color: #d24a2a;
}

.tip {
  font-size: 16px;
  color: #8a6a3a;
  margin-top: 16px;
}

.big-btn {
  margin-top: 18px;
  font-family: inherit;
  font-size: 32px;
  font-weight: bold;
  color: white;
  background: linear-gradient(180deg, #ff9248 0%, #f06030 100%);
  border: none;
  padding: 18px 48px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 6px 0 #b03810, 0 8px 16px rgba(0, 0, 0, 0.2);
  transition: transform 0.1s, box-shadow 0.1s;
  letter-spacing: 4px;
}

.big-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #b03810, 0 4px 8px rgba(0, 0, 0, 0.2);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pop {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes wiggle {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(5deg); }
}

/* Name input */
.name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 16px 0 8px;
  flex-wrap: wrap;
}

.name-row label {
  font-size: 18px;
  color: #5a3a1a;
  font-weight: bold;
}

#player-name {
  font-family: inherit;
  font-size: 22px;
  font-weight: bold;
  color: #d24a2a;
  text-align: center;
  background: white;
  border: 3px solid #d24a2a;
  border-radius: 999px;
  padding: 6px 14px;
  width: 140px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1) inset;
}

#player-name:focus {
  border-color: #ff8a00;
  box-shadow: 0 0 0 3px rgba(255, 138, 0, 0.3);
}

/* Leaderboard */
.leaderboard {
  background: rgba(255, 255, 255, 0.65);
  border-radius: 18px;
  padding: 12px 14px;
  margin: 14px 0;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.08) inset;
}

.lb-title {
  font-size: 18px;
  font-weight: bold;
  color: #5a3a1a;
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.lb-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lb-list li {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 12px;
  padding: 6px 12px;
  font-size: 20px;
  color: #3a2510;
  font-weight: bold;
}

.lb-list li.empty {
  justify-content: center;
  color: #8a6a3a;
  font-size: 16px;
  font-weight: normal;
  padding: 10px;
}

.lb-list li.highlight {
  background: linear-gradient(180deg, #ffe48a 0%, #ffcc4d 100%);
  box-shadow: 0 0 0 2px #ff8a00, 0 0 12px rgba(255, 138, 0, 0.5);
  animation: shine 1s ease-in-out infinite alternate;
}

.lb-list .medal {
  font-size: 24px;
  margin-right: 8px;
  min-width: 28px;
}

.lb-list .name {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-list .score {
  font-size: 22px;
  color: #d24a2a;
  margin-left: 8px;
}

/* New record callout */
.new-record {
  background: linear-gradient(135deg, #fff48a 0%, #ffb347 100%);
  color: #5a2a00;
  font-size: 22px;
  font-weight: bold;
  padding: 10px 18px;
  border-radius: 999px;
  margin: 14px auto;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15);
  animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), shine 0.8s ease-in-out infinite alternate 0.4s;
}

@keyframes shine {
  from { filter: brightness(1); }
  to   { filter: brightness(1.15); }
}

/* Button row */
.btn-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
}

.small-btn {
  font-family: inherit;
  font-size: 18px;
  font-weight: bold;
  color: #5a3a1a;
  background: rgba(255, 255, 255, 0.85);
  border: 2px solid #b08040;
  padding: 8px 22px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 3px 0 #8a6020;
  transition: transform 0.1s, box-shadow 0.1s;
}

.small-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #8a6020;
}

/* Level select */
.overlay-card-wide {
  width: 480px;
}

.name-tag {
  color: #d24a2a;
  font-weight: bold;
  font-size: 26px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.level-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: linear-gradient(180deg, #ffffff 0%, #ffe9b0 100%);
  border: 3px solid #d8a050;
  border-radius: 18px;
  padding: 12px 8px;
  cursor: pointer;
  font-family: inherit;
  font-weight: bold;
  color: #5a3a1a;
  box-shadow: 0 4px 0 #b07830;
  transition: transform 0.1s, box-shadow 0.1s;
}

.level-card:hover:not(.locked) {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #b07830;
}

.level-card:active:not(.locked) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #b07830;
}

.level-card.locked {
  background: linear-gradient(180deg, #ddd 0%, #bbb 100%);
  border-color: #888;
  box-shadow: 0 4px 0 #666;
  cursor: not-allowed;
  color: #555;
  filter: grayscale(0.4);
}

.level-card .level-emoji {
  font-size: 38px;
  line-height: 1;
}

.level-card .level-num {
  font-size: 14px;
  color: #8a6a3a;
}

.level-card .level-name {
  font-size: 18px;
  letter-spacing: 1px;
}

.level-card .level-target {
  font-size: 13px;
  color: #8a6a3a;
}

.level-card .level-stars {
  font-size: 16px;
  letter-spacing: 1px;
  min-height: 20px;
}

.level-card.locked .level-stars::after {
  content: '🔒';
  font-size: 22px;
}

/* Stars row in end screen */
.stars-row {
  font-size: 48px;
  letter-spacing: 8px;
  margin: 10px 0 4px;
  animation: pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  min-height: 56px;
}

.stars-row .star {
  display: inline-block;
  animation: starDrop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.stars-row .star.dim {
  filter: grayscale(1) brightness(0.7);
}
.stars-row .star:nth-child(1) { animation-delay: 0.1s; }
.stars-row .star:nth-child(2) { animation-delay: 0.35s; }
.stars-row .star:nth-child(3) { animation-delay: 0.6s; }

@keyframes starDrop {
  0%   { transform: translateY(-40px) scale(0.3) rotate(-90deg); opacity: 0; }
  100% { transform: translateY(0)     scale(1)   rotate(0deg);   opacity: 1; }
}

.confetti {
  font-size: 32px;
  letter-spacing: 6px;
  margin: 10px 0;
  animation: shine 0.8s ease-in-out infinite alternate;
}

/* Slightly tighter card padding on small phones */
@media (max-height: 700px) {
  .overlay-card { padding: 22px 22px; }
  .big-emoji { font-size: 56px; }
  h1 { font-size: 32px; }
}
