:root {
  --ink: #284348;
  --cream: #fff8df;
  --orange: #ff7b38;
  --orange-dark: #d95524;
  --yellow: #ffd95c;
  --green: #4dbf72;
  --sky: #6ed0d2;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 14%, rgba(255, 255, 255, .8) 0 4px, transparent 5px),
    radial-gradient(circle at 88% 24%, rgba(255, 255, 255, .62) 0 7px, transparent 8px),
    radial-gradient(circle at 8% 72%, rgba(255, 244, 166, .7) 0 5px, transparent 6px),
    linear-gradient(180deg, #8de0db 0%, #d9f5c7 62%, #fff0b5 100%);
  font-family: "Fredoka", "Arial Rounded MT Bold", system-ui, sans-serif;
  overscroll-behavior: none;
  overflow-x: hidden;
  transition: background .5s ease;
}

body[data-lane="soap"] {
  background:
    radial-gradient(circle at 12% 20%, rgba(255,255,255,.86) 0 10px, transparent 11px),
    radial-gradient(circle at 88% 58%, rgba(255,255,255,.72) 0 18px, transparent 19px),
    linear-gradient(180deg, #63cdf1 0%, #d8fbff 100%);
}

body[data-lane="wind"] {
  background:
    radial-gradient(ellipse at 18% 28%, rgba(255,255,255,.76) 0 42px, transparent 44px),
    radial-gradient(ellipse at 82% 68%, rgba(255,255,255,.62) 0 58px, transparent 60px),
    linear-gradient(180deg, #70b8e7 0%, #e8f8ff 100%);
}

body[data-lane="portal"] {
  background:
    radial-gradient(circle at 18% 18%, rgba(105,238,255,.5) 0 3px, transparent 4px),
    radial-gradient(circle at 82% 32%, rgba(255,120,220,.45) 0 4px, transparent 5px),
    linear-gradient(180deg, #25164f 0%, #7040a2 100%);
}

body[data-lane="party"] {
  background:
    radial-gradient(circle at 12% 18%, rgba(255,243,101,.85) 0 7px, transparent 8px),
    radial-gradient(circle at 86% 34%, rgba(98,234,255,.75) 0 8px, transparent 9px),
    linear-gradient(150deg, #ff79b6 0%, #ffd95e 50%, #7b54dc 100%);
}

button,
a {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: 100%;
  min-height: 100svh;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
}

.topbar {
  width: min(100%, 600px);
  height: 58px;
  margin: 0 auto 8px;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
}

.round-button,
.pause-button {
  border: 0;
  color: #336367;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 5px 0 rgba(41, 83, 83, .12), 0 9px 20px rgba(40, 77, 79, .14);
  cursor: pointer;
  transition: transform .14s ease, box-shadow .14s ease, filter .14s ease;
}

.round-button {
  width: 44px;
  height: 44px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  font-size: 25px;
  font-weight: 700;
  text-decoration: none;
}

.round-button:hover,
.pause-button:hover,
.primary-button:hover {
  filter: brightness(1.04);
  transform: translateY(-2px);
}

.round-button:active,
.pause-button:active,
.primary-button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(41, 83, 83, .14);
}

.mini-brand {
  justify-self: center;
  width: 98px;
  height: 56px;
  display: grid;
  place-items: center;
  text-decoration: none;
  filter: drop-shadow(0 2px 0 rgba(255, 255, 255, .72));
}

.mini-brand img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  mix-blend-mode: multiply;
}

.sound-button.is-muted {
  color: #9badad;
}

.game-shell {
  position: relative;
  width: min(100%, 600px);
  margin: 0 auto;
}

.hud {
  display: grid;
  grid-template-columns: 1.1fr .9fr 1fr 48px;
  gap: 8px;
  margin-bottom: 8px;
}

.hud-card,
.pause-button {
  min-height: 52px;
  border-radius: 15px;
}

.hud-card {
  padding: 6px 8px 5px;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 5px 0 rgba(41, 83, 83, .1), 0 8px 18px rgba(40, 77, 79, .12);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.hud-card span {
  color: #d9613e;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.2px;
}

.hud-card strong {
  margin-top: 1px;
  color: #2d6263;
  font-size: clamp(18px, 4.2vw, 22px);
  line-height: 1;
  white-space: nowrap;
}

.hud-score strong {
  color: #f0792e;
}

.pause-button {
  width: 48px;
  font-size: 22px;
  font-weight: 700;
}

.stage-wrap {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 3 / 4;
  border: 5px solid rgba(45, 83, 83, .92);
  border-radius: 28px;
  background: #fff8df;
  box-shadow:
    0 8px 0 rgba(45, 83, 83, .16),
    0 18px 36px rgba(37, 79, 80, .18),
    inset 0 0 0 3px rgba(255, 255, 255, .8);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

canvas.is-dragging {
  cursor: grabbing;
}

canvas.is-targeting {
  cursor: crosshair;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(32, 77, 79, .18);
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .22s ease, visibility .22s ease;
}

.overlay.is-visible {
  opacity: 1;
  visibility: visible;
}

.overlay-card {
  width: min(100%, 430px);
  padding: clamp(20px, 5vw, 32px) clamp(18px, 5vw, 34px) 22px;
  border: 4px solid #fff;
  border-radius: 30px;
  background:
    radial-gradient(circle at 12% 14%, rgba(255, 255, 255, .92) 0 4px, transparent 5px),
    linear-gradient(160deg, #fffbed 0%, #fff0b2 100%);
  box-shadow: 0 14px 0 rgba(118, 73, 38, .16), 0 28px 50px rgba(53, 65, 55, .24);
  text-align: center;
  transform: translateY(16px) scale(.96);
  transition: transform .28s cubic-bezier(.2, 1.25, .4, 1);
}

.overlay.is-visible .overlay-card {
  transform: translateY(0) scale(1);
}

.title-kicker {
  color: #448b72;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1.7px;
}

.overlay.is-menu .title-kicker {
  display: none;
}

.game-logo {
  display: none;
  width: min(100%, 340px);
  max-height: 237px;
  height: auto;
  margin: -12px auto -8px;
  object-fit: contain;
  mix-blend-mode: multiply;
  filter: drop-shadow(0 7px 0 rgba(111, 65, 43, .12));
}

.overlay.is-menu .game-logo {
  display: block;
}

.overlay.is-menu h1,
.overlay.is-menu .overlay-subtitle,
.overlay.is-menu .mascot-badge {
  display: none;
}

.overlay.is-menu .overlay-card {
  padding-top: clamp(16px, 4vw, 24px);
}

.overlay h1 {
  margin: 5px 0 0;
  color: #ff6c33;
  font-size: clamp(40px, 10vw, 70px);
  line-height: .84;
  letter-spacing: -3px;
  text-shadow: 0 4px 0 #7a412b, 0 7px 0 rgba(122, 65, 43, .14);
  transform: rotate(-2deg);
}

.overlay h1 span {
  color: #ffc73d;
}

.overlay-subtitle {
  margin: 10px 0 0;
  color: #376a68;
  font-size: clamp(18px, 4.2vw, 23px);
  font-weight: 700;
  letter-spacing: .8px;
}

.mascot-badge {
  position: relative;
  width: 112px;
  height: 112px;
  margin: 12px auto 10px;
  border: 5px solid #fff;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 28%, #fff7d6, #ffd98f 76%);
  box-shadow: 0 7px 0 rgba(91, 56, 35, .18), inset 0 -8px 14px rgba(70, 34, 23, .18);
  overflow: hidden;
}

.mascot-badge canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
  pointer-events: none;
}

.overlay-copy {
  max-width: 340px;
  margin: 10px auto 17px;
  color: #476562;
  font-size: clamp(16px, 3.9vw, 19px);
  line-height: 1.4;
}

.primary-button {
  width: 100%;
  min-height: 55px;
  border: 0;
  border-radius: 18px;
  color: #fff;
  background: linear-gradient(180deg, #ff9344, #f2632c);
  box-shadow: 0 7px 0 #bd4723, 0 13px 24px rgba(190, 76, 35, .22);
  cursor: pointer;
  font-size: clamp(17px, 4.5vw, 22px);
  font-weight: 700;
  letter-spacing: .2px;
  transition: transform .14s ease, box-shadow .14s ease, filter .14s ease;
}

.best-score {
  margin: 15px 0 0;
  color: #8a765c;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
}

.message-dock {
  min-height: 62px;
  padding: 10px 4px 0;
  display: grid;
  place-items: center;
}

.toast {
  position: relative;
  z-index: 8;
  width: fit-content;
  min-width: 190px;
  max-width: 100%;
  padding: 10px 18px;
  border: 3px solid rgba(255, 255, 255, .9);
  border-radius: 999px;
  color: #fff;
  background: rgba(45, 91, 87, .9);
  box-shadow: 0 7px 0 rgba(32, 66, 64, .18), 0 12px 25px rgba(30, 60, 58, .18);
  font-size: clamp(17px, 4.2vw, 23px);
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-7px) scale(.94);
  transition: none;
}

.toast.is-visible {
  opacity: 1 !important;
  visibility: visible !important;
  transform: translateY(0) scale(1) !important;
}

.power-panel {
  position: absolute;
  z-index: 7;
  right: 2.6%;
  bottom: 9%;
  width: 58px;
  height: min(42%, 238px);
  padding: 10px 7px;
  border: 3px solid rgba(255, 255, 255, .88);
  border-radius: 20px;
  background: rgba(39, 80, 77, .88);
  box-shadow: 0 7px 18px rgba(35, 70, 67, .2);
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateX(14px) scale(.96);
  opacity: 0;
  transition: opacity .15s ease, transform .15s ease;
}

.power-panel.is-visible {
  opacity: 1;
  transform: translateX(0) scale(1);
}

.power-panel span {
  display: block;
  margin-bottom: 7px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .8px;
  text-align: center;
}

.power-track {
  overflow: hidden;
  width: 17px;
  min-height: 0;
  flex: 1;
  border: 2px solid rgba(255, 255, 255, .75);
  border-radius: 999px;
  background: rgba(255, 255, 255, .25);
  display: flex;
  align-items: flex-end;
}

.power-track i {
  display: block;
  width: 100%;
  height: 0;
  border-radius: inherit;
  background: linear-gradient(0deg, #70df78 0%, #ffdf55 55%, #ff7045 100%);
  transition: height .04s linear;
}

.controls-hint {
  margin: 2px 0 0;
  color: #537672;
  font-size: clamp(14px, 3.3vw, 16px);
  font-weight: 700;
  text-align: center;
}

.keyboard-hint {
  display: inline;
}

.touch-hint {
  display: none;
}

@media (min-width: 1000px) {
  .message-dock {
    position: absolute;
    left: calc(100% + 18px);
    top: 68px;
    width: min(240px, calc((100vw - 640px) / 2));
    min-height: 58px;
    padding: 0;
  }

  .toast {
    width: 100%;
    min-width: 0;
    border-radius: 22px;
  }
}

@media (pointer: coarse), (max-width: 720px) {
  .app {
    padding-left: 8px;
    padding-right: 8px;
  }

  .topbar {
    height: 54px;
    margin-bottom: 6px;
    grid-template-columns: 42px 1fr 42px;
  }

  .mini-brand {
    width: 94px;
    height: 52px;
  }

  .round-button {
    width: 40px;
    height: 40px;
    border-radius: 13px;
  }

  .hud {
    gap: 5px;
    margin-bottom: 6px;
    grid-template-columns: 1fr .9fr 1fr 43px;
  }

  .hud-card,
  .pause-button {
    min-height: 46px;
    border-radius: 13px;
  }

  .pause-button {
    width: 43px;
  }

  .hud-card span {
    font-size: 12px;
    letter-spacing: 1px;
  }

  .stage-wrap {
    border-width: 4px;
    border-radius: 23px;
  }

  .power-panel {
    right: 1.4%;
    bottom: 10%;
    width: 49px;
    height: min(38%, 196px);
    padding: 8px 5px;
  }

  .power-track {
    width: 15px;
  }

  .power-panel span {
    font-size: 10px;
  }

  .message-dock {
    min-height: 56px;
    padding-top: 8px;
  }

  .toast {
    padding: 9px 14px;
    font-size: clamp(16px, 4.2vw, 20px);
  }

  .game-logo {
    width: min(100%, 310px);
    max-height: 207px;
  }

  .keyboard-hint {
    display: none;
  }

  .touch-hint {
    display: inline;
  }
}

@media (max-height: 760px) and (min-width: 500px) {
  .app {
    padding-top: 5px;
  }

  .topbar {
    height: 38px;
    margin-bottom: 4px;
  }

  .round-button {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    font-size: 21px;
  }

  .hud-card,
  .pause-button {
    min-height: 42px;
  }

  .stage-wrap {
    width: min(100%, calc((100svh - 112px) * .75));
    margin: 0 auto;
  }

  .controls-hint {
    margin-top: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}

@media (prefers-contrast: more) {
  .stage-wrap,
  .overlay-card {
    border-color: #173d40;
  }
}
