/* Channel 004: a paper-card experiment in the shared channel screen. */
.site-home-screen--memory {
  overflow: hidden;
  background-color: #164d35;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='felt'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.72 .45' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23felt)' opacity='.24'/%3E%3C/svg%3E"),
    radial-gradient(ellipse at 40% 30%, #32835b66, transparent 75%),
    radial-gradient(ellipse at center, transparent 35%, #061e17a6);
  box-shadow: inset 0 0 30px #061e1740;
  container-type: size;
}

.site-home-screen--memory::after {
  display: none;
}

.site-home-screen--memory .memory-game__noise {
  z-index: 2;
}

.memory-game {
  position: absolute;
  inset: 20px;
}

.memory-game__table {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: clamp(6px, 1.5cqh, 12px);
  min-height: 0;
  width: 100%;
  height: 100%;
}

.memory-card {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #2d2922;
  perspective: 700px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  container-type: size;
  transform-origin: center;
  transition: transform var(--memory-shrink-duration, 300ms) cubic-bezier(0.4, 0, 0.6, 1);
}

.memory-card[aria-disabled="true"] { cursor: default; }

.memory-card:focus-visible {
  outline: 2px solid #e4dccb;
  outline-offset: 3px;
}

.memory-card__inside {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.36s cubic-bezier(0.2, 0.65, 0.3, 1);
}

.memory-card.is-face-up .memory-card__inside { transform: rotateY(180deg); }

.memory-card__paper {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid #d1c4aa;
  border-radius: 4px;
  background-color: #e7decb;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='paper'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.6' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23paper)' opacity='.15'/%3E%3C/svg%3E"), linear-gradient(115deg, #f0e9d7, #ded3bc);
  box-shadow: inset 0 0 10px #84765918, 0 2px 4px #0003;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.memory-card__back::before {
  position: absolute;
  inset: 5px;
  content: "";
  border-radius: 4px;
  background: url("/images/rs-channel-004-card-pattern.svg") center / 100% 100% no-repeat;
  pointer-events: none;
}

.memory-card__front { transform: rotateY(180deg); }

.memory-card__front svg {
  width: min(70cqw, 76cqh);
  height: min(70cqw, 76cqh);
  fill: none;
  stroke: currentColor;
  stroke-width: 5;
  stroke-linecap: square;
  stroke-linejoin: round;
}

.memory-card.is-clearing {
  transform: scale(0);
  pointer-events: none;
}

.memory-card.is-sparkling::before,
.memory-card.is-sparkling::after {
  position: absolute;
  z-index: 1;
  content: "";
  pointer-events: none;
}

.memory-card.is-sparkling::after {
  inset: -2px;
  border: 1px solid #ffe8a3;
  border-radius: 6px;
  box-shadow: 0 0 8px #ffe7a3, 0 0 20px #ffd36980, inset 0 0 8px #ffe7a366;
  animation: memory-match-glow var(--memory-sparkle-duration, 300ms) ease-in-out both;
}

.memory-card.is-sparkling::before {
  --match-orb: radial-gradient(circle, #fff8dc 0 15%, #ffe8a3 25%, #ffd36988 45%, transparent 72%);
  inset: -9px;
  background-image: var(--match-orb), var(--match-orb), var(--match-orb), var(--match-orb), var(--match-orb), var(--match-orb), var(--match-orb), var(--match-orb);
  background-position: 4% 0%, 39% 0%, 96% 0%, 100% 58%, 88% 100%, 56% 100%, 6% 100%, 0% 34%;
  background-size: var(--match-orb-sizes, 10px 10px);
  background-repeat: no-repeat;
  filter: drop-shadow(0 0 3px #ffd369);
  animation: memory-match-twinkle var(--memory-sparkle-duration, 300ms) ease-out both;
}

@keyframes memory-match-glow {
  0%, 100% { opacity: 0; }
  35%, 65% { opacity: 1; }
}

@keyframes memory-match-twinkle {
  0% { opacity: 0; transform: scale(0.94); }
  30% { opacity: 1; transform: scale(1); }
  55% { opacity: 0.55; }
  75% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.04); }
}

/* Keep live turn announcements available without taking space from the cards. */
.memory-game__status,
.memory-game__turn {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.memory-game.is-complete .memory-game__status {
  left: 50%;
  top: 50%;
  z-index: 3;
  width: max-content;
  max-width: 90%;
  height: auto;
  margin: 0;
  padding: 18px 24px;
  border: 0;
  border-radius: 4px;
  background: #191816f2;
  color: #e4dccb;
  font-size: 18px;
  text-align: center;
  clip-path: none;
  transform: translate(-50%, -50%);
}

.site-footer__effects--memory {
  display: flex;
  padding: 16px 20px;
  container-type: size;
  --memory-control-size: 48px;
}

.memory-game__panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: clamp(8px, 2cqw, 20px);
  width: 100%;
  height: 100%;
  min-width: 0;
}

.memory-game__scoreboard,
.memory-game__settings {
  display: flex;
  align-items: center;
  gap: clamp(8px, 3cqw, 20px);
}

.memory-game__score,
.memory-game__new-game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.memory-game__score-frame,
.memory-game__new-game-frame {
  display: grid;
  place-items: center;
  width: var(--memory-control-size);
  height: var(--memory-control-size);
  border: 1px solid var(--color-white);
  border-radius: 6px;
}

.memory-game__score-label,
.memory-game__control-label {
  color: var(--color-white);
  font-size: 12px;
  font-weight: 600;
  line-height: var(--leading-normal);
  white-space: nowrap;
}

.memory-game__score.is-active .memory-game__score-frame {
  box-shadow: 0 0 12px #cb2b301a;
}

.memory-game__score-number {
  font-family: "Segment7 Standard", monospace;
  font-size: calc(var(--memory-control-size) * 0.66);
  transform: translateY(0.1em);
  line-height: 1;
  color: var(--color-brand);
  text-shadow: 0 0 0.15em currentColor, 0 0 0.5em #cb2b3066;
}

.memory-game__difficulty {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.memory-game__difficulty-option {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: clamp(8px, 3cqw, 14px);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-white);
  font: inherit;
  font-size: clamp(8px, 3cqw, 12px);
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.memory-game__difficulty-light {
  width: clamp(8px, 3cqw, 14px);
  height: clamp(8px, 3cqw, 14px);
  border-radius: 50%;
  background: #595f5e;
}

.memory-game__difficulty-option[aria-checked="true"] .memory-game__difficulty-light {
  background: #d8d321;
  box-shadow: 0 0 7px #d8d321b3, 0 0 14px #d8d32159;
}

.memory-game__new-game {
  width: var(--memory-control-size);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-white);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.memory-game__new-game-frame svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
}

.memory-game__new-game:hover .memory-game__new-game-frame { background: #ffffff08; }

.memory-game__new-game:focus-visible,
.memory-game__difficulty-option:focus-visible {
  outline: 2px solid #d8d321;
  outline-offset: 5px;
}

@media (min-width: 641px) and (max-width: 900px) {
  .memory-game__panel {
    flex-direction: column;
    justify-content: center;
    gap: 24px;
  }
  .memory-game__difficulty-option { font-size: 10px; }
}

@media (max-width: 640px) {
  .site-footer__effects--memory { padding: 10px 20px; }
  .memory-game__settings { gap: 40px; }
}

@media (max-width: 360px) {
  .memory-game__panel,
  .memory-game__scoreboard { gap: 4px; }
  .memory-game__difficulty-option { gap: 4px; font-size: 7.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .memory-card,
  .memory-card__inside { transition: none; }
  .memory-card.is-sparkling::before,
  .memory-card.is-sparkling::after { animation: none; }
}
