/* Hearts & O's — Matching Game styles */
:root {
  --mg-p1: #ff5da2;
  --mg-p2: #7c4dff;
  --mg-brand: #ff5da2;
  --mg-brand-2: #9b72f5;
  --mg-ink: #2d1b4e;
  --mg-muted: #9b8aad;
  --mg-card: #ffffff;
  --mg-bg: #fff0f7;
  --mg-radius: 14px;
  --mg-shadow: 0 8px 24px rgba(100,0,80,.10);
  --mg-timer-warn: #ff8800;
  --mg-timer-danger: #ff3030;
}

body {
  background: var(--mg-bg);
  background-image:
    radial-gradient(circle at 10% 20%, #ffe0f0 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, #e8d5ff 0%, transparent 40%);
}

.mg-title {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 800;
  text-align: center;
  margin-bottom: 4px;
  color: var(--mg-ink);
}

/* INSTRUCTIONS */
.mg-instructions {
  background: var(--mg-card);
  border: 2px solid #f0d6ff;
  border-radius: var(--mg-radius);
  padding: 14px 18px;
  margin-bottom: 18px;
  box-shadow: var(--mg-shadow);
}
.mg-instructions summary {
  font-weight: 700;
  cursor: pointer;
  color: var(--mg-brand-2);
  font-size: 1rem;
  list-style: none;
  display: flex; align-items: center; gap: 8px;
}
.mg-instructions ol {
  margin-top: 10px;
  padding-left: 20px;
  line-height: 1.9;
  color: var(--mg-ink);
  font-size: .95rem;
}

/* SCOREBOARD */
.mg-scoreboard {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 16px;
}
.mg-player-card {
  flex: 1; max-width: 220px;
  background: var(--mg-card);
  border-radius: var(--mg-radius);
  padding: 12px 16px;
  box-shadow: var(--mg-shadow);
  border: 3px solid transparent;
  transition: border-color .3s, transform .2s, box-shadow .2s;
  text-align: center;
  position: relative;
}
.mg-player-card.active { transform: translateY(-3px); }
.mg-player-card.p1.active { border-color: var(--mg-p1); box-shadow: 0 8px 24px rgba(255,93,162,.25); }
.mg-player-card.p2.active { border-color: var(--mg-p2); box-shadow: 0 8px 24px rgba(124,77,255,.25); }
.mg-turn-badge {
  position: absolute;
  top: -10px; left: 50%; transform: translateX(-50%);
  background: var(--mg-p1);
  color: #fff;
  font-weight: 800;
  font-size: .7rem;
  padding: 2px 10px;
  border-radius: 99px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .25s;
  pointer-events: none;
}
.mg-player-card.p2 .mg-turn-badge { background: var(--mg-p2); }
.mg-player-card.active .mg-turn-badge { opacity: 1; }
.mg-player-label { font-weight: 800; font-size: 1rem; margin-bottom: 2px; }
.mg-player-card.p1 .mg-player-label { color: var(--mg-p1); }
.mg-player-card.p2 .mg-player-label { color: var(--mg-p2); }
.mg-player-score { font-size: 2.2rem; font-weight: 800; line-height: 1; }
.mg-player-card.p1 .mg-player-score { color: var(--mg-p1); }
.mg-player-card.p2 .mg-player-score { color: var(--mg-p2); }

/* TIMER */
.mg-timer-wrap { text-align: center; margin-bottom: 14px; }
.mg-timer-label { font-size: .8rem; font-weight: 700; color: var(--mg-muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }
.mg-timer-bar-bg { width: 100%; max-width: 400px; height: 14px; background: #f0e0f8; border-radius: 99px; margin: 0 auto; overflow: hidden; }
.mg-timer-bar { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--mg-brand), var(--mg-brand-2)); transition: width .9s linear, background .3s; width: 100%; }
.mg-timer-bar.warn { background: var(--mg-timer-warn); }
.mg-timer-bar.danger { background: var(--mg-timer-danger); }
.mg-timer-num { font-size: 1.3rem; font-weight: 800; color: var(--mg-ink); margin-top: 4px; }
.mg-timer-num.warn { color: var(--mg-timer-warn); }
.mg-timer-num.danger { color: var(--mg-timer-danger); }

/* BOARD */
.mg-board {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: clamp(6px, 1.5vw, 10px);
  max-width: 640px;
  margin: 0 auto 20px;
}
.mg-card {
  aspect-ratio: 1/1;
  cursor: pointer;
  perspective: 600px;
  border-radius: 12px;
}
.mg-card-inner {
  width: 100%; height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform .4s cubic-bezier(.4,0,.2,1);
  border-radius: 12px;
}
.mg-card.flipped .mg-card-inner,
.mg-card.matched .mg-card-inner { transform: rotateY(180deg); }
.mg-card-face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(18px, 4vw, 28px);
}
.mg-card-front {
  background: linear-gradient(135deg, #ffb3d1, #c9a0f5);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.1);
}
.mg-card-front::after { content: '✦'; color: rgba(255,255,255,.5); font-size: clamp(16px, 3.5vw, 24px); }
.mg-card-back { background: #fff; transform: rotateY(180deg); box-shadow: var(--mg-shadow); border: 2px solid #f5e6ff; }
.mg-card.matched .mg-card-back { background: linear-gradient(135deg, #fff0f7, #f0e8ff); border-color: #e0ccff; }
.mg-card:hover:not(.flipped):not(.matched) .mg-card-front { filter: brightness(1.08); }

/* CONTROLS */
.mg-controls { text-align: center; }
.mg-btn {
  display: inline-block;
  font-weight: 800;
  font-size: 1.1rem;
  padding: 12px 32px;
  border: none;
  border-radius: 99px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--mg-brand), var(--mg-brand-2));
  color: #fff;
  box-shadow: 0 4px 16px rgba(180,0,100,.3);
  transition: transform .15s, box-shadow .15s;
  letter-spacing: .02em;
}
.mg-btn-secondary {
  background: #f3e8ff;
  color: var(--mg-brand-2);
  box-shadow: 0 2px 8px rgba(120,80,200,.12);
}
.mg-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(180,0,100,.35); }
.mg-btn:active { transform: translateY(0); }

/* WIN OVERLAY */
#winOverlay { display: none; position: fixed; inset: 0; background: rgba(45,27,78,.75); z-index: 100; align-items: center; justify-content: center; flex-direction: column; }
#winOverlay.show { display: flex; }
.win-card { background: #fff; border-radius: 24px; padding: 40px 48px; text-align: center; box-shadow: 0 24px 64px rgba(0,0,0,.25); animation: popIn .4s cubic-bezier(.34,1.56,.64,1); position: relative; z-index: 101; max-width: 380px; width: 90%; }
@keyframes popIn { from { opacity: 0; transform: scale(.7); } to { opacity: 1; transform: scale(1); } }
.win-emoji { font-size: 4rem; margin-bottom: 8px; }
.win-title { font-size: 2rem; font-weight: 800; margin-bottom: 6px; }
.win-subtitle { color: var(--mg-muted); margin-bottom: 24px; font-size: 1.05rem; }
.win-scores { display: flex; gap: 16px; justify-content: center; margin-bottom: 24px; }
.win-score-item { background: var(--mg-bg); border-radius: 12px; padding: 10px 20px; font-weight: 800; }
.win-score-item .ws-name { font-size: .85rem; color: var(--mg-muted); }
.win-score-item .ws-num { font-size: 1.8rem; }
.ws-p1 .ws-num { color: var(--mg-p1); }
.ws-p2 .ws-num { color: var(--mg-p2); }

/* CONFETTI */
#confettiCanvas { position: fixed; inset: 0; pointer-events: none; z-index: 99; }

@media (max-width: 480px) {
  .mg-scoreboard { gap: 8px; }
  .mg-player-card { padding: 10px 12px; }
  .win-card { padding: 28px 24px; }
}
@media (prefers-reduced-motion: reduce) {
  .mg-card-inner, .mg-btn { transition: none; }
}
@media (prefers-color-scheme: dark) {
  body { background-image: radial-gradient(circle at 10% 20%, #2a0f2a 0%, transparent 40%), radial-gradient(circle at 90% 80%, #1a0d30 0%, transparent 40%); }
  .mg-instructions, .mg-player-card { background: #1e1030; border-color: #3d1f6e; }
  .mg-card-back { background: #1e1030; border-color: #3d1f6e; }
  .win-card { background: #1e1030; }
  .win-score-item { background: #120820; }
  .mg-timer-bar-bg { background: #2a1545; }
}
