:root {
  --ink: #1f2a44;
  --bg-1: #d8f6ff;
  --bg-2: #eaf6ff;
  --card: rgba(255, 255, 255, 0.8);
  --line: rgba(31, 42, 68, 0.08);
  --good: #16a34a;
  --bad: #dc2626;
  --shadow: 0 14px 34px rgba(31, 42, 68, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Baloo 2', cursive;
  color: var(--ink);
  background: linear-gradient(150deg, var(--bg-1), var(--bg-2));
  overflow-x: hidden;
}

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(1px);
  z-index: -1;
  animation: float 12s ease-in-out infinite;
}

.orb-a {
  width: 260px;
  height: 260px;
  background: rgba(255, 123, 123, 0.25);
  left: -60px;
  top: 70px;
}

.orb-b {
  width: 340px;
  height: 340px;
  background: rgba(38, 198, 218, 0.2);
  right: -90px;
  top: 140px;
  animation-delay: -4s;
}

.orb-c {
  width: 280px;
  height: 280px;
  background: rgba(255, 201, 71, 0.2);
  left: 38%;
  bottom: -90px;
  animation-delay: -7s;
}

.hero {
  text-align: center;
  padding: 1.1rem 1rem 0.7rem;
}

.kicker {
  margin: 0;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #0f766e;
}

.hero h1 {
  margin: 0.15rem 0;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1;
}

.subtitle {
  margin: 0.4rem auto 0;
  max-width: 760px;
  font-size: 1.12rem;
}

.student-greeting {
  margin: 0.45rem 0 0;
  font-size: 1.15rem;
  font-weight: 800;
  color: #0f766e;
}

.layout {
  width: min(1580px, 96%);
  margin: 0.6rem auto 1.2rem;
  display: grid;
  gap: 1.2rem;
  grid-template-columns: minmax(280px, 320px) minmax(760px, 1.8fr) minmax(260px, 320px);
  align-items: start;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 1.2rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  animation: slideIn 0.45s ease both;
}

.sidebar {
  padding: 0.9rem;
}

.sidebar h2 {
  margin-bottom: 0.55rem;
}

.sidebar h3 {
  margin: 0.8rem 0 0.45rem;
}

.game {
  min-height: auto;
}

.progress {
  min-height: auto;
}

.featured {
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid rgba(255, 255, 255, 0.85);
}

h2 {
  margin: 0 0 0.85rem;
  font-size: clamp(1.3rem, 3vw, 2rem);
}

#question {
  text-align: center;
  font-size: clamp(1.45rem, 3vw, 2.45rem);
  line-height: 1.06;
  margin-bottom: 0.65rem;
}

h3 {
  margin: 1rem 0 0.65rem;
  font-size: 1.15rem;
}

.exercise-list,
.difficulty-list {
  display: grid;
  gap: 0.4rem;
}

.difficulty-list {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

#difficultyGroup .menu-btn {
  text-align: center;
  padding: 0.42rem 0.32rem;
}

#difficultyGroup .level-btn.active[data-level='easy'] {
  background: linear-gradient(180deg, #d7f1ff, #a5dbff);
  border-color: #7ec8f8;
  color: #0b3c5f;
}

#difficultyGroup .level-btn.active[data-level='medium'] {
  background: linear-gradient(180deg, #ffe8a3, #ffb347);
  border-color: #f59e0b;
  color: #5f370e;
}

#difficultyGroup .level-btn.active[data-level='hard'] {
  background: linear-gradient(180deg, #ffb0bf, #d90429);
  border-color: #a30222;
  color: #ffffff;
}

#difficultyGroup .level-btn.active {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9) inset, 0 8px 16px rgba(31, 42, 68, 0.16);
}

.menu-btn {
  width: 100%;
  border: 2px solid #bfd5ff;
  border-radius: 14px;
  padding: 0.5rem 0.62rem;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  transition: 0.2s transform, 0.2s border-color, 0.2s box-shadow;
}

.menu-btn:hover {
  transform: translateY(-1px);
  border-color: #6ec1ff;
  box-shadow: 0 8px 16px rgba(110, 193, 255, 0.22);
}

.menu-btn.active {
  border-color: #22c3d8;
  background: linear-gradient(90deg, rgba(34, 195, 216, 0.2), rgba(255, 255, 255, 0.95));
}

.difficulty-list.disabled {
  opacity: 0.45;
  pointer-events: none;
}

#difficultyHint.hint{
  font-size: 14px;
  text-align: center;
}

.hint {
  margin: 0.4rem 0 0;
  font-weight: 700;
  color: #475569;
}

input {
  border: 2px solid #bdd5ff;
  border-radius: 14px;
  padding: 0.65rem 0.7rem;
  font-size: 1.02rem;
  font-family: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  transition: 0.2s border-color, 0.2s transform;
}

input:focus {
  outline: none;
  border-color: #22c3d8;
  transform: translateY(-1px);
}

.btn {
  margin-top: 0.9rem;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(45deg, #ff8ea5, #ffc65a);
  color: #331f1f;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 800;
  padding: 0.7rem 1rem;
  cursor: pointer;
  transition: transform 0.17s ease, box-shadow 0.17s ease;
}

#newChallenge {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.btn:hover {
  transform: translateY(-2px) scale(1.01);
  box-shadow: 0 10px 18px rgba(255, 122, 122, 0.35);
}

.btn.secondary {
  margin-top: 0;
  background: linear-gradient(45deg, #58d8ea, #9ef3c8);
}

.answer-row {
  display: flex;
  gap: 0.7rem;
  margin: 0.7rem 0;
}

.answer-row input {
  flex: 1;
  font-size: clamp(1.25rem, 2.6vw, 1.9rem);
  padding: 0.9rem 1rem;
  min-height: 62px;
}

.batch-questions {
  display: grid;
  gap: 0.65rem;
  margin: 0.55rem 0;
}

.batch-row {
  display: grid;
  grid-template-columns: 1fr 200px;
  gap: 0.6rem;
  align-items: center;
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid rgba(31, 42, 68, 0.1);
  border-radius: 14px;
  padding: 0.45rem 0.65rem;
}

.batch-row p {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.batch-index {
  width: 1.95rem;
  height: 1.95rem;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  font-size: 0.95rem;
  color: #ffffff;
  background: linear-gradient(180deg, #0ea5e9, #3063d3);
  flex-shrink: 0;
}

.batch-prompt {
  display: inline-block;
  line-height: 1.1;
}

.batch-row input {
  min-height: 52px;
  font-size: 1.05rem;
}

.batch-actions {
  display: flex;
  justify-content: center;
}

.batch-actions .btn {
  margin-top: 0.2rem;
  min-width: 220px;
}

.abaco-game {
  margin: 0.8rem 0;
  border-radius: 16px;
  border: 2px dashed #99c4ff;
  background: rgba(239, 247, 255, 0.85);
  padding: 0.75rem;
}

.abaco-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 1rem;
}

.abaco-modal-overlay.hidden {
  display: none;
}

.abaco-modal-card {
  position: relative;
  width: min(1380px, 92vw);
  height: 88vh;
  background: rgba(255, 255, 255, 0.97);
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 1rem;
  overflow: hidden;
}

.abaco-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  font-weight: 800;
  font-size: 1rem;
  background: #ef4444;
  color: #fff;
  cursor: pointer;
}

.abaco-modal-card .abaco-game {
  margin: 0;
  border: none;
  background: transparent;
  padding: 0.35rem 0.2rem;
  height: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  gap: 0.45rem;
}

.abaco-modal-card .abaco-field {
  height: 100%;
  min-height: 340px;
}

.abaco-modal-card .abaco-instruction {
  margin: 0;
  font-size: 1.05rem;
}

.abaco-hud.floating {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 2;
  margin: 0;
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  align-items: center;
}

.abaco-score-pill {
  margin-left: auto !important;
  background: linear-gradient(180deg, #dcfce7, #86efac) !important;
  border-color: #22c55e !important;
}

.abaco-countdown {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.45rem;
  background: rgba(15, 23, 42, 0.45);
  color: #ffffff;
  text-align: center;
}

.abaco-countdown-target {
  margin: 0;
  font-size: clamp(1.1rem, 2.2vw, 1.8rem);
  font-weight: 800;
}

.abaco-countdown-number {
  margin: 0;
  line-height: 1;
  font-size: clamp(3.4rem, 12vw, 7rem);
  font-weight: 800;
}

.abaco-countdown-message {
  margin: 0;
  font-size: clamp(1.1rem, 2.4vw, 2rem);
  font-weight: 800;
  opacity: 0;
}

.abaco-result {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  gap: 0.45rem;
  background: rgba(15, 23, 42, 0.48);
  color: #ffffff;
  padding: 1rem;
}

.abaco-result h3 {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 2.25rem);
}

.abaco-result p {
  margin: 0;
  font-size: clamp(1rem, 2vw, 1.3rem);
  font-weight: 700;
}

.abaco-instruction {
  margin: 0 0 0.45rem;
  font-weight: 700;
}

.abaco-hud {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.55rem;
}

.abaco-hud p {
  margin: 0;
  background: #fff;
  border: 1px solid rgba(31, 42, 68, 0.12);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-weight: 700;
}

.abaco-field {
  position: relative;
  height: 280px;
  border-radius: 14px;
  border: 2px solid rgba(49, 130, 206, 0.26);
  background: linear-gradient(180deg, #e0f2fe, #bae6fd 58%, #bbf7d0 58%, #86efac);
  overflow: hidden;
}

.abaco-controls {
  margin-top: 0.55rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.abaco-move-btn {
  text-align: center;
  font-size: 0.95rem;
  padding: 0.55rem 0.4rem;
}

#abacoStart {
  display: block;
  margin: 0.8rem auto 0;
  min-width: 210px;
}

.capybara {
  position: absolute;
  bottom: 12px;
  left: 10px;
  width: 130px;
  height: 88px;
  object-fit: contain;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.25));
  user-select: none;
  pointer-events: none;
}

.falling-item {
  position: absolute;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.4rem;
  border: 2px solid rgba(31, 42, 68, 0.16);
  color: #1f2a44;
  box-shadow: 0 7px 14px rgba(15, 23, 42, 0.2);
  animation: tokenSpin 0.9s linear infinite;
}

.falling-item.unit {
  background: radial-gradient(circle at 30% 30%, #e0f2fe, #7dd3fc);
}

.falling-item.ten {
  background: radial-gradient(circle at 30% 30%, #fef3c7, #fbbf24);
}

.falling-item.hundred {
  background: radial-gradient(circle at 30% 30%, #fecdd3, #fb7185);
}

.feedback {
  font-weight: 800;
  min-height: 1.4rem;
  border-radius: 12px;
  padding: 0.35rem 0.5rem;
  background: rgba(255, 255, 255, 0.65);
  font-size: 16px;
}

.feedback.good {
  color: var(--good);
  animation: pop 0.26s ease;
}

.feedback.bad {
  color: var(--bad);
  animation: shake 0.26s ease;
}

.place-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.7rem;
  margin: 0.8rem 0;
}

.place-board div {
  background: #f1f7ff;
  border: 2px dashed #90c2ff;
  border-radius: 14px;
  text-align: center;
  padding: 0.65rem;
}

.place-board strong {
  display: block;
  font-size: 1.8rem;
}

.stats {
  display: grid;
  gap: 0.65rem;
}

.avatar-panel {
  display: grid;
  justify-items: center;
  gap: 0.38rem;
  margin-top: 0.85rem;
}

.avatar-figure {
  width: 108px;
  height: 108px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 3px solid rgba(31, 42, 68, 0.12);
  box-shadow: 0 8px 20px rgba(31, 42, 68, 0.15);
  transition: transform 0.2s ease, background 0.2s ease;
}

.avatar-icon {
  font-size: 2.35rem;
  line-height: 1;
}

.avatar-figure.level-up {
  animation: levelUpPop 0.35s ease;
}

.avatar-figure.level-1 {
  background: linear-gradient(150deg, #fde68a, #fdba74);
}

.avatar-figure.level-2 {
  background: linear-gradient(150deg, #93c5fd, #67e8f9);
}

.avatar-figure.level-3 {
  background: linear-gradient(150deg, #86efac, #4ade80);
}

.avatar-figure.level-4 {
  background: linear-gradient(150deg, #f9a8d4, #c4b5fd);
  transform: scale(1.06);
}

.avatar-figure.level-5 {
  background: linear-gradient(150deg, #fcd34d, #fb7185);
  transform: scale(1.08);
}

.avatar-label {
  margin: 0;
  font-weight: 800;
  font-size: 1.06rem;
}

.level-progress {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 700;
  color: #334155;
}

.stat-pill {
  margin: 0;
  font-size: 1.05rem;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(31, 42, 68, 0.08);
  border-radius: 14px;
  padding: 0.45rem 0.6rem;
}

.streak-meter {
  margin-top: 0.8rem;
  height: 14px;
  border-radius: 999px;
  background: rgba(31, 42, 68, 0.12);
  overflow: hidden;
}

.streak-meter span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #ffd166, #22c55e);
  transition: width 0.3s ease;
}

.hidden {
  display: none;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 1rem;
}

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

.modal-card {
  width: min(520px, 96%);
  background: rgba(255, 255, 255, 0.96);
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 1.2rem;
  text-align: center;
  animation: slideIn 0.25s ease both;
}

.modal-card p {
  margin: 0 0 0.8rem;
  font-size: 1.25rem;
  font-weight: 700;
}

.modal-card input {
  width: 100%;
  margin-bottom: 0.8rem;
  font-size: 1.15rem;
  min-height: 56px;
}

.modal-card .btn {
  width: 100%;
  margin-top: 0;
  font-size: 1.1rem;
}

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

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 16px;
  border-radius: 3px;
  opacity: 0.95;
  animation: confettiFall 1s ease-out forwards;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-18px);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pop {
  0% {
    transform: scale(0.97);
  }
  100% {
    transform: scale(1);
  }
}

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

@keyframes confettiFall {
  0% {
    transform: translateY(-8px) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(520deg);
    opacity: 0;
  }
}

@keyframes levelUpPop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.14);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes tokenSpin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1320px) {
  .layout {
    width: min(1240px, 96%);
    grid-template-columns: 280px 1fr;
  }

  .progress {
    grid-column: 1 / -1;
    min-height: auto;
  }

  .game {
    min-height: auto;
  }
}

@media (max-width: 1000px) {
  .layout {
    grid-template-columns: 1fr 1fr;
  }

  .sidebar {
    grid-column: 1 / -1;
  }

  .game,
  .progress {
    min-height: auto;
  }
}

@media (max-width: 720px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 0.9rem;
  }

  .avatar-figure {
    width: 96px;
    height: 96px;
  }

  .avatar-icon {
    font-size: 2.2rem;
  }

  .avatar-label {
    font-size: 0.9rem;
  }

  .answer-row {
    flex-direction: column;
  }

  .batch-row {
    grid-template-columns: 1fr;
  }

  .batch-row p {
    font-size: 1.4rem;
  }

  .abaco-field {
    height: 240px;
  }

  .abaco-modal-card {
    width: 96vw;
    height: 90vh;
    padding: 0.7rem;
  }

  .abaco-modal-card .abaco-field {
    min-height: 42vh;
  }

  .abaco-hud.floating {
    gap: 0.35rem;
  }

  .abaco-hud {
    flex-direction: column;
    align-items: flex-start;
  }

  .abaco-controls {
    grid-template-columns: 1fr;
  }

  .capybara {
    width: 98px;
    height: 68px;
  }

  .falling-item {
    width: 48px;
    height: 48px;
    font-size: 1.1rem;
  }
}
