/* Reset and base styles */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a5f23, #0d3b1e);
    color: #fff;
    min-height: 100vh;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.ai-win-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.win-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: none;
    /* 改为flex布局 */
    justify-content: center;
    align-items: center;
    z-index: 1000;
}


/* 当需要显示时设置为flex */

.win-modal.show,
.ai-win-modal.show {
    display: flex;
}

.ai-win-content {
    background: linear-gradient(135deg, #ffd700, #ff8c00);
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    animation: aiWinAnimation 0.5s ease-out;
}

.ai-win-content h2 {
    color: #8b0000;
    font-size: 2em;
    margin-bottom: 15px;
}

.ai-win-content p {
    color: #fff;
    font-size: 1.2em;
    margin: 0;
}

@keyframes aiWinAnimation {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    70% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}


/* Loading overlay */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a5f23, #0d3b1e);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

.loading-content {
    text-align: center;
    padding: 30px;
    background: rgba(0, 20, 0, 0.8);
    border-radius: 20px;
    border: 3px solid #4a7c59;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.6);
    max-width: 400px;
    width: 90%;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 5px solid rgba(255, 215, 0, 0.3);
    border-top: 5px solid #ffd700;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.loading-text {
    font-size: 1.5rem;
    color: #ffd700;
    margin-bottom: 10px;
    font-weight: bold;
}

.loading-subtext {
    font-size: 1rem;
    color: #ccc;
}


/* Game container */

.game-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.game-container.loaded {
    opacity: 1;
    transform: translateY(0);
}

h1 {
    text-align: center;
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: #ffd700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    letter-spacing: 2px;
}

a {
    text-decoration: none;
}


/* Game status */

#gameStatus {
    background: rgba(0, 0, 0, 0.6);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 20px;
    text-align: center;
    font-size: 1.2rem;
    border: 2px solid #ffd700;
    min-height: 2.5em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

#gameStatus.init {
    color: #ffd700;
    font-style: italic;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
    100% {
        opacity: 1;
    }
}


/* Player areas */

.ai-area {
    background: rgba(0, 30, 0, 0.7);
    border-radius: 15px;
    padding: 15px;
    margin: 15px 0;
    border: 2px solid #4a7c59;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    position: relative;
}

.ai-area.top {
    margin-bottom: 30px;
}

.ai-area.left,
.ai-area.right {
    position: absolute;
    height: 300px;
    width: 200px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.ai-area.left {
    left: 20px;
}

.ai-area.right {
    right: 20px;
}

.ai-info {
    text-align: center;
    font-size: 1.2rem;
    margin-bottom: 10px;
    color: #ffd700;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.3);
    padding: 5px;
    border-radius: 5px;
}


/* 为不同方向的玩家添加特殊标识 */

.ai-area.top .ai-info {
    background: linear-gradient(to right, #ff8c00, #ffd700);
    color: #fff;
    font-weight: bold;
}

.ai-area.left .ai-info {
    background: linear-gradient(to right, #4169e1, #6495ed);
    color: #fff;
    font-weight: bold;
}

.ai-area.right .ai-info {
    background: linear-gradient(to right, #d2691e, #cd853f);
    color: #fff;
    font-weight: bold;
}

.player-area {
    background: rgba(0, 30, 0, 0.7);
    border-radius: 15px;
    padding: 15px;
    margin-top: 30px;
    border: 2px solid #4a7c59;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.player-info {
    text-align: center;
    font-size: 1.2rem;
    margin-bottom: 10px;
    color: #ffd700;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.3);
    padding: 5px 15px;
    border-radius: 20px;
    width: auto;
}

.player-area .player-info {
    background: linear-gradient(to right, #2e8b57, #3cb371);
    color: #fff;
    font-weight: bold;
}


/* Player hand area - ensure tiles are in a row */

.player-hand {
    display: flex;
    flex-wrap: nowrap;
    /* Prevent wrapping */
    justify-content: center;
    gap: 5px;
    padding: 10px 0;
    overflow-x: auto;
    /* Allow horizontal scrolling if needed */
    min-height: 80px;
    /* Ensure space for tiles */
    padding: 15px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    width: 100%;
}


/* Center area */

.center-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    margin: 20px 0;
    background: rgba(0, 20, 0, 0.5);
    border-radius: 20px;
    border: 3px solid #4a7c59;
    position: relative;
    padding: 20px;
}

.discard-pile {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    justify-content: center;
    margin-bottom: 20px;
    min-height: 100px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    min-width: 200px;
    max-width: 100%;
}

.draw-btn {
    background: linear-gradient(to bottom, #ffd700, #ffa500);
    color: #8b4513;
    border: none;
    border-radius: 50px;
    padding: 15px 30px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    margin-top: 20px;
    position: relative;
    overflow: hidden;
}

.draw-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient( 90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: 0.5s;
}

.draw-btn:hover::before {
    left: 100%;
}

.draw-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.4);
    background: linear-gradient(to bottom, #ffdf40, #ffb733);
}

.draw-btn:active {
    transform: translateY(1px);
}


/* Tile styling - more elegant design */

.tile {
    width: 50px;
    height: 70px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
    border: 2px solid transparent;
    flex-shrink: 0;
    /* Prevent tiles from shrinking */
    background: linear-gradient(145deg, #ffffff, #f0f0f0);
}

.tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.3));
    border-radius: 6px;
    z-index: 1;
}

.tile span {
    position: relative;
    z-index: 2;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}


/* Suit-specific styling with better colors */

.tile.wan {
    color: #d2691e;
}

.tile.tiao {
    color: #2e8b57;
}

.tile.bing {
    color: #1e90ff;
}

.tile.character {
    background: linear-gradient(145deg, #fff8dc, #ffe4b5);
    color: #8b0000;
}

.tile.discard {
    cursor: pointer;
}

.tile.discard:hover {
    transform: translateY(-8px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.4);
    border-color: #ffd700;
}

.tile.selected {
    transform: translateY(-10px);
    box-shadow: 0 10px 20px rgba(255, 215, 0, 0.6);
    border-color: gold;
    background: linear-gradient(145deg, #fffacd, #ffffe0);
}

.tile.discarded {
    opacity: 0.8;
    transform: rotate(2deg);
}

.tile.highlighted {
    animation: pulse 1.5s infinite;
    border-color: #ff4500;
    background: linear-gradient(145deg, #fffacd, #ffd700);
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}


/* Meld displays */

.meld-display {
    display: flex;
    flex-wrap: nowrap;
    /* Keep melds in a row */
    gap: 10px;
    margin: 10px 0;
    justify-content: center;
    min-height: 80px;
    /* Space for melded tiles */
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    width: 100%;
}

.meld-group.compact {
    display: flex;
    gap: 2px;
}


/* Action panel */

.action-panel {
    background: rgba(30, 30, 30, 0.95);
    border-radius: 15px;
    padding: 20px;
    margin: 20px auto;
    max-width: 500px;
    text-align: center;
    border: 2px solid #ffd700;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
}

.action-panel h3 {
    color: #ffd700;
    margin-bottom: 15px;
    font-size: 1.4rem;
}

.action-btn {
    background: linear-gradient(to bottom, #4a7c59, #2d5a3d);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 20px;
    margin: 5px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 100px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.action-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
    background: linear-gradient(to bottom, #5a8c69, #3d6a4d);
}

.action-btn.win-btn {
    background: linear-gradient(to bottom, #d4af37, #b8860b);
    animation: glow 2s infinite alternate;
}

@keyframes glow {
    from {
        box-shadow: 0 0 5px #ffd700;
    }
    to {
        box-shadow: 0 0 20px #ffd700, 0 0 30px #ffa500;
    }
}

.action-btn.pass-btn {
    background: linear-gradient(to bottom, #696969, #494949);
}


/* Controls */

.controls {
    text-align: center;
    margin-top: 20px;
}

.control-btn {
    background: linear-gradient(to bottom, #8b4513, #6b3a0e);
    color: #ffd700;
    border: none;
    border-radius: 8px;
    padding: 12px 25px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.control-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
    background: linear-gradient(to bottom, #9b5523, #7b4a1e);
}


/* Responsive adjustments */

@media (max-width: 768px) {
    .ai-area.left,
    .ai-area.right {
        position: static;
        transform: none;
        width: auto;
        height: auto;
        margin: 15px 0;
    }
    .player-hand {
        gap: 3px;
    }
    .tile {
        width: 40px;
        height: 60px;
        font-size: 1rem;
    }
    h1 {
        font-size: 1.2rem;
    }
    .loading-content {
        padding: 2px;
        max-width: 300px;
    }
    .ai-area.top {
        margin-bottom: 2px;
    }
}


/* Win modal styling - enhanced */

.win-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.9) 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    backdrop-filter: blur(5px);
}

.win-content {
    background: linear-gradient(145deg, #2c3e50, #1a2530);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 0 50px rgba(212, 175, 55, 0.6);
    border: 3px solid #d4af37;
    max-width: 90%;
    width: 500px;
    position: relative;
    overflow: hidden;
}

.win-content::before {
    content: "";
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(212, 175, 55, 0.1) 0%, transparent 70%);
    z-index: 0;
}

.win-content>* {
    position: relative;
    z-index: 1;
}

.win-content h2 {
    color: #ffd700;
    font-size: 2.5rem;
    margin-bottom: 15px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    animation: shine 3s infinite;
}

@keyframes shine {
    0% {
        text-shadow: 0 0 5px #ffd700;
    }
    50% {
        text-shadow: 0 0 20px #ffd700, 0 0 30px #ffa500;
    }
    100% {
        text-shadow: 0 0 5px #ffd700;
    }
}

.win-content p {
    font-size: 1.4rem;
    margin-bottom: 25px;
    color: #fff;
}

#continueGameBtn {
    background: linear-gradient(to bottom, #d4af37, #b8860b);
    color: #1a1a1a;
    border: none;
    padding: 15px 30px;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.4);
}

#continueGameBtn:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 20px rgba(212, 175, 55, 0.6);
    background: linear-gradient(to bottom, #ffd700, #daa520);
}