/* =========================================================
   Raining Tacos · bright maximalist style
   Vibrant warm palette, decorative party banners, chunky type.
   ========================================================= */

:root {
  --marigold: #ffb302;
  --papaya:   #ff7a1a;
  --tomato:   #e63946;
  --rosa:     #ff3d8b;
  --lime:     #7fd33f;
  --sky:      #2ec4ff;
  --cobalt:   #0d62a8;
  --cream:    #fff6e3;
  --ink:      #1a1230;
  --dusk:     #2a1747;
  --mole:     #4a2a14;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Nunito", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 50% -10%, #ffd86b 0%, #ff9a3c 28%, #f25b3a 55%, #c8327d 80%, #5e2a8c 100%);
  position: relative;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(255,255,255,0.85) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 78% 9%, rgba(255,255,255,0.7) 0 1.2px, transparent 2px),
    radial-gradient(circle at 44% 30%, rgba(255,255,255,0.6) 0 1px, transparent 2px),
    radial-gradient(circle at 88% 38%, rgba(255,255,255,0.5) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 22% 60%, rgba(255,255,255,0.45) 0 1px, transparent 2px),
    radial-gradient(circle at 64% 68%, rgba(255,255,255,0.6) 0 1.4px, transparent 2.4px);
  background-size: 480px 380px;
  animation: twinkle 14s ease-in-out infinite;
  z-index: 0;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 0.95; }
}

/* ---- Decorative top banner ---- */
.banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  display: flex;
  z-index: 5;
  pointer-events: none;
  filter: drop-shadow(0 6px 0 rgba(0,0,0,0.18));
}

.flag {
  flex: 1;
  height: 100%;
  position: relative;
  clip-path: polygon(
    0 0, 100% 0, 100% 50%,
    90% 60%, 80% 50%, 70% 60%, 60% 50%,
    50% 60%, 40% 50%, 30% 60%, 20% 50%,
    10% 60%, 0 50%
  );
  background-image:
    radial-gradient(circle at 25% 30%, rgba(255,255,255,0.65) 0 3px, transparent 4px),
    radial-gradient(circle at 65% 26%, rgba(255,255,255,0.65) 0 3px, transparent 4px),
    radial-gradient(circle at 45% 42%, rgba(255,255,255,0.55) 0 4px, transparent 5px);
}

.flag-1, .flag-6  { background-color: var(--tomato); }
.flag-2, .flag-7  { background-color: var(--marigold); }
.flag-3, .flag-8  { background-color: var(--lime); }
.flag-4, .flag-9  { background-color: var(--sky); }
.flag-5, .flag-10 { background-color: var(--rosa); }

/* ---- Stage ---- */
.stage {
  position: relative;
  z-index: 2;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 76px 20px 18px;
  gap: 12px;
}

/* ---- HUD ---- */
.hud {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 12px;
  max-width: 980px;
  margin: 0 auto;
  width: 100%;
  flex-wrap: wrap;
}

.hud-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 18px;
  min-width: 110px;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 6px 0 var(--ink), 0 12px 22px rgba(26, 18, 48, 0.35);
  position: relative;
}

.hud-label {
  font-family: "Bungee", sans-serif;
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--mole);
  margin-bottom: 2px;
}

.hud-value {
  font-family: "Bungee", sans-serif;
  font-size: 28px;
  line-height: 1;
  color: var(--ink);
}

.hud-sub {
  font-size: 10px;
  font-weight: 700;
  color: var(--mole);
  opacity: 0.7;
  margin-top: 2px;
}

.level-block {
  min-width: 80px;
  background: var(--ink);
}
.level-block .hud-label { color: var(--marigold); }
.level-block .hud-value { color: var(--cream); }
.level-block.level-2 { background: linear-gradient(135deg, #e63946 0%, #ff7a1a 100%); }
.level-block.level-2 .hud-value { color: #fff; }
.level-block.level-2 .hud-label { color: rgba(255,255,255,0.85); }

.timer-block .hud-value { color: var(--cobalt); }
.timer-block.warn .hud-value { color: var(--tomato); animation: shake 0.4s infinite; }

@keyframes shake {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  25%      { transform: translate(-2px, 1px) rotate(-2deg); }
  75%      { transform: translate(2px, -1px) rotate(2deg); }
}

.score-block .hud-value { color: var(--papaya); }
.score-block.pulse .hud-value { animation: pop 0.28s ease; }

@keyframes pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.35); color: var(--tomato); }
  100% { transform: scale(1); }
}

.rotten-block { gap: 4px; }
.rotten-pips {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.pip {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(0,0,0,0.12);
  border: 2px solid var(--ink);
  transition: background 0.2s, transform 0.2s;
}
.pip.lit {
  background: radial-gradient(circle at 35% 30%, #b6e36b 0%, #4a7a18 70%);
  transform: scale(1.15);
  box-shadow: 0 0 12px rgba(127, 211, 63, 0.7);
}

.combo-block .hud-value { color: var(--rosa); }

.mute-btn {
  font-size: 20px;
  background: var(--ink);
  color: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  cursor: pointer;
  align-self: center;
  box-shadow: 0 4px 0 rgba(0,0,0,0.35);
  transition: transform 0.1s;
}
.mute-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.35); }

/* ---- Canvas ---- */
.canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  border-radius: 24px;
  overflow: hidden;
  border: 4px solid var(--ink);
  box-shadow:
    0 10px 0 var(--ink),
    0 26px 60px rgba(26, 18, 48, 0.55);
  background: linear-gradient(180deg, #62c4ff 0%, #ffb84d 65%, #ff7a3c 100%);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 900 / 640;
  cursor: none;
}

/* ---- Overlays ---- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  background: radial-gradient(ellipse at center, rgba(26, 18, 48, 0.35), rgba(26, 18, 48, 0.85));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fadeIn 0.4s ease;
  overflow-y: auto;
}

.hidden { display: none !important; }

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

.card {
  background: var(--cream);
  border: 5px solid var(--ink);
  border-radius: 28px;
  padding: 28px 32px 24px;
  text-align: center;
  max-width: 520px;
  width: 100%;
  position: relative;
  box-shadow: 0 12px 0 var(--ink), 0 28px 60px rgba(0,0,0,0.4);
  background-image:
    radial-gradient(circle at 10% 90%, rgba(255, 122, 26, 0.18) 0 22px, transparent 23px),
    radial-gradient(circle at 90% 12%, rgba(46, 196, 255, 0.2) 0 18px, transparent 19px),
    radial-gradient(circle at 88% 85%, rgba(255, 61, 139, 0.15) 0 14px, transparent 15px);
}

.title {
  font-family: "Bungee Shade", "Bungee", sans-serif;
  line-height: 0.95;
  margin-bottom: 10px;
  letter-spacing: 0.02em;
}

.title-line {
  display: block;
  font-size: clamp(36px, 7vw, 56px);
  color: var(--tomato);
  text-shadow: 4px 4px 0 var(--marigold);
}

.title-line-2 {
  color: var(--cobalt);
  text-shadow: 4px 4px 0 var(--lime);
  transform: rotate(-2deg);
  margin-top: 2px;
}

.tagline {
  font-size: 15px;
  line-height: 1.4;
  margin: 4px auto 14px;
  color: var(--dusk);
  font-weight: 600;
}

.tagline strong { color: var(--tomato); font-weight: 900; }

.legend {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  padding: 5px 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-weight: 700;
  font-size: 12px;
}

.taco-chip {
  width: 24px;
  height: 16px;
  border-radius: 16px 16px 4px 4px;
  position: relative;
  display: inline-block;
  border: 2px solid var(--mole);
}

.taco-chip-good {
  background: linear-gradient(180deg, #ffd14d 0%, #ffae2b 100%);
}
.taco-chip-good::after {
  content: "";
  position: absolute;
  inset: 2px 3px auto 3px;
  height: 5px;
  background: linear-gradient(90deg, var(--tomato), var(--lime), var(--tomato));
  border-radius: 4px;
}

.taco-chip-rotten {
  background: linear-gradient(180deg, #9bbf3a 0%, #5d7a1d 100%);
  border-color: #2d3a09;
}
.taco-chip-rotten::after {
  content: "";
  position: absolute;
  inset: 2px 3px auto 3px;
  height: 5px;
  background: #3a4d10;
  border-radius: 4px;
  box-shadow: inset 0 0 0 2px #2a3a08;
}

/* ---- Level Select ---- */
.level-select {
  margin: 6px auto 14px;
}

.level-select-title {
  font-family: "Bungee", sans-serif;
  font-size: 14px;
  color: var(--mole);
  letter-spacing: 0.18em;
  margin-bottom: 10px;
}

.level-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.level-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px 12px 14px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 18px;
  cursor: pointer;
  font-family: "Nunito", sans-serif;
  color: var(--ink);
  box-shadow: 0 5px 0 var(--ink);
  transition: transform 0.1s, box-shadow 0.1s, background 0.2s;
  overflow: hidden;
}

.level-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,179,2,0.08) 0%, transparent 50%, rgba(255,61,139,0.08) 100%);
  pointer-events: none;
}

.level-card:not(.locked):hover {
  transform: translateY(-2px);
  box-shadow: 0 7px 0 var(--ink);
  background: #fffdf3;
}
.level-card:not(.locked):active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--ink);
}

.level-card[data-level="1"] .level-card-badge {
  background: var(--cobalt);
  color: var(--cream);
}
.level-card[data-level="2"] .level-card-badge {
  background: linear-gradient(135deg, var(--tomato) 0%, var(--papaya) 100%);
  color: var(--cream);
}

.level-card-badge {
  font-family: "Bungee", sans-serif;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  letter-spacing: 0.08em;
}

.level-card-goal {
  font-family: "Bungee", sans-serif;
  font-size: 22px;
  color: var(--tomato);
  margin-top: 4px;
}

.level-card-time {
  font-size: 12px;
  font-weight: 800;
  color: var(--dusk);
  letter-spacing: 0.05em;
}

.level-card-best {
  font-size: 11px;
  font-weight: 700;
  color: var(--mole);
  margin-top: 4px;
}
.level-card-best strong {
  color: var(--cobalt);
  font-family: "Bungee", sans-serif;
}

.level-card.locked {
  cursor: not-allowed;
  opacity: 0.55;
  background: #efe9da;
}
.level-card.locked .level-card-badge {
  filter: grayscale(0.6);
}

.level-card-lock {
  display: none;
  font-size: 11px;
  font-weight: 800;
  color: var(--mole);
  margin-top: 2px;
  letter-spacing: 0.04em;
}
.level-card.locked .level-card-lock {
  display: inline-block;
}

.controls-hint {
  font-size: 13px;
  color: var(--mole);
  margin-top: 4px;
  font-weight: 700;
}

.controls-hint kbd {
  background: #fff;
  border: 2px solid var(--ink);
  border-bottom-width: 3px;
  border-radius: 6px;
  padding: 2px 7px;
  font-family: "Bungee", monospace;
  font-size: 11px;
  margin: 0 2px;
  color: var(--ink);
}

.play-btn {
  font-family: "Bungee", sans-serif;
  font-size: 18px;
  padding: 12px 24px;
  background: var(--tomato);
  color: var(--cream);
  border: 4px solid var(--ink);
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s, background 0.2s;
  letter-spacing: 0.04em;
}

.play-btn:hover { background: #ff5263; }
.play-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--ink);
}

.play-btn-secondary {
  background: var(--marigold);
  color: var(--ink);
}
.play-btn-secondary:hover { background: #ffc340; }

.play-btn-ghost {
  background: transparent;
  color: var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  font-size: 14px;
  padding: 10px 18px;
}
.play-btn-ghost:hover { background: rgba(0,0,0,0.05); }

/* End screen */
.card-end .end-title {
  font-family: "Bungee", sans-serif;
  font-size: 40px;
  color: var(--tomato);
  text-shadow: 3px 3px 0 var(--marigold);
  margin-bottom: 6px;
  line-height: 1;
}
.card-end.lose .end-title { color: var(--cobalt); text-shadow: 3px 3px 0 var(--rosa); }
.card-end.dead .end-title { color: #4a7a18; text-shadow: 3px 3px 0 var(--ink); }
.card-end.champion .end-title { color: var(--rosa); text-shadow: 3px 3px 0 var(--marigold); }

.end-sub {
  color: var(--dusk);
  font-weight: 700;
  margin-bottom: 16px;
  font-size: 14px;
}

.end-stats {
  text-align: left;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 5px 0;
  font-weight: 700;
  color: var(--dusk);
  border-bottom: 1px dashed rgba(26, 18, 48, 0.18);
  font-size: 13px;
}
.stat-row:last-child { border-bottom: none; }
.stat-row strong {
  font-family: "Bungee", sans-serif;
  font-size: 20px;
  color: var(--tomato);
}
.stat-row-total strong { color: var(--cobalt); }

.end-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.home-link {
  font-weight: 800;
  color: var(--cobalt);
  text-decoration: none;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 2px dashed var(--cobalt);
  transition: background 0.2s;
}
.home-link:hover { background: rgba(13, 98, 168, 0.1); }

/* ---- Responsive ---- */
@media (max-width: 720px) {
  .stage { padding: 64px 10px 10px; }
  .banner { height: 42px; }
  .hud-block { padding: 6px 12px; min-width: 80px; }
  .hud-value { font-size: 20px; }
  .hud-label { font-size: 9px; }
  .mute-btn { width: 40px; height: 40px; font-size: 16px; }
  .card { padding: 22px 18px 18px; }
  .title-line { font-size: 38px; }
  .tagline { font-size: 13px; }
  .play-btn { font-size: 16px; padding: 10px 20px; }
  .level-cards { grid-template-columns: 1fr; }
  .level-card-goal { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
