/* ============ BISCUIT BANDIT ============ */
:root {
  --cream: #f7ead7;
  --choc: #4a2c1a;
  --choc-dark: #2c1810;
  --jam: #d63c3c;
  --gold: #f2b632;
  --moon: #a8c6e8;
}

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

html, body {
  height: 100%;
  background: radial-gradient(ellipse at 50% 30%, #1d2b45 0%, #0b1220 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Trebuchet MS", "Comic Sans MS", "Segoe UI", sans-serif;
  overflow: hidden;
  user-select: none;
}

#game-frame {
  position: relative;
  width: min(100vw, 177.78vh); /* 16:9 */
  aspect-ratio: 16 / 9;
  box-shadow: 0 0 80px rgba(242, 182, 50, 0.15), 0 30px 60px rgba(0,0,0,0.6);
  border-radius: 12px;
  overflow: hidden;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #141d2e;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: 18px 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  color: var(--cream);
  text-shadow: 0 2px 4px rgba(0,0,0,0.8);
  z-index: 5;
}

.hearts { font-size: 30px; letter-spacing: 4px; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.6)); }
.hearts .lost { opacity: 0.25; filter: grayscale(1); }

#waddle-meter { margin-top: 10px; }
.waddle-label { font-size: 11px; font-weight: bold; letter-spacing: 2px; color: var(--gold); }
.waddle-bar {
  width: 130px; height: 10px;
  background: rgba(0,0,0,0.5);
  border: 2px solid rgba(247,234,215,0.5);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 3px;
}
#waddle-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--jam));
  border-radius: 4px;
  transition: width 0.3s ease;
}

.hud-centre { text-align: center; }
#wave-label {
  font-size: 26px; font-weight: 900; letter-spacing: 4px; color: var(--gold);
}
#biscuits-left { font-size: 18px; margin-top: 4px; font-weight: bold; }

.hud-right { text-align: right; }
.score-row { display: flex; gap: 14px; justify-content: flex-end; font-size: 20px; font-weight: 900; }
.score-row span:first-child { color: var(--moon); font-size: 13px; align-self: center; letter-spacing: 2px; }
.score-row.hi span:last-child { color: var(--gold); }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

#title-screen {
  background:
    radial-gradient(ellipse at 50% 120%, rgba(214,60,60,0.25), transparent 60%),
    radial-gradient(ellipse at 50% -20%, rgba(168,198,232,0.25), transparent 60%),
    linear-gradient(180deg, #16233c 0%, #2c1810 100%);
  text-align: center;
  color: var(--cream);
}

.title-kicker {
  font-size: 15px; letter-spacing: 8px; color: var(--moon);
  font-weight: bold; margin-bottom: 6px;
}

.game-title {
  font-size: 84px;
  font-weight: 900;
  letter-spacing: 4px;
  line-height: 0.95;
  color: var(--cream);
  text-shadow: 0 4px 0 var(--choc-dark), 0 8px 24px rgba(0,0,0,0.7);
  transform: rotate(-2deg);
}
.game-title .title-alt {
  color: var(--gold);
  text-shadow: 0 4px 0 #7a5410, 0 8px 24px rgba(0,0,0,0.7);
}

#title-mouse {
  width: 170px;
  margin: 10px 0 4px;
  animation: bob 2.2s ease-in-out infinite;
  filter: drop-shadow(0 10px 16px rgba(0,0,0,0.6));
}

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-14px) rotate(3deg); }
}

.tagline { font-size: 17px; font-style: italic; color: var(--cream); opacity: 0.85; }

.controls-card {
  display: inline-block;
  margin: 14px 0 8px;
  padding: 12px 26px;
  background: rgba(0,0,0,0.35);
  border: 2px solid rgba(247,234,215,0.25);
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.9;
}
kbd {
  background: var(--cream);
  color: var(--choc-dark);
  border-radius: 5px;
  padding: 2px 8px;
  font-family: inherit;
  font-weight: 900;
  font-size: 13px;
  box-shadow: 0 2px 0 #a08c72;
  margin: 0 2px;
}

.silly-rule { color: var(--gold); font-weight: bold; font-size: 15px; margin-bottom: 12px; }

.press-start {
  font-size: 21px; font-weight: 900; letter-spacing: 3px; color: var(--jam);
  text-shadow: 0 0 18px rgba(214,60,60,0.6);
}
.blink { animation: blink 1.1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.15; } }

/* ---------- Wave banner ---------- */
#wave-banner {
  flex-direction: column;
  background: transparent;
  pointer-events: none;
}
#wave-banner-text {
  font-size: 90px;
  font-weight: 900;
  letter-spacing: 10px;
  color: var(--gold);
  text-shadow: 0 6px 0 #7a5410, 0 12px 40px rgba(0,0,0,0.8);
  animation: bannerPop 0.5s cubic-bezier(0.2, 2.2, 0.4, 1);
}
#wave-banner-sub {
  font-size: 24px; color: var(--cream); font-weight: bold;
  text-shadow: 0 2px 6px rgba(0,0,0,0.8);
  margin-top: 8px;
  animation: bannerPop 0.5s 0.1s cubic-bezier(0.2, 2.2, 0.4, 1) backwards;
}
@keyframes bannerPop {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
#wave-banner.fadeout { animation: bannerFade 0.5s forwards; }
@keyframes bannerFade { to { opacity: 0; } }

/* ---------- End screens ---------- */
#gameover-screen, #win-screen {
  background: rgba(10, 6, 4, 0.82);
  backdrop-filter: blur(3px);
}
.panel {
  text-align: center;
  color: var(--cream);
  background: linear-gradient(180deg, #3a2113, #241209);
  border: 4px solid var(--choc);
  border-radius: 24px;
  padding: 40px 70px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8), inset 0 0 60px rgba(0,0,0,0.4);
  animation: bannerPop 0.45s cubic-bezier(0.2, 2.0, 0.4, 1);
}
.panel.gold { border-color: var(--gold); box-shadow: 0 0 80px rgba(242,182,50,0.35), 0 20px 60px rgba(0,0,0,0.8); }

.go-title {
  font-size: 54px; font-weight: 900; letter-spacing: 3px;
  color: var(--jam);
  text-shadow: 0 4px 0 rgba(0,0,0,0.5);
}
.gold-text {
  color: var(--gold) !important;
  font-size: 40px !important;
  text-shadow: 0 0 30px rgba(242,182,50,0.6), 0 4px 0 rgba(0,0,0,0.5) !important;
}
.go-sub { font-style: italic; opacity: 0.8; margin: 8px 0 18px; }

#win-biscuit { width: 130px; animation: spinBob 3s ease-in-out infinite; }
@keyframes spinBob {
  0%, 100% { transform: translateY(0) rotate(-6deg) scale(1); }
  50% { transform: translateY(-10px) rotate(6deg) scale(1.08); }
}

.final-scores { font-size: 22px; font-weight: 900; line-height: 1.8; margin-bottom: 18px; }
.final-scores span { color: var(--gold); margin-left: 12px; }
#new-record { color: var(--jam); font-size: 26px; animation: blink 0.8s steps(2) infinite; }

#mute-indicator {
  position: absolute;
  bottom: 14px; right: 18px;
  z-index: 20;
  background: rgba(0,0,0,0.6);
  color: var(--cream);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: bold;
}

/* ---------- Touch controls ---------- */
#touch-ui { position: absolute; inset: 0; pointer-events: none; z-index: 8; }

#joystick {
  position: absolute;
  width: 110px; height: 110px;
  border-radius: 50%;
  border: 3px solid rgba(247,234,215,0.5);
  background: rgba(0,0,0,0.25);
  display: none; /* positioned at touch point while dragging */
  pointer-events: none;
}
#joystick-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 48px; height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: rgba(247,234,215,0.75);
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

#dash-btn, #mute-btn {
  position: absolute;
  pointer-events: auto;
  border: none;
  font-family: inherit;
  font-weight: 900;
  color: var(--choc-dark);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
#dash-btn {
  right: 26px; bottom: 26px;
  width: 92px; height: 92px;
  border-radius: 50%;
  font-size: 19px;
  letter-spacing: 1px;
  background: radial-gradient(circle at 35% 30%, #ffd97a, var(--gold) 60%, #c98f1b);
  box-shadow: 0 5px 0 #8a6310, 0 10px 24px rgba(0,0,0,0.5);
}
#dash-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #8a6310; }
#dash-btn.cooling { opacity: 0.45; }

#mute-btn {
  left: 18px; bottom: 18px;
  width: 52px; height: 52px;
  border-radius: 50%;
  font-size: 22px;
  background: rgba(0,0,0,0.5);
  color: var(--cream);
  border: 2px solid rgba(247,234,215,0.4);
}

#rotate-hint {
  color: var(--moon);
  font-weight: bold;
  font-size: 14px;
  margin-top: 6px;
}

/* ---------- Small screens (phones) ---------- */
@media (max-width: 760px), (max-height: 540px) {
  .game-title { font-size: 42px; letter-spacing: 2px; }
  .title-kicker { font-size: 10px; letter-spacing: 5px; }
  #title-mouse { width: 100px; margin: 4px 0 2px; }
  .tagline { font-size: 12px; }
  .controls-card { font-size: 12px; padding: 8px 14px; line-height: 1.7; margin: 8px 0 4px; }
  .silly-rule { font-size: 11px; margin-bottom: 6px; }
  .press-start { font-size: 15px; letter-spacing: 2px; }
  #wave-banner-text { font-size: 44px; letter-spacing: 5px; }
  #wave-banner-sub { font-size: 15px; }
  .panel { padding: 18px 26px; }
  .go-title { font-size: 30px; }
  .gold-text { font-size: 22px !important; }
  .go-sub { font-size: 12px; }
  .final-scores { font-size: 15px; margin-bottom: 8px; }
  #new-record { font-size: 17px; }
  #win-biscuit { width: 80px; }
  #hud { padding: 8px 10px; }
  .hearts { font-size: 20px; }
  #wave-label { font-size: 16px; }
  #biscuits-left { font-size: 12px; }
  .score-row { font-size: 14px; }
  .score-row span:first-child { font-size: 10px; }
  .waddle-bar { width: 90px; height: 8px; }
  .waddle-label { font-size: 9px; }
}

/* Portrait phones: let the frame fill the screen and letterbox the canvas */
@media (max-width: 760px) and (orientation: portrait) {
  #game-frame {
    width: 100vw;
    height: 100dvh;
    aspect-ratio: auto;
    border-radius: 0;
  }
  canvas { object-fit: contain; background: #0b1220; }
  .game-title { font-size: 9.5vw; letter-spacing: 1px; }
  #title-screen, #gameover-screen, #win-screen { overflow-y: auto; overflow-x: hidden; }
  .title-inner { padding: 14px 0 24px; }
}
