@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800&display=swap");

:root {
  /* Clean Light Theme Base */
  --bg-main: #fcfcfc;
  --bg-gradient: #f8f9fa;
  --card-bg: #ffffff;

  /* SpeedoMaths Red Accents */
  --primary: #d72217;
  --primary-dark: #191919;
  --primary-gradient: linear-gradient(to bottom right, #d72217, #7a0f0a);
  --secondary: #4a5568;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 12px 35px rgba(0, 0, 0, 0.05);

  /* Abacus Specific Colors */
  --frame-inner: #191919; /* Solid black frame */
  --rod-color: #94a3b8; /* Metallic grey rods */
  --bead-color: #d72217; /* Primary red beads */
  --bead-border: #7a0f0a;
  --bead-hover: #ff4d42;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  padding: 0;
  font-family: "Poppins", sans-serif;
  color: var(--secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 100px;
  min-height: 100vh;

  /* Soft vignette background to reduce eye strain */
  background: radial-gradient(circle at top center, #ffffff 0%, #f0f4f9 120%);
  background-attachment: fixed;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: -2;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
  opacity: 0.04;
}

/* Glassmorphism Back Button */
.back-refresh-btn {
  position: fixed;
  top: 80px;
  left: 15px;
  z-index: 1000;
  background: var(--card-bg);
  backdrop-filter: blur(10px);
  color: var(--primary-dark);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 50px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.back-refresh-btn:hover {
  background: var(--primary);
  color: white;
}

/* Clean Flat Score Board */
.score-board {
  background: var(--card-bg);
  border: none; /* Removed glass border */
  padding: 30px 20px;
  border-radius: 20px; /* Squarer, flatter radius */
  box-shadow: var(--shadow);
  text-align: center;
  width: 95%;
  max-width: 500px;
  margin-bottom: 20px;
  z-index: 100;
}

.score-label {
  font-size: 0.85rem;
  color: var(--secondary);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.score-value {
  font-size: 3.5rem;
  font-weight: 800;
  color: var(--primary-dark); /* Dark text for better contrast */
  margin: 0 0 15px 0;
}

.free-modules-container {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-bottom: 20px;
  width: 100%;
}

.module-btn {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 16px;
  padding: 12px 20px;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  color: var(--primary-dark);
  box-shadow: 0 4px 15px rgba(0, 86, 179, 0.05);
  border: 2px solid transparent;
  transition: all 0.3s ease;
  flex: 1;
  justify-content: center;
}

.module-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0, 86, 179, 0.15);
  border-color: var(--primary);
}

.module-icon-box {
  width: 35px;
  height: 35px;
  margin-right: 12px;
  border-radius: 50%;
  background-color: rgba(0, 86, 179, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.module-icon-box i {
  font-size: 16px;
  color: var(--primary);
  transition: color 0.3s ease;
}

.module-btn:hover .module-icon-box {
  background-color: var(--primary);
}
.module-btn:hover .module-icon-box i {
  color: white;
}

.module-btn-label {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary-dark);
  display: block;
}

.free-tag {
  display: block;
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.btn {
  padding: 10px 18px;
  border-radius: 6px; /* Flatter squarer buttons */
  border: 1px solid #cbd5e1; /* Subtle gray border */
  background: transparent;
  color: var(--secondary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: "Poppins", sans-serif;
}

.btn:hover {
  background: #fdf2f2;
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-2px);
}

.btn-clear {
  background: var(--primary-gradient);
  color: white;
  border: none;
  box-shadow: 0 4px 10px rgba(215, 34, 23, 0.2);
}

.btn-clear:hover {
  background: linear-gradient(to top left, #d72217, #7a0f0a);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(215, 34, 23, 0.35);
}

.abacus-scroll-container {
  width: 100%;
  overflow: auto;
  max-height: 70vh;
  display: block;
  text-align: center;
  padding: 20px 0;
  -webkit-overflow-scrolling: touch;
}

.abacus-zoom-layer {
  display: inline-block;
  transition: transform 0.2s ease-out;
  padding: 80px;
  transform-origin: center center;
}

.abacus-frame {
  background-color: #ffffff; /* White board interior */
  border: 12px solid var(--frame-inner); /* Thick black frame */
  padding: 10px 15px; /* Tighter padding */
  border-radius: 8px; /* Sharper corners */
  display: flex;
  gap: 10px; /* Tighter gap between rods */
  position: relative;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
}

.beam {
  position: absolute;
  left: 0;
  right: 0;
  top: 62px; /* Positioned between upper and lower beads */
  height: 12px;
  background: var(--frame-inner); /* Solid black center beam */
  z-index: 5;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

.rod {
  width: 46px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.rod::before {
  content: "";
  position: absolute;
  top: -10px;
  bottom: -10px; /* Rods extend into frame */
  width: 4px; /* Thinner rods */
  background: var(--rod-color);
  border-radius: 2px;
  box-shadow: inset -2px 0 3px rgba(0, 0, 0, 0.2);
}

.bead {
  width: 44px;
  height: 22px; /* Flatter, pill-shaped beads */
  border-radius: 11px; /* Half of height */
  background: var(--bead-color);
  border: 1px solid var(--bead-border);
  z-index: 10;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow:
    inset -2px -2px 4px rgba(0, 0, 0, 0.2),
    0 3px 4px rgba(0, 0, 0, 0.2);
}

/* Adjust travel distances and spacing for the flatter beads */
.bead.heaven {
  margin-bottom: 80px; /* Space for the beam */
}

.bead.heaven.active {
  transform: translateY(26px); /* Move down to beam */
}

.bead.earth {
  margin-top: 6px;
}

.rod .bead.earth:first-of-type {
  margin-top: 30px; /* Space below the beam */
}

.bead.earth.active {
  transform: translateY(-26px); /* Move up to beam */
}

.rod-mark {
  position: absolute;
  top: 52px;
  width: 12px;
  height: 12px;
  background: #efc744;
  border-radius: 50%;
  z-index: 20;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Glassmorphism About Section */
.about-container {
  width: 90%;
  max-width: 800px;
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.4);
  padding: 40px;
  margin: 40px auto;
  border-radius: 28px;
  text-align: center;
  box-shadow: var(--shadow);
}

.about-container h2 {
  color: var(--primary-dark);
  margin-bottom: 20px;
}

.about-container p {
  color: var(--text-light);
  line-height: 1.6;
}

@media (max-width: 600px) {
  .abacus-zoom-layer {
    padding: 20px 10px;
  }

  .score-board {
    padding: 15px;
    border-radius: 24px;
    margin-top: 5px;
    width: 92%;
  }

  .score-value {
    font-size: 2.5rem;
    margin-bottom: 10px;
  }

  .free-modules-container {
    flex-direction: row;
    gap: 8px;
    margin-bottom: 15px;
  }

  .module-btn {
    padding: 8px 5px;
    border-radius: 12px;
  }

  .module-icon-box {
    width: 28px;
    height: 28px;
    margin-right: 6px;
  }

  .module-icon-box i {
    font-size: 13px;
  }

  .free-tag {
    font-size: 0.65rem;
  }

  .module-btn-label {
    font-size: 0.8rem;
  }

  .controls {
    gap: 6px;
  }

  .btn {
    padding: 8px 4px;
    font-size: 0.75rem;
    flex: 1 1 calc(33% - 6px);
  }

  .about-container {
    padding: 25px 15px;
    border-radius: 24px;
    width: 92%;
  }
}

/* --- PREMIUM BACKGROUND ANIMATION --- */
.bg-animation {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: -1; /* Keeps it behind the abacus */
  overflow: hidden;
  pointer-events: none;
}

.math-shape {
  position: absolute;
  color: var(--primary);
  opacity: 0.2;
  bottom: -100px;
  animation: floatUp linear infinite;
  filter: blur(4px); /* Adds depth of field */
}

@keyframes floatUp {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 0.2;
  }
  90% {
    opacity: 0.2;
  }
  100% {
    transform: translateY(-120vh) rotate(360deg);
    opacity: 0;
  }
}

/* Randomized floating speeds and positions */
.math-shape:nth-child(1) {
  left: 10%;
  font-size: 3rem;
  animation-duration: 25s;
  animation-delay: 0s;
}
.math-shape:nth-child(2) {
  left: 25%;
  font-size: 2rem;
  animation-duration: 20s;
  animation-delay: 5s;
}
.math-shape:nth-child(3) {
  left: 40%;
  font-size: 4rem;
  animation-duration: 35s;
  animation-delay: 2s;
}
.math-shape:nth-child(4) {
  left: 60%;
  font-size: 2.5rem;
  animation-duration: 22s;
  animation-delay: 8s;
}
.math-shape:nth-child(5) {
  left: 75%;
  font-size: 3.5rem;
  animation-duration: 30s;
  animation-delay: 4s;
}
.math-shape:nth-child(6) {
  left: 90%;
  font-size: 2rem;
  animation-duration: 18s;
  animation-delay: 1s;
}
