/* MtG Match Tracker - Commander card stacks */

.mtgmt-card-stack {
  --mtgmt-card-width: 200px;
  /* How far each card below the top one peeks out */
  --mtgmt-card-offset-x: calc(var(--mtgmt-card-width) * 0.12);
  --mtgmt-card-offset-y: calc(var(--mtgmt-card-width) * 0.08);
  --mtgmt-card-radius: 4.75% / 3.5%;

  display: grid;
  isolation: isolate;
  width: max-content;
}

.mtgmt-card-stack[data-mtgmt-count="2"] {
  padding-block-end: var(--mtgmt-card-offset-y);
  padding-inline-end: var(--mtgmt-card-offset-x);
}

.mtgmt-card-stack[data-mtgmt-count="3"] {
  padding-block-end: calc(var(--mtgmt-card-offset-y) * 2);
  padding-inline-end: calc(var(--mtgmt-card-offset-x) * 2);
}

.mtgmt-card-stack[data-mtgmt-count="4"] {
  padding-block-end: calc(var(--mtgmt-card-offset-y) * 3);
  padding-inline-end: calc(var(--mtgmt-card-offset-x) * 3);
}

/* Every card sits in the same cell; order in the DOM sets the layering */
.mtgmt-card-stack-card {
  grid-area: 1 / 1;
  position: relative;
  transition: transform 0.25s ease;
  width: var(--mtgmt-card-width);
}

.mtgmt-card-stack-card:nth-child(1) {
  z-index: 4;
}

.mtgmt-card-stack-card:nth-child(2) {
  transform: translate(var(--mtgmt-card-offset-x), var(--mtgmt-card-offset-y)) rotate(4deg);
  z-index: 3;
}

.mtgmt-card-stack-card:nth-child(3) {
  transform: translate(calc(var(--mtgmt-card-offset-x) * 2), calc(var(--mtgmt-card-offset-y) * 2)) rotate(8deg);
  z-index: 2;
}

.mtgmt-card-stack-card:nth-child(4) {
  transform: translate(calc(var(--mtgmt-card-offset-x) * 3), calc(var(--mtgmt-card-offset-y) * 3)) rotate(12deg);
  z-index: 1;
}

/* Card body: a button when the stack can cycle, a plain wrapper otherwise */
.mtgmt-card-stack-cycle,
.mtgmt-card-stack-single {
  background: none;
  border: 0;
  border-radius: var(--mtgmt-card-radius);
  display: block;
  margin: 0;
  padding: 0;
  perspective: 1200px;
  width: 100%;
}

.mtgmt-card-stack-cycle {
  cursor: pointer;
}

.mtgmt-card-stack-cycle:focus-visible {
  outline: 3px solid var(--mtgmt--color--link);
  outline-offset: 2px;
}

/* Front and back faces share one cell; flipping turns the pair over */
.mtgmt-card-faces {
  display: grid;
  transform-style: preserve-3d;
  transition: transform 0.5s ease;
}

.mtgmt-card-stack-card.is-flipped .mtgmt-card-faces {
  transform: rotateY(180deg);
}

.mtgmt-card-face {
  backface-visibility: hidden;
  border-radius: var(--mtgmt-card-radius);
  box-shadow: 0 2px 8px var(--mtgmt--color--tooltip-shadow);
  display: block;
  grid-area: 1 / 1;
  height: auto;
  width: 100%;
}

.mtgmt-card-face--back {
  transform: rotateY(180deg);
}

/* Flip (bottom left) and magnifier (bottom right) buttons, top card only */
.mtgmt-card-button {
  align-items: center;
  background-color: var(--mtgmt--color--tooltip-bg);
  border: 2px solid var(--mtgmt--color--tooltip-text);
  border-radius: 50%;
  color: var(--mtgmt--color--tooltip-text);
  cursor: pointer;
  display: flex;
  height: 2.5rem;
  inset-block-end: 0.5rem;
  justify-content: center;
  opacity: 0;
  padding: 0;
  pointer-events: none;
  position: absolute;
  transition: opacity 0.2s;
  width: 2.5rem;
  z-index: 1;
}

.mtgmt-card-button:focus-visible {
  outline: 3px solid var(--mtgmt--color--link);
  outline-offset: 2px;
}


.mtgmt-card-flip {
  inset-inline-start: 0.5rem;
}

.mtgmt-card-zoom {
  cursor: zoom-in;
  inset-inline-end: 0.5rem;
}

/* Flip and magnifier are revealed when the top card is hovered or focused,
   so they don't cover the card's rules text the rest of the time */
.mtgmt-card-stack-card:first-child:hover .mtgmt-card-button,
.mtgmt-card-stack-card:first-child:focus-within .mtgmt-card-button {
  opacity: 0.9;
  pointer-events: auto;
}

.mtgmt-card-stack-card:first-child .mtgmt-card-button:hover,
.mtgmt-card-stack-card:first-child .mtgmt-card-button:focus-visible {
  opacity: 1;
}

/* Touch screens can't hover, so the top card's buttons are always shown */
@media (hover: none) {
  .mtgmt-card-stack-card:first-child .mtgmt-card-button {
    opacity: 0.9;
    pointer-events: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mtgmt-card-stack-card,
  .mtgmt-card-faces,
  .mtgmt-card-button {
    transition: none;
  }
}

/* Zoomed stack, shown in the modal */
.mtgmt-card-modal {
  background: transparent;
  border: 0;
  max-height: none;
  max-width: none;
  overflow: visible;
  padding: 0;
}

.mtgmt-card-modal::backdrop {
  background-color: var(--mtgmt--color--modal-backdrop);
  cursor: zoom-out;
}

/* Sized so a full four-card stack, offsets included, fits the viewport */
.mtgmt-card-stack.mtgmt-card-stack--zoomed {
  --mtgmt-card-width: min(488px, 66vw, 52vh);
}

.mtgmt-card-stack--zoomed .mtgmt-card-button {
  height: 3rem;
  width: 3rem;
}

/* Already zoomed in */
.mtgmt-card-stack--zoomed .mtgmt-card-zoom {
  display: none;
}

.mtgmt-card-modal-close {
  align-items: center;
  background-color: var(--mtgmt--color--tooltip-bg);
  border: 2px solid var(--mtgmt--color--tooltip-text);
  border-radius: 50%;
  color: var(--mtgmt--color--tooltip-text);
  cursor: pointer;
  display: flex;
  font-size: 1.75rem;
  height: 3rem;
  inset-block-start: 1rem;
  inset-inline-end: 1rem;
  justify-content: center;
  line-height: 1;
  padding: 0;
  position: fixed;
  width: 3rem;
}

.mtgmt-card-modal-close:focus-visible {
  outline: 3px solid var(--mtgmt--color--link);
  outline-offset: 2px;
}

/* Holds the stack's place on the page while it's zoomed */
.mtgmt-card-stack-placeholder {
  visibility: hidden;
}
