/* ==========================================================================
   TZAAR replay widget
   ========================================================================== */

.retro-match-replay--tzaar {
  margin: 1rem 0 1.4rem;
}

.retro-match-replay--tzaar .retro-match-replay__title {
  margin: 0 0 0.6rem;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.retro-match-replay--tzaar .retro-match-replay__controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.retro-match-replay--tzaar .retro-match-replay__nav-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.retro-match-replay--tzaar .retro-match-replay__controls button,
.retro-match-replay--tzaar .retro-match-replay__controls select {
  border: 1px solid var(--retro-line);
  background: var(--retro-surface-highlight);
  color: var(--retro-ink);
  font-family: var(--retro-sans);
  cursor: pointer;
}

.retro-match-replay--tzaar .retro-match-replay__controls .retro-match-replay__control-btn,
.retro-match-replay--tzaar .retro-match-replay__controls .retro-match-replay__speed-select {
  border-width: 2px;
  border-style: solid;
  border-color: var(--retro-line);
  border-radius: 0.35rem;
  box-shadow: 2px 2px 0 rgba(30, 25, 20, 0.2);
  background: var(--retro-surface-highlight);
  color: var(--retro-ink);
  min-height: 2.85rem;
}

.retro-match-replay--tzaar .retro-match-replay__controls .retro-match-replay__control-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.85rem;
  text-transform: none;
  letter-spacing: 0;
}

.retro-match-replay--tzaar .retro-match-replay__speed-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  font-family: var(--retro-sans);
  font-size: 0.72rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--retro-ink);
}

.retro-match-replay--tzaar .retro-match-replay__controls .retro-match-replay__speed-select {
  padding: 0 1.85rem 0 0.65rem;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
  line-height: 1;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231a1a1a' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.45rem center;
  background-size: 0.85rem;
}

.retro-match-replay--tzaar .retro-match-replay__btn-icon {
  display: block;
  width: 2rem;
  height: 2rem;
  fill: currentColor;
}

.retro-match-replay--tzaar .retro-match-replay__controls button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.retro-match-replay--tzaar .retro-match-replay__controls .retro-match-replay__speed-select:disabled,
.retro-match-replay--tzaar .retro-match-replay__move-item:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.retro-match-replay--tzaar .retro-match-replay__status {
  font-family: var(--retro-sans);
  color: var(--retro-ink);
  margin: 0.35rem 0 0.5rem;
  min-height: 1.2em;
}

.retro-match-replay--tzaar .retro-match-replay__board-host {
  container-type: inline-size;
  position: relative;
  overflow: visible;
  width: 100%;
  margin-inline: auto;
  box-sizing: border-box;
  aspect-ratio: 1/1;
  /* 8.5% of board width — scales with resize, no JS measurement. */
  --tzaar-piece-size: 8.5cqw;
  /* Stack compression controls (height cap, vertical lift, overlap). */
  --tzaar-stack-overlap-mult: -0.9;
  /* Piece palette (matches official TZAAR app look). */
  --tzaar-piece-outline: #1a1a1a;
  --tzaar-piece-tan: #c4a070;
  --tzaar-piece-white: #ffffff;
  --tzaar-piece-black: #121212;
  --tzaar-piece-silver: #d4d4d4;
  --tzaar-piece-ring-outer-size: 80%;
  --tzaar-piece-ring-inner-size: 50%;
  /* Stack height on pieces */
  --tzaar-board-digit-font-family: var(--retro-sans);
  --tzaar-board-digit-font-weight: 700;
  /* Row numbers and s-axis column letters */
  --tzaar-axis-label-font-size: clamp(0.95rem, 3.2vw, 1.35rem);
  /* Playable board surface tint inside the SVG shape. */
  --tzaar-surface: #f3ecdf;
  background: linear-gradient(160deg, #c9a86c 0%, #a8844a 50%, #8a6a38 100%);
}

.retro-match-replay--tzaar .retro-match-replay__grid,
.retro-match-replay--tzaar .retro-match-replay__cells,
.retro-match-replay--tzaar .retro-match-replay__axis-labels {
  position: absolute;
  width: 100%;
  height: 100%;
}

.retro-match-replay--tzaar .retro-match-replay__axis-labels {
  pointer-events: none;
  z-index: 1;
}

.retro-match-replay--tzaar .retro-match-replay__axis-label {
  position: absolute;
  font-family: var(--tzaar-board-digit-font-family);
  font-size: var(--tzaar-axis-label-font-size);
  font-weight: var(--tzaar-board-digit-font-weight);
  line-height: 1;
  color: var(--tzaar-piece-black);
  text-shadow: 0 0 2px rgba(255, 255, 255, 0.85);
}

.retro-match-replay--tzaar .retro-match-replay__grid {
  pointer-events: none;
}

.retro-match-replay--tzaar .retro-match-replay__grid line {
  stroke: rgba(30, 25, 20, 0.42);
  stroke-width: 0.35;
  fill: none;
}

.retro-match-replay--tzaar .retro-match-replay__surface {
  fill: var(--tzaar-surface);
  stroke: none;
}

.retro-match-replay--tzaar .retro-match-replay__cells {
  z-index: 2;
}

.retro-match-replay--tzaar .retro-match-replay__cell {
  position: absolute;
  width: 0;
  height: 0;
  transform: translate(-50%, -50%);
  /* display: none; */
}

.retro-match-replay--tzaar .retro-match-replay__cell--from,
.retro-match-replay--tzaar .retro-match-replay__cell--to {
  filter: drop-shadow(0 0 0.3rem rgba(255, 240, 200, 0.85));
}

.retro-match-replay--tzaar .retro-match-replay__stack {
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  position: absolute;
  left: 0;
  top: 0;
  /* Pin the bottom disc center to the cell anchor; stack grows upward only. */
  transform: translate(-50%, calc(-100% + var(--tzaar-piece-size) * 0.5));
}

.retro-match-replay--tzaar .retro-match-replay__piece {
  --tzaar-piece-ring-width: max(1px, calc(var(--tzaar-piece-size, 3rem) * 0.045));
  position: relative;
  flex-shrink: 0;
  width: var(--tzaar-piece-size);
  height: var(--tzaar-piece-size);
  margin-top: calc(var(--tzaar-piece-size) * var(--tzaar-stack-overlap-mult));
  border-radius: 50%;
  border-width: 1px;
  border-style: solid;
  box-sizing: border-box;
}

.retro-match-replay--tzaar .retro-match-replay__stack .retro-match-replay__piece:last-child {
  margin-top: 0;
}

.retro-match-replay--tzaar .retro-match-replay__piece--w {
  background: var(--tzaar-piece-white);
  border-color: var(--tzaar-piece-black);
}

.retro-match-replay--tzaar .retro-match-replay__piece--b {
  background: var(--tzaar-piece-black);
  border-color: var(--tzaar-piece-silver);
}

/* Tzarra — one concentric ring */
.retro-match-replay--tzaar .retro-match-replay__piece--a::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: var(--tzaar-piece-ring-inner-size);
  height: var(--tzaar-piece-ring-inner-size);
  border-radius: 50%;
  box-sizing: border-box;
  pointer-events: none;
}

.retro-match-replay--tzaar .retro-match-replay__piece--w.retro-match-replay__piece--a::after {
  background-color: var(--tzaar-piece-tan);
}

.retro-match-replay--tzaar .retro-match-replay__piece--b.retro-match-replay__piece--a::after {
  background-color: var(--tzaar-piece-silver);
}

/* Tzaar — two concentric rings */
.retro-match-replay--tzaar .retro-match-replay__piece--z::before,
.retro-match-replay--tzaar .retro-match-replay__piece--z::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 50%;
  box-sizing: border-box;
  pointer-events: none;
}

.retro-match-replay--tzaar .retro-match-replay__piece--z::before {
  width: var(--tzaar-piece-ring-outer-size);
  height: var(--tzaar-piece-ring-outer-size);
  border-style: solid;
  border-width: var(--tzaar-piece-ring-width);
}

.retro-match-replay--tzaar .retro-match-replay__piece--z::after {
  width: var(--tzaar-piece-ring-inner-size);
  height: var(--tzaar-piece-ring-inner-size);
}

.retro-match-replay--tzaar .retro-match-replay__piece--w.retro-match-replay__piece--z::before {
  border-color: var(--tzaar-piece-tan);
}

.retro-match-replay--tzaar .retro-match-replay__piece--b.retro-match-replay__piece--z::before {
  border-color: var(--tzaar-piece-silver);
}

.retro-match-replay--tzaar .retro-match-replay__piece--w.retro-match-replay__piece--z::after {
  background-color: var(--tzaar-piece-tan);
}

.retro-match-replay--tzaar .retro-match-replay__piece--b.retro-match-replay__piece--z::after {
  border-color: var(--tzaar-piece-silver);
  background-color: var(--tzaar-piece-silver);
}

/* Only the top disc in a stack shows type markers (avoids peeking rings). */
.retro-match-replay--tzaar
  .retro-match-replay__stack
  .retro-match-replay__piece:not(:last-child).retro-match-replay__piece--a::after,
.retro-match-replay--tzaar
  .retro-match-replay__stack
  .retro-match-replay__piece:not(:last-child).retro-match-replay__piece--z::before,
.retro-match-replay--tzaar
  .retro-match-replay__stack
  .retro-match-replay__piece:not(:last-child).retro-match-replay__piece--z::after {
  display: none;
}

.retro-match-replay--tzaar .retro-match-replay__piece .retro-match-replay__height {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35em;
  min-height: 1.35em;
  padding: 0;
  font-family: var(--tzaar-board-digit-font-family);
  font-size: calc(var(--tzaar-piece-size) * 0.35);
  font-weight: var(--tzaar-board-digit-font-weight);
  line-height: 1;
  text-align: center;
  background: transparent;
  border: none;
  box-shadow: none;
  pointer-events: none;
  color: var(--tzaar-piece-black);
}

.retro-match-replay--tzaar .retro-match-replay__piece--b.retro-match-replay__piece--t .retro-match-replay__height {
  color: var(--tzaar-piece-white);
}

.retro-match-replay--tzaar .retro-match-replay__stack--flying {
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  max-height: calc(
    var(--tzaar-piece-size) *
      (1 + (var(--tzaar-stack-piece-count, 1) - 1) * (1 + var(--tzaar-stack-overlap-mult)))
  );
}

.retro-match-replay--tzaar .retro-match-replay__stack--flying .retro-match-replay__piece {
  width: var(--tzaar-piece-size);
  height: var(--tzaar-piece-size);
  margin-top: calc(var(--tzaar-piece-size) * var(--tzaar-stack-overlap-mult));
}

.retro-match-replay--tzaar .retro-match-replay__stack--flying .retro-match-replay__piece:last-child {
  margin-top: 0;
}

.retro-match-replay--tzaar .retro-match-replay__cell--vanish .retro-match-replay__stack {
  animation: retro-tzaar-vanish 0.45s ease forwards;
}

@keyframes retro-tzaar-vanish {
  from {
    opacity: 1;
    filter: none;
  }
  to {
    opacity: 0;
    filter: blur(3px);
  }
}

.retro-match-replay--tzaar .retro-match-replay__cell--appear .retro-match-replay__stack {
  opacity: 0;
  filter: blur(3px);
}

.retro-match-replay--tzaar .retro-match-replay__cell--appear-run .retro-match-replay__stack {
  animation: retro-tzaar-appear 0.45s ease forwards;
}

@keyframes retro-tzaar-appear {
  from {
    opacity: 0;
    filter: blur(3px);
  }
  to {
    opacity: 1;
    filter: none;
  }
}

.retro-match-replay--tzaar .retro-match-replay__move-list {
  margin-top: 0.65rem;
  max-height: 10rem;
  overflow-y: auto;
  border: 1px solid var(--retro-line);
  background: var(--retro-surface-inset);
}

.retro-match-replay--tzaar .retro-match-replay__move-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px dashed var(--retro-border-soft);
  background: transparent;
  padding: 0.3rem 0.45rem;
  cursor: pointer;
  font-family: var(--retro-sans);
  font-size: 1rem;
  line-height: 1.35;
  color: var(--retro-ink);
}

.retro-match-replay--tzaar .retro-match-replay__move-item.is-active {
  background: var(--retro-surface-highlight);
  font-weight: 700;
}

.retro-match-replay--tzaar .retro-match-replay__error {
  color: #8e1d1d;
}

@media (max-width: 720px) {
  .retro-match-replay--tzaar .retro-match-replay__controls {
    flex-wrap: nowrap;
    gap: 0.25rem;
    width: 100%;
  }

  .retro-match-replay--tzaar .retro-match-replay__nav-btns {
    flex: 1 1 auto;
    flex-wrap: nowrap;
    gap: 0.2rem;
    min-width: 0;
  }

  .retro-match-replay--tzaar .retro-match-replay__controls .retro-match-replay__control-btn,
  .retro-match-replay--tzaar .retro-match-replay__controls .retro-match-replay__speed-select {
    min-height: 2.35rem;
    box-shadow: 1px 1px 0 rgba(30, 25, 20, 0.2);
  }

  .retro-match-replay--tzaar .retro-match-replay__controls .retro-match-replay__control-btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 0.25rem;
  }

  .retro-match-replay--tzaar .retro-match-replay__btn-icon {
    width: 1.35rem;
    height: 1.35rem;
  }

  .retro-match-replay--tzaar .retro-match-replay__speed-label {
    flex: 0 0 auto;
    gap: 0;
    font-size: 0;
  }

  .retro-match-replay--tzaar .retro-match-replay__controls .retro-match-replay__speed-select {
    min-width: 3.1rem;
    padding: 0 1.45rem 0 0.4rem;
    font-size: 0.8rem;
  }

  .retro-match-replay--tzaar .retro-match-replay__board-host {
    max-width: none;
    width: 100%;
  }

}

@media (prefers-reduced-motion: reduce) {
  .retro-match-replay--tzaar .retro-match-replay__cell--vanish .retro-match-replay__stack {
    animation: none;
    opacity: 0;
  }
}

/* --------------------------------------------------------------------------
   Print — preserve piece fills and type rings; host frame gradient omitted.
   -------------------------------------------------------------------------- */
@media print {
  .retro-match-replay--tzaar .retro-match-replay__controls,
  .retro-match-replay--tzaar .retro-match-replay__status,
  .retro-match-replay--tzaar .retro-match-replay__move-list {
    display: none !important;
  }

  .retro-match-replay--tzaar .retro-match-replay__board-host {
    break-inside: avoid;
    page-break-inside: avoid;
    max-width: min(100%, 520px);
    margin-inline: auto;
    background: transparent !important;
    background-image: none !important;
  }

  .retro-match-replay--tzaar .retro-match-replay__piece,
  .retro-match-replay--tzaar .retro-match-replay__piece::before,
  .retro-match-replay--tzaar .retro-match-replay__piece::after,
  .retro-match-replay--tzaar .retro-match-replay__surface {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .retro-match-replay--tzaar .retro-match-replay__piece {
    box-shadow: none;
    filter: none;
  }

  .retro-match-replay--tzaar .retro-match-replay__piece--w {
    background: #fff !important;
    border-color: #1a1a1a !important;
  }

  .retro-match-replay--tzaar .retro-match-replay__piece--b {
    background: #121212 !important;
    border-color: #555 !important;
  }

  .retro-match-replay--tzaar .retro-match-replay__piece--w.retro-match-replay__piece--a::after {
    background-color: #c4a070 !important;
  }

  .retro-match-replay--tzaar .retro-match-replay__piece--b.retro-match-replay__piece--a::after {
    background-color: #bbb !important;
  }

  .retro-match-replay--tzaar .retro-match-replay__piece--w.retro-match-replay__piece--z::before {
    border-color: #8a6a38 !important;
  }

  .retro-match-replay--tzaar .retro-match-replay__piece--b.retro-match-replay__piece--z::before {
    border-color: #888 !important;
  }

  .retro-match-replay--tzaar .retro-match-replay__piece--w.retro-match-replay__piece--z::after {
    background-color: #c4a070 !important;
  }

  .retro-match-replay--tzaar .retro-match-replay__piece--b.retro-match-replay__piece--z::after {
    background-color: #bbb !important;
    border-color: #888 !important;
  }

  .retro-match-replay--tzaar .retro-match-replay__axis-label {
    text-shadow: none;
  }
}
