:root {
  --wood-dark: #5b3a29;
  --bead-color: #6b4226;
  --bead-active: #3d2314;
  --bar-color: #2a1c12;
}

/* ---- Abacus frame ---- */
.abacus-wrapper {
  position: relative;
  overflow-x: auto;
  max-width: 100%;
  padding-top: 6px;
}

.abacus {
  position: relative;
  background: transparent;
  border: 3px solid var(--wood-dark);
  border-radius: 6px;
  padding: 0 35px;
  display: inline-flex;
  gap: 6px;
  overflow: hidden;
}

.rod {
  position: relative;
  width: var(--rod-width, 44px);
  height: 190px;
  display: flex;
  justify-content: center;
}

.rod::before {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  width: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, #3a2517, #6b4429 50%, #3a2517);
}

.reckoning-bar {
  position: absolute;
  left: -8px;
  right: -8px;
  top: 70px;
  height: 10px;
  background: linear-gradient(180deg, var(--bar-color), #100a06);
  box-shadow: 0 2px 3px rgba(0,0,0,0.4);
  z-index: 3;
}

/* Small clickable dots along the beam marking every rod's position, so a
   learner can start counting/reading from any column. Every 3rd rod (a
   traditional "unit point") gets a slightly larger, gold dot. */
.bar-dot {
  position: absolute;
  left: 50%;
  top: 71px;
  width: 8px;
  height: 8px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: #d8cdbb;
  border: 1px solid #3a2517;
  z-index: 4;
  cursor: pointer;
}

.bar-dot:hover { background: #fff2c9; }

.bar-dot.unit-point {
  width: 11px;
  height: 11px;
  top: 69.5px;
  background: #ffd93d;
  border-color: #7a5a12;
}

.bar-dot.unit-point:hover { background: #ffe98a; }

.rod.rod-highlighted::before {
  background: linear-gradient(90deg, #d68c2f, #ffb84d 50%, #d68c2f);
  box-shadow: 0 0 6px rgba(255, 184, 77, 0.8);
}

.bead {
  position: absolute;
  left: 50%;
  width: 34px;
  height: 24px;
  transform: translate(-50%, 0);
  cursor: pointer;
  z-index: 2;
  transition: top 0.15s ease-out;
}

.bead .diamond {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 35% 30%, #a97c53, var(--bead-color) 60%, #3a2313 100%);
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  box-shadow: 0 2px 3px rgba(0,0,0,0.5);
  transition: filter 0.15s ease-out;
}

.bead:hover .diamond { filter: brightness(1.12); }

.bead.active .diamond {
  background: radial-gradient(circle at 35% 30%, #c99a68, var(--bead-active) 65%, #1c0f07 100%);
}

/* Heaven bead sits above the bar with real travel room, drops flush onto it when active.
   Note: .bead positions are relative to .rod, while .reckoning-bar/.bar-dot are
   relative to .abacus's padding box (6px higher) - that offset is accounted for
   below so active beads land exactly on the bar, not into it. */
.bead.heaven { top: 16px; }
.bead.heaven.active { top: 46px; }

/* Earth beads sit below the bar with a clear stack; active ones rise flush to meet it */
.bead.earth-0 { top: 160px; }
.bead.earth-1 { top: 140px; }
.bead.earth-2 { top: 120px; }
.bead.earth-3 { top: 100px; }

.bead.earth-0.active { top: 140px; }
.bead.earth-1.active { top: 120px; }
.bead.earth-2.active { top: 100px; }
.bead.earth-3.active { top: 80px; }

/* ---- Tutorial modal ---- */
.tutorial-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

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

.tutorial-box {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  position: relative;
  text-align: center;
}

.tutorial-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: #6b6258;
  padding: 0;
}

.tutorial-step-content {
  min-height: 130px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.tutorial-step-content h3 { margin: 0; }
.tutorial-step-content p { margin: 0; font-size: 0.95rem; }

.tutorial-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
}

#tutorial-progress { font-size: 0.8rem; color: #6b6258; }

button.secondary {
  background: #fff;
  color: var(--wood-dark);
  border: 1px solid var(--wood-dark);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}

#tutorial-next {
  background: var(--wood-dark);
  color: #fff;
  border: 1px solid var(--wood-dark);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}

/* ---- Fullscreen toggle ---- */
.fullscreen-btn {
  position: absolute;
  top: 0;
  right: 6px;
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--wood-dark);
  border: none;
  color: #fff;
  cursor: pointer;
  z-index: 20;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.fullscreen-btn:hover { opacity: 0.85; }
.fullscreen-btn svg { width: 16px; height: 16px; fill: currentColor; display: block; }

.abacus-wrapper:fullscreen,
.abacus-wrapper:-webkit-full-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  background: #f4f1ec;
  padding-top: 0;
  overflow: hidden;
}

.abacus-wrapper:fullscreen .abacus,
.abacus-wrapper:-webkit-full-screen .abacus {
  transform-origin: center center;
}

@media (max-width: 700px) {
  .rod { width: 30px; height: 200px; }
  .bead { width: 28px; height: 20px; }
  .bead.heaven { top: 12px; }
  .bead.heaven.active { top: 50px; }
  .bead.earth-0 { top: 146px; }
  .bead.earth-1 { top: 128px; }
  .bead.earth-2 { top: 110px; }
  .bead.earth-3 { top: 92px; }
  .bead.earth-0.active { top: 134px; }
  .bead.earth-1.active { top: 116px; }
  .bead.earth-2.active { top: 98px; }
  .bead.earth-3.active { top: 80px; }
}