/* Smocza Matematyka — module 'gniazdo' (Gniazdo smoka). Every selector starts with .mod-gniazdo. */

/* ---------- common ---------- */

.mod-gniazdo .gn-band {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  white-space: nowrap;
}
.mod-gniazdo .gn-band-text {
  font-family: var(--font);
  font-size: 34px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.1;
}
.mod-gniazdo .action-bar {
  z-index: 10;
}
.mod-gniazdo .gn-layer,
.mod-gniazdo .gn-decor {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.mod-gniazdo .gn-layer {
  z-index: 3;
}
.mod-gniazdo .gn-decor {
  z-index: 4;
}

/* gold sparkle burst (success) */
.mod-gniazdo .gn-sparks {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 8;
}
.mod-gniazdo .gn-sparks i {
  position: absolute;
  left: -5px;
  top: -5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle, #fffbe0 0%, var(--gold) 60%, rgba(242, 183, 5, 0) 100%);
  transform: rotate(var(--a)) translateY(0);
  animation: gn-spark 0.8s ease-out forwards;
}
@keyframes gn-spark {
  0% { transform: rotate(var(--a)) translateY(0) scale(0.6); opacity: 1; }
  100% { transform: rotate(var(--a)) translateY(-44px) scale(1); opacity: 0; }
}
@keyframes gn-pulse {
  0%, 100% { scale: 1; filter: none; }
  45% { scale: 1.18; filter: brightness(1.25) drop-shadow(0 0 6px rgba(242, 183, 5, 0.9)); }
}
@keyframes gn-extra {
  0%, 100% { filter: none; }
  50% { filter: drop-shadow(0 0 6px var(--err)) brightness(1.1); }
}
@keyframes gn-wobble {
  0%, 100% { rotate: 0deg; }
  20% { rotate: -7deg; }
  45% { rotate: 6deg; }
  70% { rotate: -4deg; }
  90% { rotate: 2deg; }
}

/* ======================= L1: the spindle box ======================= */

.mod-gniazdo .gn-tray {
  position: absolute;
  border-radius: 22px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.05) 0 3px, rgba(0, 0, 0, 0) 3px 23px),
    linear-gradient(180deg, #cf9d66 0%, #b9824a 55%, #a87239 100%);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.35),
    inset 0 -4px 0 rgba(90, 52, 18, 0.25),
    0 6px 0 rgba(90, 55, 20, 0.22),
    0 12px 22px rgba(42, 34, 56, 0.14);
  z-index: 1;
}

.mod-gniazdo .gn-nest {
  position: absolute;
  border-radius: 16px;
  background: linear-gradient(180deg, #8a5c33 0%, #744b28 100%);
  box-shadow: inset 0 4px 8px rgba(40, 20, 4, 0.45), inset 0 -2px 0 rgba(255, 255, 255, 0.12);
  cursor: pointer;
  z-index: 2;
  transition: box-shadow 0.25s ease, background-color 0.25s ease;
  -webkit-tap-highlight-color: transparent;
}
.mod-gniazdo .gn-nest:active {
  filter: brightness(1.06);
}
.mod-gniazdo .gn-plate {
  position: absolute;
  left: 20px;
  right: 20px;
  top: 6px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(180deg, #fffefb, #f6efdc);
  box-shadow: inset 0 0 0 2px #d9ccae, 0 2px 0 rgba(40, 20, 4, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.mod-gniazdo .gn-num {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 36px;
  line-height: 1;
  color: var(--m-units);
  font-variant-numeric: tabular-nums;
}
/* the nest bed: dark woven twigs, so the light sticks are easy to count */
.mod-gniazdo .gn-bed {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 52px;
  bottom: 7px;
  border-radius: 12px 12px 34px 34px;
  background:
    repeating-linear-gradient(28deg, rgba(196, 140, 82, 0.22) 0 2px, rgba(0, 0, 0, 0) 2px 12px),
    repeating-linear-gradient(-32deg, rgba(196, 140, 82, 0.18) 0 2px, rgba(0, 0, 0, 0) 2px 14px),
    radial-gradient(ellipse at 50% 100%, #6f4524 0%, #5a361b 55%, #4a2c15 100%);
  box-shadow: inset 0 4px 8px rgba(20, 10, 2, 0.5);
  pointer-events: none;
}
/* the stick pile of a nest: tap here = the top stick goes back */
.mod-gniazdo .gn-zone {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0;
  border-radius: 0 0 16px 16px;
}
.mod-gniazdo .gn-nest.is-amber {
  outline: 6px solid var(--err);
  outline-offset: 3px;
}
.mod-gniazdo .gn-nest.is-ok {
  box-shadow: inset 0 4px 8px rgba(40, 20, 4, 0.45), 0 0 0 5px rgba(242, 183, 5, 0.75);
}
.mod-gniazdo .gn-nest.is-gold {
  box-shadow: inset 0 4px 8px rgba(40, 20, 4, 0.45), 0 0 0 6px var(--gold), 0 0 18px rgba(242, 183, 5, 0.55);
}
.mod-gniazdo .gn-nest.is-gold .gn-plate {
  background: linear-gradient(180deg, #fffbe8, var(--gold-soft));
}

/* the basket with exactly 45 sticks (no number: the pile itself shrinks) */
.mod-gniazdo .gn-basket {
  position: absolute;
  border-radius: 22px 22px 46px 46px;
  border: 12px solid #c48c52;
  background:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.07) 0 2px, rgba(0, 0, 0, 0) 2px 18px),
    linear-gradient(180deg, #5d3b1f 0%, #6f4727 60%, #7c5230 100%);
  box-shadow:
    inset 0 6px 14px rgba(20, 10, 2, 0.5),
    0 6px 0 rgba(90, 55, 20, 0.25),
    0 12px 22px rgba(42, 34, 56, 0.16);
  cursor: pointer;
  z-index: 2;
  transition: box-shadow 0.3s ease;
}
.mod-gniazdo .gn-basket::before {
  /* woven border pattern drawn over the frame */
  content: '';
  position: absolute;
  inset: -12px;
  border-radius: 22px 22px 46px 46px;
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.16) 0 6px, rgba(0, 0, 0, 0) 6px 12px),
    repeating-linear-gradient(0deg, rgba(90, 50, 15, 0.22) 0 3px, rgba(0, 0, 0, 0) 3px 12px);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  padding: 12px;
}
.mod-gniazdo .gn-basket-rim {
  position: absolute;
  left: -16px;
  right: -16px;
  top: -14px;
  height: 22px;
  border-radius: 12px;
  background:
    repeating-linear-gradient(60deg, rgba(255, 255, 255, 0.2) 0 5px, rgba(0, 0, 0, 0) 5px 11px),
    linear-gradient(180deg, #d9a266, #b47a40);
  box-shadow: 0 3px 0 rgba(70, 40, 12, 0.35);
}
.mod-gniazdo .gn-basket.is-gold {
  box-shadow:
    inset 0 6px 14px rgba(20, 10, 2, 0.5),
    0 0 0 6px var(--gold),
    0 0 24px rgba(242, 183, 5, 0.6);
}

/* a stick: a smooth wooden spindle, long and tapered at both ends (drawn as an SVG background so it reads as
   a stick, not as a stack of plates) — visual only */
.mod-gniazdo .gn-stick {
  position: absolute;
  width: 110px;
  height: 9px;
  background: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 110 9' preserveAspectRatio='none'%3E%3Cdefs%3E%3ClinearGradient id='g' x1='0' y1='0' x2='0' y2='1'%3E%3Cstop offset='0' stop-color='%23fff1d6'/%3E%3Cstop offset='.38' stop-color='%23f2cd92'/%3E%3Cstop offset='.78' stop-color='%23d4955a'/%3E%3Cstop offset='1' stop-color='%239c612c'/%3E%3C/linearGradient%3E%3C/defs%3E%3Cpath d='M0.5 4.5 L8 1 Q55 0 102 1 L109.5 4.5 L102 8 Q55 9 8 8 Z' fill='url%28%23g%29' stroke='%237a4a1f' stroke-width='0.8'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
  will-change: transform;
}
.mod-gniazdo .gn-stick.is-flying {
  z-index: 2;
  filter: drop-shadow(0 6px 6px rgba(40, 20, 4, 0.35));
}
.mod-gniazdo .gn-stick.is-pulse {
  animation: gn-pulse 0.42s ease;
}
.mod-gniazdo .gn-stick.is-extra {
  animation: gn-extra 0.9s ease-in-out infinite;
  outline: 2px solid var(--err);
  outline-offset: 1px;
  border-radius: 5px;
}
.mod-gniazdo .gn-ghost-stick {
  position: absolute;
  width: 110px;
  height: 9px;
  border-radius: 8px / 50%;
  border: 3px dashed var(--err);
  background: rgba(255, 233, 212, 0.75);
  animation: gn-ghost 1.1s ease-in-out infinite;
}
@keyframes gn-ghost {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
/* the golden ribbon that ties a finished bundle */
.mod-gniazdo .gn-ribbon {
  position: absolute;
  border-radius: 4px;
  background: linear-gradient(90deg, #c98f00, #f2b705 40%, #ffe27a 55%, #e0a800);
  box-shadow: 0 1px 2px rgba(60, 40, 0, 0.35);
  animation: gn-ribbon 0.35s ease-out both;
}
.mod-gniazdo .gn-bow {
  position: absolute;
  left: 50%;
  top: -13px;
  width: 40px;
  height: 22px;
  margin-left: -20px;
}
.mod-gniazdo .gn-bow svg {
  display: block;
}
@keyframes gn-ribbon {
  from { opacity: 0; scale: 1 0.3; }
  to { opacity: 1; scale: 1 1; }
}

/* ======================= L2: cards and counters ======================= */

/* the scattered cards lie on a soft rug */
.mod-gniazdo .gn-scatter {
  position: absolute;
  z-index: 1;
}
.mod-gniazdo .gn-scatter::before {
  content: '';
  position: absolute;
  left: 10px;
  right: 10px;
  top: 4px;
  bottom: 2px;
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.32);
  border: 3px solid rgba(226, 213, 184, 0.7);
  transition: opacity 0.4s ease;
}
.mod-gniazdo.gn-l2.has-pool .gn-scatter::before {
  opacity: 0;
}

/* the nest with exactly 55 dragon eggs (appears once the cards are in order) */
.mod-gniazdo .gn-pool {
  position: absolute;
  z-index: 2;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-16px);
  transition: opacity 0.45s ease, transform 0.45s ease;
  cursor: pointer;
}
.mod-gniazdo.has-pool .gn-pool {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.mod-gniazdo .gn-pool-bowl {
  position: absolute;
  inset: 4px 0 0;
  border-radius: 50% / 46%;
  background:
    repeating-linear-gradient(24deg, rgba(110, 66, 22, 0.18) 0 3px, rgba(0, 0, 0, 0) 3px 12px),
    repeating-linear-gradient(-30deg, rgba(110, 66, 22, 0.14) 0 3px, rgba(0, 0, 0, 0) 3px 14px),
    radial-gradient(ellipse at 50% 40%, #f4e2b0 0%, #e2c27f 45%, #c08a47 80%, #9a6a33 100%);
  box-shadow: inset 0 6px 12px rgba(70, 40, 10, 0.35), 0 6px 0 rgba(90, 55, 20, 0.2), 0 10px 18px rgba(42, 34, 56, 0.12);
}
.mod-gniazdo .gn-pool.is-gold .gn-pool-bowl {
  box-shadow: inset 0 6px 12px rgba(70, 40, 10, 0.35), 0 0 0 6px var(--gold);
}

/* one column per card: the whole column is the tap target */
.mod-gniazdo .gn-col {
  position: absolute;
  z-index: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.mod-gniazdo .gn-col::before {
  content: '';
  position: absolute;
  left: 6px;
  right: 6px;
  top: 104px;
  bottom: 4px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.34);
  border: 2px solid rgba(226, 213, 184, 0.65);
  opacity: 0;
  transition: opacity 0.4s ease, background-color 0.3s ease;
}
.mod-gniazdo.has-pool .gn-col::before {
  opacity: 1;
}
.mod-gniazdo .gn-col.is-amber::before {
  opacity: 1;
  border: 5px solid var(--err);
  background: rgba(255, 233, 212, 0.55);
}
.mod-gniazdo .gn-col.is-gold::before {
  opacity: 1;
  border: 4px solid var(--gold);
  background: rgba(255, 241, 191, 0.7);
}
.mod-gniazdo .gn-slotmark {
  position: absolute;
  left: 10px;
  top: 6px;
  width: 84px;
  height: 96px;
  border-radius: 13px;
  border: 3px dashed #cbb98f;
  background: rgba(255, 255, 255, 0.28);
  transition: opacity 0.2s ease;
}
.mod-gniazdo .gn-slotmark.is-filled,
.mod-gniazdo.has-pool .gn-slotmark {
  opacity: 0;
}
.mod-gniazdo .gn-col.is-amber .gn-slotmark {
  opacity: 1;
  border: 4px solid var(--err);
  background: rgba(255, 233, 212, 0.5);
}
.mod-gniazdo .gn-ezone {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
}
/* the baby dragon's path down the middle */
.mod-gniazdo .gn-path {
  position: absolute;
  left: 50%;
  top: 108px;
  bottom: 10px;
  width: 4px;
  margin-left: -2px;
  border-radius: 2px;
  background: repeating-linear-gradient(180deg, rgba(123, 92, 214, 0.42) 0 7px, rgba(0, 0, 0, 0) 7px 15px);
  opacity: 0;
  transition: opacity 0.4s ease;
}
.mod-gniazdo.is-walk .gn-path,
.mod-gniazdo.is-odd .gn-path,
.mod-gniazdo.is-done .gn-path {
  opacity: 1;
}

/* number cards 1–10 */
.mod-gniazdo .gn-cards {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}
.mod-gniazdo .gn-card {
  position: absolute;
  width: 80px;
  height: 92px;
  border-radius: 12px;
  background: linear-gradient(180deg, #fffefb, #faf3e3);
  box-shadow: inset 0 0 0 2px #d9ccae, 0 3px 0 rgba(42, 34, 56, 0.14), 0 6px 12px rgba(42, 34, 56, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: translate 0.18s ease, scale 0.18s ease, box-shadow 0.25s ease, background-color 0.25s ease;
  will-change: transform;
}
.mod-gniazdo.is-order .gn-card {
  pointer-events: auto;
}
/* §1.4: the card is drawn 80 × 92; a transparent margin widens its tap area to 92 × 92 (≥ 88). No margin above
   or below: the scattered cards' tap areas stay ≥ 24 px clear of the ear button and of the place columns. */
.mod-gniazdo .gn-card::before {
  content: '';
  position: absolute;
  inset: 0 -6px;
}
.mod-gniazdo .gn-card-num {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 56px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.mod-gniazdo .gn-card.is-hand {
  translate: 0 -14px;
  scale: 1.08;
  z-index: 2;
  box-shadow: inset 0 0 0 2px #d9ccae, 0 0 0 5px var(--accent), 0 16px 24px rgba(42, 34, 56, 0.25);
}
.mod-gniazdo .gn-card.is-flying {
  z-index: 3;
}
.mod-gniazdo .gn-card.is-amber {
  box-shadow: inset 0 0 0 2px #d9ccae, 0 0 0 6px var(--err);
}
.mod-gniazdo .gn-card.is-wobble {
  animation: gn-wobble 0.5s ease;
}
.mod-gniazdo .gn-card.is-ok {
  box-shadow: inset 0 0 0 2px #d9ccae, 0 0 0 5px rgba(242, 183, 5, 0.8);
}
.mod-gniazdo .gn-card.is-gold {
  background: linear-gradient(180deg, #fffbe8, var(--gold-soft));
  box-shadow: inset 0 0 0 2px #e8c860, 0 0 0 6px var(--gold), 0 0 18px rgba(242, 183, 5, 0.55);
}
.mod-gniazdo .gn-card.is-even {
  animation: gn-pulse 0.6s ease;
}
.mod-gniazdo .gn-card.is-picked {
  translate: 0 -4px;
  background: linear-gradient(180deg, #fbf8ff, var(--accent-soft));
  box-shadow: inset 0 0 0 2px #c7b8f0, 0 0 0 6px var(--accent), 0 8px 14px rgba(42, 34, 56, 0.18);
}
.mod-gniazdo .gn-card.is-picked.is-amber {
  box-shadow: inset 0 0 0 2px #c7b8f0, 0 0 0 6px var(--err), 0 8px 14px rgba(42, 34, 56, 0.18);
}
.mod-gniazdo .gn-card.is-picked.is-gold {
  background: linear-gradient(180deg, #fffbe8, var(--gold-soft));
  box-shadow: inset 0 0 0 2px #e8c860, 0 0 0 6px var(--gold), 0 0 18px rgba(242, 183, 5, 0.55);
}
.mod-gniazdo .gn-card-badge {
  position: absolute;
  right: -12px;
  top: -12px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 0 rgba(42, 34, 56, 0.25);
  display: none;
}
.mod-gniazdo .gn-card-badge::after {
  content: '';
  position: absolute;
  left: 9px;
  top: 6px;
  width: 8px;
  height: 13px;
  border-right: 4px solid #fff;
  border-bottom: 4px solid #fff;
  transform: rotate(40deg);
}
.mod-gniazdo .gn-card.is-picked .gn-card-badge {
  display: block;
}
.mod-gniazdo .gn-card.is-picked.is-gold .gn-card-badge {
  background: var(--gold-deep);
}
.mod-gniazdo .gn-ghost-card {
  position: absolute;
  width: 80px;
  height: 92px;
  border-radius: 12px;
  border: 3px dashed var(--err);
  background: rgba(255, 233, 212, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 54px;
  color: rgba(160, 90, 20, 0.55);
}

/* dragon eggs: violet with golden speckles — visual only (the column is the target) */
.mod-gniazdo .gn-egg {
  position: absolute;
  width: 26px;
  height: 32px;
  border-radius: 50% 50% 50% 50% / 58% 58% 42% 42%;
  background:
    radial-gradient(circle at 66% 62%, rgba(255, 214, 102, 0.95) 0 2px, rgba(0, 0, 0, 0) 2.5px),
    radial-gradient(circle at 40% 74%, rgba(255, 214, 102, 0.9) 0 1.6px, rgba(0, 0, 0, 0) 2px),
    radial-gradient(circle at 58% 36%, rgba(255, 214, 102, 0.85) 0 1.4px, rgba(0, 0, 0, 0) 1.8px),
    radial-gradient(circle at 34% 28%, #f3ecff 0 10%, #b9a3f5 24%, #7b5cd6 56%, #4a3591 100%);
  box-shadow: 0 2px 0 rgba(42, 34, 56, 0.28), inset -2px -3px 4px rgba(30, 18, 70, 0.35);
  transition: opacity 0.4s ease;
  will-change: transform;
}
.mod-gniazdo.gn-l2:not(.has-pool) .gn-egg {
  opacity: 0;
}
.mod-gniazdo .gn-egg.is-flying {
  z-index: 2;
  filter: drop-shadow(0 6px 6px rgba(42, 34, 56, 0.3));
}
.mod-gniazdo .gn-egg.is-pulse {
  animation: gn-pulse 0.42s ease;
}
.mod-gniazdo .gn-egg.is-extra {
  animation: gn-extra 0.9s ease-in-out infinite;
  outline: 3px solid var(--err);
  outline-offset: 2px;
}
.mod-gniazdo .gn-egg.is-lone {
  animation: gn-lone 1s ease-in-out infinite;
}
@keyframes gn-lone {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(242, 183, 5, 0)); scale: 1; }
  50% { filter: drop-shadow(0 0 7px rgba(242, 183, 5, 0.95)); scale: 1.15; }
}
.mod-gniazdo .gn-egg.is-wobble {
  animation: gn-wobble 0.55s ease;
}
.mod-gniazdo .gn-ghost-egg {
  position: absolute;
  width: 26px;
  height: 32px;
  border-radius: 50% 50% 50% 50% / 58% 58% 42% 42%;
  border: 3px dashed var(--err);
  background: rgba(255, 233, 212, 0.55);
}

/* the baby dragon walking down the middle */
.mod-gniazdo .gn-walker {
  position: absolute;
  z-index: 6;
  pointer-events: none;
  transition: opacity 0.25s ease;
  filter: drop-shadow(0 3px 2px rgba(42, 34, 56, 0.3));
}
.mod-gniazdo .gn-walker .mat-babydragon {
  display: block;
}
.mod-gniazdo .gn-walker.is-walking .mat-babydragon {
  animation: gn-step 0.32s ease-in-out infinite;
}
.mod-gniazdo .gn-walker.is-bump .mat-babydragon {
  animation: gn-bump 0.5s ease-out;
}
.mod-gniazdo .gn-walker.is-gone {
  opacity: 0;
}
@keyframes gn-step {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(-4px) rotate(5deg); }
}
@keyframes gn-bump {
  0% { transform: translateY(0); }
  30% { transform: translateY(-9px) rotate(-6deg); }
  60% { transform: translateY(0) rotate(4deg); }
  100% { transform: translateY(0) rotate(0); }
}

/* ---------- reduced motion: fades instead of movement ---------- */

/* (the core's #stage.reduced-motion already shortens every transition to 0.15 s) */
@media (prefers-reduced-motion: reduce) {
  .mod-gniazdo .gn-walker.is-walking .mat-babydragon,
  .mod-gniazdo .gn-stick.is-extra,
  .mod-gniazdo .gn-egg.is-extra {
    animation: none;
  }
}
