* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Microsoft YaHei', 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 16px;
}

.game-container {
    max-width: 560px;
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

/* ===== Header ===== */
.game-header {
    text-align: center;
    margin-bottom: 16px;
}

.game-header h1 {
    font-size: 1.6rem;
    color: #333;
    margin-bottom: 12px;
}

.stats {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    align-items: baseline;
    gap: 4px;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: #fff;
    padding: 6px 14px;
    border-radius: 10px;
    font-size: 14px;
}

.stat-item.best {
    background: linear-gradient(135deg, #f7971e 0%, #ffd200 100%);
    color: #5a3e00;
}

.stat-label {
    opacity: 0.85;
    font-size: 12px;
}

.stat-value {
    font-weight: bold;
    font-size: 16px;
}

.stat-sep {
    opacity: 0.6;
    font-size: 14px;
}

/* ===== Difficulty ===== */
.difficulty-selector {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.diff-btn {
    padding: 7px 16px;
    border: 2px solid #ddd;
    border-radius: 20px;
    background: #fff;
    color: #555;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.diff-btn:hover {
    border-color: #667eea;
    color: #667eea;
}

.diff-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: transparent;
    color: #fff;
}

/* ===== Board ===== */
.board {
    display: grid;
    gap: 8px;
    padding: 12px;
    background: #e8e0f0;
    border-radius: 16px;
    margin-bottom: 14px;
    touch-action: manipulation;
}

.board[data-cols="4"] {
    grid-template-columns: repeat(4, 1fr);
}

.board[data-cols="6"] {
    grid-template-columns: repeat(6, 1fr);
}

/* ===== Card ===== */
.card {
    aspect-ratio: 1;
    perspective: 600px;
    cursor: pointer;
    user-select: none;
}

.card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.45s ease;
    transform-style: preserve-3d;
}

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

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

.card-back {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.35);
    font-size: 28px;
    color: rgba(255,255,255,0.3);
}

.card-back::after {
    content: '?';
    font-weight: bold;
}

.card-front {
    background: #fff;
    border: 2px solid #e0d6f0;
    transform: rotateY(180deg);
    font-size: clamp(22px, 6vw, 36px);
    line-height: 1;
}

.card.matched .card-front {
    background: #e8fce8;
    border-color: #81c784;
    animation: matchPop 0.4s ease;
}

.card.shake .card-inner {
    animation: cardShake 0.35s ease;
}

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

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

/* ===== Controls ===== */
.controls {
    text-align: center;
    margin-bottom: 10px;
}

.btn {
    padding: 10px 28px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

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

/* ===== Tip ===== */
.game-tip {
    text-align: center;
    color: #888;
    font-size: 13px;
    padding: 8px;
    background: #f5f2fa;
    border-radius: 8px;
}

/* ===== Modal ===== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.show {
    display: flex;
    animation: fadeIn 0.3s;
}

.modal-content {
    background: #fff;
    padding: 36px 32px;
    border-radius: 20px;
    text-align: center;
    max-width: 360px;
    width: 90%;
    animation: slideUp 0.35s;
}

.modal-content h2 {
    color: #667eea;
    margin-bottom: 16px;
    font-size: 1.6rem;
}

.modal-content p {
    color: #555;
    margin-bottom: 8px;
    font-size: 15px;
}

.best-msg {
    color: #f7971e;
    font-weight: bold;
    font-size: 16px !important;
    margin: 12px 0 !important;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(40px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
    body { padding: 8px; }
    .game-container { padding: 14px; border-radius: 14px; }
    .game-header h1 { font-size: 1.3rem; }
    .stats { gap: 6px; }
    .stat-item { padding: 5px 10px; font-size: 12px; }
    .stat-value { font-size: 14px; }
    .diff-btn { padding: 5px 12px; font-size: 12px; }
    .board { gap: 6px; padding: 8px; }
    .card-back::after { font-size: 20px; }
}
