/* ───────────────────────────────────────────────────────────
   CARNIVAL CASCADE — Trinidad Block Fete
   a Lumen Labs original · 2.5D block puzzle
   ─────────────────────────────────────────────────────────── */

:root {
  --bg-0: #0a0612;
  --bg-1: #150a26;
  --red: #e8112d;       /* chaconia / flag red */
  --gold: #ffc21f;      /* steelpan / soca gold */
  --green: #00a651;     /* hummingbird green */
  --teal: #00c2c7;      /* Caribbean sea */
  --magenta: #ff2d8e;   /* carnival feathers */
  --purple: #8b2fc9;    /* mas costume */
  --orange: #ff7a1a;    /* mango / sunset */
  --ink: #fff;
  --ink-2: rgba(255, 255, 255, 0.72);
  --ink-3: rgba(255, 255, 255, 0.45);
  --head: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
  --mono: 'SFMono-Regular', Consolas, monospace;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-0);
  color: var(--ink);
  font-family: var(--head);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: none;
}

#stage {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 12%, rgba(139, 47, 201, 0.30), transparent 60%),
    radial-gradient(ellipse 70% 50% at 80% 90%, rgba(0, 194, 199, 0.18), transparent 60%),
    radial-gradient(ellipse 70% 50% at 15% 85%, rgba(232, 17, 45, 0.16), transparent 60%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 70%);
  overflow: hidden;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ── HUD ─────────────────────────────────────────────────── */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#hud.hidden { display: none; }

.hud-top {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.hud-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 92px;
  padding: 7px 16px;
  border-radius: 14px;
  background: rgba(10, 6, 18, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

.hud-best { border-color: rgba(255, 194, 31, 0.4); }

.hud-label {
  font-family: var(--mono);
  font-size: 0.56rem;
  letter-spacing: 2px;
  color: var(--ink-3);
}

.hud-value {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.05;
}

.hud-best .hud-value { color: var(--gold); }

.hud-btn {
  pointer-events: auto;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(10, 6, 18, 0.66);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--ink);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}

.hud-btn:active { transform: scale(0.92); background: rgba(255, 45, 142, 0.25); }

/* combo popup */
.combo-pop {
  position: absolute;
  top: 26%;
  left: 50%;
  transform: translate(-50%, 0) scale(0.6);
  font-size: clamp(1.6rem, 8vw, 3rem);
  font-weight: 900;
  letter-spacing: 0.02em;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
}

.combo-pop.show {
  animation: combo-burst 0.95s cubic-bezier(0.2, 0.9, 0.3, 1) forwards;
}

@keyframes combo-burst {
  0%   { opacity: 0; transform: translate(-50%, 10px) scale(0.5) rotate(-4deg); }
  25%  { opacity: 1; transform: translate(-50%, -6px) scale(1.15) rotate(2deg); }
  70%  { opacity: 1; transform: translate(-50%, -10px) scale(1) rotate(0deg); }
  100% { opacity: 0; transform: translate(-50%, -38px) scale(0.95); }
}

/* ── OVERLAYS ────────────────────────────────────────────── */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(6, 3, 12, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.overlay.hidden { display: none; }

.overlay-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: linear-gradient(165deg, rgba(31, 14, 54, 0.96), rgba(12, 7, 22, 0.96));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  padding: 30px 26px 26px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.flag-stripe {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 6px;
  background: linear-gradient(90deg,
    var(--red) 0%, var(--red) 33%,
    #fff 33%, #fff 38%,
    #0a0a0a 38%, #0a0a0a 62%,
    #fff 62%, #fff 67%,
    var(--red) 67%, var(--red) 100%);
}

/* logo */
.game-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.92;
  margin: 8px 0 16px;
}

.logo-carnival {
  font-size: clamp(2.1rem, 11vw, 2.9rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  background: linear-gradient(100deg, var(--gold), var(--orange), var(--magenta));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-cascade {
  font-size: clamp(2.4rem, 13vw, 3.4rem);
  font-weight: 900;
  letter-spacing: 0.02em;
  background: linear-gradient(100deg, var(--teal), var(--green), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-top: -4px;
}

.logo-sub {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 4px;
  color: var(--magenta);
  margin-top: 8px;
}

.title-tag {
  color: var(--ink-2);
  font-size: 0.92rem;
  line-height: 1.5;
  margin-bottom: 22px;
}

.btn-fete {
  display: block;
  width: 100%;
  padding: 15px;
  border-radius: 14px;
  border: none;
  font-family: var(--head);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  margin-top: 10px;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.btn-fete:active { transform: scale(0.97); }

.btn-primary {
  color: #2a0810;
  background: linear-gradient(135deg, var(--gold) 0%, var(--orange) 60%, var(--magenta) 130%);
  box-shadow: 0 10px 30px rgba(255, 122, 26, 0.4);
}

.btn-ghost {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.made-by {
  margin-top: 18px;
  font-size: 0.74rem;
  color: var(--ink-3);
}

.made-by strong { color: var(--teal); }

/* funnel CTA on the end screens — the "get your own game" button */
.cta-build {
  margin-top: 12px;
  color: #2a0810;
  background: linear-gradient(135deg, var(--gold) 0%, var(--orange) 55%, var(--magenta) 120%);
  box-shadow: 0 8px 26px rgba(255, 122, 26, 0.45);
  text-decoration: none;
  animation: cta-glow 2.4s ease-in-out infinite;
}
@keyframes cta-glow { 50% { box-shadow: 0 8px 36px rgba(255, 45, 142, 0.6); } }
.cta-by {
  margin-top: 8px;
  font-size: 0.64rem;
  color: var(--ink-3);
  font-family: var(--mono);
  line-height: 1.4;
}

/* how to play */
.how-title, .over-title {
  font-size: 1.7rem;
  font-weight: 900;
  letter-spacing: 0.02em;
  margin-bottom: 16px;
}

.how-title {
  background: linear-gradient(100deg, var(--teal), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.how-list {
  list-style: none;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 22px;
}

.how-list li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 0.92rem;
  line-height: 1.4;
  color: var(--ink-2);
}

.how-list em { color: var(--gold); font-style: normal; font-weight: 700; }
.how-ico { font-size: 1.3rem; flex-shrink: 0; line-height: 1.1; }

/* game over */
.over-title {
  background: linear-gradient(100deg, var(--magenta), var(--red), var(--orange));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-top: 6px;
}

.over-line {
  color: var(--ink-2);
  font-size: 0.95rem;
  margin-bottom: 22px;
}

.over-scores {
  display: flex;
  gap: 14px;
  margin-bottom: 18px;
}

.over-score {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 10px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.over-val {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.over-score:first-child .over-val { color: var(--teal); }
.over-score:last-child .over-val { color: var(--gold); }

.over-newbest {
  color: var(--gold);
  font-weight: 800;
  font-size: 0.92rem;
  margin-bottom: 18px;
  animation: newbest-pulse 1.2s ease-in-out infinite;
}

.over-newbest.hidden { display: none; }

@keyframes newbest-pulse {
  50% { transform: scale(1.05); opacity: 0.85; }
}

/* boot */
#boot {
  flex-direction: column;
  gap: 18px;
  background: var(--bg-0);
}

.boot-spinner {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px solid rgba(255, 194, 31, 0.2);
  border-top-color: var(--gold);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.boot-text {
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 2px;
  color: var(--ink-3);
}

/* ── armed-powerup hint ──────────────────────────────────── */
.armed-hint {
  position: absolute;
  top: 15%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 6, 18, 0.82);
  border: 1px solid rgba(57, 255, 20, 0.45);
  color: #fff;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.5px;
  padding: 9px 16px;
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
.armed-hint.show { opacity: 1; }

/* ── powerup dock + fete meter ───────────────────────────── */
.dock {
  position: absolute;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(420px, calc(100% - 28px));
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meter {
  position: relative;
  height: 16px;
  border-radius: 999px;
  background: rgba(10, 6, 18, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.12);
  overflow: hidden;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.meter-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: linear-gradient(90deg, var(--teal), var(--gold), var(--magenta));
  transition: width 0.3s ease;
  box-shadow: 0 0 14px rgba(255, 194, 31, 0.5);
}

.meter-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 0.56rem;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}

.dock-row { display: flex; gap: 6px; }

.pw {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 2px 6px;
  border-radius: 13px;
  background: rgba(10, 6, 18, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.pw:active { transform: scale(0.94); }
.pw-ico { font-size: 1.2rem; line-height: 1; }
.pw-name { font-family: var(--mono); font-size: 0.44rem; letter-spacing: 0.8px; color: var(--ink-3); white-space: nowrap; }

.pw-n {
  position: absolute;
  top: -6px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--gold);
  color: #2a0810;
  font-size: 0.66rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.pw.armed {
  border-color: var(--volt);
  background: rgba(57, 255, 20, 0.12);
  box-shadow: 0 0 18px rgba(57, 255, 20, 0.5);
}
.pw.empty { opacity: 0.4; }
.pw.empty .pw-n { background: rgba(255, 255, 255, 0.2); color: #fff; }
.pw.granted { animation: pw-grant 0.6s ease; }

@keyframes pw-grant {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.18); box-shadow: 0 0 24px var(--gold); }
}

/* ── title sound toggle ──────────────────────────────────── */
.sound-toggle {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 9px;
  border-radius: 12px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 1px;
  cursor: pointer;
}
.sound-toggle:active { transform: scale(0.97); }

/* ── floating +score popups ──────────────────────────────── */
.cc-float {
  position: fixed;
  transform: translate(-50%, -50%);
  font-size: 1.45rem;
  font-weight: 900;
  pointer-events: none;
  z-index: 20;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.75);
  animation: cc-float-up 1s ease-out forwards;
}

@keyframes cc-float-up {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  20% { opacity: 1; transform: translate(-50%, -60%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1); }
}

/* ── level goal bar (HUD) ────────────────────────────────── */
.goal-bar {
  position: absolute;
  top: calc(66px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, calc(100% - 32px));
  background: rgba(10, 6, 18, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 6px 14px 8px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  pointer-events: none;
}
.goal-bar.hidden { display: none; }
.goal-text {
  display: block;
  font-family: var(--mono);
  font-size: 0.56rem;
  letter-spacing: 1.2px;
  color: var(--ink-2);
  text-align: center;
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.goal-track { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.goal-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--teal), var(--gold), var(--magenta));
  transition: width 0.4s ease;
  box-shadow: 0 0 10px rgba(255, 194, 31, 0.5);
}

/* ── level select ────────────────────────────────────────── */
.overlay-card-wide { max-width: 520px; }
.levels-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.level-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: flex-start;
  padding: 14px;
  border-radius: 14px;
  cursor: pointer;
  text-align: left;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-left: 4px solid var(--lvl, #fff);
  color: #fff;
  transition: transform 0.15s, background 0.2s;
}
.level-card:active { transform: scale(0.97); }
.level-card:hover:not(.locked) { background: rgba(255, 255, 255, 0.07); }
.level-card.locked { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.6); }
.lvl-num { font-family: var(--mono); font-size: 0.56rem; letter-spacing: 1.5px; color: var(--lvl, #fff); font-weight: 800; }
.lvl-name { font-size: 0.95rem; font-weight: 800; line-height: 1.1; }
.lvl-goal { font-size: 0.7rem; color: var(--ink-2); }
.lvl-tag { font-family: var(--mono); font-size: 0.54rem; color: var(--ink-3); margin-top: 2px; }

/* ── level complete ──────────────────────────────────────── */
.lc-trophy { font-size: 3rem; margin: 6px 0 2px; }

/* ── reacting Carnival mascot ────────────────────────────── */
#mascot {
  position: absolute;
  top: calc(4px + env(safe-area-inset-top));
  left: 4px;
  width: 66px;
  height: 66px;
  z-index: 35;
  pointer-events: none;
}
#mascot-canvas { width: 100%; height: 100%; display: block; }
.mascot-say {
  position: absolute;
  left: 72%;
  top: 0;
  white-space: nowrap;
  background: rgba(10, 6, 18, 0.88);
  border: 1px solid var(--gold);
  color: #fff;
  font-family: var(--head);
  font-weight: 800;
  font-size: 0.62rem;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: 10px;
  opacity: 0;
  transform-origin: left center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
@media (min-width: 720px) {
  #mascot { width: 132px; height: 150px; top: 14px; left: 14px; }
  .mascot-say { font-size: 0.82rem; top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .combo-pop.show, .over-newbest, .boot-spinner, .pw.granted, .cc-float { animation: none; }
}
