/* Brolly Bobbins Felt-and-Button screen transition (DESIGN.md section 9).
   Two painted Harbour-Teal wool-felt panels (scalloped upper hem with cream whip-stitches, stitched oak-and-brass seam bar
   on the lower panel) meet cleanly at the midline, a glossy chestnut-wood & brass button (~108 px) spins onto the seam with
   braided X-stitch threads holding it fast, a stitched cream linen Tailor's Label unrolls for a new district, and two crossed
   gold scissor-snip lines flash across the X-thread as the felt opens.
   Above the map and win card (.nm, z 20), below toasts (z 40).
   Motion is transform / opacity only, zero CSS filters; hidden (display: none) when idle. */
.nx {
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow: hidden;
  pointer-events: auto;
  font-family: "Baloo 2", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  font-weight: 800;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  --nx-t: .38s;
  --nx-felt: url("../../../packs/swap-bobbins/ui/transition/felt-tile.webp");
  --nx-hem-img: url("../../../packs/swap-bobbins/ui/transition/hem-top.webp");
  --nx-bar-img: url("../../../packs/swap-bobbins/ui/transition/seam-bar.webp");
  --nx-btn: url("../../../packs/swap-bobbins/ui/transition/button.webp");
  --nx-xs: url("../../../packs/swap-bobbins/ui/transition/xstitch.webp");
  --nx-label: url("../../../packs/swap-bobbins/ui/transition/label.webp");
  --nx-snip: url("../../../packs/swap-bobbins/ui/transition/snip.webp");
}
.nx[hidden] { display: none; }
.nx.open { pointer-events: none; --nx-t: .48s; }
.nx.quick { --nx-t: .30s; }
.nx.quick.open { --nx-t: .38s; }

/* Opaque painted Harbour-Teal wool-felt panels (tile seamlessly to any portrait, landscape, or tablet viewport) */
.nx-p {
  position: absolute;
  left: 0;
  right: 0;
  height: calc(50% + 2px);
  will-change: transform;
  background-color: #2d5263;
  background-image: var(--nx-felt);
  background-repeat: repeat;
  background-size: 256px 256px;
  transition: transform var(--nx-t) cubic-bezier(.30, .10, .20, 1);
}
.nx.open .nx-p { transition-timing-function: cubic-bezier(.26, .08, .20, 1); }

/* Subtle cream blanket-stitched side inset borders along the left/right edges of both felt halves */
.nx-p::before {
  content: "";
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 10px;
  right: 10px;
  pointer-events: none;
  border-left: 2px dashed rgba(255, 243, 220, .34);
  border-right: 2px dashed rgba(255, 243, 220, .34);
}
.nx-a::before { border-top: 2px dashed rgba(255, 243, 220, .28); bottom: 18px; }
.nx-b::before { border-bottom: 2px dashed rgba(255, 243, 220, .28); top: 44px; }

.nx-a {
  top: 0;
  z-index: 2;
  transform: translate3d(0, calc(-100% - 20px), 0);
  box-shadow: inset 0 54px 56px -26px rgba(10, 26, 34, .46), inset 16px 0 32px -18px rgba(10, 26, 34, .34), inset -16px 0 32px -18px rgba(10, 26, 34, .34);
}
.nx-b {
  bottom: 0;
  z-index: 1;
  transform: translate3d(0, calc(100% + 4px), 0);
  box-shadow: inset 0 -54px 56px -26px rgba(10, 26, 34, .46), inset 16px 0 32px -18px rgba(10, 26, 34, .34), inset -16px 0 32px -18px rgba(10, 26, 34, .34);
}
.nx.shut .nx-p { transform: translate3d(0, 0, 0); }

/* Scalloped upper hem with painted warm cream whip-stitches + baked contact shadow (horizontally seamless) */
.nx-hem {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -18px;
  height: 68px;
  pointer-events: none;
  background-image: var(--nx-hem-img);
  background-repeat: repeat-x;
  background-position: center bottom;
  background-size: 192px 68px;
}

/* Stitched varnished oak-and-brass seam bar along top edge of lower felt panel (horizontally seamless) */
.nx-bar {
  position: absolute;
  left: 0;
  right: 0;
  top: -2px;
  height: 54px;
  pointer-events: none;
  background-image: var(--nx-bar-img);
  background-repeat: repeat-x;
  background-position: center top;
  background-size: 210px 54px;
}

/* Centre anchor layer (above both felt panels) */
.nx-mid {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

/* Glossy Chestnut-Wood & Brass Button (~108 px visual diameter inside 124 px shadow box), pinned dead-on the midline seam */
.nx-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 124px;
  height: 124px;
  margin-left: -62px;
  margin-top: -62px;
  display: grid;
  place-items: center;
  opacity: 0;
  will-change: transform, opacity;
  transform: scale(.25) rotate(-180deg);
  transition: transform .30s cubic-bezier(.26, 1.38, .48, 1) .11s, opacity .14s linear .11s;
}
.nx.quick .nx-knob {
  transition: transform .24s cubic-bezier(.26, 1.36, .48, 1) .08s, opacity .12s linear .08s;
}
.nx-btn-bg,
.nx-xs {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
}
.nx-btn-bg { background-image: var(--nx-btn); }
.nx-xs {
  background-image: var(--nx-xs);
  opacity: 0;
  transform: scale(1.22);
  will-change: transform, opacity;
  transition: transform .16s cubic-bezier(.2, 1.3, .4, 1) .24s, opacity .11s linear .24s;
}
.nx.quick .nx-xs {
  transition: transform .14s cubic-bezier(.2, 1.3, .4, 1) .18s, opacity .10s linear .18s;
}

/* Level number, House icon, or Restart arrow: crisp and readable over the chestnut button & X-stitch */
.nx-knob b {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(36, 16, 8, .46) 0%, rgba(36, 16, 8, .22) 48%, rgba(36, 16, 8, 0) 74%);
  color: #fff8e7;
  font-size: 38px;
  line-height: 1;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  text-shadow:
    0 2px 0 #2a1d16,
    0 -1.5px 0 #2a1d16,
    2px 0 0 #2a1d16,
    -2px 0 0 #2a1d16,
    1.5px 1.5px 0 #2a1d16,
    -1.5px 1.5px 0 #2a1d16,
    0 4px 10px rgba(20, 10, 4, .75);
}
.nx-knob b.long { font-size: 30px; }
.nx-knob b.mk svg { display: block; width: 44px; height: 44px; }

.nx.shut .nx-knob { opacity: 1; transform: scale(1) rotate(0deg); }
.nx.shut .nx-xs { opacity: 1; transform: scale(1); }

/* Scissor-snip cue: two crossed gleaming gold slash lines flash across the X-thread right as the seam opens */
.nx-snip {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 152px;
  height: 152px;
  margin-left: -76px;
  margin-top: -76px;
  z-index: 4;
  pointer-events: none;
  background: var(--nx-snip) center / 100% 100% no-repeat;
  opacity: 0;
  transform: scale(.35) rotate(-14deg);
  will-change: transform, opacity;
}
.nx.snip .nx-snip {
  animation: nx-snip-flash .24s cubic-bezier(.16, .9, .3, 1) forwards;
}
.nx.snip .nx-xs {
  opacity: 0;
  transform: scale(1.26);
  transition: transform .09s ease-out, opacity .09s linear;
}
@keyframes nx-snip-flash {
  0%   { opacity: 0; transform: scale(.35) rotate(-12deg); }
  28%  { opacity: 1; transform: scale(1.08) rotate(0deg); }
  62%  { opacity: .95; transform: scale(1.16) rotate(3deg); }
  100% { opacity: 0; transform: scale(1.30) rotate(6deg); }
}

.nx.open .nx-knob {
  opacity: 0;
  transform: scale(.38) rotate(160deg);
  transition: transform .26s cubic-bezier(.58, 0, .86, .36) .04s, opacity .18s linear .08s;
}
.nx.quick.open .nx-knob {
  transition: transform .22s cubic-bezier(.58, 0, .86, .36) .03s, opacity .15s linear .06s;
}

/* Stitched cream linen Tailor's Label for a new district (`big: true`): unrolls cleanly below the centre button */
.nx-plate {
  position: absolute;
  left: 50%;
  top: calc(50% + 66px);
  min-width: 240px;
  max-width: min(88vw, 390px);
  padding: 2px 10px 4px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  border-style: solid;
  border-color: transparent;
  border-width: 24px 38px 26px 38px;
  border-image-source: var(--nx-label);
  border-image-slice: 56 80 60 80 fill;
  border-image-repeat: stretch;
  color: #2a1d16;
  font-size: 20px;
  line-height: 1.15;
  text-align: center;
  opacity: 0;
  will-change: transform, opacity;
  transform: translate3d(-50%, -10px, 0) scaleY(.2);
  transform-origin: center top;
  transition: transform .28s cubic-bezier(.22, 1.24, .42, 1) .28s, opacity .18s linear .28s;
}
.nx-plate span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  text-shadow: 0 1px 0 rgba(255, 250, 238, .85);
}
.nx-plate[hidden] { display: none; }
.nx.shut .nx-plate {
  opacity: 1;
  transform: translate3d(-50%, 0, 0) scaleY(1);
}
.nx.open .nx-plate {
  opacity: 0;
  transform: translate3d(-50%, 8px, 0) scaleY(.75);
  transition: transform .18s ease-in, opacity .16s linear;
}

/* Short landscape phones (e.g. 844x390): keep button, seam, and district label completely inside viewport */
@media (max-height: 440px) {
  .nx-hem { height: 54px; bottom: -14px; background-size: 152px 54px; }
  .nx-bar { height: 44px; background-size: 170px 44px; }
  .nx-knob { width: 98px; height: 98px; margin-left: -49px; margin-top: -49px; }
  .nx-knob b { width: 56px; height: 56px; font-size: 31px; }
  .nx-knob b.long { font-size: 24px; }
  .nx-knob b.mk svg { width: 36px; height: 36px; }
  .nx-snip { width: 124px; height: 124px; margin-left: -62px; margin-top: -62px; }
  .nx-plate {
    top: calc(50% + 52px);
    min-width: 210px;
    border-width: 18px 32px 20px 32px;
    font-size: 17px;
  }
}

/* Reduced motion: one calm wool-felt scrim fades in and out; nothing travels, scales, or spins */
.nx.rm .nx-p {
  transform: none;
  opacity: 0;
  transition: opacity .15s linear;
}
.nx.rm.shut .nx-p { opacity: 1; }
.nx.rm.open .nx-p { opacity: 0; transition: opacity .19s linear; }
.nx.rm .nx-hem,
.nx.rm .nx-bar,
.nx.rm .nx-snip,
.nx.rm .nx-p::before { display: none; }
.nx.rm .nx-knob {
  transform: none;
  opacity: 0;
  transition: opacity .14s linear;
}
.nx.rm .nx-xs {
  transform: none;
  opacity: 1;
  transition: none;
}
.nx.rm.shut .nx-knob { opacity: 1; }
.nx.rm.open .nx-knob { opacity: 0; transform: none; transition: opacity .16s linear; }
.nx.rm .nx-plate {
  transform: translate3d(-50%, 0, 0);
  opacity: 0;
  transition: opacity .14s linear;
}
.nx.rm.shut .nx-plate { opacity: 1; transform: translate3d(-50%, 0, 0); }
.nx.rm.open .nx-plate { opacity: 0; transform: translate3d(-50%, 0, 0); transition: opacity .16s linear; }
