:root {
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: #24433d;
  background: #bce8dd;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --safe-top: max(18px, env(safe-area-inset-top));
  --safe-right: max(18px, env(safe-area-inset-right));
  --safe-bottom: max(18px, env(safe-area-inset-bottom));
  --safe-left: max(18px, env(safe-area-inset-left));
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

html {
  background: #bce8dd;
}

body {
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

button,
canvas {
  touch-action: none;
}

button {
  font: inherit;
}

#app {
  position: relative;
  isolation: isolate;
  background: linear-gradient(180deg, #8ed0ed 0%, #c9eadc 62%, #82ae62 100%);
}

#game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  cursor: default;
}

.hud {
  position: absolute;
  z-index: 10;
  inset: 0;
  pointer-events: none;
}

.pollen-counter {
  position: absolute;
  top: var(--safe-top);
  left: var(--safe-left);
  display: grid;
  grid-template-columns: 36px auto;
  grid-template-rows: auto auto;
  min-width: 126px;
  min-height: 68px;
  padding: 10px 15px 10px 10px;
  border: 1px solid rgb(255 255 255 / 58%);
  border-radius: 22px;
  background: linear-gradient(135deg, rgb(255 255 255 / 82%), rgb(241 255 247 / 68%));
  box-shadow: 0 12px 34px rgb(43 91 73 / 18%), inset 0 1px 0 rgb(255 255 255 / 72%);
  backdrop-filter: blur(12px) saturate(1.15);
  -webkit-backdrop-filter: blur(12px) saturate(1.15);
  transform-origin: 28px 34px;
}

.pollen-counter.is-pop {
  animation: pollen-pop 480ms cubic-bezier(.2, .9, .25, 1.25);
}

.pollen-counter__flower {
  grid-row: 1 / 3;
  align-self: center;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: #fff8cc;
  background: linear-gradient(145deg, #ffbf56, #ff879d);
  box-shadow: 0 5px 14px rgb(230 111 106 / 30%);
  font-size: 25px;
  line-height: 1;
}

.pollen-counter__label {
  align-self: end;
  padding-left: 10px;
  color: #52736a;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.pollen-counter__value {
  align-self: start;
  padding-left: 10px;
  color: #25473e;
  font-size: 25px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.hud-actions {
  position: absolute;
  top: var(--safe-top);
  right: var(--safe-right);
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.round-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid rgb(255 255 255 / 58%);
  border-radius: 50%;
  color: #31594f;
  background: rgb(255 255 255 / 72%);
  box-shadow: 0 10px 28px rgb(43 91 73 / 16%), inset 0 1px 0 rgb(255 255 255 / 80%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  transition: transform 180ms ease, background-color 180ms ease, opacity 180ms ease;
}

.round-button:hover {
  transform: translateY(-2px) scale(1.03);
  background: rgb(255 255 255 / 88%);
}

.round-button:active {
  transform: translateY(1px) scale(.96);
}

.round-button:focus-visible {
  outline: 3px solid rgb(255 230 115 / 88%);
  outline-offset: 3px;
}

.round-button.is-muted {
  opacity: .65;
}

.round-button.is-active {
  background: rgb(255 246 193 / 88%);
}

.welcome {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 22px);
  width: min(560px, calc(100% - var(--safe-left) - var(--safe-right)));
  padding: 18px 26px 20px;
  border: 1px solid rgb(255 255 255 / 68%);
  border-radius: 28px;
  background: linear-gradient(145deg, rgb(255 255 255 / 88%), rgb(245 255 247 / 72%));
  box-shadow: 0 20px 50px rgb(42 88 70 / 22%), inset 0 1px 0 rgb(255 255 255 / 86%);
  backdrop-filter: blur(15px) saturate(1.12);
  -webkit-backdrop-filter: blur(15px) saturate(1.12);
  text-align: center;
  transform: translateX(-50%);
  transition: opacity 650ms ease, transform 650ms cubic-bezier(.2, .8, .2, 1), visibility 650ms;
  pointer-events: none;
}

.welcome.is-hidden {
  visibility: hidden;
  opacity: 0;
  transform: translate(-50%, 24px) scale(.96);
}

.welcome__butterfly {
  position: absolute;
  top: -29px;
  left: 50%;
  filter: drop-shadow(0 7px 7px rgb(64 60 90 / 20%));
  font-size: 44px;
  transform: translateX(-50%);
  animation: welcome-butterfly 2.6s ease-in-out infinite;
}

.welcome h1 {
  margin: 3px 0 5px;
  color: #24483f;
  font-size: clamp(22px, 4.3vw, 34px);
  line-height: 1.05;
  letter-spacing: -.025em;
}

.welcome p {
  margin: 0;
  color: #496b62;
  font-size: clamp(14px, 2.4vw, 18px);
  font-weight: 700;
}

.welcome span {
  display: block;
  margin-top: 5px;
  color: #668078;
  font-size: clamp(12px, 2vw, 15px);
}

.message {
  position: absolute;
  z-index: 12;
  top: max(100px, calc(var(--safe-top) + 82px));
  left: 50%;
  max-width: min(440px, calc(100% - 44px));
  padding: 11px 20px;
  border: 1px solid rgb(255 255 255 / 62%);
  border-radius: 999px;
  color: #24483f;
  background: rgb(255 255 255 / 78%);
  box-shadow: 0 12px 30px rgb(43 91 73 / 16%);
  backdrop-filter: blur(11px);
  -webkit-backdrop-filter: blur(11px);
  font-size: clamp(14px, 2.2vw, 18px);
  font-weight: 800;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, -12px) scale(.96);
  transition: opacity 220ms ease, transform 280ms cubic-bezier(.2, .9, .25, 1.15);
  pointer-events: none;
}

.message.is-visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.webgl-error {
  position: absolute;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, #d6f5ea, #f8efc5);
  text-align: center;
}

.webgl-error[hidden] {
  display: none;
}

.webgl-error > div {
  max-width: 560px;
  padding: 34px;
  border-radius: 28px;
  background: rgb(255 255 255 / 82%);
  box-shadow: 0 24px 60px rgb(47 83 71 / 18%);
}

.webgl-error h1 {
  margin: 0 0 12px;
  font-size: clamp(26px, 6vw, 44px);
}

.webgl-error p {
  margin: 0;
  color: #55736b;
  font-size: 18px;
}

@keyframes pollen-pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.13) rotate(-2deg); }
  66% { transform: scale(.98) rotate(1deg); }
  100% { transform: scale(1); }
}

@keyframes welcome-butterfly {
  0%, 100% { transform: translate(-50%, 0) rotate(-4deg); }
  50% { transform: translate(-50%, -8px) rotate(4deg); }
}

@media (max-width: 700px) {
  :root {
    --safe-top: max(12px, env(safe-area-inset-top));
    --safe-right: max(12px, env(safe-area-inset-right));
    --safe-bottom: max(12px, env(safe-area-inset-bottom));
    --safe-left: max(12px, env(safe-area-inset-left));
  }

  .pollen-counter {
    min-width: 110px;
    min-height: 58px;
    padding: 8px 12px 8px 8px;
    border-radius: 19px;
    grid-template-columns: 32px auto;
  }

  .pollen-counter__flower {
    width: 32px;
    height: 32px;
    font-size: 22px;
  }

  .pollen-counter__label {
    padding-left: 8px;
    font-size: 10px;
  }

  .pollen-counter__value {
    padding-left: 8px;
    font-size: 22px;
  }

  .hud-actions {
    gap: 7px;
  }

  .round-button {
    width: 42px;
    height: 42px;
    font-size: 21px;
  }

  .welcome {
    bottom: calc(var(--safe-bottom) + 10px);
    padding: 17px 16px 16px;
    border-radius: 23px;
  }

  .welcome__butterfly {
    top: -25px;
    font-size: 38px;
  }
}

@media (max-height: 580px) and (orientation: landscape) {
  .welcome {
    left: var(--safe-left);
    bottom: var(--safe-bottom);
    width: min(430px, 58vw);
    padding: 13px 18px 14px;
    text-align: left;
    transform: none;
  }

  .welcome.is-hidden {
    transform: translateY(20px) scale(.96);
  }

  .welcome__butterfly {
    display: none;
  }

  .welcome h1 {
    font-size: 23px;
  }

  .welcome p,
  .welcome span {
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .welcome,
  .message,
  .round-button {
    transition-duration: 1ms;
  }

  .welcome__butterfly,
  .pollen-counter.is-pop {
    animation: none;
  }
}

#app::before,
#app::after {
  position: absolute;
  z-index: 0;
  inset: 0;
  content: "";
  pointer-events: none;
}

#app::before {
  background:
    radial-gradient(circle at 14% 14%, rgb(255 250 198 / 96%) 0 2.2%, rgb(255 224 139 / 52%) 2.3% 5.5%, transparent 10%),
    radial-gradient(ellipse at 74% 16%, rgb(255 255 255 / 62%) 0 3.4%, transparent 3.8%),
    radial-gradient(ellipse at 70% 16%, rgb(255 255 255 / 54%) 0 2.9%, transparent 3.4%),
    radial-gradient(ellipse at 79% 17%, rgb(255 255 255 / 48%) 0 2.6%, transparent 3.1%),
    radial-gradient(ellipse at 35% 27%, rgb(255 255 255 / 38%) 0 2.6%, transparent 3.2%);
  filter: blur(.2px);
}

#app::after {
  opacity: .3;
  background: linear-gradient(112deg, transparent 12%, rgb(255 255 220 / 36%) 27%, transparent 42%);
  transform: translateX(-28%);
  animation: light-drift 16s ease-in-out infinite alternate;
}

#game-canvas {
  z-index: 1;
}

@keyframes light-drift {
  from { transform: translateX(-30%); opacity: .18; }
  to { transform: translateX(34%); opacity: .36; }
}

@media (prefers-reduced-motion: reduce) {
  #app::after {
    animation: none;
  }
}
