:root {
  --ui: #2b2440;
  --accent: #f3a712;
  --accent2: #e23b2e;
  --panel: #fffaf0;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #3a3f48;
  overscroll-behavior: none;
  touch-action: none;
}

#app {
  position: fixed;
  inset: 0;
}

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

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  pointer-events: none;
  z-index: 10;
  gap: 8px;
}
#hud > div { display: flex; align-items: center; gap: 8px; pointer-events: auto; }
.hud-center { flex: 1; justify-content: center; }

.pill {
  background: rgba(43,36,64,.82);
  color: #fff;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: clamp(13px, 2.4vw, 18px);
  box-shadow: 0 3px 0 rgba(0,0,0,.25);
  white-space: nowrap;
}
#score { min-width: 60px; text-align: center; color: var(--accent); }

.iconbtn {
  width: clamp(44px, 10vw, 54px);
  height: clamp(44px, 10vw, 54px);
  border: none;
  border-radius: 50%;
  background: rgba(43,36,64,.82);
  color: #fff;
  font-size: clamp(18px, 4vw, 24px);
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,.25);
  transition: transform .08s, background .15s;
  line-height: 1;
}
.iconbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }

#birdQueue {
  display: flex;
  gap: 6px;
  align-items: center;
  background: rgba(43,36,64,.55);
  padding: 6px 12px;
  border-radius: 999px;
}
#birdQueue .qbird {
  width: clamp(20px, 4vw, 28px);
  height: clamp(20px, 4vw, 28px);
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.85);
  box-shadow: inset -3px -4px 0 rgba(0,0,0,.18);
}
#birdQueue .qbird.spent { opacity: .25; filter: grayscale(1); }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26,20,40,.55);
  backdrop-filter: blur(3px);
  z-index: 20;
  padding: 20px;
  animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.panel {
  background: var(--panel);
  border-radius: 28px;
  padding: clamp(22px, 5vw, 40px);
  max-width: 460px;
  width: 100%;
  text-align: center;
  box-shadow: 0 14px 0 rgba(0,0,0,.25), 0 22px 50px rgba(0,0,0,.35);
  border: 4px solid #fff;
}
.panel.wide { max-width: 620px; }

.title {
  margin: 0 0 8px;
  font-size: clamp(34px, 9vw, 60px);
  font-weight: 900;
  letter-spacing: -1px;
  color: var(--accent2);
  text-shadow: 0 3px 0 #fff, 0 4px 0 rgba(0,0,0,.25);
  line-height: .95;
}
.title.small { font-size: clamp(26px, 6vw, 40px); }
.subtitle { color: #5a5168; font-size: clamp(14px, 3vw, 17px); margin: 6px 0 22px; line-height: 1.45; }
.tip { color: #9a90ad; font-size: 13px; margin-top: 18px; }
.score-line { color: var(--ui); font-weight: 700; font-size: 20px; margin: 6px 0 22px; }
.score-line span { color: var(--accent2); }

.bigbtn {
  border: none;
  background: var(--accent2);
  color: #fff;
  font-weight: 800;
  font-size: clamp(17px, 4vw, 22px);
  padding: 14px 30px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 5px 0 #a32319;
  transition: transform .08s, box-shadow .08s;
}
.bigbtn:active { transform: translateY(4px); box-shadow: 0 1px 0 #a32319; }
.bigbtn.ghost { background: #ece6f5; color: var(--ui); box-shadow: 0 5px 0 #c8bfdc; }
.bigbtn.ghost:active { box-shadow: 0 1px 0 #c8bfdc; }

.btnrow { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.stars {
  font-size: clamp(44px, 11vw, 64px);
  color: var(--accent);
  letter-spacing: 6px;
  margin: 4px 0 12px;
  text-shadow: 0 3px 0 rgba(0,0,0,.18);
}
.stars .dim { color: #ddd4ea; }

/* ---------- Level grid ---------- */
#levelGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 12px;
  margin: 10px 0 22px;
}
.levelcard {
  position: relative;
  aspect-ratio: 1;
  border: none;
  border-radius: 18px;
  background: linear-gradient(160deg, #e25b4e, #c2362a);
  color: #fff;
  font-weight: 900;
  font-size: 26px;
  cursor: pointer;
  box-shadow: 0 5px 0 #8e2018;
  transition: transform .08s, box-shadow .08s;
  display: flex; align-items: center; justify-content: center;
}
.levelcard:active { transform: translateY(4px); box-shadow: 0 1px 0 #8e2018; }
.levelcard.locked { background: #d8d0e6; box-shadow: 0 5px 0 #b6abcc; color: #9a90ad; cursor: not-allowed; }
.levelcard .ministars {
  position: absolute;
  bottom: 6px; left: 0; right: 0;
  font-size: 12px;
  color: var(--accent);
  text-shadow: 0 1px 1px rgba(0,0,0,.3);
}
.levelcard .ministars .dim { color: rgba(255,255,255,.55); }
.levelcard .lock { font-size: 22px; }

/* ---------- Mobile-first: portrait gate ---------- */
#rotateHint { display: none; }
@media (orientation: portrait) and (pointer: coarse) and (max-width: 920px) {
  #rotateHint {
    display: flex;
    position: absolute; inset: 0; z-index: 60;
    flex-direction: column; align-items: center; justify-content: center;
    text-align: center; gap: 14px; padding: 30px;
    background: linear-gradient(160deg, #3a3f48, #2b2440);
    color: #fff;
  }
  #hud { opacity: 0; pointer-events: none; }
}
#rotateHint .rotate-phone { font-size: 72px; animation: rotatephone 1.9s ease-in-out infinite; }
#rotateHint h2 { margin: 0; font-size: clamp(22px, 6vw, 30px); font-weight: 900; color: var(--accent); }
#rotateHint p { margin: 0; font-size: clamp(14px, 4vw, 17px); line-height: 1.5; color: #ece6f5; }
#rotateHint .rh-en { color: #9a90ad; font-size: 13px; }
@keyframes rotatephone { 0%, 35% { transform: rotate(0deg); } 60%, 100% { transform: rotate(-90deg); } }
