/* ===== Reset & Base ===== */

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

body {
  font-family: -apple-system, 'SF Pro Rounded', system-ui, sans-serif;
  background: linear-gradient(135deg, #e8f4fd 0%, #f5e6ff 50%, #fff5e6 100%);
  display: flex;
  justify-content: center;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 600px;
  height: 100dvh;
  height: 100vh; /* fallback */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ===== Mode Bar ===== */

#mode-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  flex-shrink: 0;
}

.mode-btn {
  width: 4rem;
  height: 4rem;
  border-radius: 1.2rem;
  border: 3px solid transparent;
  background: rgba(255, 255, 255, 0.7);
  font-size: 1.8rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.mode-btn.active {
  border-color: var(--mode-color, #7c4dff);
  background: white;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.12);
  transform: scale(1.1);
}

.mode-btn:active {
  transform: scale(0.95);
}

.sound-toggle {
  margin-left: auto;
  width: 3rem;
  height: 3rem;
  font-size: 1.4rem;
}

/* Mode colors */
body[data-mode="counting"]    { --mode-color: #7c4dff; }
body[data-mode="addition"]    { --mode-color: #00c853; }
body[data-mode="subtraction"] { --mode-color: #ff6d00; }

/* ===== Problem Area ===== */

#problem-area {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem 1.5rem 2rem;
  min-height: 0;
}

.objects-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  gap: 0.8rem;
  max-width: 95%;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 2rem;
  padding: 1.5rem;
}

.obj {
  font-size: clamp(4.5rem, 16vw, 7rem);
  line-height: 1;
  animation: popIn 0.3s ease-out backwards;
}

/* Addition layout */

.addition-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  flex-wrap: nowrap;
  width: 100%;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 2rem;
  padding: 1.5rem 1rem;
}

.objects-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  gap: 0.5rem;
  max-width: 40%;
  min-width: 4rem;
}

.operator {
  font-size: clamp(3rem, 10vw, 5rem);
  font-weight: bold;
  color: var(--mode-color, #666);
  flex-shrink: 0;
}

/* Addition layout objects are a bit smaller to fit side by side */
.addition-layout .obj {
  font-size: clamp(3.5rem, 11vw, 5rem);
}

.subtraction-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* Crossed-out objects in subtraction */
.obj.crossed {
  position: relative;
  opacity: 0.5;
}

.obj.crossed::after {
  content: '✕';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.6em;
  color: #e53935;
  font-weight: 900;
  text-shadow: 0 0 4px white, 0 0 4px white;
}

.removed-group {
  opacity: 0.7;
}

/* Number equation layout */
.number-equation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 2rem;
  padding: 1.5rem 2rem;
}

.digit {
  font-size: clamp(4rem, 14vw, 6rem);
  font-weight: 800;
  color: #4a3580;
  line-height: 1;
  animation: popIn 0.3s ease-out backwards;
}

.digit.question-mark {
  color: #ff6d00;
}

/* ===== Object Animations ===== */

@keyframes popIn {
  0%  { transform: scale(0); opacity: 0; }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

.obj.removing {
  animation: floatAway 0.5s ease-in forwards !important;
}

@keyframes floatAway {
  0%   { transform: scale(1); opacity: 1; }
  40%  { transform: scale(1.2) translateY(-10px); opacity: 0.8; }
  100% { transform: scale(0) translateY(-50px) rotate(20deg); opacity: 0; }
}

.obj.bounce {
  animation: bounce 0.4s ease;
}

@keyframes bounce {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.3); }
}

/* ===== Answer Area ===== */

#answer-area {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
  padding: 1.5rem 1rem;
  flex-shrink: 0;
  min-height: 7rem;
}

.answer-btn {
  width: clamp(5rem, 18vw, 7rem);
  height: clamp(5rem, 18vw, 7rem);
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.8);
  background: linear-gradient(135deg, #a8e6cf, #88d8a8);
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 800;
  color: #2d5a3d;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  animation: slideUp 0.3s ease-out backwards;
  transition: transform 0.15s, background-color 0.2s, border-color 0.2s;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.12), inset 0 -3px 0 rgba(0,0,0,0.08);
}

.answer-btn:nth-child(2) {
  background: linear-gradient(135deg, #ffd3b6, #ffb088);
  color: #5a3a2d;
}

.answer-btn:nth-child(3) {
  background: linear-gradient(135deg, #c3b1e1, #a78bfa);
  color: #3d2d5a;
}

.answer-btn:active:not(.disabled) {
  transform: scale(0.92);
}

.answer-btn.correct {
  background: linear-gradient(135deg, #4caf50, #66bb6a) !important;
  color: white;
  border-color: #388e3c;
  animation: correctPop 0.5s ease;
}

.answer-btn.wrong {
  animation: shake 0.5s ease;
}

.answer-btn.disabled {
  opacity: 0.3;
  pointer-events: none;
}

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

@keyframes correctPop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX(8px); }
  60%      { transform: translateX(-6px); }
  80%      { transform: translateX(6px); }
}

/* ===== Progress Bar ===== */

#progress-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.5rem;
  flex-shrink: 0;
}

.star {
  font-size: 2rem;
  line-height: 1;
  transition: transform 0.3s;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.15));
}

.star.empty {
  opacity: 0.25;
  filter: grayscale(0.5);
}

.star.earned {
  animation: starEarn 0.4s ease;
}

@keyframes starEarn {
  0%   { transform: scale(0) rotate(-180deg); }
  60%  { transform: scale(1.3) rotate(10deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.progress-counter {
  font-size: 1.2rem;
  font-weight: 700;
  color: #888;
  margin-left: 0.5rem;
}

/* ===== Celebration Overlay ===== */

#celebration-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  overflow: hidden;
}

#celebration-overlay.hidden {
  display: none;
}

.confetti {
  position: absolute;
  top: -10px;
  border-radius: 3px;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg) translateX(0);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg) translateX(var(--drift, 30px));
    opacity: 0;
  }
}

.big-star {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  font-size: 6rem;
  animation: bigStarPop 2s ease forwards;
}

@keyframes bigStarPop {
  0%   { transform: translate(-50%, -50%) scale(0) rotate(-180deg); }
  30%  { transform: translate(-50%, -50%) scale(1.5) rotate(10deg); }
  50%  { transform: translate(-50%, -50%) scale(1.2) rotate(-5deg); }
  70%  { transform: translate(-50%, -50%) scale(1.3) rotate(3deg); }
  100% { transform: translate(-50%, -50%) scale(0) rotate(180deg); opacity: 0; }
}

/* ===== Landscape (short screens) ===== */

@media (orientation: landscape) and (max-height: 500px) {
  #mode-bar     { padding: 0.3rem; gap: 0.5rem; }
  .mode-btn     { width: 2.8rem; height: 2.8rem; font-size: 1.3rem; border-radius: 0.75rem; }
  .sound-toggle { width: 2.5rem; height: 2.5rem; font-size: 1.1rem; }
  #problem-area { padding: 0.4rem; }
  .obj          { font-size: 2.5rem; }
  .operator     { font-size: 2rem; }
  #answer-area  { padding: 0.5rem; gap: 1rem; min-height: 4.5rem; }
  .answer-btn   { width: 4rem; height: 4rem; font-size: 1.5rem; }
  #progress-bar { padding: 0.2rem; }
  .star         { font-size: 1.4rem; }
  .star.empty   { font-size: 1.3rem; }
}
