* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    background:
        radial-gradient(circle at 20% 0%, rgba(186, 104, 200, 0.25), transparent 50%),
        radial-gradient(circle at 80% 100%, rgba(77, 182, 172, 0.22), transparent 50%),
        linear-gradient(135deg, #15131f 0%, #1c1a2b 60%, #1a1a2e 100%);
    height: 100vh;
    height: 100dvh;
    padding: 10px;
    color: #fff;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.user-bar { margin: 0 auto 12px; }

.memory-game {
    max-width: 460px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* Grid-size selector */
.memory-sizes {
    display: flex;
    gap: 6px;
    width: 100%;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 4px;
}
.mem-size {
    flex: 1;
    padding: 9px 0;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: rgba(255,255,255,0.6);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
}
.mem-size:hover  { color: #fff; }
.mem-size.active {
    background: linear-gradient(135deg, #66bb6a, #2e7d32);
    color: #fff;
    box-shadow: 0 2px 8px rgba(102, 187, 106, 0.35);
}

.memory-status {
    display: flex;
    justify-content: space-between;
    width: 100%;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
}
.memory-status .best { color: #ffd980; }
.memory-status { align-items: center; gap: 10px; }
.mem-restart {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 9px;
    color: #fff; font-size: 15px; line-height: 1;
    padding: 6px 9px; cursor: pointer; flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    transition: transform .12s, background .15s;
}
.mem-restart:active { transform: scale(0.9) rotate(-35deg); background: rgba(255,255,255,0.16); }

.memory-board {
    display: grid;
    grid-template-columns: repeat(var(--cols, 4), 1fr);
    gap: 8px;
    width: 100%;
    aspect-ratio: var(--cols, 4) / var(--rows, 4);
    padding: 8px;
    background: rgba(0,0,0,0.25);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 16px;
    container-type: inline-size;
}
.mem-card {
    aspect-ratio: 1;
    border-radius: 12px;
    background: linear-gradient(135deg, #4a4e69, #22223b);
    border: 1px solid rgba(255,255,255,0.10);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    /* fallback first, then container query if supported */
    font-size: clamp(20px, 9vw, 52px);
    transition: transform 0.2s ease, background 0.2s ease;
    user-select: none;
    color: #fff;
}
/* Emoji scales with the number of columns so it fills each card nicely */
@supports (font-size: 16cqi) {
    .mem-card { font-size: calc(64cqi / var(--cols, 4)); }
}
.mem-card.open {
    background: linear-gradient(135deg, #ffd980, #f9a825);
    color: #1a1a2e;
    transform: rotateY(0);
}
.mem-card.matched {
    background: linear-gradient(135deg, #66bb6a, #2e7d32);
    color: #fff;
    pointer-events: none;
    box-shadow: 0 0 16px rgba(102, 187, 106, 0.5);
}
.mem-card:active { transform: scale(0.95); }

.memory-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}
.memory-overlay.show { display: flex; }
.memory-overlay-box {
    background: #1c1a2b;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 18px;
    padding: 24px 28px;
    text-align: center;
    max-width: 320px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}
.memory-overlay-box h2 {
    margin-bottom: 8px;
    font-size: 22px;
    color: #fff;
}
.memory-overlay-box p  {
    margin-bottom: 16px;
    color: rgba(255,255,255,0.75);
    font-size: 14px;
    line-height: 1.4;
}
.memory-overlay-box button {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: #2ea6ff;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}
