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

/* iJeeto brand palette — sampled from the star logo. Copied per game rather
   than shared, so each game folder stays self-contained (guidelines 9.1/9.3). */
:root {
  --purple: #4A1A63;
  --purple-soft: #6B3A85;
  --amber: #FFC42E;
  --amber-dark: #E8A511;
  --orange: #FF7A2F;
  --orange-dark: #DD5E15;
  --teal: #2FAFAF;
  --teal-dark: #218A8A;
  --cream: #FFF7EA;
  --cream-2: #FCEBD2;
  --bad: #d4564f;
  --shadow-soft: #e6d8c2;
  --font-brand: ui-rounded, "SF Pro Rounded", Nunito, Quicksand,
                "Hiragino Maru Gothic ProN", "Trebuchet MS", system-ui, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font-brand);
  background: var(--cream);
  color: var(--purple);
  overflow: hidden;
}

#app { height: 100%; display: flex; flex-direction: column; }
.screen { display: none; flex: 1; min-height: 0; flex-direction: column; }
.screen.active { display: flex; }
.hidden { display: none !important; }

/* ---------- menus ---------- */

.menu-screen { align-items: center; padding: 20px 16px; overflow-y: auto; }
.brand-mark { width: clamp(84px, 22vw, 116px); height: auto; display: block; margin: 0 auto; }
.logo { font-size: clamp(28px, 7vw, 44px); margin-top: 4px; text-align: center; }
.tagline { font-size: clamp(14px, 3vw, 18px); margin: 12px 0 26px; text-align: center; line-height: 1.6; }
.menu-buttons { display: flex; flex-direction: column; gap: 14px; width: min(340px, 92vw); }

.big-btn {
  min-height: 54px; border: 0; border-radius: 14px;
  background: var(--orange); color: #fff;
  font-family: inherit; font-size: 18px; font-weight: 700;
  cursor: pointer; padding: 10px 18px; box-shadow: 0 4px 0 var(--orange-dark);
}
.big-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--orange-dark); }
.big-btn.ghost { background: #fff; color: var(--purple); box-shadow: 0 4px 0 var(--shadow-soft); }
.big-btn.danger { background: var(--bad); box-shadow: 0 4px 0 #a53b36; }

.portal-link {
  margin-top: 22px; padding: 12px 20px; min-height: 44px;
  display: inline-flex; align-items: center;
  font-size: 14px; color: var(--purple); text-decoration: none;
  background: #fff; border-radius: 999px; box-shadow: 0 2px 0 var(--shadow-soft);
}
.build { margin-top: 14px; font-size: 12px; color: var(--purple-soft); }

.menu-header {
  display: flex; align-items: center; gap: 12px;
  width: min(760px, 100%); margin-bottom: 8px;
}
.menu-header h2 { font-size: clamp(18px, 4vw, 24px); }
.back-btn, .hud-btn {
  min-width: 44px; min-height: 44px; border: 0; border-radius: 12px;
  background: #fff; color: var(--purple); font-size: 18px; cursor: pointer;
  box-shadow: 0 2px 0 var(--shadow-soft);
}
.map-progress { width: min(760px, 100%); font-size: 14px; margin-bottom: 10px; color: var(--purple-soft); }

.world-grid { width: min(760px, 100%); display: flex; flex-direction: column; gap: 4px; }
.world-block { margin-bottom: 8px; }
.world-row { display: flex; align-items: center; gap: 9px; margin: 10px 0 6px; font-weight: 700; font-size: 15px; }
.world-emoji { font-size: 21px; }
.world-tag {
  font-size: 11px; font-weight: 700; color: #fff; background: var(--teal);
  border-radius: 999px; padding: 2px 9px;
}
.level-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }

.tile {
  border: 0; border-radius: 12px; background: #fff;
  font-family: inherit; color: var(--purple); cursor: pointer;
  padding: 10px 4px; min-height: 58px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  box-shadow: 0 3px 0 var(--shadow-soft);
}
.tile:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow-soft); }
.tile.locked { opacity: 0.5; cursor: default; }
.tile-num { font-size: 19px; font-weight: 700; }
.tile-stars { font-size: 11px; color: var(--amber-dark); }
.dim { color: #e9dfcb; }

/* ---------- game ---------- */

#game-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: rgba(255,255,255,0.85);
  font-weight: 700; font-size: clamp(13px, 2.6vw, 16px);
}
#level-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.task { text-align: center; padding: 10px 12px 4px; }
.prompt { font-size: clamp(26px, 7vw, 40px); font-weight: 700; letter-spacing: 0.5px; }
.prompt-dots { display: flex; gap: 7px; justify-content: center; margin-top: 8px; flex-wrap: wrap; }
.pdot {
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--amber); border: 2px solid var(--purple);
}

.board-area {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 4px 8px;
}

/* ---------- the soroban ----------
   An active bead sits exactly ONE slot closer to the beam than an inactive
   one, so CSS derives every position from the bead's index and the only thing
   that ever changes is a single one-slot transform. */
.soroban {
  /* One slot. Sized off BOTH axes: with only 1-2 rods the limit is the
     column height, so vh has to count or the abacus looks tiny on a phone. */
  --bh: clamp(24px, min(11vw, 7.5vh), 46px);
  --bw: calc(var(--bh) * 1.75);
  --beam: 10px;
  --labelH: 16px;
  transition: opacity .5s ease, filter .5s ease;
}
.soroban .frame {
  position: relative;
  display: flex; gap: 8px;
  padding: 12px 14px 4px;
  background: #FFF3DF;
  border: 4px solid var(--purple);
  border-radius: 16px;
  box-shadow: 0 4px 0 var(--shadow-soft);
}
.rod {
  position: relative;
  width: var(--bw);
  height: calc(7 * var(--bh) + var(--beam) + var(--labelH));
}
.wire {
  position: absolute; left: 50%; top: 2px;
  bottom: var(--labelH); width: 3px; margin-left: -1.5px;
  background: rgba(74, 26, 99, 0.32); border-radius: 2px;
}
/* spans the whole frame; 12px matches the frame's padding-top */
.beam {
  position: absolute; left: 0; right: 0;
  top: calc(12px + 2 * var(--bh)); height: var(--beam);
  background: var(--purple); z-index: 2;
}
.bead {
  position: absolute; left: 0;
  width: var(--bw); height: var(--bh);
  border: 2.5px solid var(--purple);
  border-radius: 50%;
  padding: 0; cursor: pointer; z-index: 3;
  font-family: inherit;
  transition: transform .2s cubic-bezier(.34, 1.5, .64, 1);
}
/* the 5-bead is a different colour on purpose: "this one is special" */
.bead.heaven { top: 0; background: var(--teal); }
.bead.heaven.on { transform: translateY(var(--bh)); }
.bead.earth {
  background: var(--amber);
  top: calc(2 * var(--bh) + var(--beam) + (var(--j) + 1) * var(--bh));
}
.bead.earth.on { transform: translateY(calc(-1 * var(--bh))); }

.place {
  position: absolute; left: 0; right: 0; bottom: 0;
  text-align: center; font-size: 11px; font-weight: 700;
  color: var(--purple-soft);
}

.soroban.no-anim .bead { transition: none; }
.soroban.locked .bead { cursor: default; }
.soroban.faded { opacity: 0.1; filter: grayscale(1); }
.soroban.cheer { animation: cheer .6s ease; }
@keyframes cheer {
  0%, 100% { transform: scale(1); }
  35% { transform: scale(1.06) rotate(-1deg); }
  70% { transform: scale(1.02) rotate(1deg); }
}
.bead.hint { animation: beadhint 1s ease-in-out infinite; }
@keyframes beadhint {
  0%, 100% { box-shadow: 0 0 0 0 rgba(47,175,175,.9); }
  50% { box-shadow: 0 0 0 7px rgba(47,175,175,0); }
}
.bead.shake { animation: beadshake .4s ease; }
@keyframes beadshake {
  0%, 100% { margin-left: 0; } 25% { margin-left: -4px; } 75% { margin-left: 4px; }
}

.readout {
  font-size: clamp(22px, 6vw, 32px); font-weight: 800;
  background: #fff; border: 3px solid var(--purple);
  border-radius: 999px; padding: 2px 22px; min-width: 84px; text-align: center;
}

/* ---------- answers & feedback ---------- */

.choices { display: flex; gap: 10px; justify-content: center; padding: 4px 10px 0; flex-wrap: wrap; }
.choice {
  min-width: 74px; min-height: 58px;
  border: 0; border-radius: 14px;
  background: var(--teal); color: #fff;
  font-family: inherit; font-size: 26px; font-weight: 800;
  cursor: pointer; box-shadow: 0 4px 0 var(--teal-dark);
}
.choice:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--teal-dark); }
.choice.wrong { background: #ddd2c2; box-shadow: 0 4px 0 #c4b8a6; color: #fff; opacity: .7; }

.caption {
  text-align: center; padding: 8px 18px;
  font-size: clamp(14px, 3.2vw, 18px); font-weight: 700; line-height: 1.45;
  color: var(--purple);
  background: #FFFCF4; border-radius: 12px;
  margin: 0 12px;
}

.game-footer {
  padding: 6px 14px 12px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
}
.help { font-size: clamp(13px, 2.8vw, 15px); color: var(--purple-soft); min-height: 1.2em; }
.streak { font-size: 14px; font-weight: 700; color: var(--orange-dark); min-height: 1.1em; }
.streak.hot { animation: hot 1s ease-in-out infinite; }
@keyframes hot { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }

.footer-btns { display: flex; gap: 10px; }
.tool-btn {
  min-height: 44px; padding: 8px 18px; border: 0; border-radius: 999px;
  background: #fff; color: var(--purple);
  font-family: inherit; font-size: 14px; cursor: pointer;
  box-shadow: 0 2px 0 var(--shadow-soft);
}
.tool-btn:active { transform: translateY(2px); box-shadow: 0 0 0 var(--shadow-soft); }

.demo-bar {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  background: var(--purple); color: #fff;
  font-size: 13px; font-weight: 700;
  padding: 6px 16px; border-radius: 999px; z-index: 6;
}
#screen-game { position: relative; }

.spark {
  position: absolute; z-index: 20; pointer-events: none;
  font-size: clamp(18px, 4vw, 26px);
  animation: sparkfly var(--dur, 1.8s) cubic-bezier(.15,.7,.4,1) forwards;
}
@keyframes sparkfly {
  0% { transform: translate(0,0) rotate(0) scale(.3); opacity: 0; }
  12% { opacity: 1; }
  75% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scale(1); opacity: 0; }
}

/* ---------- overlays ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 30; padding: 16px;
  background: rgba(74, 26, 99, 0.55);
  display: flex; align-items: center; justify-content: center;
}
.card {
  background: #fff; border-radius: 18px; padding: 24px;
  width: min(420px, 94vw); max-height: 90vh; overflow-y: auto; text-align: center;
}
.card h2 { font-size: clamp(19px, 4vw, 25px); margin-bottom: 6px; }
.card p { font-size: 15px; line-height: 1.6; }
.big-answer {
  font-size: clamp(44px, 12vw, 66px); font-weight: 800;
  color: var(--orange); line-height: 1.1; margin: 4px 0;
}
.stars { font-size: 34px; color: var(--amber-dark); margin: 2px 0 8px; }
.card-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.setting-row {
  display: flex; align-items: center; gap: 12px;
  font-size: 16px; font-weight: 700; padding: 12px 6px; cursor: pointer;
}
.setting-row input { width: 22px; height: 22px; }

/* short landscape phones: shrink the beads so everything still fits */
@media (orientation: landscape) and (max-height: 560px) {
  .soroban { --bh: clamp(18px, 4.2vh, 26px); }
  .prompt { font-size: 22px; }
  .task { padding: 4px 12px 2px; }
  .game-footer { padding: 2px 10px 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .bead { transition: none; }
  .soroban.cheer, .bead.hint, .bead.shake, .streak.hot { animation: none; }
}
