:root {
  color-scheme: light;
  font-family: "Trebuchet MS", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  background: #1f62bb;
  color: #113476;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.35), transparent 34rem),
    linear-gradient(180deg, #5aa8fb, #1f62bb 58%, #174c9d);
}

#shell {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#game {
  width: min(100vw, 56.25vh);
  height: min(177.78vw, 100vh);
  max-width: 900px;
  max-height: 1600px;
  display: block;
  background: #70b6ff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35), 0 1.5rem 4rem rgba(0, 29, 83, 0.35);
}

.clear-overlay {
  position: absolute;
  width: min(100vw, 56.25vh);
  height: min(177.78vw, 100vh);
  max-width: 900px;
  max-height: 1600px;
  overflow: hidden;
  background: #050506;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  z-index: 2;
}

.clear-overlay.active {
  opacity: 1;
}

.clear-overlay.hidden {
  display: none;
}

.clear-overlay.ready {
  pointer-events: auto;
}

.clear-stage {
  position: absolute;
  top: clamp(3rem, 7vh, 6.5rem);
  left: 50%;
  width: min(92%, 72vh);
  aspect-ratio: 1;
  transform: translateX(-50%);
  overflow: hidden;
}

.clear-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 70%, rgba(255, 218, 72, 0.2), transparent 36%);
  mix-blend-mode: screen;
  pointer-events: none;
}

.clear-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: 50% 70%;
  pointer-events: none;
  user-select: none;
}

.clear-bg {
  object-fit: cover;
  opacity: 0;
}

.clear-ring {
  opacity: 0;
  transform: translateY(5.5%) scale(0.9);
  animation: none;
}

.clear-nyabit {
  opacity: 0;
  transform: translateY(7%) scale(0.98);
  animation: none;
}

.clear-logo {
  opacity: 0;
  transform: scale(0.85);
  transform-origin: 50% 37%;
  animation: none;
}

.clear-confetti {
  opacity: 0;
  transform: translateY(-1.8%);
  animation: none;
}

.clear-floor {
  position: absolute;
  top: 9.8%;
  left: 50%;
  display: grid;
  grid-template-columns: minmax(2.8rem, 1fr) auto minmax(2.8rem, 1fr);
  align-items: center;
  width: min(75%, 42rem);
  transform: translateX(-50%) translateY(0.6rem);
  opacity: 0;
  gap: clamp(0.45rem, 1.6vw, 0.9rem);
  color: #fff8cd;
  font-family: "Trebuchet MS", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  font-size: clamp(1.25rem, 6.4vw, 3.55rem);
  font-style: italic;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  text-align: center;
  text-shadow:
    0 0 0.12em #fff,
    0 0 0.24em #ffd65e,
    0 0 0.52em #f5a500,
    0 0 0.9em rgba(255, 196, 31, 0.78);
  white-space: nowrap;
}

.clear-floor-line {
  position: relative;
  height: 0.18em;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, #fff5a8 18%, #ffba27 58%, transparent);
  box-shadow: 0 0 0.5em #ffd65e, 0 0 1.1em rgba(255, 176, 16, 0.7);
}

.clear-floor-line:last-child {
  transform: scaleX(-1);
}

.clear-floor-line::after {
  content: "";
  position: absolute;
  right: 7%;
  top: 50%;
  width: 26%;
  height: 0.34em;
  border-radius: 999px;
  background: #fff8cf;
  transform: translateY(-50%);
  box-shadow: 0 0 0.5em #ffcf4d;
}

.clear-overlay.active .clear-bg {
  animation: clearFadeIn 0.32s ease forwards;
}

.clear-overlay.active .clear-ring {
  animation:
    clearRingIn 0.64s 0.22s cubic-bezier(0.2, 0.8, 0.25, 1) forwards,
    clearLightPulse 1.8s 0.88s ease-in-out infinite;
}

.clear-overlay.active .clear-nyabit {
  animation:
    clearNyabitIn 0.7s 0.58s cubic-bezier(0.2, 0.9, 0.3, 1) forwards,
    clearFloat 1.85s 1.28s ease-in-out infinite;
}

.clear-overlay.active .clear-logo {
  animation: clearLogoPop 0.58s 1.05s cubic-bezier(0.2, 0.85, 0.28, 1.25) forwards;
}

.clear-overlay.active .clear-floor {
  animation: clearFloorIn 0.42s 1.48s ease forwards;
}

.clear-overlay.active .clear-confetti {
  animation:
    clearConfettiIn 0.42s 1.78s ease forwards,
    clearConfettiDrift 2.2s 2.2s ease-in-out infinite;
}

.clear-speech {
  position: absolute;
  left: 50%;
  bottom: clamp(7rem, 23vh, 12rem);
  transform: translateX(-50%) translateY(0.6rem);
  width: min(86%, 30rem);
  margin: 0;
  padding: 0.9rem 1.25rem;
  border-radius: 1.15rem;
  background: linear-gradient(180deg, rgba(255, 251, 224, 0.98), rgba(255, 234, 173, 0.98));
  color: #5b3a00;
  font-size: clamp(1.05rem, 4.6vw, 1.42rem);
  font-weight: 800;
  line-height: 1.4;
  text-align: center;
  box-shadow:
    inset 0 2px rgba(255, 255, 255, 0.85),
    0 0.35rem 0 rgba(125, 74, 0, 0.5),
    0 0 1.1rem rgba(255, 200, 50, 0.42);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.clear-speech::before {
  content: "";
  position: absolute;
  top: -0.62rem;
  left: 50%;
  transform: translateX(-50%);
  border-left: 0.72rem solid transparent;
  border-right: 0.72rem solid transparent;
  border-bottom: 0.72rem solid rgba(255, 250, 220, 0.98);
}

.clear-overlay.active .clear-speech {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  transition-delay: 1.05s;
}

.clear-next {
  position: absolute;
  left: calc(50% - 10rem);
  right: auto;
  bottom: max(2.6rem, env(safe-area-inset-bottom));
  width: 20rem;
  height: 3.25rem;
  margin: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, #fff8d1, #ffc73c 52%, #d58410);
  color: #3b2300;
  font-size: clamp(1.2rem, 4.8vw, 1.55rem);
  letter-spacing: 0;
  opacity: 0;
  transform: translateY(0.7rem);
  box-shadow:
    inset 0 2px rgba(255, 255, 255, 0.75),
    0 0.4rem 0 #7d4a00,
    0 0 1.25rem rgba(255, 200, 50, 0.48);
  transition: opacity 0.24s ease, transform 0.24s ease;
}

.clear-overlay.ready .clear-next {
  opacity: 1;
  transform: translateY(0);
}

@keyframes clearFadeIn {
  to { opacity: 1; }
}

@keyframes clearRingIn {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes clearLightPulse {
  0%, 100% { filter: brightness(1) saturate(1); }
  50% { filter: brightness(1.12) saturate(1.08); }
}

@keyframes clearNyabitIn {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes clearFloat {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-1.2%) scale(1); }
}

@keyframes clearLogoPop {
  0% {
    opacity: 0;
    transform: scale(0.85);
  }
  68% {
    opacity: 1;
    transform: scale(1.05);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes clearFloorIn {
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes clearConfettiIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes clearConfettiDrift {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(1.1%) rotate(0.4deg); }
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(16, 60, 130, 0.34);
  backdrop-filter: blur(8px);
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(92vw, 420px);
  padding: 1.25rem;
  border: 2px solid rgba(37, 88, 171, 0.35);
  border-radius: 18px;
  background: linear-gradient(180deg, #fffdf6, #edf5ff);
  box-shadow: 0 1rem 2.5rem rgba(0, 36, 98, 0.25);
  text-align: center;
}

.mark {
  display: inline-block;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: #e2f1ff;
  color: #2865bd;
  font-weight: 900;
  letter-spacing: 0;
  font-size: 0.8rem;
}

h1 {
  margin: 0.7rem 0 0.35rem;
  color: #123b8c;
  font-size: 2rem;
  letter-spacing: 0;
}

p {
  margin: 0.45rem 0;
  line-height: 1.55;
  font-weight: 700;
  line-break: anywhere;
  overflow-wrap: anywhere;
  word-break: break-all;
}

button {
  width: 100%;
  height: 3.5rem;
  margin: 1rem 0 0.3rem;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(180deg, #36a7ff, #176ddd);
  color: white;
  font: inherit;
  font-size: 1.4rem;
  font-weight: 900;
  box-shadow: inset 0 2px rgba(255, 255, 255, 0.45), 0 0.45rem 0 #0d4cad;
}

button:active {
  transform: translateY(0.25rem);
  box-shadow: inset 0 2px rgba(255, 255, 255, 0.45), 0 0.2rem 0 #0d4cad;
}

.difficulty-select {
  display: flex;
  gap: 0.5rem;
  margin: 0.9rem 0 0.2rem;
}
.diff-btn {
  width: auto;
  flex: 1;
  height: 2.6rem;
  margin: 0;
  font-size: 1rem;
  background: #eaf2ff;
  color: #2865bd;
  box-shadow: inset 0 0 0 2px rgba(37, 88, 171, 0.3);
}
.diff-btn.selected {
  background: linear-gradient(180deg, #36a7ff, #176ddd);
  color: #fff;
  box-shadow: inset 0 2px rgba(255, 255, 255, 0.45), 0 0.3rem 0 #0d4cad;
}

.note {
  color: #4e668f;
  font-size: 0.82rem;
  font-weight: 700;
}

#clearNextButton.clear-next {
  left: calc(50% - 110px) !important;
  right: auto !important;
  width: 220px !important;
  height: 3.25rem !important;
  margin: 0 !important;
  transform: translateY(0.7rem) !important;
}

.clear-overlay.ready #clearNextButton.clear-next {
  transform: translateY(0) !important;
}

.result-overlay {
  position: absolute;
  width: min(100vw, 56.25vh);
  height: min(177.78vw, 100vh);
  max-width: 900px;
  max-height: 1600px;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 4vw, 2rem);
  background:
    radial-gradient(circle at 50% 12%, rgba(139, 220, 255, 0.36), transparent 18rem),
    linear-gradient(180deg, rgba(5, 14, 38, 0.96), rgba(3, 8, 24, 0.98));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  z-index: 8;
}

.result-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.result-overlay.hidden {
  display: none;
}

.result-panel {
  width: min(92%, 34rem);
  max-height: 92%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(1.1rem, 4vw, 2rem);
  border-radius: 1.25rem;
  background: linear-gradient(180deg, rgba(249, 253, 255, 0.98), rgba(218, 236, 255, 0.97));
  color: #12336b;
  box-shadow: 0 1.25rem 3rem rgba(0, 0, 0, 0.38), inset 0 0 0 3px rgba(255, 255, 255, 0.75);
  text-align: center;
}

.result-kicker {
  margin: 0;
  color: #2e76d6;
  font-size: clamp(.78rem, 2.8vw, 1rem);
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.result-panel h1 {
  margin: .2rem 0 .9rem;
  color: #0b55bf;
  font-size: clamp(2rem, 8vw, 4rem);
  line-height: .95;
}

.result-summary {
  display: grid;
  gap: .42rem;
}

.result-row,
.result-score,
.result-rank,
.result-comment {
  opacity: 0;
  transform: translateY(.65rem);
  transition: opacity .26s ease, transform .26s ease;
  transition-delay: calc(var(--i, 0) * .08s);
}

.result-overlay.active .result-row,
.result-overlay.active .result-score,
.result-overlay.active .result-rank,
.result-overlay.active .result-comment {
  opacity: 1;
  transform: translateY(0);
}

.result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  padding: .5rem .75rem;
  border-radius: .7rem;
  background: rgba(255, 255, 255, 0.74);
  font-weight: 900;
}

.result-row span {
  color: #456599;
}

.result-row strong {
  color: #113476;
}

.result-score,
.result-rank {
  margin-top: .75rem;
  padding: .75rem;
  border-radius: .9rem;
  background: linear-gradient(180deg, #fff3a7, #ffd15b);
  box-shadow: inset 0 2px rgba(255, 255, 255, 0.7), 0 .35rem 0 rgba(182, 113, 18, .45);
  font-weight: 900;
}

.result-score span,
.result-rank span {
  display: block;
  color: #7b4e00;
  font-size: .9rem;
}

.result-score strong {
  display: block;
  color: #143c83;
  font-size: clamp(2rem, 8vw, 3.5rem);
  line-height: 1;
}

.result-rank strong {
  display: block;
  color: #f44957;
  font-size: clamp(3.2rem, 15vw, 6rem);
  line-height: .95;
}

.result-comment {
  margin: .9rem 0 0;
  color: #1e4d99;
  font-weight: 900;
}

.result-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: .7rem;
  margin-top: 1rem;
  padding-top: .55rem;
  background: linear-gradient(180deg, rgba(218, 236, 255, 0), rgba(218, 236, 255, 0.98) 28%);
  z-index: 1;
}

.result-actions button {
  flex: 1;
  min-width: 0;
  height: 3.1rem;
  margin: 0;
  font-size: clamp(.85rem, 3.6vw, 1.15rem);
}

.result-actions button:disabled {
  cursor: not-allowed;
  filter: grayscale(.45);
  opacity: .62;
  transform: none !important;
}

@media (max-width: 440px) {
  #clearNextButton.clear-next {
    left: calc(50% - 110px) !important;
    width: 220px !important;
  }

  .result-panel {
    width: min(94%, 22rem);
    max-height: 96%;
    padding: .85rem;
    border-radius: 1rem;
  }

  .result-panel h1 {
    margin-bottom: .55rem;
    font-size: clamp(1.6rem, 7vw, 2.15rem);
  }

  .result-summary {
    gap: .25rem;
  }

  .result-row {
    padding: .34rem .55rem;
    border-radius: .55rem;
  }

  .result-score,
  .result-rank {
    margin-top: .45rem;
    padding: .5rem;
    border-radius: .65rem;
  }

  .result-score strong {
    font-size: clamp(1.7rem, 7vw, 2.35rem);
  }

  .result-rank strong {
    font-size: clamp(2.6rem, 12vw, 4rem);
  }

  .result-comment {
    margin-top: .65rem;
    font-size: .9rem;
  }

  .result-actions {
    margin-top: .75rem;
    gap: .45rem;
  }

  .result-actions button {
    height: 2.65rem;
    font-size: .82rem;
  }
}

/* Start screen */
.start-screen {
  position: absolute;
  top: 50%;
  left: 50%;
  right: auto;
  bottom: auto;
  width: min(100vw, 56.25vh);
  height: min(177.78vw, 100vh);
  max-width: 900px;
  max-height: 1600px;
  display: block;
  padding: 0;
  overflow: hidden;
  background: #06183e;
  backdrop-filter: none;
  z-index: 5;
  transform: translate(-50%, -50%);
  transition: opacity .32s ease, transform .32s ease;
}

.start-screen.leaving {
  opacity: 0;
  transform: translate(-50%, -50%) scale(1.025);
  pointer-events: none;
}

.start-step.hidden { display: none; }

.start-bg,
.start-vignette {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.start-bg { object-fit: cover; }

.start-vignette {
  background:
    linear-gradient(180deg, rgba(2, 12, 43, .12) 0%, transparent 50%, rgba(2, 12, 43, .12) 100%),
    radial-gradient(ellipse at 50% 56%, transparent 48%, rgba(1, 10, 34, .4) 100%);
  pointer-events: none;
}

.start-brand {
  position: absolute;
  top: max(3.1%, env(safe-area-inset-top));
  left: 5%;
  width: 90%;
  text-align: center;
}

.start-logo {
  padding: .13em .2em .2em;
  border: clamp(2px, .45vw, 4px) solid #52baff;
  border-radius: .34em;
  background: linear-gradient(180deg, #fffaf0 0%, #f6ead1 100%);
  color: #061d58;
  font-size: clamp(2rem, min(9.4vw, 5vh), 3.2rem);
  font-weight: 1000;
  letter-spacing: -.08em;
  line-height: 1.1;
  text-shadow: 0 .04em 0 #fff;
  box-shadow: 0 0 0 .1em #0a2c70, 0 .16em .42em rgba(0, 0, 0, .42), inset 0 2px #fff;
  transform: rotate(-1deg);
}

.start-logo span { margin-right: .07em; }
.start-logo span::after { content: " ●"; color: #19dffc; font-size: .35em; vertical-align: .5em; }

.start-brand p {
  display: inline-block;
  margin: .8em 0 0;
  padding: .42em 1.15em;
  border: 2px solid #4fa9ff;
  border-radius: 999px;
  background: rgba(2, 25, 76, .92);
  color: #7cc3ff;
  font-size: clamp(.72rem, 3.2vw, 1.35rem);
  letter-spacing: .04em;
  box-shadow: 0 .28em .65em rgba(0, 0, 0, .35);
}

.start-menu {
  position: absolute;
  left: 4.5%;
  right: 4.5%;
  bottom: max(3.5%, env(safe-area-inset-bottom));
  text-align: center;
}

.start-menu h1 {
  width: 74%;
  margin: 0 auto;
  padding: .18em .35em .24em;
  border: clamp(2px, .45vw, 4px) solid #55b9ff;
  border-radius: .35em;
  background: linear-gradient(180deg, #fffdf6, #f1e3c8);
  color: #061d58;
  font-size: clamp(2rem, min(9vw, 5vh), 3.2rem);
  line-height: 1.08;
  box-shadow: 0 0 0 .09em #092967, 0 .2em .5em rgba(0, 0, 0, .5), inset 0 2px #fff;
}

.start-main-button {
  width: 74%;
  height: auto;
  margin: 0 auto;
  padding: .18em .35em .24em;
  display: flex;
  align-items: center;
  justify-content: space-around;
  border: clamp(2px, .45vw, 4px) solid #55b9ff;
  border-radius: .35em;
  background: linear-gradient(180deg, #fffdf6, #f1e3c8);
  color: #061d58;
  font-size: clamp(2.2rem, min(10.5vw, 6vh), 3.7rem);
  line-height: 1.08;
  box-shadow: 0 0 0 .09em #092967, 0 .2em .5em rgba(0, 0, 0, .5), inset 0 2px #fff;
  animation: startPulse 1.8s ease-in-out infinite;
  cursor: pointer;
  touch-action: manipulation;
}

.start-main-button span {
  color: #56baff;
  font-size: .8em;
}

.difficulty-label {
  margin: .75em 0 .5em;
  color: #d9ecff;
  font-size: clamp(.72rem, 3.1vw, 1.15rem);
  text-shadow: 0 2px 5px #00133e;
}

.start-screen .difficulty-select {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2.5%;
  margin: 0;
}

.start-screen .diff-btn {
  min-width: 0;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / .92;
  margin: 0;
  padding: 8% 4% 6%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4%;
  border: clamp(2px, .45vw, 4px) solid #183a77;
  border-radius: 12%;
  background: linear-gradient(180deg, #fffdf7, #eee0c5);
  color: #08245f;
  box-shadow: 0 .35em 0 #061a4a, 0 .45em 1em rgba(0, 0, 0, .35), inset 0 2px #fff;
  opacity: .62;
  cursor: pointer;
  touch-action: manipulation;
}

.start-screen .diff-btn:disabled { cursor: not-allowed; }

.start-screen .diff-btn.selected {
  border-color: #67dbff;
  color: #0752b9;
  opacity: 1;
  box-shadow: 0 0 0 .18em #1678dc, 0 0 1.25em rgba(69, 210, 255, .8), 0 .35em 0 #05275f, inset 0 2px #fff;
  animation: startPulse 1.8s ease-in-out infinite;
}

.start-screen .diff-btn:active:not(:disabled) { transform: translateY(.18rem); }
.start-screen .diff-btn strong { font-size: clamp(.8rem, 4vw, 1.65rem); white-space: nowrap; }
.start-screen .diff-btn small { color: inherit; font-size: clamp(.52rem, 2.2vw, .9rem); font-weight: 900; white-space: nowrap; }

.cat-face {
  display: grid;
  place-items: center;
  width: 43%;
  aspect-ratio: 1;
  border: .22em solid currentColor;
  border-radius: 45% 45% 50% 50%;
  background: #08142c;
  font-size: clamp(.62rem, 3vw, 1.25rem);
  line-height: 1;
}
.cat-face.green { color: #49d174; }
.cat-face.blue { color: #58e8ff; }
.cat-face.red { color: #ff7373; }

.start-note {
  margin: .8em 0 0;
  color: #d9ecff;
  font-size: clamp(.66rem, 2.8vw, 1rem);
  text-shadow: 0 2px 5px #00133e;
}

@keyframes startPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.12); }
}
