
  :root {
    --membg: #0a0a0f;
    --memsurface: #13131a;
    --memcard-back: #1c1c28;
    --memcard-front: #ffffff;
    --memaccent: #e8ff3c;
    --memaccent2: #ff3c6e;
    --memaccent3: #3cffda;
    --memtext: #f0f0f0;
    --memmuted: #555566;
    --memborder: #2a2a3a;
    --memmatched: #3cffda22;
    --memmatched-border: #3cffda;
    --memradius: 12px;
    --memflip-time: 0.5s;
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }

  .memory_match_main header {
    text-align: center;
  }

  .memory_match_main .logo {
    font-size: clamp(2rem, 6vw, 3.5rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1;
  }

  .memory_match_main .logo span:first-child { color: var(--memaccent); }
  .memory_match_main .logo span:last-child { color: #000; }

  .memory_match_main .tagline {
    font-family: 'Space Mono', monospace;
    font-size: 0.7rem;
    color: var(--memmuted);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    margin-top: 6px;
  }

  /* Controls */
  .memory_match_main .controls {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
  }

  .memory_match_main .size-group {
    display: flex;
    background: var(--memsurface);
    border: 1px solid var(--memborder);
    border-radius: 8px;
    overflow: hidden;
  }

  .memory_match_main .size-btn {
    background: none;
    border: none;
    color: var(--memmuted);
    font-family: 'Space Mono', monospace;
    font-size: 0.75rem;
    padding: 8px 16px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    border-right: 1px solid var(--memborder);
  }

  .memory_match_main .size-btn:last-child { border-right: none; }

  .memory_match_main .size-btn.active {
    background: var(--memaccent);
    color: #0a0a0f;
    font-weight: 700;
  }

  .memory_match_main .size-btn:hover:not(.active) {
    background: var(--memborder);
    color: var(--text);
  }

  .memory_match_main .btn {
    background: var(--memaccent);
    color: #0a0a0f;
    border: none;
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 9px 22px;
    border-radius: 8px;
    cursor: pointer;
    letter-spacing: 0.05em;
    transition: transform 0.15s, box-shadow 0.15s;
  }

  .memory_match_main .btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px #e8ff3c44;
  }

  .memory_match_main .btn:active { transform: translateY(0); }

  /* Stats */
  .memory_match_main .stats {
    display: flex;
    gap: 20px;
    font-family: 'Space Mono', monospace;
  }

  .memory_match_main .stat {
    text-align: center;
    background: var(--memsurface);
    border: 1px solid var(--memborder);
    border-radius: 10px;
    padding: 10px 20px;
    min-width: 80px;
  }

  .memory_match_main .stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--memaccent);
    line-height: 1;
  }

  .memory_match_main .stat-label {
    font-size: 0.6rem;
    color: var(--memmuted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-top: 4px;
  }

  /* Grid */
  .memory_match_main .grid-wrap {
    width: 100%;
    display: flex;
    justify-content: center;
  }

  .memory_match_main .grid {
    display: grid;
    gap: 10px;
    width: 100%;
    max-width: 680px;
  }

  .memory_match_main .grid.g4 { grid-template-columns: repeat(4, 1fr); }
  .memory_match_main .grid.g6 { grid-template-columns: repeat(6, 1fr); }
  .memory_match_main .grid.g8 { grid-template-columns: repeat(8, 1fr); }

  /* Card */
  .memory_match_main .card {
    aspect-ratio: 1;
    perspective: 600px;
    cursor: pointer;
  }

  .memory_match_main .card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform var(--memflip-time) cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: var(--memradius);
  }

  .memory_match_main .card.flipped .card-inner,
  .memory_match_main .card.matched .card-inner {
    transform: rotateY(180deg);
  }

  .memory_match_main .card-face {
    position: absolute;
    inset: 0;
    border-radius: var(--memradius);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.2rem, 4vw, 2rem);
  }

  .memory_match_main .card-back {
    background: var(--memcard-back);
    border: 1.5px solid var(--memborder);
    transition: border-color 0.2s, box-shadow 0.2s;
  }

  .memory_match_main .card:not(.flipped):not(.matched):hover .card-back {
    border-color: var(--memaccent);
    box-shadow: 0 0 16px #e8ff3c33, inset 0 0 20px #e8ff3c08;
  }

  .memory_match_main .card-back::after {
    content: '?';
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    font-size: clamp(1rem, 3vw, 1.5rem);
    color: var(--memmuted);
    letter-spacing: -0.05em;
  }

  .memory_match_main .card-front {
    background: var(--memsurface);
    border: 1.5px solid var(--memborder);
    transform: rotateY(180deg);
  }

  .memory_match_main .card.matched .card-front {
    background: var(--memmatched);
    border-color: var(--memmatched-border);
    box-shadow: 0 0 20px #3cffda33;
  }

  .memory_match_main .card.matched .card-inner {
    animation: matchPop var(--memflip-time) ease forwards;
  }

  @keyframes matchPop {
    0% { transform: rotateY(180deg) scale(1); }
    50% { transform: rotateY(180deg) scale(1.1); }
    100% { transform: rotateY(180deg) scale(1); }
  }

  .memory_match_main .card.shake .card-inner {
    animation: shake 0.4s ease;
  }

  @keyframes shake {
    0%, 100% { transform: rotateY(180deg) translateX(0); }
    25% { transform: rotateY(180deg) translateX(-6px); }
    75% { transform: rotateY(180deg) translateX(6px); }
  }

  /* Win overlay */
  .memory_match_main .win-overlay {
    position: fixed;
    inset: 0;
    background: #0a0a0fcc;
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s;
  }

  .memory_match_main .win-overlay.show {
    opacity: 1;
    pointer-events: all;
  }

  .memory_match_main .win-box {
    background: var(--memsurface);
    border: 1px solid var(--memborder);
    border-radius: 20px;
    padding: 48px 56px;
    text-align: center;
    transform: scale(0.8);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
  }

  .memory_match_main .win-overlay.show .win-box {
    transform: scale(1);
  }

  .memory_match_main .win-box::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: conic-gradient(from 0deg, transparent 0%, #e8ff3c11 25%, transparent 50%, #3cffda11 75%, transparent 100%);
    animation: spin 6s linear infinite;
  }

  @keyframes spin { to { transform: rotate(360deg); } }

  .memory_match_main .win-title {
    font-size: 3rem;
    font-weight: 800;
    color: var(--memaccent);
    line-height: 1;
    position: relative;
    z-index: 1;
  }

  .memory_match_main .win-sub {
    font-family: 'Space Mono', monospace;
    font-size: 0.75rem;
    color: var(--memamuted);
    margin-top: 8px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    position: relative;
    z-index: 1;
  }

  .memory_match_main .win-stats {
    display: flex;
    gap: 20px;
    margin: 24px 0;
    justify-content: center;
    position: relative;
    z-index: 1;
  }

  .memory_match_main .win-btn {
    position: relative;
    z-index: 1;
    background: var(--memaccent);
    color: #0a0a0f;
    border: none;
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    font-size: 1rem;
    padding: 14px 40px;
    border-radius: 10px;
    cursor: pointer;
    letter-spacing: 0.05em;
    transition: transform 0.15s, box-shadow 0.15s;
  }

  .memory_match_main .win-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 30px #e8ff3c55;
  }

  /* Confetti */
  .memory_match_main .confetti-piece {
    position: fixed;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    pointer-events: none;
    z-index: 200;
    animation: confettiFall linear forwards;
  }

  @keyframes confettiFall {
    0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
  }

  /* Timer color feedback */
  .memory_match_main .stat-value.danger { color: var(--memaccent2); }

  @media (max-width: 480px) {
    .memory_match_main .grid { gap: 6px; }
    .memory_match_main .card-face { font-size: clamp(0.9rem, 4vw, 1.5rem); }
  }