@import url("https://fonts.googleapis.com/css2?family=Fredoka:wght@500;700&display=swap");

:root {
  --sky-top: #8fd8ff;
  --sky-mid: #c7f0ff;
  --sky-low: #eef9c9;
  --olive: #3f6b3a;
  --olive-deep: #2c4e29;
  --red: #e23b3b;
  --cream: #fff7e8;
  --ink: #2a241c;
  --gold: #ffc928;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "Fredoka", "Trebuchet MS", sans-serif;
  background: var(--sky-top);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: none;
  overscroll-behavior: none;
}
/* Pin the page so nothing can scroll, rubber-band or pull-to-refresh while playing. */
html, body { position: fixed; inset: 0; width: 100%; }

body { background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 55%, var(--sky-low) 100%); }

/* position:fixed + inset:0 tracks the visible viewport on phones (100vh doesn't on iOS). */
#game { position: fixed; inset: 0; overflow: hidden; }

/* game.js sizes/positions the canvas: uniform scale (never stretched), DPR-sharp. */
canvas#play { position: absolute; display: block; left: 0; top: 0; touch-action: none; }
canvas#fx { display: none; position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 8; }

.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(4vh + env(safe-area-inset-top)) calc(5vw + env(safe-area-inset-right))
           calc(6vh + env(safe-area-inset-bottom)) calc(5vw + env(safe-area-inset-left));
  z-index: 2;
  text-align: center;
}
.screen.hidden, .hidden { display: none !important; }

h1 {
  font-size: clamp(2rem, 7vw, 4.2rem);
  color: var(--olive-deep);
  text-shadow: 0 3px 0 rgba(255,255,255,0.7);
  letter-spacing: 0.02em;
  line-height: 1.05;
}
.sub { font-size: clamp(1rem, 3vw, 1.4rem); color: var(--olive); margin-top: 0.2rem; }

.talk-wrap {
  position: relative; margin: 2vh 0 1vh;
  display: flex; align-items: center; gap: 2vw;
  max-width: 920px; width: 100%; justify-content: center;
}
.billy-img {
  display: block; height: auto; width: auto; max-width: 100%;
  max-height: min(44vh, 380px); object-fit: contain;
  filter: drop-shadow(0 10px 18px rgba(40, 70, 40, 0.25));
  pointer-events: none;
  animation: hover 2.4s ease-in-out infinite;
}
@keyframes hover { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

.bubble {
  background: var(--cream); border: 5px solid var(--olive); border-radius: 28px;
  padding: 0.9rem 1.3rem 1rem; max-width: 340px;
  box-shadow: 4px 6px 0 var(--olive-deep); position: relative;
}
.bubble-big { font-size: clamp(1.8rem, 6vw, 2.6rem); font-weight: 700; color: var(--red); line-height: 1.05; }
.bubble-small { font-size: clamp(1rem, 3vw, 1.3rem); line-height: 1.25; margin-top: 0.3rem; }
.bubble::after {
  content: ""; position: absolute; left: -18px; top: 50%; margin-top: -12px;
  border-top: 12px solid transparent; border-bottom: 12px solid transparent; border-right: 18px solid var(--olive);
}

.tap-row { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.6rem; }
.tap-hand { width: clamp(56px, 12vh, 84px); height: auto; overflow: visible; }
.tap-hand .finger { animation: tap 1.1s ease-in-out infinite; transform-origin: 46px 120px; }
.tap-hand .ripple { fill: none; stroke: #fff; stroke-width: 5; opacity: 0; transform-origin: 46px 30px; animation: ripple 1.1s ease-out infinite; }
.tap-hand .ripple.r2 { animation-delay: 0.25s; }
@keyframes tap { 0%,100% { transform: translateY(0) scale(1); } 45% { transform: translateY(10px) scale(0.94); } }
@keyframes ripple { 0%,40% { opacity: 0; transform: scale(0.4); } 50% { opacity: 0.95; } 100% { opacity: 0; transform: scale(2.1); } }
.tap-hand.floating { position: absolute; z-index: 4; pointer-events: none; width: clamp(60px, 10vh, 90px); }

button {
  font-family: inherit; font-weight: 700; font-size: clamp(1.3rem, 4vw, 1.9rem);
  border: 0; cursor: pointer; border-radius: 999px; padding: 0.7rem 2.2rem 0.85rem;
  background: var(--red); color: #fff; box-shadow: 0 6px 0 #a81f1f;
  transition: transform 0.08s ease, opacity 0.2s;
  touch-action: manipulation;
}
button:hover { transform: translateY(-2px); }
button:active { transform: translateY(4px); box-shadow: 0 2px 0 #a81f1f; }
button:disabled { opacity: 0.6; }

.best-line { margin-top: 0.8rem; font-size: clamp(1rem, 3vw, 1.3rem); color: var(--olive-deep); font-weight: 700; }

.hud {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: calc(14px + env(safe-area-inset-left));
  right: calc(84px + env(safe-area-inset-right));   /* leave room for the mute button */
  display: flex; justify-content: space-between; align-items: flex-start;
  pointer-events: none; z-index: 3;
}
.score, .timer {
  background: rgba(255, 247, 232, 0.92); border: 3px solid var(--olive); border-radius: 18px;
  padding: 0.25rem 0.85rem 0.35rem; font-size: clamp(1.2rem, 4vw, 2rem); color: var(--olive-deep);
}
.timer.frozen { opacity: 0.6; }

.stage-bar {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom));
  display: flex; gap: 6px; z-index: 3; pointer-events: none;
}
.stage-bar .dot {
  font-size: 0.85rem; font-weight: 700; padding: 0.15rem 0.6rem; border-radius: 999px;
  background: rgba(255,247,232,0.6); color: rgba(44,78,41,0.6); border: 2px solid rgba(63,107,58,0.4);
}
.stage-bar .dot.on { background: var(--cream); color: var(--olive-deep); border-color: var(--olive); }

.banner {
  position: absolute; left: 50%; top: 24%; transform: translate(-50%, -50%);
  z-index: 4; pointer-events: none; white-space: nowrap;
  background: var(--cream); border: 5px solid var(--olive); border-radius: 26px;
  box-shadow: 4px 6px 0 var(--olive-deep);
  padding: 0.5rem 1.4rem 0.6rem; font-weight: 700; color: var(--olive-deep);
  font-size: clamp(1.4rem, 5.5vw, 2.6rem); text-align: center;
  animation: pop 0.35s ease-out;
}
.banner small { display: block; font-size: 0.55em; color: var(--olive); }
.banner.count { font-size: clamp(3rem, 14vw, 6rem); color: var(--red); padding: 0.2rem 1.6rem; }
@keyframes pop { 0% { transform: translate(-50%, -50%) scale(0.6); opacity: 0; } 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; } }

/* Big, clear, always-visible mute button */
.mute-btn {
  position: absolute; z-index: 9;
  /* top-right corner: never covers the title, the end card or the "New best!" ribbon */
  top: calc(10px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right));
  width: 60px; height: 60px; padding: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--olive); box-shadow: 0 5px 0 var(--olive-deep);
  border: 3px solid #fff;
}
.mute-btn:hover { transform: translateY(-2px); }
.mute-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--olive-deep); }
.mute-btn svg { width: 38px; height: 38px; }
.mute-btn .cross { display: none; }
.mute-btn.muted { background: #8a8a8a; box-shadow: 0 5px 0 #5c5c5c; }
.mute-btn.muted .waves { display: none; }
.mute-btn.muted .cross { display: inline; }

.done-card {
  position: relative;
  background: var(--cream); border: 6px solid var(--olive); border-radius: 32px;
  padding: 1.6rem 2rem 1.5rem; text-align: center; box-shadow: 6px 8px 0 var(--olive-deep);
  max-width: 520px; width: min(92vw, 520px);
}
.done-card .billy-img { max-height: min(26vh, 220px); margin: 0.3rem auto 0.4rem; }
.new-best {
  position: absolute; top: -26px; left: 50%; transform: translateX(-50%) rotate(-4deg);
  background: var(--red); color: #fff; font-weight: 700; font-size: clamp(1.3rem, 5vw, 1.9rem);
  padding: 0.3rem 1.2rem 0.4rem; border-radius: 14px; box-shadow: 0 5px 0 #a81f1f; white-space: nowrap;
  animation: wiggle 0.9s ease-in-out infinite;
}
@keyframes wiggle { 0%,100% { transform: translateX(-50%) rotate(-4deg) scale(1); } 50% { transform: translateX(-50%) rotate(3deg) scale(1.08); } }
.stars { display: flex; justify-content: center; gap: 0.5rem; margin: 0.5rem 0 0.2rem; }
.star { width: clamp(40px, 10vw, 58px); height: auto; }
.star path { fill: #e6dccb; stroke: #b9ab92; stroke-width: 3; stroke-linejoin: round; }
.star.on path { fill: var(--gold); stroke: #e09a00; }
.star.on { animation: starIn 0.5s cubic-bezier(.2,1.6,.4,1) both; }
.star.on:nth-child(2) { animation-delay: 0.35s; }
.star.on:nth-child(3) { animation-delay: 0.7s; }
@keyframes starIn { 0% { transform: scale(0) rotate(-90deg); } 100% { transform: scale(1) rotate(0); } }
.big-score { font-size: clamp(2rem, 7vw, 3.2rem); color: var(--red); font-weight: 700; margin: 0.1rem 0 0.2rem; }
.done-card .best-line { margin: 0 0 0.9rem; }

@media (max-width: 700px) {
  .talk-wrap { flex-direction: column; }
  .bubble { text-align: center; }
  .bubble::after {
    left: 50%; top: -18px; margin-left: -12px; margin-top: 0;
    border-left: 12px solid transparent; border-right: 12px solid transparent;
    border-bottom: 18px solid var(--olive); border-top: 0;
  }
  .billy-img { max-height: min(32vh, 300px); }
  .mute-btn { width: 54px; height: 54px; }
  .hud { right: calc(76px + env(safe-area-inset-right)); }
  .mute-btn svg { width: 34px; height: 34px; }
}

/* Short screens: phones held sideways (about 320-430px tall). */
@media (max-height: 500px) {
  .screen { padding-top: calc(1.5vh + env(safe-area-inset-top)); padding-bottom: calc(2vh + env(safe-area-inset-bottom)); }
  h1 { font-size: clamp(1.4rem, 8vh, 2.4rem); }
  .sub { font-size: clamp(0.9rem, 4.5vh, 1.2rem); margin-top: 0; }
  .talk-wrap { margin: 0.5vh 0; }
  .billy-img { max-height: min(38vh, 180px); max-width: 40vw; }
  .bubble { padding: 0.5rem 0.9rem 0.6rem; border-width: 4px; }
  .bubble-big { font-size: clamp(1.4rem, 9vh, 2rem); }
  .bubble-small { font-size: clamp(0.85rem, 4.5vh, 1.1rem); }
  .tap-row { margin-top: 0.2rem; }
  .tap-hand { width: 52px; }
  button { font-size: clamp(1.1rem, 6vh, 1.5rem); padding: 0.45rem 1.8rem 0.55rem; }
  .best-line { margin-top: 0.3rem; font-size: 1rem; }
  .score, .timer { font-size: clamp(1rem, 6vh, 1.4rem); }
  .mute-btn { width: 50px; height: 50px; top: calc(6px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); }
  .hud { right: calc(72px + env(safe-area-inset-right)); }
  .mute-btn svg { width: 30px; height: 30px; }
  .done-card { padding: 1.1rem 1.4rem 0.8rem; width: min(70vw, 520px); }
  .done-card h1 { font-size: 1.6rem; }
  .done-card .billy-img { display: none; }
  .done-card .sub { font-size: 1rem; }
  .star { width: 38px; }
  .big-score { font-size: clamp(1.5rem, 9vh, 2.2rem); }
  .done-card .best-line { margin-bottom: 0.4rem; }
  .new-best { top: -20px; font-size: 1.2rem; }
  .stage-bar .dot { font-size: 0.7rem; }
  .banner { top: 30%; }
}
