* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  background: #0f172a;
  color: #f8fafc;
}

#canvas-container {
  position: fixed;
  inset: 0;
  z-index: 1;
}

#canvas-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hidden {
  display: none !important;
}

/* ==================== MENU OVERLAY ==================== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, rgba(15, 23, 42, 0.35), rgba(15, 23, 42, 0.82));
  backdrop-filter: blur(4px);
}

.menu-panel {
  width: min(1140px, 95vw);
  max-height: 94vh;
  overflow-y: auto;
  background: linear-gradient(160deg, rgba(30, 41, 59, 0.92), rgba(15, 23, 42, 0.95));
  border: 3px solid rgba(134, 239, 172, 0.45);
  border-radius: 24px;
  padding: 24px 26px 22px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65);
  text-align: center;
}

.game-logo {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.game-logo h1 {
  font-size: clamp(28px, 4.2vw, 44px);
  font-weight: 900;
  letter-spacing: 2px;
  background: linear-gradient(180deg, #fef08a 0%, #4ade80 55%, #16a34a 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.55));
}

.tag-3d {
  background: linear-gradient(135deg, #f97316, #ef4444);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  padding: 4px 12px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.5);
}

.menu-desc {
  color: #cbd5e1;
  font-size: 15px;
  margin-bottom: 22px;
}

.level-cards {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.level-card {
  position: relative;
  border-radius: 16px;
  padding: 14px 13px;
  text-align: left;
  cursor: pointer;
  border: 2px solid rgba(255, 255, 255, 0.16);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.level-card.theme-day {
  background: linear-gradient(155deg, rgba(56, 189, 248, 0.35), rgba(34, 197, 94, 0.32));
}
.level-card.theme-sunset {
  background: linear-gradient(155deg, rgba(249, 115, 22, 0.4), rgba(180, 83, 9, 0.34));
}
.level-card.theme-night {
  background: linear-gradient(155deg, rgba(59, 130, 246, 0.35), rgba(30, 27, 75, 0.72));
}
.level-card.theme-storm {
  background: linear-gradient(155deg, rgba(100, 116, 139, 0.48), rgba(15, 118, 110, 0.45));
}
.level-card.theme-bloodmoon {
  background: linear-gradient(155deg, rgba(220, 38, 38, 0.48), rgba(76, 5, 25, 0.78));
}

.level-card:hover {
  transform: translateY(-5px);
  border-color: #fde047;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

.level-card.completed {
  border-color: #4ade80;
}

.level-badge {
  font-size: 12px;
  font-weight: 700;
  color: #fef08a;
  letter-spacing: 0.5px;
}

.level-card h3 {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
}

.level-sub {
  font-size: 13px;
  color: #e2e8f0;
  line-height: 1.4;
}

.level-plants {
  font-size: 18px;
  letter-spacing: 2px;
  line-height: 1.35;
  margin: 2px 0 6px;
}

.btn-level-start {
  margin-top: auto;
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  font-weight: 800;
  color: #052e16;
  background: linear-gradient(180deg, #86efac, #22c55e);
  cursor: pointer;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.menu-btn-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.menu-perf-btn {
  padding: 12px 18px;
  font-size: 14px;
  border-radius: 12px;
}

.btn-primary {
  border: none;
  border-radius: 14px;
  padding: 13px 38px;
  font-size: 18px;
  font-weight: 900;
  color: #422006;
  background: linear-gradient(180deg, #fef08a, #facc15 65%, #eab308);
  box-shadow: 0 6px 0 #a16207, 0 10px 25px rgba(234, 179, 8, 0.35);
  cursor: pointer;
  transition: transform 0.12s ease;
}

.btn-primary:hover {
  transform: translateY(-2px);
}

.btn-primary:active {
  transform: translateY(2px);
}

.controls-guide {
  font-size: 12.5px;
  color: #94a3b8;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
}

.controls-guide span b {
  color: #e2e8f0;
}

/* ==================== IN-GAME HUD ==================== */
#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.hud-top {
  position: absolute;
  top: 12px;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

/* Wood-styled Seed Bank Bar */
.seed-bar {
  pointer-events: auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 7px 10px;
  max-width: calc(100vw - 28px);
  border-radius: 16px;
  background: linear-gradient(180deg, #7c4a24 0%, #5c3417 100%);
  border: 3px solid #9a6033;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.48), inset 0 2px 3px rgba(255, 255, 255, 0.2);
}

.sun-box {
  width: 74px;
  height: 76px;
  border-radius: 12px;
  background: radial-gradient(circle at 50% 35%, #fffbeb 0%, #fef08a 58%, #facc15 100%);
  border: 2px solid #d97706;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #422006;
  box-shadow: 0 0 14px rgba(250, 204, 21, 0.45), inset 0 -3px 8px rgba(217, 119, 6, 0.35);
}

.sun-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  filter: drop-shadow(0 0 6px rgba(245, 158, 11, 0.7));
}

.sun-svg {
  display: block;
}

.sun-rays-outer {
  transform-origin: 32px 32px;
  animation: sunSpinCW 14s linear infinite;
}

.sun-rays-inner {
  transform-origin: 32px 32px;
  animation: sunSpinCCW 10s linear infinite;
}

@keyframes sunSpinCW {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes sunSpinCCW {
  from { transform: rotate(360deg); }
  to { transform: rotate(0deg); }
}

#sun-count {
  font-size: 19px;
  font-weight: 900;
  margin-top: -1px;
  transition: transform 0.15s ease;
}

#sun-count.pop {
  animation: sunPop 0.28s ease;
}

@keyframes sunPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.28); color: #b45309; }
  100% { transform: scale(1); }
}

.seed-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.seed-card {
  position: relative;
  width: 64px;
  height: 74px;
  border-radius: 10px;
  background: linear-gradient(180deg, #f1f5f9 0%, #cbd5e1 100%);
  border: 2px solid #475569;
  color: #0f172a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 5px 3px 4px;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.seed-card:hover:not(.disabled) {
  transform: translateY(-3px);
  border-color: #fde047;
}

.seed-card.selected {
  transform: translateY(-4px) scale(1.04);
  border-color: #22c55e;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.65);
  background: linear-gradient(180deg, #dcfce7, #bbf7d0);
}

.seed-card.disabled {
  filter: grayscale(0.75) brightness(0.68);
  cursor: not-allowed;
}

.seed-key {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 10px;
  font-weight: 800;
  color: #64748b;
}

.seed-icon {
  font-size: 27px;
  line-height: 1.05;
  margin-top: 2px;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25));
}

.seed-name {
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.seed-cost {
  font-size: 11px;
  font-weight: 900;
  color: #92400e;
  background: rgba(254, 240, 138, 0.85);
  border-radius: 6px;
  padding: 0 5px;
}

.seed-cooldown {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0%;
  background: rgba(15, 23, 42, 0.62);
  pointer-events: none;
}

.shovel-btn {
  width: 64px;
  height: 76px;
  border-radius: 10px;
  border: 2px solid #94a3b8;
  background: linear-gradient(180deg, #475569, #1e293b);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.shovel-btn .shovel-icon {
  font-size: 26px;
}

.shovel-btn:hover {
  transform: translateY(-2px);
  border-color: #fb923c;
}

.shovel-btn.selected {
  border-color: #f97316;
  background: linear-gradient(180deg, #ea580c, #9a3412);
  box-shadow: 0 0 0 3px rgba(251, 146, 60, 0.55);
}

/* Top-Right Controls */
.hud-controls {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.level-pill {
  background: rgba(15, 23, 42, 0.78);
  border: 1.5px solid rgba(255, 255, 255, 0.22);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
  color: #fef08a;
  backdrop-filter: blur(6px);
}

.ctrl-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.hud-btn {
  border: 1.5px solid rgba(255, 255, 255, 0.22);
  background: rgba(15, 23, 42, 0.78);
  color: #f1f5f9;
  border-radius: 10px;
  padding: 6px 11px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.hud-btn:hover {
  background: rgba(30, 41, 59, 0.95);
  border-color: #fde047;
}

.hud-btn.active {
  background: rgba(22, 163, 74, 0.85);
  border-color: #86efac;
}

/* Wave Banner */
.wave-banner {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.7);
  opacity: 0;
  padding: 14px 36px;
  border-radius: 18px;
  font-size: clamp(22px, 3vw, 34px);
  font-weight: 900;
  letter-spacing: 2px;
  color: #fef08a;
  background: rgba(15, 23, 42, 0.86);
  border: 3px solid #facc15;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.6);
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
  white-space: nowrap;
}

.wave-banner.danger {
  color: #fecaca;
  background: rgba(127, 29, 29, 0.9);
  border-color: #ef4444;
}

.wave-banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Bottom HUD */
.hud-bottom {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 14px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.tip-box {
  max-width: 440px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 8px 13px;
  font-size: 12.5px;
  color: #e2e8f0;
  backdrop-filter: blur(6px);
}

.progress-box {
  width: 270px;
  background: rgba(15, 23, 42, 0.82);
  border: 2px solid rgba(148, 163, 184, 0.45);
  border-radius: 14px;
  padding: 10px 14px;
  backdrop-filter: blur(6px);
}

.progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  color: #cbd5e1;
  margin-bottom: 8px;
}

.progress-track {
  position: relative;
  height: 12px;
  border-radius: 999px;
  background: #1e293b;
  border: 1px solid #475569;
}

#progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #22c55e, #84cc16, #facc15);
  transition: width 0.2s linear;
}

#progress-head {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%);
  font-size: 18px;
  transition: left 0.2s linear;
}

.progress-flag {
  position: absolute;
  top: -12px;
  transform: translateX(-50%);
  font-size: 13px;
}

/* ==================== MODALS & FLOATING TEXT ==================== */
.modal-card {
  width: min(460px, 92vw);
  background: linear-gradient(160deg, #1e293b, #0f172a);
  border: 3px solid rgba(250, 204, 21, 0.55);
  border-radius: 22px;
  padding: 28px 28px 24px;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.72);
}

.modal-title {
  font-size: 30px;
  font-weight: 900;
  margin-bottom: 6px;
}

.modal-title.victory {
  color: #4ade80;
}

.modal-title.defeat {
  color: #f87171;
}

.modal-sub {
  color: #cbd5e1;
  font-size: 15px;
  margin-bottom: 18px;
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.modal-stats > div {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-stats span {
  font-size: 12px;
  color: #94a3b8;
}

.modal-stats strong {
  font-size: 22px;
  color: #fef08a;
}

.modal-reward {
  background: rgba(34, 197, 94, 0.18);
  border: 1.5px solid rgba(74, 222, 128, 0.5);
  color: #bbf7d0;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 18px;
}

.modal-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-secondary {
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  background: rgba(51, 65, 85, 0.85);
  color: #f8fafc;
  border-radius: 12px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.btn-secondary:hover {
  background: rgba(71, 85, 105, 0.95);
}

#floating-text-layer {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  overflow: hidden;
}

.float-text {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 22px;
  font-weight: 900;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.85);
  animation: floatUp 0.95s ease-out forwards;
}

@keyframes floatUp {
  0% { opacity: 1; transform: translate(-50%, -40%) scale(0.85); }
  25% { opacity: 1; transform: translate(-50%, -85%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -175%) scale(0.95); }
}

@media (max-width: 1020px) {
  .level-cards {
    grid-template-columns: repeat(3, 1fr);
  }
  .hud-top {
    flex-direction: column;
  }
}

@media (max-width: 780px) {
  .level-cards {
    grid-template-columns: repeat(2, 1fr);
  }
  .seed-card {
    width: 58px;
    height: 72px;
    padding: 4px 2px 3px;
  }
  .seed-icon {
    font-size: 22px;
  }
  .tip-box {
    display: none;
  }
}

@media (max-width: 520px) {
  .level-cards {
    grid-template-columns: 1fr;
  }
}
