* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: #ffd9ec;
  color: #402a3a;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, #ffe3f0 0%, #ffc9e2 100%);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
#hud {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: rgba(255,255,255,0.5);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid rgba(255,255,255,0.6);
  z-index: 2;
}
.hud-center { text-align: center; flex: 1; }
#levelLabel { font-weight: 700; font-size: 16px; letter-spacing: 0.5px; }
#coinCounter { font-size: 13px; color: #7a5567; margin-top: 2px; font-variant-numeric: tabular-nums; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: #fff; border: none; font-size: 22px;
  color: #d4618e; box-shadow: 0 2px 6px rgba(200,100,150,0.2);
  cursor: pointer;
  margin-left: 4px;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }

#inkBarWrap {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 14px;
  background: rgba(255,255,255,0.3);
  z-index: 2;
}
#inkBar {
  flex: 1; height: 10px; background: rgba(255,255,255,0.6);
  border-radius: 5px; overflow: hidden; position: relative;
}
#inkFill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #7ed957 0%, #ffd166 60%, #ef476f 100%);
  transition: width 0.1s linear;
  transform-origin: left;
}
#starPreview { font-size: 14px; letter-spacing: 2px; }
#starPreview span { color: #ccc; transition: color 0.2s; }
#starPreview span.on { color: #ffc93c; text-shadow: 0 0 4px #fff2a8; }

#stage {
  flex: 1 1 auto;
  width: 100%;
  max-height: 72vh;
  display: block;
  touch-action: none;
}

.go-btn {
  position: absolute;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #ef476f; color: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px 34px;
  font-size: 18px; font-weight: 800;
  letter-spacing: 1px;
  box-shadow: 0 8px 20px rgba(239,71,111,0.45);
  z-index: 3;
  cursor: pointer;
  animation: goPulse 1.6s ease-in-out infinite;
}
.go-btn.hidden { display: none; }
.go-btn:active { transform: translateX(-50%) scale(0.94); }
@keyframes goPulse {
  0%, 100% { box-shadow: 0 8px 20px rgba(239,71,111,0.45); }
  50%      { box-shadow: 0 10px 28px rgba(239,71,111,0.7); }
}

.overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 24px 20px;
  background: linear-gradient(180deg, #ffe3f0 0%, #ffc9e2 100%);
  overflow-y: auto;
}
.overlay.hidden { display: none; }
.overlay h1 { font-size: 36px; margin: 32px 0 6px; }
.overlay h1 .pig { display: inline-block; transform: translateY(2px); }
.subtitle { color: #7a5567; margin: 0 0 24px; text-align: center; }
#levelGrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  width: 100%;
  max-width: 420px;
}
.level-tile {
  aspect-ratio: 1;
  background: #fff; border-radius: 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: none;
  box-shadow: 0 4px 12px rgba(200,100,150,0.15);
  cursor: pointer;
  position: relative;
  padding: 0;
}
.level-tile:active { transform: scale(0.96); }
.level-tile .num { font-size: 28px; font-weight: 800; color: #d4618e; }
.level-tile .stars { font-size: 12px; letter-spacing: 2px; color: #ccc; margin-top: 4px; }
.level-tile .stars span.on { color: #ffc93c; }
.level-tile.locked { opacity: 0.45; }
.level-tile.locked .num::before { content: "🔒 "; font-size: 14px; }

.result-card {
  margin: auto;
  background: #fff; border-radius: 24px;
  padding: 28px 24px; min-width: 280px; max-width: 360px; width: 100%;
  text-align: center;
  box-shadow: 0 12px 32px rgba(120,60,90,0.25);
}
.result-card h2 { margin: 0 0 14px; font-size: 22px; }
.stars-big { font-size: 38px; letter-spacing: 6px; margin: 8px 0 12px; color: #ddd; }
.stars-big span.on { color: #ffc93c; text-shadow: 0 0 8px #fff2a8; animation: pop 0.4s ease-out both; }
.stars-big span:nth-child(2) { animation-delay: 0.15s; }
.stars-big span:nth-child(3) { animation-delay: 0.3s; }
@keyframes pop { 0% { transform: scale(0.2); opacity: 0; } 70% { transform: scale(1.25); } 100% { transform: scale(1); opacity: 1; } }
#resultStats { color: #7a5567; font-size: 14px; margin-bottom: 18px; line-height: 1.5; }
.result-actions { display: flex; gap: 8px; justify-content: center; }
.btn {
  flex: 1; min-height: 44px;
  border: none; border-radius: 12px; padding: 0 14px;
  background: #f6e0ea; color: #7a3d5a; font-weight: 600; font-size: 15px;
  cursor: pointer;
}
.btn.primary { background: #ef476f; color: #fff; box-shadow: 0 4px 10px rgba(239,71,111,0.3); }
.btn:active { transform: scale(0.96); }

@media (orientation: landscape) and (max-height: 500px) {
  .overlay h1 { margin-top: 8px; font-size: 26px; }
  #levelGrid { max-width: 540px; grid-template-columns: repeat(6, 1fr); }
}
