:root {
  --sky-top: #5ec8f0;
  --sky-bot: #b8e8ff;
  --grass: #5cb85c;
  --dirt: #8b5a2b;
  --wood: #c48a3a;
  --stone: #8a9099;
  --glass: #9ad7ef;
  --ink: #2b1a0e;
  --cream: #fff6e8;
  --gold: #ffc14a;
  --red: #e6392f;
  --orange: #ff8a3d;
  --panel: rgba(255, 246, 232, 0.94);
  --shadow: 0 12px 32px rgba(43, 26, 14, 0.22);
  --radius: 18px;
  --font-display: "ZCOOL KuaiLe", "Fredoka", system-ui, sans-serif;
  --font-body: "Fredoka", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.boot-error {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 9999;
  padding: 12px 14px;
  border-radius: 12px;
  background: #3b0d0d;
  color: #ffe0e0;
  border: 2px solid #ff6b6b;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}

.boot-error.hidden {
  display: none;
}

.menu-cloud,
.sky-bg {
  pointer-events: none;
}

html, body, #app {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  color: var(--ink);
  background: #1a120c;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.screen {
  display: none;
  position: absolute;
  inset: 0;
  overflow: auto;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* ===== 主菜单 ===== */
#screen-menu {
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bot) 62%, #7ed957 62%, #5cb85c 78%, #8b5a2b 78%);
}

.sky-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 18% 22%, rgba(255,255,255,.55) 0 4%, transparent 5%),
    radial-gradient(circle at 78% 18%, rgba(255,255,255,.45) 0 3%, transparent 4%),
    linear-gradient(180deg, transparent 55%, rgba(126, 217, 87, .35) 70%);
  pointer-events: none;
}

.menu-cloud {
  position: absolute;
  background: rgba(255,255,255,.85);
  border-radius: 999px;
  filter: blur(0.2px);
  opacity: .9;
  animation: float 8s ease-in-out infinite;
}

.cloud-a {
  width: 160px;
  height: 48px;
  top: 14%;
  left: 8%;
  box-shadow: 40px 10px 0 -4px rgba(255,255,255,.8), 80px 4px 0 -10px rgba(255,255,255,.75);
}

.cloud-b {
  width: 120px;
  height: 40px;
  top: 22%;
  right: 10%;
  animation-delay: -3s;
  box-shadow: 36px 8px 0 -6px rgba(255,255,255,.8);
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.menu-panel {
  position: relative;
  z-index: 2;
  width: min(420px, 92vw);
  padding: 28px 24px 22px;
  background: var(--panel);
  border-radius: 28px;
  box-shadow: var(--shadow);
  border: 4px solid #fff;
  text-align: center;
}

.logo-wrap {
  margin-bottom: 18px;
}

.logo-bird {
  font-size: 56px;
  line-height: 1;
  filter: drop-shadow(0 6px 0 rgba(0,0,0,.08));
  animation: bob 1.6s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-8px) rotate(4deg); }
}

.menu-panel h1 {
  font-family: var(--font-display);
  font-size: 42px;
  letter-spacing: 2px;
  color: var(--red);
  text-shadow: 3px 3px 0 #ffd27a;
}

.subtitle {
  margin-top: 4px;
  color: #7a5840;
  font-weight: 600;
}

.menu-stats {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 16px 0 18px;
}

.stat-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: #fff;
  border-radius: 999px;
  border: 2px solid #f0d8b0;
  box-shadow: 0 3px 0 #e8c48a;
  font-size: 14px;
}

.stat-chip.compact {
  padding: 6px 12px;
  font-size: 13px;
}

.stat-chip span {
  opacity: .7;
}

.stat-chip strong {
  font-size: 16px;
  color: #c45a12;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 16px;
  border-radius: 14px;
  padding: 12px 18px;
  transition: transform .12s ease, filter .12s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.btn:active:not(:disabled) {
  transform: translateY(2px);
}

.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, #ff6b4a, var(--red));
  color: #fff;
  box-shadow: 0 5px 0 #9c1f18;
}

.btn-secondary {
  background: linear-gradient(180deg, #ffd36a, var(--gold));
  color: #5a3208;
  box-shadow: 0 5px 0 #c48a1a;
}

.btn-ghost {
  background: transparent;
  color: #7a5840;
  border: 2px dashed #d2b48c;
}

.btn-icon {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 12px;
  background: #fff;
  border: 2px solid #f0d8b0;
  box-shadow: 0 3px 0 #e8c48a;
  font-size: 18px;
}

.hint {
  margin-top: 14px;
  font-size: 12px;
  color: #9a7050;
}

/* ===== 顶栏通用 ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(255,246,232,.95), rgba(255,246,232,.8));
  border-bottom: 3px solid #f0d8b0;
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h2 {
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--red);
}

#screen-levels,
#screen-shop,
#screen-loadout {
  background:
    radial-gradient(circle at 20% 0%, #fff7 0 8%, transparent 9%),
    linear-gradient(180deg, #7fd3f5, #d7f3ff 40%, #c8ef9a 100%);
}

/* ===== 关卡列表 ===== */
.levels-worlds {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.world-block {
  background: var(--panel);
  border-radius: var(--radius);
  border: 3px solid #fff;
  box-shadow: var(--shadow);
  padding: 14px;
}

.world-title {
  font-family: var(--font-display);
  font-size: 20px;
  margin-bottom: 12px;
  color: #5a3208;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 10px;
}

.level-card {
  aspect-ratio: 1;
  border: none;
  border-radius: 16px;
  background: linear-gradient(180deg, #fff, #ffe9c4);
  box-shadow: 0 4px 0 #e0b86a;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-body);
  font-weight: 700;
  color: var(--ink);
  position: relative;
}

.level-card .num {
  font-size: 22px;
}

.level-card .stars {
  color: #e0a800;
  letter-spacing: 1px;
  font-size: 12px;
}

.level-card.locked {
  opacity: .45;
  cursor: not-allowed;
  filter: grayscale(.4);
}

.level-card.cleared {
  background: linear-gradient(180deg, #fff8e8, #ffd27a);
}

/* ===== 商店 ===== */
.shop-grid {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.shop-card {
  background: var(--panel);
  border: 3px solid #fff;
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shop-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bird-avatar {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 30px;
  border: 3px solid #fff;
  box-shadow: 0 4px 0 rgba(0,0,0,.08);
}

.shop-card h3 {
  font-family: var(--font-display);
  font-size: 20px;
}

.shop-card .tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #ffe0a8;
  color: #8a4b00;
  font-weight: 700;
}

.shop-card p {
  font-size: 13px;
  line-height: 1.45;
  color: #6b4a32;
  min-height: 38px;
}

.shop-card .meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #8a6348;
}

.shop-card .owned {
  color: #2d8a3e;
  font-weight: 700;
}

/* ===== 编队 ===== */
.loadout-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: stretch;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.loadout-slots {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.slot {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  border: 3px dashed #d2b48c;
  background: rgba(255,255,255,.55);
  display: grid;
  place-items: center;
  font-size: 28px;
  cursor: pointer;
}

.slot.filled {
  border-style: solid;
  background: #fff;
  box-shadow: 0 4px 0 #e0b86a;
}

.owned-birds {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.bird-pick {
  width: 70px;
  padding: 8px 6px;
  border-radius: 14px;
  border: 2px solid #fff;
  background: var(--panel);
  box-shadow: 0 3px 0 #e0b86a;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
}

.bird-pick .emoji {
  font-size: 28px;
}

.bird-pick.selected {
  outline: 3px solid var(--red);
}

#btn-start-level {
  margin-top: 6px;
}

/* ===== 对局 ===== */
#screen-game {
  background: #1a120c;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #5ec8f0;
}

.game-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  pointer-events: none;
}

.game-hud .btn,
.game-hud .stat-chip {
  pointer-events: auto;
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255,246,232,.9);
  border-radius: 14px;
  padding: 6px 16px;
  border: 2px solid #fff;
  box-shadow: 0 3px 0 rgba(0,0,0,.12);
  min-width: 120px;
}

#hud-level {
  font-size: 12px;
  color: #8a6348;
  font-weight: 700;
}

#hud-score {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--red);
}

.game-queue {
  position: absolute;
  left: 12px;
  bottom: 14px;
  z-index: 4;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: min(70vw, 420px);
  flex-wrap: wrap;
  pointer-events: auto;
}

.game-queue.selectable .queue-bird:not(:disabled) {
  cursor: pointer;
}

.game-queue.selectable .queue-bird:not(:disabled):hover {
  transform: translateY(-4px) scale(1.06);
  filter: brightness(1.05);
}

.queue-bird {
  width: 52px;
  min-height: 52px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-size: 22px;
  background: rgba(255,255,255,.92);
  border: 2px solid #fff;
  box-shadow: 0 3px 0 rgba(0,0,0,.15);
  opacity: .88;
  padding: 4px 4px 3px;
  font-family: var(--font-body);
  color: var(--ink);
  transition: transform .12s ease, outline-color .12s ease, opacity .12s ease;
}

.queue-bird:disabled {
  cursor: default;
  opacity: .7;
}

.queue-bird.next {
  width: 62px;
  min-height: 62px;
  font-size: 28px;
  opacity: 1;
  outline: 3px solid var(--gold);
  box-shadow: 0 4px 0 rgba(196, 138, 26, .45);
}

.queue-bird .queue-emoji {
  line-height: 1;
}

.queue-bird .queue-name {
  font-size: 9px;
  font-weight: 700;
  line-height: 1.1;
  max-width: 56px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #6b4a32;
}

.queue-bird.next .queue-name {
  font-size: 10px;
  color: #8a4b00;
}

.queue-empty {
  font-size: 12px;
  color: rgba(255,255,255,.85);
  background: rgba(43, 26, 14, .55);
  padding: 6px 10px;
  border-radius: 999px;
}

.ability-hint {
  position: absolute;
  right: 12px;
  bottom: 18px;
  z-index: 4;
  background: rgba(43, 26, 14, .72);
  color: #fff;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  opacity: 0;
  transition: opacity .2s ease;
  pointer-events: none;
}

.ability-hint.show {
  opacity: 1;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(20, 12, 8, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(360px, 100%);
  background: var(--panel);
  border-radius: 24px;
  border: 4px solid #fff;
  box-shadow: var(--shadow);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}

.panel h3 {
  font-family: var(--font-display);
  font-size: 28px;
  color: var(--red);
}

.result-stars {
  font-size: 36px;
  letter-spacing: 6px;
  color: #e0a800;
  min-height: 44px;
}

.result-score,
.result-reward {
  color: #6b4a32;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

@media (max-width: 480px) {
  .menu-panel h1 { font-size: 34px; }
  .topbar h2 { font-size: 20px; }
}

/* ===== 调试 CHEAT ===== */
.cheat-toggle {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 10000;
  border: 2px solid #2b1a0e;
  border-radius: 999px;
  padding: 8px 14px;
  background: linear-gradient(180deg, #3d3d3d, #1a1a1a);
  color: #7CFF6B;
  font-family: ui-monospace, Consolas, monospace;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 4px 0 #0a0a0a, 0 8px 20px rgba(0,0,0,.35);
  pointer-events: auto;
}

.cheat-toggle:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #0a0a0a;
}

.cheat-panel {
  position: fixed;
  right: 12px;
  bottom: 56px;
  z-index: 10000;
  width: min(320px, calc(100vw - 24px));
  padding: 14px;
  border-radius: 16px;
  background: rgba(18, 14, 12, 0.94);
  color: #f5ebe0;
  border: 2px solid #7CFF6B;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
  font-family: var(--font-body);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}

.cheat-panel.hidden {
  display: none;
}

.cheat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cheat-head strong {
  color: #7CFF6B;
  font-family: ui-monospace, Consolas, monospace;
  letter-spacing: 0.5px;
}

.cheat-x {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: #333;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

.cheat-hint {
  font-size: 12px;
  color: #c4b5a5;
  margin: 0;
}

.cheat-hint kbd {
  background: #2a2a2a;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 0 5px;
  font-size: 11px;
}

.cheat-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.cheat-field > span {
  opacity: 0.85;
}

.cheat-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.cheat-row.wrap {
  flex-wrap: wrap;
}

.cheat-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #555;
  background: #0f0f0f;
  color: #fff;
  font-size: 15px;
  font-family: ui-monospace, Consolas, monospace;
}

.cheat-panel .btn {
  font-size: 13px;
  padding: 8px 10px;
}

.cheat-panel .btn-ghost {
  color: #e8dcc8;
  border-color: #666;
}

.cheat-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cheat-status {
  margin: 0;
  font-size: 12px;
  color: #7CFF6B;
  min-height: 16px;
  font-family: ui-monospace, Consolas, monospace;
}