:root {
  --sky-1: #dff7ff;
  --sky-2: #fff7dd;
  --ink: #0d2a47;
  --panel: rgba(255, 255, 255, 0.84);
  --accent: #ff8e3c;
  --good: #26a84e;
  --bad: #d63d3d;
}

* {
  box-sizing: border-box;
}

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

body {
  position: relative;
  overflow: hidden;
  color: var(--ink);
  background: radial-gradient(circle at 20% 15%, #fefbe6 0%, transparent 45%),
    radial-gradient(circle at 85% 10%, #dff9ff 0%, transparent 45%),
    linear-gradient(135deg, var(--sky-1) 0%, var(--sky-2) 100%);
  font-family: "Fredoka", "Segoe UI", sans-serif;
}

.bg-orb {
  position: absolute;
  border-radius: 999px;
  filter: blur(1px);
  opacity: 0.45;
  z-index: 0;
}

.bg-orb-a {
  width: 34vmax;
  height: 34vmax;
  left: -10vmax;
  bottom: -14vmax;
  background: #9ce7ff;
}

.bg-orb-b {
  width: 28vmax;
  height: 28vmax;
  right: -8vmax;
  bottom: -11vmax;
  background: #ffd8a8;
}

.bg-orb-c {
  width: 22vmax;
  height: 22vmax;
  top: -8vmax;
  left: 50%;
  transform: translateX(-50%);
  background: #b4ffd0;
}

#app {
  position: relative;
  z-index: 1;
  width: 100vw;
  height: 100vh;
}

.screen {
  width: 100%;
  height: 100%;
  padding: 2.2rem clamp(1rem, 3vw, 2.6rem);
}

.hidden {
  display: none !important;
}

.setup-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.title {
  margin: 0;
  font-family: "Baloo 2", cursive;
  font-size: clamp(2.2rem, 7vw, 4.8rem);
  line-height: 0.95;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 0.4rem 0 0;
  font-size: clamp(1rem, 2.5vw, 1.4rem);
}

.subtitle-small {
  opacity: 0.82;
  font-size: clamp(0.95rem, 2vw, 1.15rem);
}

.grade-grid {
  width: min(900px, 100%);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.7rem;
  margin-top: 1.6rem;
}

.grade-btn {
  border: 2px solid transparent;
  border-radius: 18px;
  background: var(--panel);
  backdrop-filter: blur(6px);
  color: var(--ink);
  padding: 0.85rem 0.4rem;
  font-family: "Baloo 2", cursive;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.grade-btn:hover {
  transform: translateY(-1px);
}

.grade-btn.selected {
  border-color: #2396ff;
  box-shadow: 0 8px 22px rgba(35, 150, 255, 0.24);
}

.start-btn {
  margin-top: 1.4rem;
  padding: 0.95rem 2.1rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #ff9f53 0%, #ffcf5c 100%);
  color: #13253b;
  font-family: "Baloo 2", cursive;
  font-size: 1.15rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease;
}

.start-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.start-btn:not(:disabled):hover {
  transform: translateY(-1px);
}

.hint {
  margin-top: 1rem;
  font-size: 0.96rem;
  opacity: 0.82;
}

.game-screen {
  display: grid;
  grid-template-rows: auto auto auto 1fr auto auto;
  align-content: start;
  gap: 0.8rem;
}

.topbar {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.top-pill {
  background: rgba(255, 255, 255, 0.82);
  border-radius: 999px;
  padding: 0.45rem 0.95rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.timer-wrap {
  width: min(860px, 100%);
  height: 14px;
  margin: 0 auto;
  border-radius: 999px;
  background: rgba(20, 55, 82, 0.12);
  overflow: hidden;
}

.timer-bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #30b95e 0%, #f7c64f 65%, #f05656 100%);
  transform-origin: left center;
  transition: transform 800ms linear;
}

.timer-text {
  text-align: center;
  font-family: "Baloo 2", cursive;
  font-size: 1.35rem;
  font-weight: 700;
}

.flash-card {
  width: min(1050px, 100%);
  min-height: min(56vh, 560px);
  margin: 0 auto;
  position: relative;
  perspective: 1200px;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: inherit;
  transform-style: preserve-3d;
  transition: transform 540ms ease;
}

.flash-card.is-flipped .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 28px;
  border: 3px solid rgba(16, 69, 112, 0.18);
  background: var(--panel);
  backdrop-filter: blur(8px);
  backface-visibility: hidden;
  display: grid;
  place-items: center;
  text-align: center;
  padding: clamp(1rem, 4vw, 2.4rem);
  transition: background-color 220ms ease, border-color 220ms ease, transform 180ms ease;
}

.card-back {
  transform: rotateY(180deg);
}

.flash-card.state-correct .card-face {
  background: #dbffe4;
  border-color: #3bba62;
}

.flash-card.state-wrong .card-face {
  background: #ffd8d8;
  border-color: #df5151;
}

.card-kicker {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.8;
}

.problem-text {
  margin: 0.3rem 0 0;
  font-family: "Baloo 2", cursive;
  font-weight: 800;
  font-size: clamp(3.1rem, 16vw, 9rem);
  line-height: 0.95;
}

.answer-text {
  margin: 0.8rem 0 0;
  font-size: clamp(1rem, 2.6vw, 1.5rem);
  font-weight: 600;
}

.feedback-area {
  width: min(960px, 100%);
  margin: 0 auto;
  text-align: center;
}

.heard-line {
  margin: 0;
  font-size: clamp(0.95rem, 2.1vw, 1.16rem);
}

.status-text {
  margin: 0.3rem 0 0;
  font-size: clamp(1rem, 2.4vw, 1.28rem);
  font-weight: 600;
}

.controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.ghost-btn {
  border: 2px solid rgba(13, 42, 71, 0.26);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink);
  padding: 0.64rem 1.1rem;
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 0.98rem;
  cursor: pointer;
}

.ghost-btn:hover {
  background: rgba(255, 255, 255, 0.72);
}

@media (max-width: 760px) {
  .screen {
    padding: 1rem 0.8rem;
  }

  .flash-card {
    min-height: 48vh;
  }

  .card-face {
    border-radius: 20px;
  }

  .grade-grid {
    grid-template-columns: repeat(4, minmax(58px, 1fr));
  }
}
