/* This component only styles the source pile, never the flying tile. */
#draw-pile {
  position: relative;
  flex: 0 0 92px;
  width: 92px;
  height: 92px;
  inset: auto;
  z-index: 2;
  pointer-events: none;
  user-select: none;
}

/* Fallback for an inset pile. Prefer a separate scoreboard cell to keep the
   complete playing surface available to the four-arm game. */
.felt > #draw-pile { position: absolute; top: 15px; right: 15px; }

#draw-pile > .draw-pile-back {
  position: absolute;
  display: block;
  inset: 0 0 auto;
  width: 92px;
  height: 78px;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  opacity: 1;
}
#draw-pile > .draw-pile-back::before,
#draw-pile > .draw-pile-back::after { content: none; }

.pile-stack-art { display: block; width: 100%; height: 100%; overflow: visible; }
.pile-ground-shadow { fill: var(--tile-shadow); opacity: .24; }
.pile-layer { stroke: var(--tile-line); stroke-width: .8; }
.pile-layer-top { fill: var(--tile-back); stroke: var(--tile-back-line); }
.pile-edge-light { fill: var(--tile-face); }
.pile-edge-shade { fill: var(--tile-shade); }
.pile-back-frame { fill: none; stroke: var(--tile-back-line); stroke-width: 1; }
.pile-back-seam { fill: none; stroke: var(--tile-back-line); stroke-width: 1.3; }
.pile-back-detail { fill: var(--tile-back-line); stroke: none; opacity: .65; }
.pile-empty-slot { display: none; fill: none; stroke: var(--felt-muted); stroke-width: 1.5; stroke-dasharray: 3 3; opacity: .65; }

#draw-pile:is([data-count='1'], [data-count='2'], [data-count='3'], [data-count='4']) .pile-layer-deep,
#draw-pile[data-count='1'] .pile-layer-middle { display: none; }
#draw-pile:is([data-count='0'], .is-empty) .pile-full-stack,
#draw-pile:is([data-count='0'], .is-empty) .pile-ground-shadow { display: none; }
#draw-pile:is([data-count='0'], .is-empty) .pile-empty-slot { display: initial; }

#draw-pile > .draw-pile-count {
  position: absolute;
  inset: auto 0 1px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  width: 100%;
  height: auto;
  padding: 0;
  border: 0;
  background: none;
  color: var(--felt-text);
  font: 650 16px/1.2 var(--mono, monospace);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#draw-pile > .draw-pile-count::before { content: '牌库'; }
#draw-pile > .draw-pile-count::after { content: '张'; }
#draw-pile > .draw-pile-count::before,
#draw-pile > .draw-pile-count::after { color: var(--felt-muted); font: 500 12px/1.2 var(--sans, sans-serif); }
#draw-pile:is([data-count='0'], .is-empty) > .draw-pile-count { color: var(--felt-muted); }

/* Equal outer columns keep the opponent's hand on the table centreline. */
.scoreboard:has(> #draw-pile) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr);
  align-items: center;
  column-gap: 12px;
  min-height: 108px;
  padding-block: 8px;
}
.scoreboard:has(> #draw-pile) > .score-player {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  width: auto;
}
.scoreboard:has(> #draw-pile) > .score-player > div:last-child { min-width: 0; }
.scoreboard:has(> #draw-pile) > .score-player strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scoreboard:has(> #draw-pile) > .opponent-hand {
  position: relative;
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  justify-content: center;
  align-items: center;
  width: max-content;
  max-width: 100%;
  margin: 0;
  padding: 0 0 20px;
}
.scoreboard:has(> #draw-pile) > .opponent-hand > small {
  position: absolute;
  inset: auto 0 0;
  margin: 0;
  text-align: center;
  font-size: 12px;
}
.scoreboard > #draw-pile { grid-column: 3; grid-row: 1; justify-self: end; }
/* Keep the empty right-hand cell in Block, so changing rules never shifts the hand. */
.scoreboard:has(> #draw-pile[hidden]) { min-height: 96px; }

@media (max-width: 1100px) {
  .scoreboard:has(> #draw-pile) > .opponent-hand .tile-back:nth-child(n+8) { display: none; }
}

@media (max-width: 850px) {
  .scoreboard:has(> #draw-pile) {
    grid-template-rows: auto auto;
    gap: 2px 10px;
    padding-block: 8px;
  }
  .scoreboard:has(> #draw-pile) > .score-display {
    position: relative;
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
    top: auto;
    left: auto;
    transform: none;
    padding-bottom: 19px;
    gap: 10px;
  }
  .scoreboard:has(> #draw-pile) > .score-display > strong { font-size: 22px; line-height: 1; }
  .scoreboard:has(> #draw-pile) > .score-display > span { font-size: 17px; line-height: 1; }
  .scoreboard:has(> #draw-pile) > .score-display > small { font-size: 11px; }
}

@media (max-width: 600px) {
  #draw-pile { flex-basis: 76px; width: 76px; height: 80px; }
  #draw-pile > .draw-pile-back { width: 76px; height: 64px; }
  #draw-pile > .draw-pile-count { font-size: 15px; }
  .felt > #draw-pile { top: 12px; right: 12px; }
  .scoreboard:has(> #draw-pile) { grid-template-columns: 82px minmax(0, 1fr) 82px; column-gap: 5px; }
  .scoreboard:has(> #draw-pile) > .score-player { gap: 6px; }
  .scoreboard:has(> #draw-pile) > .score-player .avatar { width: 32px; height: 32px; flex: 0 0 32px; }
  .scoreboard:has(> #draw-pile) > .score-player small { font-size: 10px; line-height: 1.4; }
  .scoreboard:has(> #draw-pile) > .opponent-hand { gap: 3px; padding-bottom: 21px; }
  .scoreboard:has(> #draw-pile) > .opponent-hand .tile-back { width: 11px; flex-basis: 11px; height: 27px; }
}
