:root {
  --sky: #20a8f5;
  --yellow: #ffde59;
  --cream: #fff7e8;
  --green: #17b964;
  --ink: #111111;
  --shadow: 4px 4px 0 var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: linear-gradient(180deg, var(--sky) 0%, #49c9ff 54%, #69d954 55%, #12843f 100%);
  color: var(--ink);
  font-family: Chewy, system-ui, sans-serif;
  overflow: hidden;
}

button,
input { font: inherit; }
button { cursor: pointer; }

.app-shell {
  min-height: 100dvh;
  height: 100dvh;
  padding: 6px clamp(10px, 2.5vw, 28px) 12px;
  position: relative;
  overflow: hidden;
}

.game-topbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
  gap: 10px;
  align-items: center;
  position: relative;
  z-index: 10;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-lockup img {
  width: min(128px, 32vw);
  height: auto;
  object-fit: contain;
  filter: drop-shadow(2px 3px 0 var(--ink));
}

.brand-lockup span,
.score-strip,
.controls button,
.mode-card h1 { letter-spacing: 0; }

.brand-lockup span {
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 5px 10px 3px;
  transform: rotate(-2deg);
  white-space: nowrap;
}

.score-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px 10px;
  text-align: center;
  min-width: 278px;
}

.score-strip span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
}

.score-strip span:not(:last-child)::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 8px;
  border-radius: 999px;
  background: var(--yellow);
  border: 2px solid var(--ink);
}

.controls {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.controls button,
.mode-card button,
.start-actions button,
.score-submit button {
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: var(--yellow);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 7px 10px 5px;
  min-width: 72px;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.controls button:hover,
.mode-card button:hover,
.start-actions button:hover,
.score-submit button:hover {
  transform: translateY(-2px) rotate(-1deg);
  box-shadow: 6px 6px 0 var(--ink);
}

.game-stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: var(--sky);
  touch-action: none;
  cursor: auto;
  z-index: 1;
}

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

.lives {
  position: fixed;
  left: 50%;
  bottom: clamp(10px, 2vw, 20px);
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 8;
  pointer-events: none;
}

.level-banner {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 6;
  color: rgba(255, 247, 232, 0);
  font-family: Luckiest Guy, Chewy, sans-serif;
  font-size: clamp(58px, 11vw, 150px);
  line-height: 0.9;
  -webkit-text-stroke: 2px rgba(17, 17, 17, 0);
  text-shadow: none;
  transform: scale(0.9);
}

.level-banner.show {
  animation: level-splash 1.15s ease-out both;
}

@keyframes level-splash {
  0% {
    color: rgba(255, 247, 232, 0);
    -webkit-text-stroke-color: rgba(17, 17, 17, 0);
    text-shadow: none;
    transform: scale(0.82);
  }
  22% {
    color: rgba(255, 247, 232, 0.66);
    -webkit-text-stroke-color: rgba(17, 17, 17, 0.44);
    text-shadow: 0 5px 0 rgba(17, 17, 17, 0.24);
    transform: scale(1);
  }
  100% {
    color: rgba(255, 247, 232, 0);
    -webkit-text-stroke-color: rgba(17, 17, 17, 0);
    text-shadow: none;
    transform: scale(1.12);
  }
}

.life-bowl {
  width: clamp(34px, 5vw, 52px);
  height: clamp(22px, 3.6vw, 34px);
  filter: drop-shadow(2px 3px 0 var(--ink));
}

.life-bowl.empty {
  opacity: 0.28;
  filter: grayscale(1) drop-shadow(2px 3px 0 var(--ink));
}

.start-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  text-align: center;
  pointer-events: none;
  color: #fffaf0;
  text-shadow:
    0 4px 0 var(--ink),
    4px 4px 0 var(--ink),
    -3px 3px 0 var(--ink),
    0 0 12px rgba(17, 17, 17, 0.38);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 5;
}

.start-hint strong {
  font-family: Luckiest Guy, Chewy, sans-serif;
  font-size: clamp(44px, 8vw, 104px);
  letter-spacing: 0;
  -webkit-text-stroke: 2px var(--ink);
}

.start-hint span {
  justify-self: center;
  width: min(92vw, 780px);
  color: var(--cream);
  font-size: clamp(24px, 3.1vw, 42px);
  line-height: 1;
  -webkit-text-stroke: 1.2px var(--ink);
  text-shadow:
    0 3px 0 var(--ink),
    3px 3px 0 var(--ink),
    -2px 2px 0 var(--ink),
    0 0 10px rgba(17, 17, 17, 0.45);
}

.start-hint.hide {
  opacity: 0;
  transform: scale(0.96);
}

.start-actions {
  pointer-events: auto;
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 8px;
  text-shadow: none;
}

.start-actions button {
  min-width: 112px;
  font-family: Luckiest Guy, Chewy, sans-serif;
  font-size: clamp(22px, 2.6vw, 34px);
}

.mascot-wrap {
  display: none;
  pointer-events: none;
  position: fixed;
  right: clamp(8px, 2vw, 22px);
  bottom: clamp(56px, 7vw, 82px);
  width: clamp(98px, 13vw, 174px);
  z-index: 4;
}

.mascot-face { position: relative; }

.mascot-face img {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(4px 4px 0 var(--ink));
  transform-origin: bottom center;
  animation: dog-bob 1.8s ease-in-out infinite;
}

.dog-bubble {
  position: absolute;
  right: 78%;
  bottom: 64%;
  max-width: 185px;
  padding: 8px 12px 6px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--cream);
  box-shadow: var(--shadow);
  font-family: Luckiest Guy, Chewy, sans-serif;
  font-size: clamp(16px, 2vw, 24px);
  line-height: 1.05;
  text-align: center;
  opacity: 0;
  transform: translateY(8px) rotate(-3deg) scale(0.92);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.dog-bubble::after {
  content: "";
  position: absolute;
  right: 22px;
  bottom: -15px;
  width: 22px;
  height: 22px;
  background: var(--cream);
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  transform: rotate(45deg);
}

.dog-bubble.show {
  opacity: 1;
  transform: translateY(0) rotate(-2deg) scale(1);
}

@keyframes dog-bob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-7px) rotate(1deg); }
}

.choice-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(17, 17, 17, 0.42);
  z-index: 20;
}

.mode-card {
  width: min(92vw, 520px);
  max-height: min(84dvh, 680px);
  overflow: auto;
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: 10px;
  box-shadow: 8px 8px 0 var(--ink);
  padding: clamp(18px, 4vw, 30px);
  text-align: center;
}

.mode-card h1 {
  margin: 0 0 8px;
  font-family: Luckiest Guy, Chewy, sans-serif;
  font-size: clamp(38px, 7vw, 68px);
}

.modal-copy {
  margin: 8px 0 0;
  color: #138944;
  font-size: clamp(32px, 5vw, 54px);
}

.modal-detail {
  margin: 2px 0 18px;
  font-size: clamp(22px, 3vw, 30px);
}

.score-submit {
  display: grid;
  gap: 8px;
  margin: 10px auto 18px;
  max-width: 360px;
}

.score-submit p,
.leaderboard-status {
  margin: 0;
  color: #138944;
  font-size: clamp(20px, 3vw, 28px);
}

.score-form {
  display: grid;
  gap: 6px;
  text-align: left;
}

.score-form label {
  font-size: 20px;
}

.score-row {
  display: flex;
  gap: 8px;
}

.score-row input {
  min-width: 0;
  flex: 1;
  border: 3px solid var(--ink);
  border-radius: 10px;
  padding: 8px 10px 6px;
  background: #fff;
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  font-size: 20px;
}

.score-message {
  min-height: 28px;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.mode-option.secondary {
  background: #9ee8ff;
}

.how-to-list {
  margin: 10px auto 18px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
  max-width: 420px;
  text-align: left;
  font-size: clamp(20px, 3vw, 28px);
  line-height: 1.04;
}

.how-to-list li {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  align-items: start;
}

.how-to-list li::before {
  content: "";
  width: 14px;
  height: 14px;
  margin-top: 4px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
}

.quiet-button {
  min-width: 120px;
}

.leaderboard-card {
  width: min(94vw, 620px);
}

.leaderboard-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 8px 0 18px;
  list-style: none;
}

.leaderboard-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px 76px;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0 10px;
  color: #138944;
  font-size: clamp(18px, 3vw, 24px);
  text-align: left;
}

.leaderboard-head span:nth-child(2),
.leaderboard-head span:nth-child(3) {
  text-align: right;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px 76px;
  align-items: center;
  gap: 8px;
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  box-shadow: 3px 3px 0 var(--ink);
  padding: 8px 10px 6px;
  font-size: clamp(18px, 3vw, 24px);
}

.leaderboard-list span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.leaderboard-list em,
.leaderboard-list small {
  font-style: normal;
  text-align: right;
  font-family: Chewy, system-ui, sans-serif;
  font-size: 1em;
}

.music-toggle {
  position: fixed;
  left: 14px;
  bottom: 14px;
  width: 46px;
  height: 46px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--cream);
  box-shadow: var(--shadow);
  z-index: 30;
}

.music-toggle::before {
  content: "";
  position: absolute;
  left: 17px;
  top: 12px;
  width: 0;
  height: 0;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-left: 14px solid var(--ink);
}

.music-toggle[aria-pressed="true"]::before,
.music-toggle[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  top: 12px;
  width: 6px;
  height: 19px;
  background: var(--ink);
  border: 0;
}

.music-toggle[aria-pressed="true"]::before { left: 15px; }
.music-toggle[aria-pressed="true"]::after { right: 15px; }

@media (max-width: 760px), (orientation: portrait) {
  .app-shell {
    padding: 8px;
  }

  .game-topbar {
    grid-template-columns: 1fr auto;
    align-items: start;
  }

  .brand-lockup {
    grid-column: 1;
    align-items: flex-start;
    gap: 6px;
    flex-direction: column;
  }

  .brand-lockup img {
    width: min(112px, 36vw);
  }

  .brand-lockup span {
    font-size: 17px;
    padding: 4px 8px 2px;
  }

  .score-strip {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
    min-width: min(88vw, 306px);
    padding: 5px 8px;
    font-size: 18px;
  }

  .controls {
    position: fixed;
    top: 8px;
    right: 8px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    justify-content: end;
    gap: 5px;
    width: 132px;
    max-width: 132px;
    z-index: 14;
  }

  .controls button {
    min-width: 0;
    width: 100%;
    padding: 6px 5px 4px;
    font-size: 13px;
  }

  .start-hint {
    padding: 108px 18px 120px;
  }

  .start-hint strong {
    width: 100vw;
    font-size: clamp(32px, 9vw, 38px);
    line-height: 0.95;
  }

  .start-hint span {
    font-size: clamp(24px, 7vw, 34px);
  }

  .start-actions {
    flex-direction: column;
    align-items: center;
  }

  .start-actions button {
    width: min(66vw, 230px);
  }

  .mascot-wrap {
    width: clamp(76px, 22vw, 118px);
    right: 8px;
    bottom: 58px;
  }

  .dog-bubble {
    display: none;
  }

  .music-toggle {
    width: 42px;
    height: 42px;
  }

  .leaderboard-list li {
    grid-template-columns: minmax(0, 1fr) 62px 54px;
    gap: 6px;
    padding: 7px 8px 5px;
  }

  .leaderboard-head {
    grid-template-columns: minmax(0, 1fr) 62px 54px;
    gap: 6px;
    padding: 0 8px;
  }
}
