/* Mahjong Game Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-color: #1a472a;
    --bg-gradient: linear-gradient(135deg, #1a472a 0%, #2d5a3d 50%, #1a472a 100%);
    --table-color: #2d5a3d;
    --tile-bg: #fefefe;
    --tile-border: #d4a574;
    --tile-shadow: #8b6f47;
    --tile-width: 40px;
    --tile-height: 54px;
    --tile-depth: 6px;
    --primary-color: #d4a574;
    --secondary-color: #8b6f47;
    --accent-color: #e74c3c;
    --text-color: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-color);
    min-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
}

#game-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
}

.game-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.game-title {
    font-size: 24px;
    font-weight: 700;
}

.game-round {
    background: var(--primary-color);
    color: #000;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
}

.game-controls {
    display: flex;
    gap: 8px;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #fff;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

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

/* Game Area */
.game-area {
    flex: 1;
    display: grid;
    grid-template-columns: 180px 1fr 180px;
    grid-template-rows: 1fr auto;
    gap: 10px;
    padding: 10px;
    position: relative;
    min-height: 0;
}

/* Player Areas */
.player-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    z-index: 10;
}

.player-top {
    grid-column: 2;
    grid-row: 1;
}

.player-left {
    grid-column: 1;
    grid-row: 1;
    flex-direction: row;
}

.player-right {
    grid-column: 3;
    grid-row: 1;
    flex-direction: row;
}

.player-bottom {
    grid-column: 1 / span 3;
    grid-row: 2;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid var(--primary-color);
    position: relative;
    z-index: 20;
}

.player-human .hand-tiles {
    background: rgba(212, 165, 116, 0.15);
    border-radius: 8px;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.player-left .player-info,
.player-right .player-info {
    flex-direction: column;
    margin-bottom: 0;
    margin-right: 8px;
}

.avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.name {
    font-size: 14px;
    font-weight: 600;
}

.tiles-count, .score {
    font-size: 12px;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 8px;
    border-radius: 10px;
}

/* Hand Tiles */
.hand-tiles {
    display: flex;
    gap: 4px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 100%;
}

.player-bottom .hand-tiles {
    gap: 6px;
}

.hidden-tiles {
    opacity: 0.7;
}

.hidden-tiles .tile {
    background: linear-gradient(135deg, #4a3728, #2d2218);
}

.hidden-tiles .tile::before {
    content: '';
}

/* Tile Styles */
.tile {
    width: var(--tile-width);
    height: var(--tile-height);
    background: var(--tile-bg);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    cursor: pointer;
    position: relative;
    box-shadow:
        0 4px 0 var(--tile-shadow),
        0 6px 8px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    border: 2px solid var(--tile-border);
    transition: all 0.2s;
    user-select: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.player-bottom .tile {
    width: 48px;
    height: 64px;
    font-size: 36px;
    font-weight: 700;
}

.tile:hover {
    transform: translateY(-4px);
    box-shadow: 
        0 8px 0 var(--tile-shadow),
        0 12px 16px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.tile.selected {
    transform: translateY(-12px);
    box-shadow: 
        0 16px 0 var(--tile-shadow),
        0 20px 24px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    border-color: var(--accent-color);
}

.tile:last-child {
    margin-right: 20px;
}

.tile:last-child::after {
    content: '';
    position: absolute;
    right: -16px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 70%;
    background: var(--accent-color);
    border-radius: 2px;
}

/* Tile Types Colors */
.tile[data-type="wan"] { color: #e74c3c; }
.tile[data-type="tong"] { color: #3498db; }
.tile[data-type="tiao"] { color: #27ae60; }
.tile[data-type="feng"] { color: #8e44ad; }
.tile[data-type="jian"] { color: #e74c3c; }
.tile[data-type="hua"] { color: #f39c12; }

/* Discarded Tiles */
.discarded-tiles {
    display: flex;
    gap: 4px;
    padding: 8px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 200px;
}

.discarded-tiles.vertical {
    flex-direction: column;
    max-width: 60px;
    max-height: 300px;
    overflow-y: auto;
}

.discarded-tiles .tile {
    width: 30px;
    height: 40px;
    font-size: 20px;
    cursor: default;
}

.discarded-tiles .tile:hover {
    transform: none;
}

/* Center Area */
.center-area {
    grid-column: 2;
    grid-row: 1 / span 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    position: relative;
}

/* Wall Container */
.wall-container {
    position: relative;
    padding: 20px;
}

.wall-tiles {
    display: grid;
    grid-template-columns: repeat(18, 1fr);
    gap: 2px;
}

.wall-tiles .tile {
    width: 20px;
    height: 28px;
    font-size: 14px;
    background: linear-gradient(135deg, #4a3728, #2d2218);
    cursor: default;
}

.wall-tiles .tile:hover {
    transform: none;
}

.wall-count {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 700;
}

/* Center Discards */
.center-discards {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
}

.center-discards .tile {
    width: 32px;
    height: 44px;
    font-size: 22px;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.action-btn {
    padding: 12px 24px;
    font-size: 18px;
    font-weight: 700;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

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

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

.action-btn.hidden {
    display: none;
}

#btn-hu {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
}

#btn-gang {
    background: linear-gradient(135deg, #f39c12, #d68910);
}

/* Player Actions */
.player-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

/* Game Message */
.game-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 20px 40px;
    border-radius: 16px;
    font-size: 24px;
    font-weight: 700;
    text-align: center;
    z-index: 100;
    animation: pulse 1s ease-in-out infinite;
    display: none;
}

.game-message.show {
    display: block;
}

@keyframes pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.05); }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: linear-gradient(135deg, #1a472a, #2d5a3d);
    padding: 40px;
    border-radius: 24px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    border: 2px solid var(--primary-color);
}

.modal-content h2 {
    font-size: 28px;
    margin-bottom: 20px;
}

.game-results {
    margin: 20px 0;
    text-align: left;
}

.result-item {
    display: flex;
    justify-content: space-between;
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    margin-bottom: 8px;
}

.rules-content {
    max-width: 600px;
}

.rules-text {
    text-align: left;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
}

.rules-text h3 {
    color: var(--primary-color);
    margin: 16px 0 8px;
}

.rules-text ul {
    margin-left: 20px;
    line-height: 1.8;
    color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 1024px) {
    .game-area {
        grid-template-columns: 120px 1fr 120px;
    }

    :root {
        --tile-width: 32px;
        --tile-height: 44px;
    }

    .player-bottom .tile {
        width: 40px;
        height: 54px;
        font-size: 28px;
    }
}

@media (max-width: 768px) {
    .game-area {
        grid-template-columns: 80px 1fr 80px;
        gap: 5px;
    }

    .player-left, .player-right {
        display: none;
    }

    .game-header {
        flex-direction: column;
        gap: 10px;
    }

    .game-controls {
        width: 100%;
        justify-content: center;
    }

    :root {
        --tile-width: 28px;
        --tile-height: 38px;
    }

    .player-bottom .tile {
        width: 36px;
        height: 48px;
        font-size: 24px;
    }

    .action-buttons {
        gap: 6px;
    }

    .action-btn {
        padding: 10px 16px;
        font-size: 16px;
    }
}

/* Animations */
@keyframes drawTile {
    0% { transform: scale(0.5) translateY(20px); opacity: 0; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}

.tile.drawn {
    animation: drawTile 0.3s ease-out;
}

@keyframes discardTile {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.tile.discarded {
    animation: discardTile 0.3s ease-out;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 14px 28px;
    border-radius: 30px;
    font-size: 16px;
    opacity: 0;
    transition: all 0.3s;
    z-index: 2000;
    backdrop-filter: blur(10px);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
