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

:root {
    --primary-color: #4a90e2;
    --secondary-color: #f39c12;
    --success-color: #2ecc71;
    --error-color: #e74c3c;
    --bg-gradient-start: #667eea;
    --bg-gradient-end: #764ba2;
    --tile-bg: #ffffff;
    --tile-shadow: rgba(0, 0, 0, 0.1);
    --modal-bg: rgba(0, 0, 0, 0.8);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    overflow-x: hidden;
}

.container {
    width: 100%;
    max-width: 1000px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 20px;
    animation: slideIn 0.5s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.game-header {
    text-align: center;
    margin-bottom: 20px;
}

.game-header h1 {
    color: var(--bg-gradient-end);
    font-size: 2.5rem;
    margin-bottom: 15px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.info-panel {
    display: flex;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
    margin-top: 15px;
}

.info-item {
    background: linear-gradient(135deg, var(--primary-color), #357abd);
    padding: 12px 25px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    color: white;
    font-weight: 600;
}

.info-item .label {
    opacity: 0.9;
    margin-right: 8px;
}

.info-item .value {
    font-size: 1.3rem;
    font-weight: bold;
}

.game-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 20px 0;
    min-height: 400px;
}

.game-board {
    display: grid;
    gap: 8px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    width: 100%;
    max-width: 800px;
    aspect-ratio: 5/4;
}

.game-board.paused::after {
    content: '⏸️ 游戏已暂停';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 30px 50px;
    border-radius: 15px;
    font-size: 1.8rem;
    font-weight: bold;
    z-index: 100;
}

.tile {
    background: var(--tile-bg);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px var(--tile-shadow);
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.3), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.tile:hover::before {
    opacity: 1;
}

.tile:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 8px 12px rgba(0, 0, 0, 0.2);
}

.tile:active {
    transform: scale(0.95);
}

.tile-icon {
    font-size: 2.5rem;
    transition: transform 0.3s;
}

.tile:hover .tile-icon {
    transform: scale(1.2) rotate(5deg);
}

.tile.selected {
    background: linear-gradient(135deg, #ffeaa7, #fdcb6e);
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(253, 203, 110, 0.6);
    animation: pulse 0.6s infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1.1);
    }
    50% {
        transform: scale(1.15);
    }
}

.tile.matched {
    animation: matchAnimation 0.5s ease-out forwards;
}

@keyframes matchAnimation {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.3) rotate(10deg);
        background: var(--success-color);
    }
    100% {
        transform: scale(0);
        opacity: 0;
    }
}

.tile.error {
    animation: errorShake 0.5s;
    background: linear-gradient(135deg, #ff7979, #eb4d4b);
}

@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

.tile.hint {
    animation: hintBlink 1.5s;
}

@keyframes hintBlink {
    0%, 100% {
        background: var(--tile-bg);
        box-shadow: 0 4px 6px var(--tile-shadow);
    }
    50% {
        background: linear-gradient(135deg, #74b9ff, #0984e3);
        box-shadow: 0 0 25px rgba(9, 132, 227, 0.8);
        transform: scale(1.1);
    }
}

.controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
    margin-top: 20px;
}

.btn {
    padding: 12px 30px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), #357abd);
    color: white;
}

.btn-secondary {
    background: linear-gradient(135deg, #95a5a6, #7f8c8d);
    color: white;
}

.btn-hint {
    background: linear-gradient(135deg, var(--secondary-color), #e67e22);
    color: white;
}

.btn-shuffle {
    background: linear-gradient(135deg, #a29bfe, #6c5ce7);
    color: white;
}

.shuffle-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 20px 40px;
    border-radius: 15px;
    font-size: 1.5rem;
    font-weight: bold;
    z-index: 2000;
    animation: messageSlideIn 0.3s ease-out;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translate(-50%, -60%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

.shuffle-message.fade-out {
    animation: messageFadeOut 0.3s ease-out forwards;
}

@keyframes messageFadeOut {
    to {
        opacity: 0;
        transform: translate(-50%, -40%);
    }
}

.tile.shuffling {
    animation: shuffleAnimation 0.6s ease-in-out;
}

@keyframes shuffleAnimation {
    0%, 100% {
        transform: scale(1) rotate(0deg);
    }
    25% {
        transform: scale(0.8) rotate(-5deg);
    }
    50% {
        transform: scale(1.2) rotate(5deg);
    }
    75% {
        transform: scale(0.9) rotate(-3deg);
    }
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s;
}

.modal.hidden {
    display: none;
}

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

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.4s ease-out;
    max-width: 90%;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px) scale(0.8);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.modal-content h2 {
    color: var(--bg-gradient-end);
    font-size: 2.5rem;
    margin-bottom: 20px;
}

.result-text {
    font-size: 1.2rem;
    color: #555;
    margin-bottom: 20px;
}

.result-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin: 20px 0;
    font-size: 1.1rem;
}

.result-stats strong {
    color: var(--primary-color);
    font-size: 1.5rem;
}

/* 响应式设计 - 平板 */
@media (max-width: 768px) {
    .container {
        padding: 15px;
        border-radius: 15px;
    }

    .game-header h1 {
        font-size: 2rem;
    }

    .info-panel {
        gap: 15px;
    }

    .info-item {
        padding: 10px 20px;
        font-size: 0.9rem;
    }

    .info-item .value {
        font-size: 1.1rem;
    }

    .game-board {
        gap: 6px;
        padding: 15px;
        aspect-ratio: 1/1;
    }

    .tile-icon {
        font-size: 2rem;
    }

    .btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }

    .modal-content {
        padding: 30px 20px;
    }

    .modal-content h2 {
        font-size: 2rem;
    }

    .result-stats {
        flex-direction: column;
        gap: 10px;
    }
}

/* 响应式设计 - 手机 */
@media (max-width: 480px) {
    body {
        padding: 5px;
    }

    .container {
        padding: 10px;
        border-radius: 10px;
    }

    .game-header h1 {
        font-size: 1.5rem;
        margin-bottom: 10px;
    }

    .info-panel {
        gap: 10px;
    }

    .info-item {
        padding: 8px 15px;
        font-size: 0.8rem;
    }

    .info-item .value {
        font-size: 1rem;
    }

    .game-wrapper {
        min-height: 300px;
        margin: 15px 0;
    }

    .game-board {
        gap: 4px;
        padding: 10px;
    }

    .tile {
        border-radius: 8px;
    }

    .tile-icon {
        font-size: 1.5rem;
    }

    .controls {
        gap: 10px;
    }

    .btn {
        padding: 10px 15px;
        font-size: 0.85rem;
        letter-spacing: 0.5px;
    }

    .game-board.paused::after {
        padding: 20px 30px;
        font-size: 1.2rem;
    }

    .modal-content {
        padding: 25px 15px;
    }

    .modal-content h2 {
        font-size: 1.6rem;
    }

    .result-text {
        font-size: 1rem;
    }

    .result-stats {
        font-size: 0.95rem;
    }

    .result-stats strong {
        font-size: 1.2rem;
    }
}

/* 横屏优化 */
@media (max-width: 768px) and (orientation: landscape) {
    .container {
        max-width: 100%;
        display: flex;
        flex-direction: column;
    }

    .game-wrapper {
        min-height: auto;
        flex: 1;
    }

    .game-board {
        max-height: 60vh;
    }

    .game-header h1 {
        font-size: 1.5rem;
        margin-bottom: 5px;
    }

    .info-panel {
        margin-top: 5px;
    }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    .tile:hover {
        transform: none;
        box-shadow: 0 4px 6px var(--tile-shadow);
    }

    .tile:hover::before {
        opacity: 0;
    }

    .tile:hover .tile-icon {
        transform: none;
    }

    .btn:hover {
        transform: none;
    }
}
