/* Memory — restyled to the portfolio design language */

.memory-doc,
.memory-page {
  background: var(--bg);
  color: var(--black);
}

.memory-page {
  min-height: 100dvh;
  overflow-x: clip;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.webgl,
.confetti,
.connect {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.webgl { z-index: 0; }
.connect { z-index: 8; overflow: visible; }
.confetti { z-index: 30; }

.mem-shell {
  position: relative;
  z-index: 2;
  max-width: calc(var(--maxw) + var(--pad) * 2);
  margin: 0 auto;
  padding: 50px var(--pad) 48px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.mem-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 48px;
}
.mem-top__actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mem-sound {
  width: 42px;
  height: 42px;
  padding: 0;
  gap: 0;
  justify-content: center;
  cursor: pointer;
  font-family: var(--font);
}
.mem-sound:hover { transform: none; }
.mem-sound[aria-pressed="true"] {
  background: var(--black);
  color: var(--white);
  border-color: var(--black);
}
.mem-sound:focus-visible {
  outline: 2px solid var(--black);
  outline-offset: 3px;
}
.sound-icon { width: 16px; height: 16px; display: block; }
.sound-icon[hidden] { display: none !important; }

.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.mast { max-width: 660px; }
.title {
  margin: 0;
  font-weight: 500;
  font-size: clamp(40px, 8vw, 72px);
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--black);
}
.lede {
  margin: 16px 0 0;
  font-weight: 400;
  font-size: 18px;
  line-height: 1.4;
  color: var(--muted);
}

.stats {
  display: flex;
  align-items: baseline;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 16px 28px;
  margin: 36px 0 32px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 1.12px;
  text-transform: uppercase;
}
.stat {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.stat-k { color: var(--muted); }
.stat-v {
  color: var(--black);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}
.stat-num { display: inline-block; }
.stats .plus { color: var(--muted); }

.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
  max-width: 520px;
  margin: 0;
  min-height: 0;
  flex: 1;
  align-content: stretch;
}

.card {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-family: inherit;
  cursor: pointer;
  perspective: 1200px;
  transform-style: preserve-3d;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.card:focus { outline: none; }
.card:focus-visible {
  outline: 2px solid var(--black);
  outline-offset: 3px;
  border-radius: 16px;
}

.card-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  border-radius: 16px;
  will-change: transform;
  transition: transform 0.65s cubic-bezier(0.22, 1, 0.36, 1);
}

.card.is-flipped .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.card-back {
  background: var(--grey-box);
}
.card-back::before {
  content: "+";
  font-weight: 400;
  font-size: 18px;
  line-height: 1;
  color: rgba(0, 0, 0, 0.28);
}

.card-front {
  background: var(--white);
  color: var(--black);
  transform: rotateY(180deg);
  padding: 16px 12px;
  text-align: center;
}

.icon {
  width: 28px;
  height: 28px;
  margin-bottom: 10px;
  color: var(--black);
}

.skill {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: 0;
  max-width: 100%;
}

.check {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 14px;
  height: 14px;
  color: var(--menu-green);
  opacity: 0;
}

.shine {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, 0.55) 50%, transparent 65%);
  transform: translateX(-120%);
  opacity: 0;
}

.card.is-matched .card-front {
  box-shadow: inset 0 0 0 1px rgba(52, 199, 89, 0.4);
}
.card.is-matched .check { opacity: 1; }

.mem-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 8px 24px;
  border: 1px solid var(--black);
  border-radius: 40px;
  background: var(--black);
  color: var(--white);
  font-family: var(--font);
  font-weight: 500;
  font-size: 16px;
  line-height: 26px;
  cursor: pointer;
  white-space: nowrap;
}
.mem-cta:hover { background: #222; }
.mem-cta:active { transform: scale(0.98); }
.mem-cta:focus-visible {
  outline: 2px solid var(--black);
  outline-offset: 3px;
}

.win {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  pointer-events: none;
  opacity: 0;
  background: rgba(0, 0, 0, 0.06);
}
.win[hidden] { display: none !important; }
.win.is-in {
  opacity: 1;
  pointer-events: auto;
}

.win-panel {
  width: min(420px, 100%);
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  padding: 40px 32px 32px;
  background: var(--white);
  color: var(--black);
  text-align: center;
  border-radius: 16px;
  box-shadow:
    0 149px 42px rgba(191, 191, 191, 0),
    0 96px 38px rgba(191, 191, 191, 0.01),
    0 54px 32px rgba(191, 191, 191, 0.05),
    0 24px 24px rgba(191, 191, 191, 0.09),
    0 6px 13px rgba(191, 191, 191, 0.1);
}

.badge-visual {
  width: 140px;
  height: 140px;
  margin: 0 auto 20px;
  position: relative;
}
.badge-visual .badge-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.badge-visual:empty { display: none; }

.win-title {
  margin: 0;
  font-size: clamp(32px, 6vw, 48px);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--black);
}

.win-meta {
  margin: 12px 0 0;
  font-size: 16px;
  line-height: 1.4;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.win-stats {
  display: flex;
  align-items: baseline;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px 20px;
  margin: 28px 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 1.12px;
  text-transform: uppercase;
}
.win-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.win-stat-val {
  font-size: 20px;
  font-weight: 500;
  color: var(--black);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  text-transform: none;
}
.win-stat-label { color: var(--muted); }
.win-stats .plus { color: var(--muted); align-self: center; }

.win-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  margin-top: 28px;
}
.win-actions .pill,
.win-actions .mem-cta {
  width: 100%;
  justify-content: center;
}

.win-port {
  display: inline-block;
  margin-top: 20px;
  font-size: 16px;
  color: var(--muted);
  text-decoration: none;
}
.win-port:hover { color: var(--black); }

@media (hover: hover) and (pointer: fine) {
  .card:not(.is-matched):not(.is-flipped):hover .card-back {
    background: #e4e4e4;
  }
}

@media (min-width: 760px) {
  .title { font-size: 72px; }
  .board {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-template-rows: repeat(4, minmax(0, 1fr));
    max-width: 860px;
    gap: 16px;
    max-height: 520px;
    flex: none;
    height: min(520px, calc(100dvh - 340px));
  }
  .icon { width: 32px; height: 32px; }
}

/* Desktop: editorial copy left, board fills the remaining width */
@media (min-width: 1025px) {
  .app {
    display: grid;
    grid-template-columns: minmax(260px, 380px) minmax(0, 1fr);
    column-gap: 24px;
    align-items: center;
    flex: 1;
    min-height: 0;
  }
  .mem-copy {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
  .mast { max-width: none; }
  .stats {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    margin: 36px 0 0;
  }
  .stat {
    width: 100%;
    justify-content: space-between;
  }
  .board {
    max-width: none;
    width: 100%;
    height: auto;
    max-height: calc(100dvh - 160px);
    aspect-ratio: 5 / 4;
    flex: none;
    justify-self: stretch;
  }
}

@media (max-width: 767px) {
  .mem-shell { padding-bottom: 32px; }
  .mem-top { margin-bottom: 32px; }
  .title { font-size: 40px; }
  .lede { font-size: 16px; }
  .stats { margin: 24px 0 24px; gap: 12px 16px; }
  .board { gap: 8px; }
  .skill { font-size: 12px; line-height: 1.15; }
  .icon { width: 22px; height: 22px; margin-bottom: 6px; }
  .card-front { padding: 10px 6px; }
}

@media (max-height: 700px) and (max-width: 759px) {
  .lede { display: none; }
  .mem-top { margin-bottom: 20px; }
  .stats { margin: 16px 0 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .card-inner { transition: none; }
  .mem-cta:active,
  .pill:active { transform: none; }
}
