/* Admin 牌局重現：牌桌樣式（參考 WebOnline） */
.fx-flying-tile {
  border-radius: 5px;
  background: linear-gradient(180deg, #fffefc 0%, #f7f0e0 58%, #e8d9bc 100%);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.fx-flying-tile .tile-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.replay-modal {
  --felt: #1a5c3a;
  --felt-deep: #0f3d28;
  --felt-light: #2a7a4e;
  --wood: #5c3a1e;
  --cream: #f3efe4;
  --ink: #1a1814;
  --tile-face-bg: linear-gradient(180deg, #fffefc 0%, #f7f0e0 58%, #e8d9bc 100%);
  --tile-w: 2.1rem;
  --tile-h: 2.85rem;
  --tile-sm-w: calc(var(--tile-w) * 0.72);
  --tile-sm-h: calc(var(--tile-h) * 0.72);
  --font-display: "Noto Serif TC", "PingFang TC", serif;
  --font-body: "Noto Sans TC", "PingFang TC", sans-serif;

  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
}

.replay-modal[hidden] {
  display: none !important;
}

body.replay-open {
  overflow: hidden;
}

.replay-modal__panel {
  width: min(1180px, 100%);
  max-height: calc(100vh - 24px);
  display: flex;
  flex-direction: column;
  background: #121a16;
  border: 1px solid rgba(196, 163, 90, 0.35);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.replay-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.replay-modal__head h2 {
  margin: 0;
  font-size: 1.1rem;
  color: #e6c66e;
}

.replay-modal__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.2);
}

.replay-modal__controls label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  color: #b8b0a0;
}

.replay-modal__controls input[type='number'] {
  width: 4.5rem;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.35);
  color: #f3efe4;
}

.replay-modal__meta {
  flex: 1;
  min-width: 200px;
  font-size: 0.86rem;
  color: #9aa89f;
}

.replay-modal__stage-wrap {
  flex: 1;
  min-height: 0;
  padding: 10px 12px 14px;
  overflow: auto;
}

#replayStage {
  min-height: 560px;
  height: min(74vh, 720px);
  overflow: visible;
}

#replayStage .table {
  width: 100%;
  height: 100%;
  min-height: 540px;
  display: grid;
  --seat-side-w: calc(var(--tile-sm-w) * 3.5 + 1.5rem);
  --seat-top-h: calc(var(--tile-sm-h) * 2.2 + 1.8rem);
  --seat-bottom-h: calc(var(--tile-h) * 1.6 + var(--tile-sm-h) + 2.4rem);
  grid-template-columns: var(--seat-side-w) minmax(0, 1fr) var(--seat-side-w);
  grid-template-rows: var(--seat-top-h) minmax(0, 1fr) var(--seat-bottom-h);
  grid-template-areas:
    'top top top'
    'left center right'
    'bottom bottom bottom';
  gap: 0.3rem 0.45rem;
  background: radial-gradient(ellipse at center, var(--felt-light) 0%, var(--felt) 45%, var(--felt-deep) 100%);
  border: 4px solid var(--wood);
  border-radius: 12px;
  padding: 0.45rem 0.55rem;
  position: relative;
  overflow: visible;
  color: var(--cream);
  font-family: var(--font-body);
}

#replayStage .fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 60;
}

#replayStage .seat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  position: relative;
  min-width: 0;
  overflow: visible;
  z-index: 2;
}

#replayStage .seat--top { grid-area: top; overflow: visible; }
#replayStage .seat--left { grid-area: left; align-items: flex-start; justify-content: center; overflow: visible; }
#replayStage .seat--right { grid-area: right; align-items: flex-end; justify-content: center; overflow: visible; }
#replayStage .seat--bottom { grid-area: bottom; overflow: visible; }

#replayStage .seat-fx {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 12;
}

#replayStage .seat-name {
  font-size: 0.82rem;
  font-weight: 600;
  opacity: 0.9;
}

#replayStage .seat-name--turn { color: #ff6b6b; font-weight: 900; }
#replayStage .seat-name--winner { color: #ffd24d; }

#replayStage .seat--turn {
  box-shadow: inset 0 0 0 2px rgba(255, 80, 80, 0.35);
  border-radius: 8px;
}

#replayStage .seat--left,
#replayStage .seat--right {
  z-index: 5;
}

#replayStage .seat-hand,
#replayStage .player-hand {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: center;
  align-items: flex-end;
  min-height: calc(var(--tile-sm-h) + 4px);
  position: relative;
  z-index: 2;
}

#replayStage .player-hand {
  min-height: calc(var(--tile-h) + 6px);
}

#replayStage .seat-melds,
#replayStage .player-melds {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  justify-content: center;
}

#replayStage .seat-front {
  position: absolute;
  z-index: 14;
  display: flex;
  pointer-events: none;
}

#replayStage .seat-front .seat-melds:not(:empty),
#replayStage .seat-front .player-melds:not(:empty) {
  pointer-events: auto;
  flex-wrap: nowrap;
  gap: 0.35rem;
  padding: 0.15rem 0.25rem;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 6px;
  border: 1px solid rgba(230, 198, 110, 0.28);
  min-width: calc(var(--tile-sm-w) * 2.5);
}

#replayStage .seat-front .meld {
  margin: 0;
  padding: 2px;
  gap: 2px;
  background: rgba(0, 0, 0, 0.16);
}

#replayStage .seat-front .tile {
  width: var(--tile-sm-w);
  height: var(--tile-sm-h);
}

#replayStage .seat--top .seat-front {
  top: calc(100% + 0.12rem);
  left: 50%;
  transform: translateX(-50%);
  max-width: min(90%, 28rem);
}

#replayStage .seat--top .seat-melds {
  flex-direction: row;
  justify-content: center;
}

#replayStage .seat--left .seat-front {
  left: calc(100% - 2px);
  top: 50%;
  transform: translateY(-50%);
  max-height: 90%;
  width: max-content;
}

#replayStage .seat--left .seat-melds {
  flex-direction: column;
  align-items: flex-start;
  max-height: min(60vh, 18rem);
  overflow-y: auto;
}

#replayStage .seat--left .meld {
  flex-direction: row;
  flex-wrap: nowrap;
}

#replayStage .seat--right .seat-front {
  right: calc(100% - 2px);
  left: auto;
  top: 50%;
  transform: translateY(-50%);
  max-height: 90%;
  width: max-content;
}

#replayStage .seat--right .seat-melds {
  flex-direction: column;
  align-items: flex-end;
  max-height: min(60vh, 18rem);
  overflow-y: auto;
}

#replayStage .seat--right .meld {
  flex-direction: row;
  flex-wrap: nowrap;
}

#replayStage .seat-front--player {
  position: relative;
  inset: auto;
  transform: none;
  flex: 0 0 auto;
  width: 100%;
  min-height: calc(var(--tile-sm-h) + 0.35rem);
  justify-content: center;
  z-index: 3;
  margin-bottom: 4px;
}

#replayStage .seat--bottom .seat-front--player .player-melds {
  background: transparent;
  border: none;
  padding: 0.1rem 0;
}

#replayStage .player-hand-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

#replayStage .table-center {
  grid-area: center;
  place-self: center;
  /* 容納 11×6 河牌格盤，避免內部捲軸 */
  width: min(
    100%,
    calc(var(--tile-sm-w) * 11 + 3px * 10 + 24px)
  );
  height: min(
    100%,
    calc(var(--tile-sm-h) * 6 + 3px * 5 + 3.2rem)
  );
  min-width: calc(var(--tile-sm-w) * 11 + 3px * 10 + 24px);
  min-height: calc(var(--tile-sm-h) * 6 + 3px * 5 + 3.2rem);
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: auto;
  position: relative;
  z-index: 1;
}

#replayStage .walls {
  position: relative;
  width: 100%;
  height: 100%;
}

#replayStage .river-block {
  position: absolute;
  inset: 2%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  overflow: visible;
}

#replayStage .replay-wall-info {
  font-size: 0.75rem;
  color: rgba(243, 239, 228, 0.75);
  letter-spacing: 0.05em;
  flex: 0 0 auto;
}

#replayStage .river {
  --river-cols: 11;
  --river-rows: 6;
  --river-gap: 3px;
  display: grid;
  grid-template-columns: repeat(var(--river-cols), var(--tile-sm-w));
  grid-template-rows: repeat(var(--river-rows), var(--tile-sm-h));
  gap: var(--river-gap);
  align-content: start;
  justify-content: start;
  box-sizing: content-box;
  padding: 6px;
  margin: 0;
  overflow: visible;
  max-width: none;
  max-height: none;
}

#replayStage .river .tile {
  width: var(--tile-sm-w);
  height: var(--tile-sm-h);
}

#replayStage .dice-stage {
  text-align: center;
  margin-bottom: 4px;
}

#replayStage .dice-label {
  font-family: var(--font-display);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
}

#replayStage .dice-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin: 4px 0;
}

#replayStage .die {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 8px;
  background: #f7f0e0;
  color: #1a1814;
  font-size: 1.6rem;
}

#replayStage .dice-sum {
  color: #ffd24d;
  font-weight: 700;
  font-size: 0.85rem;
}

#replayStage .tile {
  display: inline-block;
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: 5px;
  background: var(--tile-face-bg);
  box-shadow: 0 2px 0 #b8a985, 0 3px 4px rgba(0, 0, 0, 0.28);
  overflow: hidden;
  flex: 0 0 auto;
}

#replayStage .tile--sm {
  width: var(--tile-sm-w);
  height: var(--tile-sm-h);
}

#replayStage .tile--drawn {
  transform: translateY(-12%);
  outline: 2px solid #ffd24d;
  outline-offset: 1px;
}

#replayStage .tile--fresh,
#replayStage .tile--claimed {
  outline: 2px solid #ff6b6b;
  outline-offset: 1px;
}

#replayStage .tile--win {
  outline: 2px solid #ffd24d;
  box-shadow: 0 0 10px rgba(255, 210, 77, 0.6);
}

#replayStage .tile-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}

#replayStage .meld {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}

#replayStage .seat-play { display: contents; }

#replayStage .seat-reveal {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  align-items: center;
}

#replayStage .table--round-end .seat-play { display: none; }
#replayStage .table--round-end .seat-reveal { display: flex !important; }

#replayStage .seat-reveal__melds,
#replayStage .seat-reveal__hand {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  justify-content: center;
}

#replayStage .seat-fx .fx-callout {
  position: relative;
  left: auto;
  top: auto;
  transform: none;
  width: clamp(3rem, 42%, 4.5rem);
  height: clamp(3rem, 42%, 4.5rem);
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4.5vw, 2.4rem);
  font-weight: 900;
  color: #ffe08a;
  background: rgba(8, 22, 16, 0.72);
  border: 1px solid rgba(240, 230, 210, 0.32);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  animation: replay-fx-pop-seat 0.9s ease-out forwards;
}

#replayStage .fx-callout--mo { color: #9ad7ff; }
#replayStage .fx-callout--chi { color: #7dffb3; }
#replayStage .fx-callout--pong { color: #ffb86b; }
#replayStage .fx-callout--kong { color: #d4a5ff; }
#replayStage .fx-callout--hu { color: #ff6b6b; }
#replayStage .fx-callout--discard { color: #ffe08a; }

@keyframes replay-fx-pop-seat {
  0% { opacity: 0; transform: scale(0.55); }
  20% { opacity: 1; transform: scale(1.08); }
  100% { opacity: 0.95; transform: scale(1); }
}

@media (max-width: 800px) {
  #replayStage {
    min-height: 420px;
    height: 58vh;
  }
  #replayStage .table {
    --tile-w: 1.65rem;
    --tile-h: 2.25rem;
  }
}
