.mod-panel { width: min(1320px, 94vw); background: rgba(8,12,16,.96); border: 1px solid #24333d;
            border-radius: 10px; padding: 18px 22px 16px; }
.mod-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.mod-head .title { font-size: 26px; letter-spacing: 6px; }
.mod-take { display: flex; align-items: center; gap: 14px; }
.mod-purse { display: flex; align-items: center; gap: 8px; font-size: 22px; color: #ffd970;
            letter-spacing: 1px; }
#mod-coins { display: inline-block; min-width: 2ch; text-align: right; }

/* Unseen until the take lands, but laid out: the flight aims at this box. */
#mod-gain {
  font-size: 14px; letter-spacing: 2px; color: #ffd970;
  padding: 4px 10px; border: 1px solid rgba(255,217,112,.3); border-radius: 999px;
  background: rgba(255,217,112,.07);
  visibility: hidden;
}
#mod-gain.hidden { display: none; }
@keyframes gainBanked {
  0%   { border-color: rgba(255,217,112,.95); box-shadow: 0 0 26px rgba(255,190,60,.6); }
  100% { border-color: rgba(255,217,112,.3); box-shadow: none; }
}
#mod-gain.banked { visibility: visible; }
#modules.reveal #mod-gain.banked { animation: gainBanked .7s ease-out; }

#mod-flight { position: fixed; inset: 0; pointer-events: none; z-index: 8; }
.coinfly {
  position: absolute; left: 0; top: 0; width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe9a0, #ffc63d 55%, #b8801a);
  box-shadow: 0 0 12px rgba(255,190,60,.55);
  will-change: transform, opacity;
}

.mod-body { display: flex; gap: 14px; align-items: stretch; }

#mod-stats { flex: 0 0 260px; height: calc(100vh - 172px); min-height: 420px; margin: 12px 0;
             display: flex; flex-direction: column; font-size: 12px; }
.s-list { flex: 1; overflow-y: auto; padding: 4px 12px 10px 2px; }
.s-head { font-size: 10px; letter-spacing: 2.5px; color: #5f7a88; margin: 14px 0 6px; }
.s-head:first-child { margin-top: 2px; }
.s-row { display: flex; justify-content: space-between; align-items: baseline;
         padding: 3px 0; border-bottom: 1px solid #141f26; }
.s-row span { color: #6d8592; letter-spacing: 1px; font-size: 11px; }
.s-row b { color: #cfe3ec; font-weight: 400; }

.s-fold { margin-top: 14px; }
.s-fold summary { margin: 0 0 6px; cursor: pointer; list-style: none;
                  display: flex; align-items: center; gap: 6px; }
.s-fold summary::-webkit-details-marker { display: none; }
.s-fold summary::before { content: '\25B8'; font-size: 9px; transition: transform .15s ease; }
.s-fold[open] summary::before { transform: rotate(90deg); }
.s-fold summary:hover { color: #8fb0c0; }

.s-dead { margin: 10px 12px 0 2px; padding-top: 12px; border-top: 1px solid #26323a;
          text-align: center; }
.s-dead-n { font-size: 46px; line-height: 1; color: #ff8f7e;
            text-shadow: 0 0 24px rgba(255,90,70,.35); }
.s-dead-label { font-size: 10px; letter-spacing: 3px; color: #5f7a88; margin: 7px 0 9px; }
/* Wrapped inline rather than a scrolling column: a run with a dozen bad waves
   is a handful of marks, not a list to scroll through. */
.s-dead-waves { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px 9px; }
.s-dead-waves span { font-size: 11px; letter-spacing: .5px; color: #52697a; white-space: nowrap; }
.s-dead-waves i { font-style: normal; font-weight: 700; color: #ff8f7e; margin-left: 1px; }

#tree-view {
  position: relative; flex: 1; height: calc(100vh - 172px); min-height: 420px; margin: 12px 0;
  border: 1px solid #1c2a33; border-radius: 8px; overflow: hidden;
  background:
    radial-gradient(circle at 50% 50%, rgba(125,211,252,.06), transparent 58%),
    #080d11;
  cursor: grab; touch-action: none;
}
#tree-view.dragging { cursor: grabbing; }

#tree-pan { position: absolute; left: 0; top: 0; width: 0; height: 0;
            transform-origin: 0 0; }

#tree-edges { position: absolute; left: -1200px; top: -1200px; pointer-events: none; }
#tree-edges .edge { fill: none; stroke: #2b3f4b; stroke-width: 2.5; }
#tree-edges .edge.open { stroke: #3d6473; }
#tree-edges .edge.done { stroke: #58a6c4; }
#tree-edges .stub { fill: none; stroke-width: 2.5; stroke-linecap: round; }
#tree-edges .gone { display: none; }

.tnode {
  position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px;
  display: grid; place-items: center;
  border-radius: 50%; border: 1px solid #47616f; background: #17242c;
  color: #86a0ae; cursor: pointer; padding: 0;
  transition: transform .12s ease, border-color .12s, color .12s, background .12s;
}
.tnode.hub { width: 46px; height: 46px; margin: -23px 0 0 -23px; }
.tnode:hover { transform: scale(1.25); z-index: 3; }
.tnode.gone { display: none; }
.tico { width: 24px; height: 24px; fill: none; stroke: currentColor;
        stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.tnode.owned { color: #06171f; border-color: #7fd8f5; background: #4fbbdf; }
.tnode.owned.hub .tico { stroke-width: 2; }

.tnode.afford { color: #ffd970; border-color: #ffd970; background: #2a2110;
                box-shadow: 0 0 0 1px rgba(255,217,112,.3), 0 0 18px rgba(255,217,112,.3); }
@keyframes nodeReady { 0%, 100% { box-shadow: 0 0 0 1px rgba(255,217,112,.3), 0 0 18px rgba(255,217,112,.3); }
                       50% { box-shadow: 0 0 0 1px rgba(255,217,112,.45), 0 0 26px rgba(255,217,112,.5); } }
.tnode.afford.hub { animation: nodeReady 2.2s ease-in-out infinite; }

.tnode.short { color: #c9a64e; border-color: #d8b757; background: #241f12;
               border-style: dashed; }
.tnode.locked { color: #63808f; border-color: #3f5867; background: #142027; }
.tnode.locked:hover { transform: scale(1.15); }
@keyframes nodeBought { 0% { transform: scale(1); } 45% { transform: scale(1.3); } 100% { transform: scale(1); } }
.tnode.bought { animation: nodeBought .26s ease-out; }


/* `stage-*` gates what is on screen, `.reveal` gates the animations: a skip
   keeps the stages and drops the class to land on the final state. */
#modules:not(.stage-stats) .mod-panel { pointer-events: none; }
#modules:not(.stage-tally) #mod-tally { visibility: hidden; }
#modules:not(.stage-tree) #tree-view,
#modules:not(.stage-stats) #mod-stats,
#modules:not(.stage-stats) .mod-actions { opacity: 0; }

@keyframes modWash { from { opacity: 0; } to { opacity: 1; } }
#modules.reveal { animation: modWash .2s ease-out; }

/* Centred with `translate` so `transform` is free for the flight and the pops. */
#mod-tally {
  position: fixed; left: 50%; top: 50%; translate: -50% -50%;
  display: flex; align-items: center; gap: 20px; z-index: 9; pointer-events: none;
  font-size: 78px; letter-spacing: 4px; color: #ffd970;
  text-shadow: 0 0 44px rgba(255,190,60,.5);
  will-change: transform, opacity;
}
#mod-tally .coin-dot { width: 46px; height: 46px; box-shadow: 0 0 22px rgba(255,190,60,.5); }

/* Rides inside the tally, so it flies to the purse and fades with the count it
   belongs to instead of being left behind on the floor of the screen. */
#mod-bonus {
  position: absolute; top: 100%; left: 50%; translate: -50% 0; margin-top: 16px;
  display: flex; align-items: baseline; justify-content: center; gap: 12px;
  white-space: nowrap; font-size: 15px; letter-spacing: 5px; color: #7ee0a1;
  text-shadow: 0 0 22px rgba(126,224,161,.4);
}
#mod-bonus b { font-size: 21px; font-weight: 700; color: #ffd970; letter-spacing: 2px; }
#mod-bonus.hidden { display: none; }
#modules:not(.stage-bonus) #mod-bonus { visibility: hidden; }
@keyframes bonusIn {
  from { opacity: 0; transform: translateY(14px) scale(.86); }
  to   { opacity: 1; transform: none; }
}
#modules.reveal.stage-bonus #mod-bonus { animation: bonusIn .34s cubic-bezier(.16,.9,.24,1); }
@keyframes tallyIn { from { opacity: 0; } to { opacity: 1; } }
#modules.reveal.stage-tally #mod-tally { animation: tallyIn .22s ease-out; }

@keyframes panelIn {
  from { opacity: 0; transform: translateY(28px) scale(.96); }
  to   { opacity: 1; transform: none; }
}
#modules.reveal .mod-panel { animation: panelIn .44s cubic-bezier(.16,.9,.24,1); }

@keyframes titleIn {
  from { opacity: 0; letter-spacing: 22px; filter: blur(7px); }
  to   { opacity: 1; letter-spacing: 6px; filter: none; }
}
@keyframes titleFlare {
  0%   { text-shadow: none; }
  30%  { text-shadow: 0 0 26px rgba(125,211,252,.9); }
  100% { text-shadow: none; }
}
@keyframes titleFail {
  0%   { text-shadow: none; color: #ff8f7e; }
  30%  { text-shadow: 0 0 26px rgba(255,90,70,.8); color: #ff8f7e; }
  100% { text-shadow: none; }
}
#modules.reveal .mod-head .title {
  animation: titleIn .5s cubic-bezier(.16,.9,.24,1) .04s backwards, titleFail 1s ease-out .1s;
}
#modules.reveal.cleared .mod-head .title {
  animation: titleIn .5s cubic-bezier(.16,.9,.24,1) .04s backwards, titleFlare 1s ease-out .1s;
}

@keyframes takeIn { from { opacity: 0; } to { opacity: 1; } }
#modules.reveal .mod-take { animation: takeIn .4s ease-out .14s backwards; }

@keyframes edgesIn { from { opacity: 0; } to { opacity: 1; } }
#modules.reveal.stage-tree #tree-edges { animation: edgesIn .5s ease-out .1s backwards; }

@keyframes nodeIn { from { opacity: 0; transform: scale(.2); } to { opacity: 1; transform: scale(1); } }
#modules.reveal.stage-tree .tnode:not(.bought) {
  animation: nodeIn .36s cubic-bezier(.2,1.5,.4,1) backwards;
  animation-delay: calc(var(--i, 0) * 30ms);
}

@keyframes treeWash { from { opacity: .9; transform: scale(.35); } to { opacity: 0; transform: scale(1.2); } }
#modules.reveal.stage-tree #tree-view::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(circle at 50% 50%, rgba(125,211,252,.22), transparent 62%);
  animation: treeWash .8s ease-out both;
}

@keyframes rowIn { from { opacity: 0; transform: translateX(-16px); } to { opacity: 1; transform: none; } }
#modules.reveal.stage-stats .s-head,
#modules.reveal.stage-stats .s-row,
#modules.reveal.stage-stats .s-dead {
  animation: rowIn .32s ease-out backwards;
  animation-delay: calc(var(--i, 0) * 24ms);
}

@keyframes actionIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
#modules.reveal.stage-stats .mod-actions .btn { animation: actionIn .34s ease-out backwards; }
#modules.reveal.stage-stats #btn-retry { animation-delay: .12s; }
#modules.reveal.stage-stats #btn-next { animation-delay: .2s; }

.mod-actions { display: flex; gap: 10px; justify-content: flex-end; }
.mod-actions .btn { margin: 0; }
