/* The soroban: a friendly wooden frame with big tappable beads.
   Heaven beads (worth 5) are Coral and sit above the bar; earth beads
   (worth 1) are Sky and sit below. "pushed" = touching the bar = counting.
   Beads that do not count rest away from the bar, with a clear gap. */

.abacusbox { display: flex; justify-content: center; margin: 8px 0 4px; }
.soroban {
  --bead: 48px;                 /* bead height */
  --gap: 40px;                  /* empty rod between resting and counted beads */
  display: grid;
  grid-template-columns: repeat(var(--rods, 1), clamp(64px, 14vw, 96px));
  grid-template-rows: auto 12px auto;
  column-gap: clamp(18px, 4vw, 32px);
  padding: clamp(12px, 2.5vw, 20px) clamp(16px, 3vw, 28px);
  background: var(--sun); border: 6px solid var(--ink); border-radius: 28px;
  box-shadow: 0 8px 0 var(--ink);
  touch-action: manipulation; user-select: none;
}
.soro-bar {
  grid-row: 2; grid-column: 1 / -1;
  margin: 0 calc(-1 * clamp(8px, 2vw, 16px));
  background: var(--ink); border-radius: 6px;
  position: relative; z-index: 1;
}

/* each rod half: a thin rod behind its beads */
.soro-heaven-box, .soro-earth {
  position: relative; display: flex; flex-direction: column; align-items: center;
}
.soro-heaven-box::before, .soro-earth::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%;
  width: 6px; margin-left: -3px; background: var(--ink); border-radius: 3px;
}
.soro-heaven-box { grid-row: 1; height: calc(var(--bead) + var(--gap)); }
.soro-earth { grid-row: 3; height: calc(var(--bead) * 4 + var(--gap)); }

.soro-bead {
  position: relative; flex: none;
  width: 100%; height: var(--bead); padding: 0;
  border: 4px solid var(--ink); border-radius: 999px;
  font: 800 0/0 var(--display); color: transparent;
  cursor: pointer; transition: transform .12s ease;
}

/* resting beads are pale; counted beads are bright and hug the bar */
.soro-heaven { background: #FFB3A8; }
.soro-heaven.pushed { background: var(--coral); margin-top: auto; }
.soro-earth-bead { background: #CDEFFF; }
.soro-earth-bead.pushed { background: var(--sky); }
/* the first resting earth bead drops to the bottom, taking the rest with it */
.soro-earth-bead:first-child:not(.pushed),
.soro-earth-bead.pushed + .soro-earth-bead:not(.pushed) { margin-top: auto; }

.soro-bead:active { transform: scale(.96); }

@media (max-width: 560px) {
  /* bead size follows the screen height so the choices stay in view.
     svh = the height left while the browser's bars show; plain vh on a phone
     is the taller bars-hidden height, which pushed the choices off screen */
  .soroban { --bead: clamp(22px, 4.4vh, 42px); --gap: clamp(21px, 3.6vh, 32px); }
  @supports (height: 1svh) {
    .soroban { --bead: clamp(22px, 4.4svh, 42px); --gap: clamp(21px, 3.6svh, 32px); }
  }
}
@media (prefers-reduced-motion: reduce) {
  .soro-bead { transition: none; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .soroban { --bead: clamp(24px, 7vh, 42px); --gap: clamp(24px, 6vh, 32px); }
}
