/* ============================================================
   Memory Match — two mirrored boards of blood-bank tiles
   Builds on quiz.css for the shared intro / HUD / result shells.
   ============================================================ */

.mshell {
  width: min(1120px, 100% - 2.2rem);
  margin-inline: auto;
  padding: clamp(1.1rem, 2.6vw, 1.9rem) 0 3rem;
}
/* The intro and result cards are narrower than the play field. */
.mshell #screenIntro .card,
.mshell #screenResult .card {
  width: min(760px, 100%);
  margin-inline: auto;
}

/* ---------- phase callout ---------------------------------- */
.callout {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.8rem 1.1rem;
  margin-bottom: 1.1rem;
  border-radius: var(--r-lg);
  border: 1px solid var(--stroke-2);
  background: rgba(22, 11, 16, 0.72);
  backdrop-filter: blur(14px);
  transition: border-color var(--t-med) var(--e-out), background var(--t-med) var(--e-out);
}
.callout__pip {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
  background: var(--blood-400);
  box-shadow: 0 0 14px currentColor;
  animation: beaconPip 2s var(--e-out) infinite;
}
@keyframes beaconPip {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.45;
    transform: scale(0.78);
  }
}
.callout__text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.callout__text strong {
  font-size: 1.02rem;
  line-height: 1.25;
}

.callout--memorise {
  border-color: rgba(255, 176, 32, 0.5);
  background: rgba(52, 32, 8, 0.6);
}
.callout--memorise .callout__pip {
  background: var(--amber-400);
}
.callout--a {
  border-color: var(--stroke-hot);
}
.callout--b {
  border-color: rgba(86, 184, 255, 0.5);
}
.callout--b .callout__pip {
  background: var(--sky-400);
}
.callout--hit {
  border-color: rgba(52, 233, 176, 0.6);
  background: rgba(6, 46, 36, 0.66);
}
.callout--hit .callout__pip {
  background: var(--mint-400);
}
.callout--miss {
  border-color: rgba(240, 73, 106, 0.6);
  background: rgba(58, 8, 20, 0.66);
}

/* ---------- board layout ----------------------------------- */
.boards {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: start;
  gap: clamp(0.6rem, 2vw, 1.4rem);
}

.board3d {
  padding: clamp(0.75rem, 1.6vw, 1.1rem);
  border-radius: var(--r-xl);
  border: 1px solid var(--stroke-1);
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  backdrop-filter: blur(14px);
  box-shadow: var(--sh-md);
  transition: border-color var(--t-med) var(--e-out), box-shadow var(--t-med) var(--e-out),
    opacity var(--t-med) var(--e-out);
}
/* The inactive board dims so the eye always knows where to click. */
.board3d.is-idle {
  opacity: 0.55;
}
.board3d.is-active {
  border-color: var(--stroke-hot);
  box-shadow: var(--sh-md), 0 0 46px -18px rgba(240, 73, 106, 0.85);
}
#sideB.is-active {
  border-color: rgba(86, 184, 255, 0.55);
  box-shadow: var(--sh-md), 0 0 46px -18px rgba(86, 184, 255, 0.8);
}

.board3d__head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.1rem 0.35rem 0.7rem;
}
.board3d__tag {
  flex: 1;
  min-width: 0;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-300);
}
.board3d__step {
  display: grid;
  place-items: center;
  width: 1.6rem;
  height: 1.6rem;
  flex: none;
  border-radius: 50%;
  border: 1px solid var(--stroke-2);
  background: rgba(0, 0, 0, 0.34);
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--ink-300);
  transition: background var(--t-med) var(--e-out), color var(--t-med) var(--e-out),
    border-color var(--t-med) var(--e-out);
}
.board3d.is-active .board3d__step {
  background: var(--blood-500);
  border-color: var(--blood-300);
  color: var(--white);
}
#sideB.is-active .board3d__step {
  background: var(--sky-400);
  border-color: rgba(86, 184, 255, 0.7);
  color: #05203a;
}

/* the ⇄ divider between the two boards */
.boards__link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  align-self: stretch;
  padding-top: 3.2rem;
  color: var(--ink-400);
}
.boards__dash {
  flex: 1;
  width: 1px;
  background: linear-gradient(to bottom, transparent, var(--stroke-2), transparent);
}
.boards__glyph {
  font-size: 1.1rem;
  opacity: 0.7;
}

/* ---------- tiles ------------------------------------------ */
/* Tracks are capped so a 3×3 round still fits on one screen without
   scrolling — memory is hard enough without hunting for the second board. */
.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), minmax(0, 7.6rem));
  justify-content: center;
  gap: clamp(0.4rem, 1vw, 0.7rem);
}

.tile {
  position: relative;
  aspect-ratio: 1;
  perspective: 900px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  transition: transform var(--t-fast) var(--e-spring);
}
.tile:disabled {
  cursor: default;
}
.tile:not(:disabled):hover {
  transform: translateY(-3px);
}
.tile:not(:disabled):active {
  transform: scale(0.97);
}
.tile:focus-visible {
  outline: 2px solid var(--blood-300);
  outline-offset: 4px;
  border-radius: var(--r-md);
}

.tile__inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.52s var(--e-spring);
}
.tile.is-up .tile__inner {
  transform: rotateY(180deg);
}

.tile__face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 0.2rem;
  padding: 0.4rem;
  border-radius: var(--r-md);
  border: 1px solid var(--stroke-2);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

/* face-down side: the campaign drop on a woven crimson back */
.tile__face--cover {
  background:
    radial-gradient(circle at 30% 22%, rgba(240, 73, 106, 0.34), transparent 58%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.045) 0 6px, transparent 6px 12px),
    linear-gradient(160deg, var(--blood-800), var(--ink-900));
}
.tile__cover-drop {
  width: 34%;
  max-width: 40px;
  opacity: 0.62;
  filter: drop-shadow(0 3px 10px rgba(240, 73, 106, 0.55));
}

/* face-up side: the tile's glyph plus its name */
.tile__face--item {
  transform: rotateY(180deg);
  align-content: center;
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.12), rgba(0, 0, 0, 0.42));
  border-color: color-mix(in srgb, var(--tile) 55%, transparent);
  box-shadow: inset 0 0 26px -6px color-mix(in srgb, var(--tile) 45%, transparent);
}
.tile__glyph {
  font-size: clamp(1.5rem, 4.4vw, 2.3rem);
  line-height: 1;
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--tile);
  text-shadow: 0 2px 14px color-mix(in srgb, var(--tile) 55%, transparent);
}
.tile__label {
  font-size: clamp(0.56rem, 1.1vw, 0.72rem);
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  color: var(--ink-200);
  padding-inline: 0.15rem;
  overflow-wrap: anywhere;
}

/* the small 1–9 keycap in the corner of every face-down tile */
.tile__key {
  position: absolute;
  z-index: 2; /* above the card faces, which paint later in DOM order */
  inset-block-start: 0.34rem;
  inset-inline-start: 0.46rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.5);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  transition: opacity var(--t-med) var(--e-out);
}
.tile.is-up .tile__key,
.tile.is-matched .tile__key {
  opacity: 0;
}

/* --- tile states --- */
.tile.is-picked .tile__face--item {
  border-color: var(--blood-300);
  box-shadow: var(--glow-blood);
}
.tile.is-matched .tile__face--item {
  border-color: rgba(52, 233, 176, 0.75);
  box-shadow: var(--glow-mint);
}
.tile.is-matched {
  animation: tileLock 0.6s var(--e-spring) both;
}
@keyframes tileLock {
  40% {
    transform: scale(1.07);
  }
  100% {
    transform: scale(1);
  }
}
.tile.is-matched .tile__face--item::after {
  content: "✓";
  position: absolute;
  inset-block-start: 0.15rem;
  inset-inline-end: 0.35rem;
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--mint-400);
}
.tile.is-missed .tile__face--item {
  border-color: rgba(240, 73, 106, 0.8);
  box-shadow: var(--glow-blood);
  background: linear-gradient(165deg, rgba(210, 30, 60, 0.34), rgba(0, 0, 0, 0.42));
}
.tile.is-missed {
  animation: shakeX 0.5s var(--e-in-out) both;
}
/* Peeked tiles read as a borrowed glance, not a solved pair. */
.tile.is-peeking .tile__face--item {
  border-color: rgba(255, 176, 32, 0.6);
  box-shadow: inset 0 0 26px -6px rgba(255, 176, 32, 0.5);
}

/* dealing animation when a round starts */
.tile.is-dealing {
  animation: tileDeal 0.5s var(--e-out) both;
  animation-delay: calc(var(--i, 0) * 34ms);
}
@keyframes tileDeal {
  from {
    opacity: 0;
    transform: translateY(22px) scale(0.86);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- memorise phase --------------------------------- */
/* A sweeping bar under the callout mirrors the HUD ring countdown. */
.callout--memorise::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  inset-block-end: 0;
  height: 3px;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--amber-400), var(--blood-400));
  transform: scaleX(var(--preview, 1));
  transition: transform 120ms linear;
}
:root[dir="rtl"] .callout--memorise::after {
  transform-origin: right;
}
:root[dir="ltr"] .callout--memorise::after {
  transform-origin: left;
}

/* Nothing is clickable while the board is on show or a turn is resolving. */
.boards.is-locked .tile,
.grid.is-locked .tile {
  pointer-events: none;
}

/* ---------- responsive ------------------------------------- */
@media (max-width: 860px) {
  .boards {
    grid-template-columns: minmax(0, 1fr);
  }
  .boards__link {
    flex-direction: row;
    padding-top: 0;
    padding-inline: 1rem;
  }
  .boards__dash {
    width: auto;
    flex: 1;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--stroke-2), transparent);
  }
  .boards__glyph {
    transform: rotate(90deg);
  }
  .board3d.is-idle {
    opacity: 0.75;
  }
}
@media (max-width: 640px) {
  .callout {
    flex-wrap: wrap;
  }
  .callout__text {
    flex-basis: 100%;
    order: 3;
  }
  .hud {
    flex-wrap: wrap;
  }
}
