:root {
  color-scheme: light;
  --ink: #213431;
  --muted: #49615c;
  --sky: #b9ecff;
  --leaf: #4f9b4f;
  --grass: #75c36e;
  --sun: #ffd35a;
  --coral: #f2674f;
  --aqua: #28a9a1;
  --plum: #7d5cc6;
  --paper: #fff8e7;
  --line: #24413c;
  --shadow: rgba(33, 52, 49, 0.16);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, var(--sky) 0 54%, #ddf5d8 54% 69%, var(--grass) 69% 100%);
  letter-spacing: 0;
  overflow-x: hidden;
}

button {
  font: inherit;
}

.game-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 0.75rem;
  padding: 1rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 0.65rem;
  background: rgba(255, 248, 231, 0.9);
  border: 3px solid rgba(36, 65, 60, 0.18);
  border-radius: 8px;
  box-shadow: 0 10px 24px var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.brand-mark {
  width: 4.25rem;
  height: 4.25rem;
  flex: 0 0 auto;
}

.brand-mark svg {
  width: 100%;
  height: 100%;
  display: block;
}

h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 1;
}

.voice-status {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 1rem;
  min-height: 1.35rem;
}

.voice-status[data-state="ready"] {
  color: #0f6a42;
}

.voice-status[data-state="fallback"] {
  color: #98551e;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.star-row {
  display: grid;
  grid-template-columns: repeat(5, 2rem);
  gap: 0.3rem;
  min-width: 11.2rem;
  direction: ltr;
}

.star {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  color: #9eb0ad;
}

.star svg {
  width: 100%;
  height: 100%;
  display: block;
  fill: currentColor;
  stroke: var(--line);
  stroke-width: 1.4;
}

.star.is-filled {
  color: var(--sun);
}

.icon-button {
  width: 3.65rem;
  height: 3.65rem;
  display: grid;
  place-items: center;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--line);
  cursor: pointer;
  box-shadow: 0 5px 0 var(--line);
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.icon-button svg {
  width: 1.75rem;
  height: 1.75rem;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.5;
}

.icon-button:active,
.answer-card:active,
.start-button:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--line);
}

.icon-button.is-active {
  background: #ffed95;
  border-color: #145c34;
}

.icon-button:focus-visible,
.answer-card:focus-visible,
.start-button:focus-visible {
  outline: 4px solid #ffffff;
  outline-offset: 4px;
}

.playfield {
  width: min(1120px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-rows: minmax(20rem, 1fr) auto;
  gap: 1rem;
}

.problem-visual {
  min-height: 22rem;
  display: grid;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
}

.problem-visual.is-add {
  grid-template-columns: minmax(0, 1fr) 5rem minmax(0, 1fr);
}

.problem-visual.is-subtract {
  grid-template-columns: minmax(0, 1fr) 5rem minmax(0, 0.72fr);
}

.visual-group {
  min-height: 18rem;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.46);
  border: 3px solid rgba(36, 65, 60, 0.16);
  border-radius: 8px;
  transition: border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.visual-group.is-guide-focus {
  background: rgba(255, 248, 231, 0.82);
  border-color: #145c34;
  box-shadow: inset 0 0 0 4px rgba(255, 211, 90, 0.72);
}

.object-board {
  display: grid;
  grid-template-columns: repeat(5, 4.25rem);
  justify-content: center;
  align-items: end;
  gap: 0.35rem 0.45rem;
  min-height: 12.5rem;
  width: 100%;
  direction: ltr;
}

.object-board.small {
  grid-template-columns: repeat(3, 4.25rem);
}

.object-slot {
  position: relative;
  width: 4.2rem;
  height: 6rem;
  display: block;
}

.math-object {
  width: 4.2rem;
  height: 6rem;
  display: block;
  filter: drop-shadow(0 7px 5px rgba(33, 52, 49, 0.15));
  animation: bob 1.8s ease-in-out infinite;
  animation-delay: calc(var(--i) * -140ms);
  transition: opacity 180ms ease, transform 180ms ease, filter 180ms ease;
}

.math-object.is-away {
  opacity: 0.42;
  transform: translateY(-1.1rem) rotate(-7deg);
}

.object-slot.is-counted .math-object {
  filter: drop-shadow(0 0 0.85rem rgba(255, 211, 90, 0.88)) drop-shadow(0 7px 5px rgba(33, 52, 49, 0.18));
}

.object-slot.is-current .math-object {
  transform: translateY(-0.75rem) scale(1.08);
}

.object-slot.is-away-slot.is-guide-away .math-object {
  opacity: 0.18;
  transform: translateY(-2.2rem) rotate(-13deg) scale(0.9);
}

.object-slot.is-counted::after {
  content: attr(data-guide-number);
  position: absolute;
  inset-inline-start: 50%;
  top: -0.7rem;
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  translate: -50% 0;
  border: 3px solid var(--line);
  border-radius: 999px;
  background: var(--sun);
  color: var(--line);
  font-size: 1.15rem;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 4px 0 var(--line);
}

.operator-symbol {
  width: 5rem;
  height: 5rem;
  display: grid;
  place-items: center;
  justify-self: center;
  align-self: center;
  border: 4px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--line);
  font-size: 3.5rem;
  line-height: 1;
  font-weight: 900;
  box-shadow: 0 8px 0 var(--line);
}

.answer-zone {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
}

.answer-card {
  min-height: 9.5rem;
  display: grid;
  grid-template-rows: auto 1fr;
  place-items: center;
  gap: 0.3rem;
  padding: 0.75rem;
  border: 4px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--line);
  cursor: pointer;
  box-shadow: 0 8px 0 var(--line);
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease, background 120ms ease;
}

.answer-card:nth-child(1) {
  background: #ffed95;
}

.answer-card:nth-child(2) {
  background: #bff1ed;
}

.answer-card:nth-child(3) {
  background: #ffd5ce;
}

.answer-card.is-correct {
  background: #bfe8a9;
  border-color: #145c34;
}

.answer-card.is-guide-answer {
  background: #bfe8a9;
  border-color: #145c34;
  box-shadow: 0 8px 0 #145c34, 0 0 0 6px rgba(255, 211, 90, 0.8);
}

.answer-card.is-wrong {
  background: #e8e2dc;
  border-color: #9d4d38;
}

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

.answer-card:disabled:not(.is-correct):not(.is-wrong) {
  opacity: 0.72;
}

.answer-number {
  font-size: 4.8rem;
  line-height: 1;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.dot-grid {
  min-height: 2.6rem;
  display: grid;
  grid-template-columns: repeat(5, 0.75rem);
  grid-auto-rows: 0.75rem;
  gap: 0.3rem;
  justify-content: center;
  align-content: center;
  direction: ltr;
}

.answer-dot {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 999px;
  background: var(--line);
}

.feedback-panel {
  width: min(1120px, 100%);
  min-height: 5rem;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.65rem;
  border: 3px solid rgba(36, 65, 60, 0.18);
  border-radius: 8px;
  background: rgba(255, 248, 231, 0.9);
  box-shadow: 0 10px 24px var(--shadow);
}

.feedback-face {
  width: 3.2rem;
  height: 3.2rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--sun);
  border: 3px solid var(--line);
  font-size: 1.9rem;
}

.feedback-text {
  min-width: 8rem;
  text-align: center;
  font-size: 1.6rem;
  font-weight: 850;
}

.celebration-layer {
  position: fixed;
  inset: 0;
  z-index: 12;
  pointer-events: none;
  overflow: hidden;
}

.sparkle {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 1.25rem;
  height: 1.25rem;
  color: var(--color);
  animation: sparkle-pop 1150ms ease-out forwards;
  animation-delay: var(--delay);
}

.sparkle svg {
  width: 100%;
  height: 100%;
  display: block;
  fill: currentColor;
  stroke: #24413c;
  stroke-width: 1.5;
}

.start-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(33, 52, 49, 0.42);
  backdrop-filter: blur(5px);
}

.start-overlay[hidden] {
  display: none;
}

.start-button {
  min-width: min(22rem, 100%);
  min-height: 8.5rem;
  display: grid;
  grid-template-columns: 5.3rem 1fr;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.35rem;
  border: 4px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--line);
  cursor: pointer;
  box-shadow: 0 9px 0 var(--line);
  font-size: 2.2rem;
  font-weight: 900;
}

.start-symbol,
.start-symbol svg {
  width: 5.3rem;
  height: 5.3rem;
  display: block;
}

@keyframes bob {
  0%,
  100% {
    translate: 0 0;
  }
  50% {
    translate: 0 -0.35rem;
  }
}

@keyframes sparkle-pop {
  0% {
    opacity: 0;
    scale: 0.3;
    translate: 0 0;
    rotate: 0deg;
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    scale: 1.2;
    translate: var(--dx) var(--dy);
    rotate: var(--rot);
  }
}

@media (max-width: 760px) {
  .game-shell {
    padding: 0.6rem;
    gap: 0.55rem;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: space-between;
  }

  .brand-mark {
    width: 3.7rem;
    height: 3.7rem;
  }

  h1 {
    font-size: 1.55rem;
  }

  .voice-status {
    font-size: 0.95rem;
  }

  .playfield {
    grid-template-rows: minmax(18rem, 1fr) auto;
    gap: 0.65rem;
  }

  .problem-visual,
  .problem-visual.is-add,
  .problem-visual.is-subtract {
    min-height: 18rem;
    grid-template-columns: 1fr;
    grid-template-rows: auto 4.2rem auto;
    padding: 0;
  }

  .visual-group {
    min-height: 8.5rem;
    padding: 0.5rem;
  }

  .object-board,
  .object-board.small {
    grid-template-columns: repeat(5, 2.9rem);
    min-height: 6.4rem;
    gap: 0.1rem 0.25rem;
  }

  .math-object {
    width: 2.85rem;
    height: 4rem;
  }

  .object-slot {
    width: 2.85rem;
    height: 4rem;
  }

  .object-slot.is-counted::after {
    top: -0.55rem;
    width: 1.55rem;
    height: 1.55rem;
    border-width: 2px;
    font-size: 0.92rem;
    box-shadow: 0 3px 0 var(--line);
  }

  .operator-symbol {
    width: 4.1rem;
    height: 4.1rem;
    font-size: 2.5rem;
    box-shadow: 0 5px 0 var(--line);
  }

  .answer-zone {
    gap: 0.5rem;
  }

  .answer-card {
    min-height: 7.6rem;
    padding: 0.45rem;
    border-width: 3px;
    box-shadow: 0 6px 0 var(--line);
  }

  .answer-number {
    font-size: 3.2rem;
  }

  .dot-grid {
    grid-template-columns: repeat(5, 0.54rem);
    grid-auto-rows: 0.54rem;
    gap: 0.22rem;
    min-height: 1.9rem;
  }

  .answer-dot {
    width: 0.54rem;
    height: 0.54rem;
  }

  .feedback-panel {
    min-height: 4.2rem;
  }

  .feedback-face {
    width: 2.8rem;
    height: 2.8rem;
    font-size: 1.55rem;
  }

  .feedback-text {
    font-size: 1.2rem;
  }

  .sparkle {
    width: 1rem;
    height: 1rem;
  }
}

@media (max-width: 430px) {
  .star-row {
    grid-template-columns: repeat(5, 1.55rem);
    min-width: 8.6rem;
  }

  .star {
    width: 1.55rem;
    height: 1.55rem;
  }

  .icon-button {
    width: 3.15rem;
    height: 3.15rem;
  }

  .answer-zone {
    grid-template-columns: 1fr;
  }

  .answer-card {
    min-height: 5.6rem;
    grid-template-columns: 6rem 1fr;
    grid-template-rows: 1fr;
  }

  .start-button {
    min-height: 7.3rem;
    grid-template-columns: 4.5rem 1fr;
    font-size: 1.8rem;
  }

  .start-symbol,
  .start-symbol svg {
    width: 4.5rem;
    height: 4.5rem;
  }
}

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