:root {
  color-scheme: light;
  --paper: #f7f2e8;
  --ink: #3f3a34;
  --muted: #726b63;
  --green: #6f8f80;
  --green-deep: #4f7162;
  --green-pale: #e6efe9;
  --yellow: #f1c96b;
  --red: #c95f54;
  --red-pale: #fae8e4;
  --white: #fffefb;
  --shadow: 0 14px 40px rgb(72 61 48 / 12%);
  --soft-shadow: 0 7px 20px rgb(72 61 48 / 10%);
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", "BIZ UDPGothic", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 7% 8%, rgb(241 201 107 / 22%) 0 92px, transparent 94px),
    radial-gradient(circle at 94% 16%, rgb(126 161 176 / 18%) 0 120px, transparent 122px),
    radial-gradient(circle at 12% 94%, rgb(111 143 128 / 14%) 0 150px, transparent 152px),
    var(--paper);
  overscroll-behavior: none;
}

button,
img {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 4px solid #5b88a1;
  outline-offset: 4px;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100%, 1080px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.screen {
  width: 100%;
}

.setup-screen {
  display: grid;
  justify-items: center;
  align-content: center;
  min-height: calc(100vh - 56px);
  min-height: calc(100dvh - 56px);
  text-align: center;
}

.brand-mark,
.finish-circle {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin-bottom: 8px;
  color: var(--red);
  font-family: Arial, sans-serif;
  font-size: 82px;
  font-weight: 400;
  line-height: 1;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--green-deep);
  font-size: clamp(0.82rem, 2vw, 1rem);
  font-weight: 800;
  letter-spacing: 0.12em;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5.5vw, 3.45rem);
  line-height: 1.25;
  letter-spacing: 0.04em;
}

.lead {
  margin: 14px 0 24px;
  color: var(--muted);
  font-size: clamp(1rem, 2.8vw, 1.25rem);
  font-weight: 700;
}

.setup-card {
  width: min(100%, 690px);
  padding: clamp(22px, 5vw, 38px);
  border: 2px solid rgb(108 91 69 / 10%);
  border-radius: 30px;
  background: rgb(255 254 251 / 92%);
  box-shadow: var(--shadow);
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  width: 100%;
  padding: 0;
  font-size: clamp(1.25rem, 3.5vw, 1.65rem);
  font-weight: 900;
}

.field-help {
  margin: 7px 0 17px;
  color: var(--muted);
  font-size: 0.96rem;
  font-weight: 650;
}

.number-picker {
  display: grid;
  grid-template-columns: repeat(5, minmax(48px, 1fr));
  gap: 10px;
}

.number-button {
  min-height: 58px;
  border: 2px solid #d8d1c4;
  border-radius: 16px;
  color: var(--ink);
  background: var(--white);
  font-size: 1.22rem;
  font-weight: 900;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
  touch-action: manipulation;
}

.number-button:hover {
  transform: translateY(-2px);
  border-color: var(--green);
}

.number-button.is-selected {
  border-color: var(--green-deep);
  color: #fff;
  background: var(--green-deep);
  box-shadow: 0 5px 0 #375548;
  transform: translateY(-2px);
}

.setup-summary {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 11px;
  min-height: 42px;
  margin: 22px 0 14px;
  color: var(--muted);
  font-weight: 750;
}

.setup-summary__number {
  color: var(--green-deep);
  font-size: 1.5rem;
  font-weight: 900;
}

.primary-button,
.secondary-button,
.quiet-button {
  min-height: 56px;
  border-radius: 18px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.primary-button {
  width: min(100%, 360px);
  border: 0;
  color: #fff;
  background: var(--green-deep);
  box-shadow: 0 6px 0 #375548;
  font-size: 1.2rem;
}

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

.secondary-button {
  width: min(100%, 360px);
  border: 2px solid var(--green-deep);
  color: var(--green-deep);
  background: var(--white);
  font-size: 1rem;
}

.privacy-note {
  margin: 18px 0 0;
  color: #898177;
  font-size: 0.82rem;
}

.game-screen {
  padding-bottom: 18px;
}

.game-header {
  display: grid;
  grid-template-columns: auto minmax(150px, 340px) auto;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: clamp(18px, 4vw, 30px);
}

.quiet-button {
  min-width: 96px;
  padding: 0 15px;
  border: 2px solid #d8d1c4;
  color: var(--ink);
  background: rgb(255 254 251 / 86%);
}

.progress-wrap {
  display: grid;
  gap: 7px;
  text-align: center;
}

.progress-text {
  font-size: 1rem;
  font-weight: 900;
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #ded7ca;
}

.progress-bar {
  width: 10%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), #92ad9f);
  transition: width 260ms ease;
}

.choice-badge {
  min-width: 74px;
  padding: 10px 13px;
  border-radius: 999px;
  color: var(--green-deep);
  background: var(--green-pale);
  font-weight: 900;
  text-align: center;
}

.instruction {
  font-size: clamp(1.45rem, 4.5vw, 2.15rem);
  text-align: center;
}

.target-area {
  display: grid;
  justify-items: center;
  margin-top: 14px;
}

.card-label {
  z-index: 1;
  margin: 0 0 -12px;
  padding: 7px 22px;
  border: 2px solid var(--green-deep);
  border-radius: 999px;
  color: #fff;
  background: var(--green-deep);
  font-weight: 900;
}

.target-card {
  display: grid;
  place-items: center;
  width: clamp(180px, 31vw, 260px);
  aspect-ratio: 1;
  overflow: hidden;
  border: 5px solid var(--green-deep);
  border-radius: 28px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.target-card img,
.choice-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.feedback {
  display: grid;
  place-items: center;
  min-height: 52px;
  margin: 4px 0 8px;
  color: var(--muted);
  font-size: clamp(1.1rem, 3vw, 1.45rem);
  font-weight: 900;
  text-align: center;
}

.feedback.is-correct {
  color: var(--red);
}

.feedback.is-wrong {
  color: #a45147;
}

.choices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(132px, 42vw), 1fr));
  gap: clamp(10px, 2vw, 17px);
  width: min(100%, 940px);
  margin: 0 auto;
}

.choice-card {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  aspect-ratio: 1;
  overflow: hidden;
  border: 3px solid #d7cfc1;
  border-radius: 22px;
  padding: 0;
  background: var(--white);
  box-shadow: var(--soft-shadow);
  cursor: pointer;
  transition: transform 130ms ease, border-color 130ms ease, box-shadow 130ms ease;
  touch-action: manipulation;
}

.choice-card:hover {
  border-color: #9bb1a6;
  transform: translateY(-3px);
}

.choice-card:active {
  transform: scale(0.97);
}

.choice-card.is-correct {
  border: 6px solid var(--red);
  box-shadow: 0 0 0 6px rgb(201 95 84 / 16%), var(--soft-shadow);
  animation: correct-pop 430ms ease both;
}

.choice-card.is-correct::after {
  position: absolute;
  inset: 7%;
  display: grid;
  place-items: center;
  border: 8px solid var(--red);
  border-radius: 50%;
  color: transparent;
  content: "";
}

.choice-card.is-wrong {
  border-color: #d58c81;
  background: var(--red-pale);
  animation: gentle-shake 360ms ease;
}

.choice-card:disabled {
  cursor: default;
}

.finish-screen {
  position: relative;
  display: grid;
  place-items: center;
  min-height: calc(100vh - 56px);
  min-height: calc(100dvh - 56px);
  overflow: hidden;
  text-align: center;
}

.finish-card {
  z-index: 1;
  display: grid;
  justify-items: center;
  width: min(100%, 610px);
  padding: clamp(30px, 7vw, 55px);
  border: 2px solid rgb(108 91 69 / 10%);
  border-radius: 34px;
  background: rgb(255 254 251 / 94%);
  box-shadow: var(--shadow);
}

.finish-card h1 {
  font-size: clamp(2rem, 6vw, 3.2rem);
}

.finish-message {
  margin: 16px 0 26px;
  color: var(--muted);
  font-size: 1.12rem;
  font-weight: 750;
}

.finish-actions {
  display: grid;
  justify-items: center;
  gap: 15px;
  width: 100%;
}

.finish-burst span {
  position: absolute;
  color: var(--yellow);
  font-size: 28px;
  animation: float-shape 2.6s ease-in-out infinite alternate;
}

.finish-burst span:nth-child(1) { top: 12%; left: 10%; color: #7da191; }
.finish-burst span:nth-child(2) { top: 20%; right: 10%; color: #d78377; animation-delay: 0.3s; }
.finish-burst span:nth-child(3) { bottom: 14%; left: 17%; color: #e1b34b; animation-delay: 0.7s; }
.finish-burst span:nth-child(4) { right: 14%; bottom: 11%; color: #7e9fb0; animation-delay: 0.45s; }
.finish-burst span:nth-child(5) { top: 8%; left: 48%; color: #d5a88c; animation-delay: 0.9s; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@keyframes gentle-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

@keyframes correct-pop {
  0% { transform: scale(0.92); }
  65% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

@keyframes float-shape {
  from { transform: translateY(-8px) rotate(-8deg); }
  to { transform: translateY(8px) rotate(8deg); }
}

@media (min-width: 900px) {
  .choices-grid[data-count="1"] { grid-template-columns: minmax(170px, 230px); justify-content: center; }
  .choices-grid[data-count="2"] { grid-template-columns: repeat(2, minmax(170px, 230px)); justify-content: center; }
  .choices-grid[data-count="3"] { grid-template-columns: repeat(3, minmax(160px, 215px)); justify-content: center; }
  .choices-grid[data-count="4"] { grid-template-columns: repeat(4, minmax(145px, 195px)); justify-content: center; }
  .choices-grid[data-count="5"] { grid-template-columns: repeat(5, minmax(130px, 170px)); justify-content: center; }
}

@media (max-width: 620px) {
  .app-shell {
    padding-inline: 12px;
  }

  .setup-card {
    border-radius: 24px;
  }

  .number-picker {
    gap: 8px;
  }

  .number-button {
    min-height: 52px;
    border-radius: 14px;
  }

  .game-header {
    grid-template-columns: 1fr auto;
    gap: 10px;
  }

  .progress-wrap {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .choice-badge {
    justify-self: end;
  }

  .target-card {
    width: min(52vw, 218px);
    border-radius: 23px;
  }

  .choices-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .choices-grid[data-count="1"] {
    grid-template-columns: minmax(150px, 210px);
    justify-content: center;
  }

  .choice-card {
    border-radius: 18px;
  }
}

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