:root {
  --sky-top: #dff4ff;
  --sky-bottom: #fff3d8;
  --grass-tint: #eefde9;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-strong: rgba(255, 255, 255, 0.96);
  --ink: #24324a;
  --muted: #57708d;
  --line: rgba(36, 50, 74, 0.14);
  --shadow: 0 14px 30px rgba(70, 90, 110, 0.14);
  --shadow-strong: 0 18px 34px rgba(70, 90, 110, 0.2);
  --accent: #ff7f6b;
  --accent-strong: #f45f54;
  --success: #71c96b;
  --success-soft: rgba(113, 201, 107, 0.24);
  --warning: #ffb347;
  --warning-soft: rgba(255, 179, 71, 0.24);
  --focus-ring: #2f8fff;
  --shell-pad: clamp(0.5rem, 2.6vw, 1rem);
  --panel-gap: clamp(0.45rem, 1.7vh, 0.85rem);
  --button-height: clamp(2.7rem, 8vw, 3.2rem);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  font-family: 'Nunito', 'Segoe UI', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 10%, rgba(255, 231, 148, 0.92), transparent 28%),
    radial-gradient(circle at 84% 14%, rgba(255, 190, 188, 0.78), transparent 22%),
    linear-gradient(180deg, var(--sky-top) 0%, var(--grass-tint) 52%, var(--sky-bottom) 100%);
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body * {
  font-family: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: var(--panel-gap);
  padding: var(--shell-pad);
  overflow: hidden;
}

.toolbar,
.instruction-panel,
.progress-panel,
.shape-card {
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.toolbar {
  display: grid;
  gap: 0.65rem;
  padding: 0.7rem 0.8rem;
  border-radius: 1.35rem;
  background: var(--panel-strong);
}

.brand {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 0.15rem;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 5.5vw, 2rem);
  line-height: 1;
}

.toolbar-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

button,
#goBack {
  min-height: var(--button-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 0.85rem;
  border: 0;
  border-radius: 999px;
  text-decoration: none;
  text-align: center;
  font-weight: 800;
  font-size: 0.92rem;
  line-height: 1.1;
  color: #ffffff;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.08), 0 10px 18px rgba(244, 95, 84, 0.24);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: transform 180ms ease, box-shadow 180ms ease, background-color 180ms ease, opacity 180ms ease;
}

#goBack {
  background: linear-gradient(180deg, #ff6f6f 0%, #e23b3b 100%);
}

button:hover,
button:focus-visible,
#goBack:hover,
#goBack:focus-visible {
  transform: translateY(-1px);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.08), 0 14px 24px rgba(70, 90, 110, 0.2);
}

button:active,
#goBack:active {
  transform: translateY(1px);
}

button:focus-visible,
#goBack:focus-visible,
.shape-card:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}

button:disabled,
.shape-card:disabled {
  opacity: 0.65;
  cursor: default;
}

button[aria-pressed='false'] {
  background: linear-gradient(180deg, #93a9c9 0%, #7990b0 100%);
}

.instruction-panel,
.progress-panel {
  background: var(--panel);
  border-radius: 1.1rem;
  padding: 0.7rem 0.85rem;
}

.instruction-panel {
  display: grid;
  gap: 0.2rem;
}

.instruction-panel p,
.progress-panel p {
  margin: 0;
}

#promptText {
  font-size: clamp(1rem, 4.1vw, 1.3rem);
  font-weight: 800;
}

#helperText,
.progress-copy {
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 700;
}

.progress-panel {
  display: grid;
  gap: 0.55rem;
}

.score-line {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.98rem;
  font-weight: 800;
}

.score-line strong {
  font-size: 1.1rem;
}

.progress-strip {
  min-height: 0.9rem;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 0.28rem;
}

.bloom-token {
  min-height: 1.55rem;
  border-radius: 999px;
  border: 1px solid rgba(87, 112, 141, 0.18);
  background: rgba(255, 255, 255, 0.72);
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.bloom-token::before {
  content: '';
  width: 1rem;
  height: 1rem;
  border-radius: 999px;
  background: rgba(135, 181, 118, 0.18);
  box-shadow:
    0 -0.38rem 0 0 rgba(135, 181, 118, 0.18),
    0 0.38rem 0 0 rgba(135, 181, 118, 0.18),
    0.38rem 0 0 0 rgba(135, 181, 118, 0.18),
    -0.38rem 0 0 0 rgba(135, 181, 118, 0.18);
  transition: transform 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
}

.bloom-token[data-filled='true']::before {
  background: #ffb7d1;
  box-shadow:
    0 -0.38rem 0 0 #ffd66e,
    0 0.38rem 0 0 #8fe0a0,
    0.38rem 0 0 0 #9ed7ff,
    -0.38rem 0 0 0 #c8b5ff;
  transform: scale(1.05);
}

.bloom-center {
  position: absolute;
  width: 0.32rem;
  height: 0.32rem;
  border-radius: 999px;
  background: #fff7c5;
  box-shadow: 0 0 0 1px rgba(36, 50, 74, 0.06);
}

.board {
  min-height: 0;
  display: grid;
  align-items: stretch;
  overflow: hidden;
}

.cards-grid {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: clamp(0.45rem, 1.8vw, 0.85rem);
}

.shape-card {
  min-width: 0;
  min-height: 0;
  padding: clamp(0.55rem, 2vw, 0.9rem);
  border-radius: 1.25rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(248, 251, 255, 0.94) 100%);
  color: var(--ink);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.45rem;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease, background-color 180ms ease;
  touch-action: manipulation;
  user-select: none;
}

.shape-card:hover,
.shape-card:focus-visible {
  transform: translateY(-2px);
  box-shadow: var(--shadow-strong);
}

.shape-card:active {
  transform: scale(0.98);
}

.shape-card[data-selected='true'] {
  border-color: rgba(47, 143, 255, 0.45);
  background: linear-gradient(180deg, #ffffff 0%, #eef7ff 100%);
}

.shape-card[data-state='correct'] {
  border-color: rgba(113, 201, 107, 0.5);
  background: linear-gradient(180deg, #ffffff 0%, #effceb 100%);
  box-shadow: 0 0 0 4px var(--success-soft), var(--shadow);
}

.shape-card[data-state='wrong'] {
  border-color: rgba(255, 179, 71, 0.65);
  background: linear-gradient(180deg, #ffffff 0%, #fff5e7 100%);
  box-shadow: 0 0 0 4px var(--warning-soft), var(--shadow);
  animation: card-shake 420ms ease;
}

.shape-figure {
  width: min(100%, 10rem);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: clamp(0.4rem, 1vw, 0.7rem);
  border-radius: 1rem;
  background: linear-gradient(180deg, #f8fbff 0%, #edf6ff 100%);
}

.shape-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 0.18rem 0.25rem rgba(36, 50, 74, 0.12));
}

.shape-label {
  display: block;
  font-size: clamp(0.92rem, 2.8vw, 1.08rem);
  font-weight: 800;
  color: var(--ink);
}

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

#confettiLayer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

#confettiLayer[data-flash='small']::before,
#confettiLayer[data-flash='big']::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.72) 0%, rgba(255, 255, 255, 0) 58%);
}

#confettiLayer[data-flash='big']::before {
  background: radial-gradient(circle, rgba(255, 239, 166, 0.82) 0%, rgba(255, 239, 166, 0) 62%);
}

.confetti-piece {
  position: absolute;
  top: -8vh;
  width: 0.8rem;
  height: 1rem;
  border-radius: 0.28rem;
  opacity: 0.95;
  animation: confetti-fall var(--duration, 1200ms) ease-in forwards;
  animation-delay: var(--delay, 0ms);
}

@keyframes confetti-fall {
  from {
    transform: translate3d(0, 0, 0) rotate(0deg);
  }

  to {
    transform: translate3d(var(--drift, 0px), 115vh, 0) rotate(var(--spin, 360deg));
  }
}

@keyframes card-shake {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-0.32rem);
  }

  50% {
    transform: translateX(0.32rem);
  }

  75% {
    transform: translateX(-0.22rem);
  }
}

@media (min-width: 700px) {
  .app-shell {
    width: min(100%, 58rem);
    margin: 0 auto;
  }

  .toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .toolbar-actions {
    width: auto;
    min-width: min(22rem, 100%);
  }

  .progress-panel {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
  }
}

@media (max-width: 540px) {
  :root {
    --shell-pad: 0.42rem;
    --panel-gap: 0.42rem;
    --button-height: 2.45rem;
  }

  .toolbar {
    padding: 0.55rem 0.6rem;
    border-radius: 1.05rem;
  }

  .eyebrow {
    display: none;
  }

  h1 {
    font-size: clamp(1.12rem, 5.4vw, 1.45rem);
  }

  .instruction-panel,
  .progress-panel {
    padding: 0.55rem 0.65rem;
    border-radius: 0.95rem;
  }

  #helperText,
  .progress-copy {
    font-size: 0.8rem;
  }

  .shape-card {
    border-radius: 1rem;
    padding: 0.45rem;
  }

  .shape-label {
    font-size: 0.88rem;
  }
}

@media (max-height: 760px) {
  :root {
    --panel-gap: 0.38rem;
  }

  .toolbar {
    padding: 0.5rem 0.6rem;
  }

  .instruction-panel,
  .progress-panel {
    padding-top: 0.52rem;
    padding-bottom: 0.52rem;
  }

  #helperText {
    display: none;
  }

  .progress-strip {
    gap: 0.22rem;
  }
}

@media (max-height: 540px) and (orientation: landscape) {
  .app-shell {
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-columns: minmax(0, 1fr) minmax(15rem, 18rem);
    align-items: stretch;
  }

  .toolbar,
  .instruction-panel {
    grid-column: 1 / -1;
  }

  .progress-panel {
    grid-column: 2;
    grid-row: 3;
    align-self: start;
  }

  .board {
    grid-column: 1;
    grid-row: 3;
  }

  .progress-panel {
    gap: 0.4rem;
  }
}

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