:root {
  --bg1: #f6fffb;
  --bg2: #e8fff0;
  --card: rgba(255, 255, 255, 0.96);
  --edge: rgba(12, 38, 26, 0.12);
  --text: rgba(12, 38, 26, 0.92);
  --muted: rgba(12, 38, 26, 0.6);
  --accent: #ff7a45;
  --good: #2fbf71;
  --bad: #ef4444;
  --shadow: rgba(8, 24, 16, 0.12);
}

* { box-sizing: border-box; }

html, body { height: 100%; overflow: hidden; }

body.match-game {
  margin: 0;
  font-family: 'Poppins', system-ui, -apple-system, Segoe UI, sans-serif;
  background: radial-gradient(1200px 800px at 70% 10%, rgba(255, 122, 69, 0.20), transparent 60%),
    radial-gradient(900px 600px at 10% 90%, rgba(47, 191, 113, 0.16), transparent 60%),
    linear-gradient(180deg, var(--bg1), var(--bg2));
  color: var(--text);
  overflow: hidden;
}

.match-app {
  width: 100vw;
  height: 100vh;
  padding: clamp(10px, 1.4vw, 18px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: clamp(10px, 1.2vw, 16px);
  box-sizing: border-box;
}

.match-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: clamp(10px, 1.2vw, 16px);
  border-radius: 26px;
  background: var(--card);
  border: 1px solid var(--edge);
  box-shadow: 0 22px 55px var(--shadow);
}

.match-kicker {
  font-size: 0.7rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--muted);
}

.match-h1 {
  margin: 6px 0 0;
  font-size: clamp(1.4rem, 2vw, 2.1rem);
}

.match-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.match-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.match-btn--ghost {
  background: transparent;
  color: var(--text);
  border: 2px solid rgba(12, 38, 26, 0.25);
}

.match-btn--primary {
  background: var(--accent);
  color: #1a0904;
}

.match-main {
  width: 100%;
  min-height: 0;
}

.match-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: clamp(10px, 1.2vw, 16px);
  width: 100%;
  align-content: stretch;
  align-items: stretch;
  height: 100%;
  grid-auto-rows: minmax(0, 1fr);
}

@media (max-width: 1440px) {
  .match-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }
}

.match-placeholder {
  width: 100%;
  height: 100%;
  visibility: hidden;
}

.match-card {
  border-radius: 22px;
  border: 2px solid rgba(12, 38, 26, 0.10);
  background: rgba(255, 255, 255, 0.92);
  padding: clamp(12px, 1.6vw, 18px);
  font-size: clamp(1.05rem, 1.55vw, 1.85rem);
  font-weight: 800;
  font-family: inherit;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease, background 0.14s ease;
  box-shadow: 0 18px 40px var(--shadow);
  line-height: 1.2;
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  aspect-ratio: unset;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.match-card:hover:not(.matched) {
  transform: translateY(-3px);
  border-color: rgba(255, 122, 69, 0.45);
}

.match-card:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(255, 122, 69, 0.25), 0 18px 40px var(--shadow);
}

.match-card.revealed,
.match-card.match-card--correct {
  background: rgba(47, 191, 113, 0.16);
  border-color: rgba(47, 191, 113, 0.55);
}

.match-card.wrong {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.6);
}

.match-card.explode {
  animation: match-pop 0.32s ease-out forwards;
}

@keyframes match-pop {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.25); }
  100% { transform: scale(0); opacity: 0; }
}

.match-card__sparkle {
  position: absolute;
  inset: auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.95), rgba(47, 191, 113, 0.55));
  animation: sparkleBurst 0.7s ease forwards;
  pointer-events: none;
  top: 50%;
  left: 50%;
}

@keyframes sparkleBurst {
  0% { transform: translate(-50%, -50%) scale(0.3); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx, 0)), calc(-50% + var(--dy, 0))) scale(1.2); opacity: 0; }
}

.match-bottom {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 12px;
  align-items: center;
  padding: clamp(10px, 1.2vw, 16px);
  border-radius: 26px;
  background: var(--card);
  border: 1px solid var(--edge);
  box-shadow: 0 22px 55px var(--shadow);
}

.match-pill {
  padding: 10px 14px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: rgba(12, 38, 26, 0.05);
  border: 1px solid rgba(12, 38, 26, 0.08);
}

.match-message {
  text-align: right;
  font-weight: 700;
  color: rgba(12, 38, 26, 0.72);
}

.match-celebration {
  position: fixed;
  inset: 0;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 24, 16, 0.35);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.match-celebration--visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.match-celebration__panel {
  width: min(860px, 92vw);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(12, 38, 26, 0.12);
  box-shadow: 0 26px 70px rgba(8, 24, 16, 0.18);
  padding: clamp(18px, 2vw, 30px);
  text-align: center;
}

.match-celebration__title {
  margin: 0;
  font-size: 2.4rem;
  font-weight: 900;
}

.match-celebration__subtitle {
  margin: 8px 0 0;
  color: var(--muted);
}

.match-celebration__actions {
  margin-top: 18px;
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.match-celebration__replay,
.match-celebration__return {
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  border: none;
  cursor: pointer;
  text-decoration: none;
}

.match-celebration__replay {
  background: var(--good);
  color: #062014;
}

.match-celebration__return {
  background: var(--accent);
  color: #160703;
}

.match-celebration__halo,
.match-celebration__sparkles,
.confetti-container {
  pointer-events: none;
}

.confetti-container {
  position: fixed;
  inset: 0;
  z-index: 80;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 8px;
  height: 14px;
  opacity: 0;
  will-change: transform, opacity;
  animation: confetti-fall 2.2s linear forwards;
}

@keyframes confetti-fall {
  0% { transform: translateY(-40px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(120vh) rotate(720deg); opacity: 0; }
}

.page-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 10px;
  text-align: center;
  padding: 0;
  color: rgba(12, 38, 26, 0.55);
  font-size: 0.9rem;
  pointer-events: none;
}

@media (max-width: 980px) {
  .match-bottom { grid-template-columns: 1fr; }
  .match-message { text-align: left; }
}
