:root {
  color-scheme: light;
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  background: #c9f2ff;
  color: #17395b;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  background:
    radial-gradient(circle at 50% 10%, rgba(255, 255, 255, 0.9), transparent 30%),
    #b9efff;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 4px solid #213f75;
  outline-offset: 4px;
}

#game-shell {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 420px;
  overflow: hidden;
  isolation: isolate;
  background: #79d8ff;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

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

#game-canvas:focus-visible {
  outline: 3px solid rgba(23, 57, 91, 0.24);
  outline-offset: -5px;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  padding:
    max(70px, calc(env(safe-area-inset-top) + 60px))
    max(18px, env(safe-area-inset-right))
    max(22px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  place-items: center;
}

.is-hidden {
  display: none !important;
}

.title-screen {
  background: linear-gradient(180deg, rgba(94, 203, 255, 0.22), rgba(46, 145, 210, 0.16));
}

.title-card,
.result-card {
  width: min(100%, 410px);
  text-align: center;
}

.eyebrow,
.result-kicker {
  display: inline-block;
  margin: 0 0 8px;
  padding: 6px 14px;
  border: 3px solid #17395b;
  border-radius: 999px;
  background: #fff7a3;
  color: #17395b;
  font-size: clamp(0.76rem, 3.2vw, 0.95rem);
  font-weight: 900;
  letter-spacing: 0.08em;
}

h1 {
  margin: 0;
  color: #fff;
  font-size: clamp(2.45rem, 12vw, 4.4rem);
  font-weight: 1000;
  line-height: 0.94;
  letter-spacing: -0.06em;
  text-shadow:
    0 5px 0 #17395b,
    3px 0 0 #17395b,
    -3px 0 0 #17395b;
  transform: rotate(-2deg);
}

h1 span {
  display: block;
  color: #fff06a;
  font-size: 0.76em;
  letter-spacing: -0.03em;
}

.hero-art {
  position: relative;
  height: clamp(120px, 24vh, 190px);
  margin: 8px auto 2px;
}

.hero-character {
  position: absolute;
  top: 30%;
  left: 50%;
  width: clamp(74px, 21vw, 108px);
  height: clamp(58px, 16vw, 84px);
  border: 5px solid #17395b;
  border-radius: 55% 50% 48% 56%;
  background: #ffd34d;
  color: transparent;
  box-shadow:
    inset -12px -10px 0 #f5a836,
    0 10px 0 rgba(29, 72, 105, 0.15);
  transform: translateX(-40%) rotate(-14deg);
}

.hero-character::before {
  position: absolute;
  top: 26%;
  right: 18%;
  width: 10px;
  height: 14px;
  border-radius: 50%;
  background: #17395b;
  box-shadow: 22px 2px 0 #17395b;
  content: "";
}

.hero-character::after {
  position: absolute;
  bottom: -7px;
  left: 19%;
  width: 58%;
  height: 24px;
  border: 5px solid #17395b;
  border-radius: 45%;
  background: #f45f5b;
  content: "";
}

.hero-puff {
  position: absolute;
  top: 56%;
  left: 18%;
  color: #fff;
  font-size: clamp(1rem, 5vw, 1.45rem);
  font-weight: 1000;
  text-shadow: 0 2px 0 #538fb1;
  transform: rotate(-12deg);
}

.hero-cloud {
  position: absolute;
  top: 5%;
  right: 6%;
  color: rgba(255, 255, 255, 0.76);
  font-size: clamp(2.5rem, 12vw, 4.5rem);
}

.primary-button {
  min-width: min(86vw, 310px);
  min-height: 68px;
  padding: 12px 30px;
  border: 4px solid #17395b;
  border-radius: 22px;
  background: #ff5f58;
  color: #fff;
  box-shadow: 0 7px 0 #a92f3e;
  font-size: clamp(1.35rem, 6vw, 1.8rem);
  font-weight: 1000;
  letter-spacing: 0.03em;
  cursor: pointer;
}

.primary-button:active {
  box-shadow: 0 2px 0 #a92f3e;
  transform: translateY(5px);
}

.primary-button:disabled {
  cursor: default;
  filter: grayscale(0.35);
  opacity: 0.62;
}

.tiny-hint {
  margin: 18px 0 0;
  color: #17395b;
  font-size: 0.84rem;
  font-weight: 800;
}

.sound-toggle {
  position: absolute;
  z-index: 30;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: grid;
  min-width: 54px;
  min-height: 54px;
  padding: 6px;
  border: 3px solid #17395b;
  border-radius: 18px;
  place-items: center;
  background: rgba(255, 255, 255, 0.88);
  color: #17395b;
  box-shadow: 0 4px 0 rgba(23, 57, 91, 0.25);
  cursor: pointer;
}

.sound-toggle span:first-child {
  font-size: 1.3rem;
  line-height: 1;
}

.sound-text {
  font-size: 0.63rem;
  font-weight: 1000;
  line-height: 1;
}

.hud {
  position: absolute;
  z-index: 5;
  top: max(12px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  min-width: 108px;
  padding: 7px 15px 8px;
  border: 3px solid #17395b;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.91);
  box-shadow: 0 4px 0 rgba(23, 57, 91, 0.18);
  text-align: center;
}

.hud-label {
  display: block;
  color: #44708d;
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1;
}

.hud strong {
  font-size: 1.65rem;
  line-height: 1;
}

.hud-unit {
  margin-left: 2px;
  font-size: 0.75rem;
}

.ready-screen {
  z-index: 6;
  pointer-events: none;
}

.ready-prompt {
  display: grid;
  padding: 18px 26px;
  border: 4px solid #17395b;
  border-radius: 28px;
  place-items: center;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 0 rgba(23, 57, 91, 0.18);
  transform: translateY(18vh) rotate(-1deg);
}

.ready-prompt strong {
  font-size: clamp(1.55rem, 8vw, 2.35rem);
  font-weight: 1000;
}

.ready-subtext {
  color: #557891;
  font-size: 0.85rem;
  font-weight: 800;
}

.ready-legend {
  display: grid;
  width: min(76vw, 280px);
  margin-top: 14px;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ready-legend > span {
  display: grid;
  min-height: 62px;
  padding: 7px 5px;
  border: 3px solid #17395b;
  border-radius: 16px;
  place-items: center;
  font-size: 1.3rem;
  line-height: 1;
}

.ready-legend b {
  font-size: 0.84rem;
  font-weight: 1000;
}

.legend-take {
  background: #fff3a0;
  color: #28703c;
}

.legend-avoid {
  background: #ffe0dc;
  color: #a82d3b;
}

.tap-icon {
  font-size: 2.1rem;
  animation: tap-bounce 0.85s ease-in-out infinite alternate;
}

.power-message {
  position: absolute;
  z-index: 8;
  top: 23%;
  left: 50%;
  padding: 8px 17px;
  border: 4px solid #17395b;
  border-radius: 999px;
  background: #fff06a;
  color: #dd3c4d;
  font-size: clamp(1.25rem, 7vw, 2rem);
  font-weight: 1000;
  white-space: nowrap;
  text-shadow: 0 2px 0 #fff;
  transform: translateX(-50%) rotate(-3deg);
  animation: power-pop 0.25s ease-out;
}

.milestone-message {
  position: absolute;
  z-index: 9;
  top: 13%;
  left: 50%;
  display: grid;
  min-width: min(82vw, 330px);
  padding: 11px 20px 10px;
  border: 4px solid #17395b;
  border-radius: 22px;
  place-items: center;
  background: linear-gradient(135deg, #fff06a, #ffb9de 55%, #9ceeff);
  color: #17395b;
  box-shadow: 0 7px 0 rgba(23, 57, 91, 0.24);
  text-align: center;
  transform: translateX(-50%) rotate(-2deg);
  animation: milestone-pop 0.32s ease-out;
}

.milestone-message strong {
  font-size: clamp(1.35rem, 7vw, 2.1rem);
  font-weight: 1000;
  line-height: 1.05;
}

.milestone-message span {
  margin-top: 4px;
  color: #9e2942;
  font-size: clamp(0.76rem, 3.5vw, 0.95rem);
  font-weight: 1000;
}

.result-screen {
  background: rgba(53, 145, 199, 0.35);
  backdrop-filter: blur(3px);
}

.result-card {
  padding: clamp(20px, 6vw, 32px);
  border: 4px solid #17395b;
  border-radius: 32px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 0 rgba(23, 57, 91, 0.25);
}

.result-card h2 {
  margin: 6px 0 0;
  color: #4c7089;
  font-size: 1rem;
}

.result-score {
  margin: 0 0 10px;
  color: #ff554f;
  font-size: clamp(3.8rem, 20vw, 6.4rem);
  font-weight: 1000;
  line-height: 1;
  letter-spacing: -0.07em;
}

.result-score small {
  margin-left: 5px;
  color: #17395b;
  font-size: 0.25em;
  letter-spacing: 0;
}

.best-score {
  display: flex;
  width: min(90%, 260px);
  margin: 0 auto 20px;
  padding: 9px 15px;
  border-radius: 14px;
  justify-content: space-between;
  background: #eaf8ff;
  font-weight: 900;
}

.result-card .primary-button {
  min-width: min(72vw, 290px);
  min-height: 62px;
}

.text-button {
  display: block;
  min-height: 48px;
  margin: 12px auto -6px;
  padding: 8px 14px;
  border: 0;
  background: transparent;
  color: #365e7c;
  font-size: 0.9rem;
  font-weight: 900;
  text-decoration: underline;
  cursor: pointer;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@keyframes tap-bounce {
  to {
    transform: translateY(9px) scale(0.94);
  }
}

@keyframes power-pop {
  from {
    opacity: 0;
    transform: translateX(-50%) scale(0.55) rotate(5deg);
  }
}

@keyframes milestone-pop {
  from {
    opacity: 0;
    transform: translateX(-50%) scale(0.55) rotate(5deg);
  }
}

@media (min-width: 760px) {
  #game-shell {
    width: min(100%, 920px);
    height: min(100dvh, 760px);
    border-inline: 4px solid rgba(23, 57, 91, 0.25);
    box-shadow: 0 0 48px rgba(27, 83, 120, 0.24);
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .screen {
    padding-block: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-bottom));
  }

  .title-card {
    display: grid;
    width: min(90%, 720px);
    grid-template-columns: 1fr 1fr;
    align-items: center;
    column-gap: 24px;
  }

  .title-card .eyebrow,
  .title-card h1,
  .title-card .tiny-hint {
    grid-column: 1;
  }

  .hero-art,
  .title-card .primary-button {
    grid-column: 2;
  }

  .hero-art {
    grid-row: 1 / span 3;
    width: 100%;
    height: 150px;
  }

  .title-card .primary-button {
    grid-row: 4;
    min-height: 58px;
  }

  .title-card .tiny-hint {
    margin-top: 8px;
  }

  .result-card {
    display: grid;
    width: min(92%, 650px);
    grid-template-columns: 1fr 1fr;
    align-items: center;
    column-gap: 24px;
    padding: 16px 28px;
  }

  .result-card > * {
    grid-column: 1;
  }

  .result-card .primary-button,
  .result-card .text-button {
    grid-column: 2;
  }

  .result-card .primary-button {
    grid-row: 2 / span 2;
  }

  .result-card .text-button {
    grid-row: 4;
  }

  .result-score {
    font-size: 4.4rem;
  }

  .ready-prompt {
    transform: translateY(4vh) rotate(-1deg);
  }

  .ready-legend {
    margin-top: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
