* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

.start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.start-content {
    text-align: center;
    color: white;
}

.game-icon {
    font-size: 100px;
    margin-bottom: 20px;
    animation: bounce 1s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

.start-content h1 {
    font-size: 36px;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.start-content p {
    font-size: 18px;
    margin-bottom: 40px;
    opacity: 0.9;
}

.start-btn {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    border: none;
    padding: 18px 60px;
    font-size: 22px;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(245, 87, 108, 0.5);
    transition: all 0.3s ease;
    min-height: 56px;
}

.start-btn:active {
    transform: scale(0.95);
}

.game-container {
    background: linear-gradient(180deg, #fff9e6 0%, #ffe4b5 100%);
    border-radius: 20px;
    padding: 15px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 480px;
    width: 100%;
    max-height: 100vh;
    overflow-y: auto;
}

.user-info {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 8px 0;
    margin-bottom: 8px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    margin-right: 10px;
}

.user-name {
    font-size: 16px;
    font-weight: bold;
    color: #333;
}

.header h1 {
    text-align: center;
    color: #ff6b6b;
    font-size: 24px;
    margin-bottom: 12px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 12px;
}

.stat-box {
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    border-radius: 12px;
    padding: 8px 12px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(252, 182, 159, 0.4);
    flex: 1;
    margin: 0 4px;
}

.stat-box .label {
    display: block;
    font-size: 12px;
    color: #8b5a2b;
    font-weight: 600;
}

.stat-box .value {
    display: block;
    font-size: 20px;
    font-weight: bold;
    color: #d35400;
}

.sound-controls {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.sound-btn {
    background: linear-gradient(135deg, #84fab0 0%, #8fd3f4 100%);
    color: #2c3e50;
    border: none;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: bold;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(133, 250, 176, 0.4);
    transition: all 0.3s ease;
    min-height: 36px;
}

.sound-btn.off {
    background: linear-gradient(135deg, #bdc3c7 0%, #95a5a6 100%);
    box-shadow: 0 4px 15px rgba(189, 195, 199, 0.4);
}

.rank-btn {
    background: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
    box-shadow: 0 4px 15px rgba(253, 160, 133, 0.4);
}

.board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    padding: 10px;
    border-radius: 15px;
    box-shadow: inset 0 4px 20px rgba(0, 0, 0, 0.1);
    touch-action: none;
}

.cell {
    aspect-ratio: 1;
    background: linear-gradient(145deg, #ffffff 0%, #f0f0f0 100%);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: transform 0.15s ease;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    min-height: 40px;
    font-size: 1.8rem;
}

.cell img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    display: block;
}

.cell:hover {
    transform: scale(1.05);
}

.cell.selected {
    background: linear-gradient(145deg, #ffd700 0%, #ffb347 100%);
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
}

.cell.matched {
    animation: matchAnim 0.4s ease-out forwards;
}

.cell.falling {
    animation: fallAnim 0.3s ease-out;
}

.cell.swapping {
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
}

@keyframes matchAnim {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.3);
        opacity: 0.8;
    }
    100% {
        transform: scale(0);
        opacity: 0;
    }
}

@keyframes fallAnim {
    0% {
        transform: translateY(-50px);
        opacity: 0;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

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

.btn {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    border: none;
    padding: 14px 40px;
    font-size: 16px;
    font-weight: bold;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(245, 87, 108, 0.4);
    transition: all 0.3s ease;
    min-height: 48px;
}

.btn:active {
    transform: scale(0.98);
}

.instructions {
    margin-top: 12px;
    text-align: center;
}

.instructions p {
    color: #7f8c8d;
    font-size: 13px;
    line-height: 1.5;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: linear-gradient(180deg, #fff9e6 0%, #ffe4b5 100%);
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalPop 0.3s ease-out;
    max-width: 320px;
    width: 90%;
}

.rank-content {
    max-width: 360px;
    max-height: 80vh;
    overflow-y: auto;
}

@keyframes modalPop {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-content h2 {
    color: #ff6b6b;
    font-size: 28px;
    margin-bottom: 12px;
}

.modal-content p {
    color: #7f8c8d;
    font-size: 16px;
    margin-bottom: 8px;
}

.final-score {
    font-size: 48px !important;
    font-weight: bold;
    color: #f39c12 !important;
    margin-bottom: 20px !important;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.rank-btn-small {
    background: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
}

.close-rank-btn {
    background: linear-gradient(135deg, #bdc3c7 0%, #95a5a6 100%);
}

.my-rank {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px;
    border-radius: 12px;
    margin-bottom: 15px;
    font-weight: bold;
    font-size: 15px;
}

.rank-list {
    max-height: 400px;
    overflow-y: auto;
}

.rank-loading {
    color: #999;
    padding: 20px;
    text-align: center;
}

.rank-item {
    display: flex;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #eee;
    background: white;
    margin-bottom: 5px;
    border-radius: 8px;
}

.rank-item:first-child {
    background: linear-gradient(135deg, #ffd700 0%, #ffb347 100%);
}

.rank-item:nth-child(2) {
    background: linear-gradient(135deg, #e0e0e0 0%, #c0c0c0 100%);
}

.rank-item:nth-child(3) {
    background: linear-gradient(135deg, #cd7f32 0%, #b8860b 100%);
}

.rank-number {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #3498db;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin-right: 10px;
    font-size: 14px;
}

.rank-item:first-child .rank-number,
.rank-item:nth-child(2) .rank-number,
.rank-item:nth-child(3) .rank-number {
    background: rgba(255,255,255,0.3);
}

.rank-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin-right: 10px;
}

.rank-name {
    flex: 1;
    text-align: left;
    font-weight: bold;
    font-size: 14px;
    color: #333;
}

.rank-score {
    font-weight: bold;
    color: #e74c3c;
    font-size: 16px;
}

@media (max-width: 375px) {
    .game-container {
        padding: 12px;
        border-radius: 16px;
    }

    .header h1 {
        font-size: 20px;
    }

    .stat-box {
        padding: 6px 8px;
    }

    .stat-box .value {
        font-size: 18px;
    }

    .cell {
        min-height: 36px;
        font-size: 1.5rem;
    }
}

@media (max-width: 320px) {
    .game-container {
        padding: 10px;
    }

    .stat-box .label {
        font-size: 11px;
    }

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

    .cell {
        min-height: 32px;
        font-size: 1.3rem;
    }
}
