/* Smocza Matematyka — module 'wagi' (pan balance with a box). All selectors start with .mod-wagi.
 * Geometry (module area 1040 x 712): task band 0–110; scale box 1040 x 300 at y 158 (one tray row) or y 92
 * (two rows); pans 80–420 / 620–960 (dish top 150 in the box), pivot (520, 225); tray 466–586 (one row of
 * 10 slots 100 x 104) or 394–586 (two rows of 9 slots 108 x 88); bead panel over the scale; action bar 592–712.
 */

.mod-wagi {
  --wg-tilt-ms: 600ms;
  --wg-wood: #e9d3a6;
  --wg-wood-2: #dcc08a;
  --wg-wood-edge: #b88e52;
  --wg-ghost: #b9ab8e;
  background:
    radial-gradient(ellipse at 50% 18%, #fbf6ea 0%, rgba(251, 246, 234, 0) 62%),
    radial-gradient(ellipse at 50% 120%, #d6efe9 0%, rgba(214, 239, 233, 0) 55%),
    var(--bg);
}

.mod-wagi .wg-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* ---------- task card ---------- */

.mod-wagi .wg-card {
  display: flex;
  align-items: center;
  gap: 18px;
  font-family: var(--font-num);
  font-weight: 700;
  line-height: 1;
}
.mod-wagi .wg-card .mat-num {
  font-weight: 700;
}
.mod-wagi .wg-c-op {
  color: var(--ink-soft);
  font-size: 56px;
  min-width: 30px;
  text-align: center;
}
.mod-wagi .wg-c-box {
  min-width: 88px;
  height: 82px;
  padding: 0 10px;
  border: 4px dashed #c9bda5;
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.55);
  transition: background 0.2s ease, border-color 0.2s ease;
}
.mod-wagi .wg-c-box.is-pending {
  border-color: #d8c59a;
  background: #fffaf0;
}
.mod-wagi .wg-c-box.is-amber {
  border-color: var(--err);
  border-style: solid;
  background: var(--err-soft);
}
.mod-wagi .wg-c-box.is-done {
  border-style: solid;
  border-color: var(--gold);
  background: var(--gold-soft);
  box-shadow: 0 0 0 4px rgba(242, 183, 5, 0.25);
}

/* ---------- the scale ---------- */

.mod-wagi .wg-scale {
  position: absolute;
  left: 0;
  width: 1040px;
  height: 300px;
  pointer-events: none;
}
.mod-wagi .wg-stand {
  position: absolute;
  left: 0;
  top: 0;
}
.mod-wagi .wg-plate,
.mod-wagi .wg-eq {
  transition: fill 0.3s ease, stroke 0.3s ease;
}
.mod-wagi .wg-scale.is-level .wg-plate {
  fill: var(--gold-soft);
  stroke: var(--gold-deep);
}
.mod-wagi .wg-scale.is-level .wg-eq {
  stroke: var(--gold-deep);
}
.mod-wagi .wg-scale.is-done .wg-plate {
  fill: #ffe27a;
  animation: wg-plate 1.1s ease-in-out 2;
}
@keyframes wg-plate {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(242, 183, 5, 0)); }
  50% { filter: drop-shadow(0 0 10px rgba(242, 183, 5, 0.95)); }
}

.mod-wagi .wg-beam,
.mod-wagi .wg-needle,
.mod-wagi .wg-pan {
  transition: transform var(--wg-tilt-ms) cubic-bezier(0.34, 1.4, 0.55, 1);
  will-change: transform;
}
.mod-wagi .wg-beam {
  position: absolute;
  left: 230px;
  top: 213px;
  width: 580px;
  height: 24px;
  transform-origin: 290px 12px;
  z-index: 3;
}
.mod-wagi .wg-beam svg {
  display: block;
}
.mod-wagi .wg-needle {
  position: absolute;
  left: 517px;
  top: 134px;
  width: 6px;
  height: 91px;
  border-radius: 3px 3px 2px 2px;
  background: linear-gradient(90deg, #8a6420, #f1d27c 50%, #8a6420);
  transform-origin: 3px 91px;
  z-index: 2;
  box-shadow: 0 0 0 1px rgba(58, 40, 28, 0.35);
}
.mod-wagi .wg-scale.is-level .wg-needle {
  background: linear-gradient(90deg, var(--gold-deep), #fff3c4 50%, var(--gold-deep));
}

.mod-wagi .wg-pan {
  position: absolute;
  top: 0;
  width: 340px;
  height: 225px;
  z-index: 4;
}
.mod-wagi .wg-stem {
  position: absolute;
  left: 163px;
  top: 172px;
  width: 14px;
  height: 56px;
  border-radius: 4px;
  background: linear-gradient(90deg, #a87b26, #f1d27c 45%, #9c7022);
  box-shadow: 0 0 0 1.5px #8a6420;
}
.mod-wagi .wg-dish {
  position: absolute;
  left: 0;
  top: 146px;
  width: 340px;
  height: 30px;
}
.mod-wagi .wg-dish svg {
  display: block;
}
.mod-wagi .wg-load {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 75px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}
.mod-wagi .wg-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
}
.mod-wagi .wg-op {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 50px;
  line-height: 1;
  color: var(--ink);
  width: 36px;
  text-align: center;
  margin-bottom: 18px;
}

/* weights (odważniki) */
.mod-wagi .wg-w {
  display: inline-block;
  width: 72px;
  height: 80px;
  flex: none;
  pointer-events: auto;
}
.mod-wagi .wg-w svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.mod-wagi .wg-num {
  font-family: var(--font-num);
}
.mod-wagi .wg-w.is-fixed {
  margin-bottom: 2px;
  filter: drop-shadow(0 3px 2px rgba(42, 34, 56, 0.25));
}
.mod-wagi .wg-w.is-in {
  filter: drop-shadow(0 3px 2px rgba(42, 34, 56, 0.25));
}
.mod-wagi .wg-ghost {
  position: absolute;
  z-index: 50;
  pointer-events: none;
  transform-origin: 50% 50%;
  filter: drop-shadow(0 8px 6px rgba(42, 34, 56, 0.3));
}

/* the box (okienko): one slot of 88 x 88 per weight */
.mod-wagi .wg-box {
  display: flex;
  height: 96px;
  border: 4px dashed #c9bda5;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.6);
  pointer-events: auto;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.mod-wagi .wg-box.wg-cap1 {
  width: 96px;
}
.mod-wagi .wg-box.wg-cap2 {
  width: 184px;
}
.mod-wagi .wg-box:not(.is-empty) {
  border-color: #d8c59a;
  background: rgba(255, 250, 240, 0.85);
}
.mod-wagi .wg-bslot {
  width: 88px;
  height: 88px;
  padding: 0 0 6px;
  margin: 0;
  border: none;
  background: transparent;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex: none;
}
.mod-wagi .wg-cap2 .wg-bslot + .wg-bslot {
  border-left: 3px dotted rgba(185, 171, 142, 0.6);
}
.mod-wagi .wg-bslot:active .wg-w {
  transform: translateY(2px);
}
.mod-wagi .wg-box.is-amber {
  border-color: var(--err);
  border-style: solid;
  background: var(--err-soft);
  box-shadow: 0 0 0 6px rgba(240, 140, 46, 0.22);
  animation: wg-amber 1.4s ease-in-out infinite;
}
.mod-wagi .wg-scale.is-done .wg-box {
  border-style: solid;
  border-color: var(--gold);
  background: var(--gold-soft);
  box-shadow: 0 0 0 4px rgba(242, 183, 5, 0.25);
}
@keyframes wg-amber {
  0%, 100% { box-shadow: 0 0 0 4px rgba(240, 140, 46, 0.18); }
  50% { box-shadow: 0 0 0 10px rgba(240, 140, 46, 0.3); }
}

/* L4: the bags under the expression (the meaning of 3 · 4) */
.mod-wagi .wg-bags {
  display: flex;
  gap: 2px;
  justify-content: center;
  align-items: flex-end;
  padding: 3px 8px;
  margin-bottom: 4px;
  border-radius: 14px;
  background: rgba(255, 253, 247, 0.85);
  border: 2px solid var(--line);
  box-shadow: 0 2px 0 rgba(42, 34, 56, 0.08);
}
.mod-wagi .wg-bag {
  display: inline-block;
  width: 48px;
  height: 51px;
}
.mod-wagi .wg-bags[data-n='7'] .wg-bag,
.mod-wagi .wg-bags[data-n='8'] .wg-bag {
  width: 39px;
  height: 42px;
}
.mod-wagi .wg-bags[data-n='9'] .wg-bag,
.mod-wagi .wg-bags[data-n='10'] .wg-bag {
  width: 31px;
  height: 33px;
}
.mod-wagi .wg-bag svg {
  display: block;
  width: 100%;
  height: 100%;
}
.mod-wagi .wg-bag.is-amber svg {
  filter: drop-shadow(0 0 4px rgba(240, 140, 46, 0.9));
}

/* ---------- tray of weights ---------- */

.mod-wagi .wg-tray {
  position: absolute;
  left: 12px;
  top: 466px;
  width: 1016px;
  height: 120px;
  padding: 6px 8px;
  border-radius: 22px;
  background: linear-gradient(180deg, var(--wg-wood) 0%, var(--wg-wood-2) 100%);
  border: 3px solid var(--wg-wood-edge);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.45), 0 4px 0 rgba(42, 34, 56, 0.12);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}
.mod-wagi.wg-rows2 .wg-tray {
  left: 22px;
  width: 996px;
  top: 394px;
  height: 192px;
  gap: 4px;
}
.mod-wagi .wg-tray-row {
  display: flex;
  justify-content: center;
  border-radius: 16px;
  transition: background 0.2s ease;
}
.mod-wagi .wg-tray-row.fx-highlight {
  background: rgba(255, 241, 191, 0.85);
}
.mod-wagi .wg-slot {
  position: relative;
  width: 100px;
  height: 104px;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.mod-wagi.wg-rows2 .wg-slot {
  width: 108px;
  height: 88px;
}
.mod-wagi .wg-slot .wg-w.is-tray {
  width: 76px;
  height: 85px;
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 3px 2px rgba(42, 34, 56, 0.28));
  transition: transform 0.12s ease;
}
.mod-wagi.wg-rows2 .wg-slot .wg-w.is-tray {
  width: 66px;
  height: 74px;
}
.mod-wagi .wg-slot:active .wg-w.is-tray {
  transform: translateY(3px);
}
/* the weight's place on the tray: a groove with the number, visible while the weight is on the scale */
.mod-wagi .wg-slot-mark {
  position: absolute;
  left: 50%;
  bottom: 8px;
  width: 70px;
  height: 30px;
  margin-left: -35px;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 40%, rgba(120, 86, 46, 0.32), rgba(120, 86, 46, 0.08) 70%);
  color: rgba(120, 86, 46, 0);
  font-family: var(--font-num);
  font-size: 20px;
  font-weight: 700;
  line-height: 30px;
  text-align: center;
  transition: color 0.2s ease;
}
.mod-wagi.wg-rows2 .wg-slot-mark {
  bottom: 4px;
  height: 26px;
  line-height: 26px;
}
.mod-wagi .wg-slot.is-out .wg-w.is-tray {
  visibility: hidden;
}
.mod-wagi .wg-slot.is-out .wg-slot-mark {
  color: rgba(120, 86, 46, 0.55);
}
/* the next element in the "together" task / a highlighted weight */
.mod-wagi .wg-slot.demo-target,
.mod-wagi .wg-slot.fx-highlight {
  border-radius: 18px;
  background: rgba(255, 241, 191, 0.75);
}
.mod-wagi .wg-slot.demo-target .wg-w.is-tray,
.mod-wagi .wg-slot.is-hint .wg-w.is-tray {
  filter: drop-shadow(0 0 8px rgba(242, 183, 5, 0.95)) drop-shadow(0 0 3px rgba(242, 183, 5, 0.9));
  animation: wg-hop 1s ease-in-out infinite;
}
@keyframes wg-hop {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}
.mod-wagi .wg-tray.is-locked .wg-slot {
  opacity: 0.32;
  filter: grayscale(0.8);
  transition: opacity 0.2s ease;
}

/* ---------- bead / bag panel ---------- */

.mod-wagi .wg-panel {
  position: absolute;
  left: 0;
  right: 0;
  margin: 0 auto;
  top: 130px;
  width: fit-content;
  min-width: 560px;
  max-width: 800px;
  min-height: 220px;
  max-height: 318px;
  padding: 26px 40px;
  z-index: 30;
  border-radius: 26px;
  background: radial-gradient(ellipse at 50% 0%, #fffdf7 0%, #fbf5e8 100%);
  border: 3px solid var(--line);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-16px) scale(0.98);
  transition: opacity 0.22s ease, transform 0.22s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mod-wagi.wg-rows2 .wg-panel {
  top: 116px;
  max-height: 272px;
  padding: 14px 36px;
}
.mod-wagi .wg-panel.is-open {
  opacity: 1;
  transform: none;
}
.mod-wagi .wg-panel-in {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
}
.mod-wagi.wg-rows2 .wg-panel-in {
  gap: 12px;
}
.mod-wagi .wg-panel.is-side .wg-panel-in {
  flex-direction: row;
  gap: 48px;
}
.mod-wagi .wg-panel-eq {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 40px;
  line-height: 1;
}
.mod-wagi .wg-m-op {
  color: var(--ink-soft);
  min-width: 20px;
  text-align: center;
}
.mod-wagi .wg-m-box {
  width: 48px;
  height: 48px;
  border: 3px dashed #c9bda5;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
}
.mod-wagi .wg-panel-body {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* golden beads: one row up to 20 (bead stair look), rows of ten above */
.mod-wagi .wg-rows {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.mod-wagi .wg-brow {
  position: relative;
  display: flex;
  align-items: center;
  height: var(--d);
}
.mod-wagi .wg-brow.is-half {
  margin-bottom: 7px;
}
/* a full ten: the beads sit on a wire (golden ten-bar) */
.mod-wagi .wg-brow.is-bar::before {
  content: '';
  position: absolute;
  left: -6px;
  right: -6px;
  top: 50%;
  height: 3px;
  margin-top: -1.5px;
  border-radius: 2px;
  background: #8f8a80;
}
.mod-wagi .wg-b {
  position: relative;
  width: var(--d);
  height: var(--d);
  margin-right: 2px;
  flex: none;
  transition: opacity 0.25s ease, transform 0.2s ease;
}
.mod-wagi .wg-b.is-five {
  margin-right: 9px;
}
.mod-wagi .wg-b.is-ten {
  margin-right: 20px;
}
.mod-wagi .wg-b > .mat,
.mod-wagi .wg-b-fill > .mat {
  display: block;
}
.mod-wagi .wg-b.is-ghost {
  border: 2.5px dashed var(--wg-ghost);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
}
.mod-wagi .wg-b-fill {
  position: absolute;
  left: -2.5px;
  top: -2.5px;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.mod-wagi .wg-b.is-ghost.is-filled {
  border-color: transparent;
  background: transparent;
}
.mod-wagi .wg-b.is-ghost.is-filled .wg-b-fill {
  opacity: 1;
}
/* taken away (subtraction): faint and lifted, the dragon takes them */
.mod-wagi .wg-b.is-faded {
  opacity: 0.26;
  transform: translateY(-6px);
}
.mod-wagi .wg-rows.is-grid .wg-b.is-faded {
  transform: none;
}
.mod-wagi .wg-b.is-faded.is-keep,
.mod-wagi .wg-b.is-faded.is-back {
  opacity: 1;
  transform: none;
}
.mod-wagi .wg-b.is-pulse {
  transform: scale(1.22);
  filter: drop-shadow(0 0 6px rgba(242, 183, 5, 0.95));
}
.mod-wagi .wg-b.is-faded.is-pulse {
  opacity: 0.6;
}
.mod-wagi .wg-b-n,
.mod-wagi .wg-pbag-n {
  position: absolute;
  left: 50%;
  top: -28px;
  min-width: 30px;
  margin-left: -15px;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 22px;
  line-height: 24px;
  text-align: center;
  color: var(--ink);
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}
.mod-wagi .wg-b-n.is-on,
.mod-wagi .wg-pbag-n.is-on {
  opacity: 1;
}

/* bags: the heap to share and the bags */
.mod-wagi .wg-bagwrap {
  display: flex;
  align-items: center;
  gap: 36px;
}
.mod-wagi .wg-heap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px;
  border-radius: 18px;
  background: rgba(233, 211, 166, 0.45);
  border: 2px solid rgba(184, 142, 82, 0.4);
}
.mod-wagi .wg-hrow {
  display: flex;
  gap: 2px;
}
.mod-wagi .wg-hb {
  width: var(--hb, 14px);
  height: var(--hb, 14px);
  border-radius: 50%;
  transition: opacity 0.18s ease;
}
.mod-wagi .wg-hb .mat {
  display: block;
}
/* bead-bar colour (the size of the bags: 4 = yellow) */
.mod-wagi .wg-hb.is-col {
  background: radial-gradient(circle at 35% 30%, #ffffff 0%, var(--c) 45%, rgba(0, 0, 0, 0.45) 140%);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.mod-wagi .wg-hb.is-gone {
  opacity: 0.1;
}
.mod-wagi .wg-pbags {
  --bag-w: 112px;
  --bag-h: 120px;
  --pb: 16px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 18px;
  max-width: 520px;
}
.mod-wagi .wg-pbags.is-many {
  --bag-w: 86px;
  --bag-h: 92px;
  --pb: 12px;
  gap: 8px 16px;
  max-width: 500px;
}
.mod-wagi .wg-pbag {
  position: relative;
  width: var(--bag-w);
  height: var(--bag-h);
  transition: opacity 0.25s ease, transform 0.2s ease;
}
.mod-wagi .wg-pbag-art svg {
  display: block;
  width: var(--bag-w);
  height: var(--bag-h);
}
/* beads inside the sack body (viewBox body: x 5–55, y 25–61 of 60 x 64) */
.mod-wagi .wg-pbag-beads {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 53%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
  gap: 2px;
}
.mod-wagi .wg-pb {
  width: var(--pb);
  height: var(--pb);
  border-radius: 50%;
  transition: opacity 0.18s ease;
}
.mod-wagi .wg-pb .mat {
  display: block;
  width: var(--pb) !important;
  height: var(--pb) !important;
}
.mod-wagi .wg-pb .mat svg {
  width: var(--pb);
  height: var(--pb);
}
.mod-wagi .wg-pb.is-col {
  background: radial-gradient(circle at 35% 30%, #ffffff 0%, var(--c) 45%, rgba(0, 0, 0, 0.45) 140%);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.mod-wagi .wg-pb.is-empty {
  opacity: 0;
}
.mod-wagi .wg-pbag.is-hidden {
  opacity: 0;
  transform: translateY(8px) scale(0.9);
}
.mod-wagi .wg-pbag.is-pulse {
  transform: scale(1.08);
  filter: drop-shadow(0 0 8px rgba(242, 183, 5, 0.9));
}
/* the count of a bag: a round badge on its corner (never over the equation above the bags) */
.mod-wagi .wg-pbag-n {
  top: auto;
  left: auto;
  right: -8px;
  bottom: -6px;
  margin: 0;
  min-width: 34px;
  height: 34px;
  padding: 0 4px;
  line-height: 30px;
  border-radius: 17px;
  background: #fffaf0;
  border: 2px solid var(--gold-deep);
  box-shadow: 0 2px 0 rgba(42, 34, 56, 0.12);
  font-size: 20px;
}

/* ---------- effects ---------- */

.mod-wagi .wg-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 40;
}
.mod-wagi .wg-sparkle {
  position: absolute;
  width: 0;
  height: 0;
}
.mod-wagi .wg-sparkle i {
  position: absolute;
  left: -5px;
  top: -5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff7cf 0%, var(--gold) 60%, rgba(242, 183, 5, 0) 100%);
  transform: rotate(var(--a)) translateY(0);
  animation: wg-spark 0.9s ease-out forwards;
}
@keyframes wg-spark {
  0% { transform: rotate(var(--a)) translateY(0) scale(0.6); opacity: 1; }
  100% { transform: rotate(var(--a)) translateY(-56px) scale(1.1); opacity: 0; }
}

/* the main button glows when the scale stands level */
.mod-wagi .action-bar .btn-main.wg-ready {
  box-shadow: 0 0 0 0 rgba(242, 183, 5, 0.8), var(--shadow);
  animation: wg-ready 1.3s ease-in-out infinite;
}
@keyframes wg-ready {
  0%, 100% { box-shadow: 0 0 0 0 rgba(242, 183, 5, 0.75), var(--shadow); }
  50% { box-shadow: 0 0 0 12px rgba(242, 183, 5, 0), var(--shadow); }
}

.mod-wagi .wg-icon svg {
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  .mod-wagi .wg-slot.demo-target .wg-w.is-tray,
  .mod-wagi .wg-slot.is-hint .wg-w.is-tray {
    animation: none;
  }
}
