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

body {
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
    min-height: 100vh;
}

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

.screen {
    background-color: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    flex: 1;
}

/* 開始畫面 */
#start-screen {
    text-align: center;
    padding: 50px;
}

#start-screen h1 {
    font-size: 48px;
    margin-bottom: 30px;
    color: #333;
}

#start-screen button {
    display: block;
    width: 200px;
    margin: 15px auto;
    padding: 15px;
    font-size: 18px;
    border: none;
    border-radius: 5px;
    background-color: #4CAF50;
    color: white;
    cursor: pointer;
}

#start-screen button:hover {
    background-color: #45a049;
}


/* 遊戲畫面 */
#game-screen {
    display: flex;
    flex-direction: column;
    gap: 20px;  /* 增加間距 */
    height: 100%;
}

/* 分數區域 */
#score-area {
    background-color: #e6f3ff;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 10px;
    height: 80px;  /* 增加高度 */
    font-size: 24px;  /* 增加字體大小 */
}

#back-to-menu {
    padding: 10px 20px;
    font-size: 20px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

#back-to-menu:hover {
    background-color: #45a049;
}

#scores {
    font-weight: normal;
}

/* 主要遊戲區域 */
.game-area {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 20px;  /* 增加間距 */
}

/* 電腦手牌區域 */
#computer-area {
    background-color: #f8f8f8;  /* 改為淺灰色背景 */
    padding: 15px;
    border-radius: 10px;
    min-height: 180px;
    display: grid;
    gap: 15px;
}

/* 根據玩家數量設置網格列數 */
#computer-area.players-2 { grid-template-columns: repeat(1, 1fr); }
#computer-area.players-3 { grid-template-columns: repeat(2, 1fr); }
#computer-area.players-4 { grid-template-columns: repeat(3, 1fr); }
#computer-area.players-6 { grid-template-columns: repeat(5, 1fr); }

.computer-hand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 8px;
    transition: background-color 0.3s;
}

.computer-hand.active {
    background-color: #ffe97f;  /* 當前玩家的高亮顏色 */
}

.computer-hand .cards-stack {
    position: relative;
    height: 120px;
    width: 100px;
}

.computer-hand img {
    position: absolute;
    width: 90px;
    height: 120px;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* 重疊效果 - 水平排列 */
.computer-hand .cards-stack img {
    transform: translateX(var(--offset-x));
}

.computer-hand .player-name {
    font-size: 16px;
    font-weight: bold;
}

/* 桌面區域 */
#table-area {
    background-color: #90EE90;
    height: 33vh;
    display: flex;
    border-radius: 10px;
    padding: 15px;
    gap: 15px;
    min-height: 220px;
    align-items: center;  /* 垂直置中 */
}

/* 動畫效果 */
@keyframes moveToPlayArea {
    0% { transform: translate(0, 0); }
    100% { transform: translate(var(--target-x), var(--target-y)); }
}

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

@keyframes fadeOut {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes highlight {
    0% { background-color: inherit; }
    50% { background-color: #ffe97f; }
    100% { background-color: inherit; }
}

/* 出牌區域 */
#played-card-area {
    background-color: #eed3c2;
    width: 150px;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    position: relative;
    height: 220px;
    z-index: 2;  /* 確保出牌區域在最上層 */
}

#played-card-area img {
    position: absolute;
    width: 140px;
    height: 190px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    animation: moveToPlayArea 0.3s ease forwards;
}

/* 公開牌區域 */
#open-cards-area {
    background-color: #FFFFE0;
    flex: 1;
    border-radius: 10px;
    padding: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: visible;
    height: 220px;
}


.card-stack {
    position: absolute;
    display: inline-block;
    transition: transform 0.3s ease;
    left: 50%;
    justify-content: center;
    transform: translateX(-50%);
}

.card-stack img {
    width: 140px;
    height: 190px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: transform 0.3s ease;
}


/* 牌堆區域 */
#deck-area {
    width: 150px;
    border-radius: 10px;
    background-color: #ddddfa;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
    position: relative;
    height: 240px;
    align-self: center;  /* 垂直置中 */
}

.deck-stack {
    position: relative;
    width: 140px;
    height: 190px;
    margin-bottom: 10px;
}

.deck-stack img {
    position: absolute;
    width: 140px;
    height: 190px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* matched card*/
#deck-area > div:last-child {
    position: relative;
    margin-top: 10px;
    width: 140px;
    height: 190px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#deck-area > div:last-child img {
    position: absolute;
    width: 140px;
    height: 190px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.deck-stack img:nth-child(1) { transform: translateY(0); }
.deck-stack img:nth-child(2) { transform: translateY(2px); }
.deck-stack img:nth-child(3) { transform: translateY(4px); }
.deck-stack img:nth-child(4) { transform: translateY(6px); }
.deck-stack img:nth-child(5) { transform: translateY(8px); }
.deck-stack img:nth-child(6) { transform: translateY(10px); }
.deck-stack img:nth-child(7) { transform: translateY(120px); }

#deck-area.active {
    background-color: #ffe97f;
}

/* 結算面板 */
#result-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 0 20px rgba(0,0,0,0.2);
    z-index: 1000;
    min-width: 300px;
}

#result-panel h2 {
    text-align: center;
    margin-bottom: 20px;
    color: #333;
}

.result-list {
    list-style: none;
    padding: 0;
}

.result-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
    font-size: 18px;
}

.result-item:last-child {
    border-bottom: none;
}

.result-rank {
    font-weight: bold;
    color: #4CAF50;
    margin-right: 15px;
}

.result-name {
    flex: 1;
}

.result-score {
    font-weight: bold;
}

#result-panel button {
    display: block;
    width: 100%;
    padding: 10px;
    margin-top: 20px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
}

#result-panel button:hover {
    background-color: #45a049;
}

/* 遮罩層 */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0,0,0,0.5);
    z-index: 999;
}

/* 玩家手牌區域 */
#player-area {
    background-color: #f8f8f8;  /* 與電腦區域相同的背景色 */
    border-radius: 10px;
    padding: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 220px;
}

.player-cards-container {
    position: relative;
    height: 190px;
    display: flex;
    justify-content: center;
}

.player-card {
    position: relative;
    /*margin: 0 -30px;  /* 重疊效果 */
    cursor: pointer;
    transition: transform 0.2s;
}

.player-card img {
    width: 140px;
    height: 190px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.player-card:hover {
    transform: translateY(-20px);
    z-index: 10;
}

/* 動畫效果 */
@keyframes highlight {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.highlight {
    animation: highlight 0.5s ease-in-out;
}

/* 玩家區域高亮 */
#player-area.active {
    background-color: #ffe97f;  /* 當前玩家的高亮顏色 */
}

/* 設定畫面 */
#settings-screen {
    max-width: 600px;
    margin: 0 auto;
}

.settings-content {
    margin: 20px 0;
}

.setting-item {
    margin: 15px 0;
    display: flex;
    align-items: center;
}

.setting-item label {
    width: 150px;
}

.setting-item input[type="range"] {
    flex: 1;
    margin: 0 10px;
}

.setting-value {
    width: 50px;
}

.radio-group {
    display: flex;
    gap: 20px;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 5px;
    width: auto;
    cursor: pointer;
}

.settings-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

#save-settings, #cancel-settings {
    padding: 10px 20px;
    font-size: 16px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

#save-settings {
    background-color: #4CAF50;
    color: white;
}

#cancel-settings {
    background-color: #f44336;
    color: white;
}

#save-settings:hover {
    background-color: #45a049;
}

#cancel-settings:hover {
    background-color: #d32f2f;
}

/* 玩家點擊牌後的動畫 */
.player-card.clicked {
    animation: cardClick 0.3s ease forwards;
}

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

/* 出牌動畫 */
@keyframes moveToPlayArea {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

#played-card-area img {
    animation: moveToPlayArea 0.3s ease forwards;
}

.overlapping-cards {
    position: relative;
    width: 140px;
    height: 190px;
    margin: 0 auto;
}

.overlapping-cards .card-bottom {
    position: absolute;
    left: 0;
    top: 40px;
    z-index: 2;
}

.overlapping-cards .card-top {
    position: absolute;
    left: 0;
    top: -10px;
    z-index: 1;
}

@keyframes moveLeftToOpenCenter {
    0% {
        transform: translate(0, 0);
        opacity: 1;
    }
    100% {
        transform: translate(-100%, 0%);
        opacity: 0;
    }
}

@keyframes moveRightToOpenCenter {
    0% {
        transform: translate(0, 0);
        opacity: 1;
    }
    100% {
        transform: translate(100%, 0%);
        opacity: 0;
    }
}

.move-to-open-left {
    animation: moveLeftToOpenCenter 0.5s ease forwards;
    position: absolute;
    left: 0;
    top: 0;
    z-index: 10;
}
.move-to-open-right {
    animation: moveRightToOpenCenter 0.5s ease forwards;
    position: absolute;
    left: 0;
    top: 0;
    z-index: 10;
}

.card-animation {
    width: 100px;
    height: 140px;
    position: absolute;
    z-index: 100;
    pointer-events: none;
}

.qualified-mark {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 6px;
    background-color: #4CAF50;
    color: white;
    border-radius: 4px;
    font-size: 14px;
    font-weight: bold;
}

.speed-buttons {
    display: flex;
    gap: 10px;
    margin: 10px 0;
}

.speed-buttons button {
    padding: 8px 15px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s;
}

#speed-fast {
    background-color: #4CAF50;
    color: white;
}

#speed-medium {
    background-color: #2196F3;
    color: white;
}

#speed-slow {
    background-color: #f44336;
    color: white;
}

.speed-buttons button:hover {
    opacity: 0.8;
    transform: scale(1.05);
}

.speed-buttons button.selected {
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(0,0,0,0.3);
}

#speed-fast.selected {
    background-color: #2E7D32;
}

#speed-medium.selected {
    background-color: #1565C0;
}

#speed-slow.selected {
    background-color: #C62828;
}

.start-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 30px;
    align-items: center;
}

.start-buttons button {
    width: 200px;
    padding: 12px 24px;
    font-size: 18px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

#start-game {
    background-color: #4CAF50;
    color: white;
}

#how-to-play {
    background-color: #2196F3;
    color: white;
}

#settings-icon {
    background-color: #f44336;
    color: white;
}

.start-buttons button:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

#how-to-play-screen {
    max-width: 800px;
    margin: 0 auto;
    padding: 30px;
}

.how-to-play-content {
    margin: 20px 0;
    line-height: 1.6;
}

.how-to-play-content h3 {
    color: #333;
    margin: 20px 0 10px;
    padding-bottom: 5px;
    border-bottom: 2px solid #eee;
}

.how-to-play-content p {
    margin-bottom: 15px;
}

.how-to-play-content ul, .how-to-play-content ol {
    margin: 10px 0;
    padding-left: 20px;
}

.how-to-play-content li {
    margin: 8px 0;
}

.how-to-play-buttons {
    margin-top: 30px;
    text-align: center;
}

#back-to-menu_h {
    padding: 10px 20px;
    font-size: 16px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s;
}

#back-to-menu_h:hover {
    background-color: #45a049;
    transform: scale(1.05);
}

/* 手機版樣式 */
@media screen and (max-width: 768px) {
    /* 調整牌的大小 */
    .player-card img,
    .computer-hand img,
    .card-stack img,
    .deck-stack img,
    #played-card-area img,
    #deck-card,
    #deck-card2 {
        width: 80px !important;
        height: 110px !important;
    }


    .computer-hand .cards-stack img {
        transform: translateX(calc(var(--offset-x) * 0.5)) !important;
    }

    /* 調整文字大小 */
    h1 {
        font-size: 24px;
    }

    h2 {
        font-size: 20px;
    }

    h3 {
        font-size: 18px;
    }

    .player-name,
    #scores {
        font-size: 14px;
    }

    /* 調整按鈕大小 */
    .start-buttons button,
    .settings-buttons button,
    .how-to-play-buttons button {
        padding: 8px 16px;
        font-size: 16px;
    }

    /* 調整設定頁面 */
    .setting-item label {
        font-size: 14px;
    }

    .radio-group label {
        font-size: 14px;
    }

    /* 調整遊戲說明頁面 */
    .how-to-play-content p,
    .how-to-play-content li {
        font-size: 14px;
    }

    /* 調整遊戲區域間距 */
    #game-screen {
        gap: 10px;
    }

    /* 調整桌面區域 */
    #table-area {
        padding: 10px;
        min-height: 150px;
        height: auto;
    }

    /* 調整出牌區域 */
    #played-card-area {
        width: 100px;
        height: 120px;
        padding: 5px;
    }

    /* 調整牌堆區域 */
    #deck-area {
        width: 100px;
        height: 140px;
        padding: 5px;
    }

    .deck-stack {
        width: 80px;
        height: 110px;
    }

    /* 調整公開牌區域 */
    #open-cards-area {
        height: 120px;
        padding: 5px;
    }

    .card-stack {
        width: 80px;
        height: 110px;
    }

    /* 調整電腦玩家區域 */
    .computer-hand {
        padding: 5px;
        min-height: 130px;
    }

    .computer-hand .cards-stack {
        height: 110px;
        width: 80px;
    }

    /* 調整玩家區域 */
    #player-area {
        padding: 10px;
        min-height: 130px;
    }

    .player-cards-container {
        height: 110px;
    }

    .overlapping-cards {
        position: relative;
        width: 80px;
        height: 110px;
        margin: 0 auto;
    }
    .overlapping-cards .card-bottom {
        position: absolute;
        left: 0;
        top: 20px;
        z-index: 2;
    }
    
    .overlapping-cards .card-top {
        position: absolute;
        left: 0;
        top: -10px;
        z-index: 1;
    }
    
    /* 調整分數區域 */
    #score-area {
        height: 60px;
        padding: 10px;
    }
}

/* 超小螢幕手機版樣式 */
@media screen and (max-width: 480px) {
    /* 調整牌的大小 */
    .player-card img,
    .computer-hand img,
    .card-stack img,
    .deck-stack img,
    #played-card-area img,
    #deck-card,
    #deck-card2 {
        width: 56px !important;
        height: 76px !important;
    }

    /* 調整重疊寬度 */
    .player-card {
        margin-left: -12px !important;
    }

    /* 調整文字大小 */
    h1 {
        font-size: 18px;
    }

    h2 {
        font-size: 16px;
    }

    h3 {
        font-size: 14px;
    }

    .player-name,
    #scores {
        font-size: 11px;
    }

    /* 調整按鈕大小 */
    .start-buttons button,
    .settings-buttons button,
    .how-to-play-buttons button {
        padding: 5px 10px;
        font-size: 12px;
    }

    /* 調整遊戲區域間距 */
    #game-screen {
        gap: 3px;
        padding: 3px;
    }

    /* 調整桌面區域 */
    #table-area {
        padding: 3px;
        min-height: 100px;
    }

    /* 調整出牌區域 */
    #played-card-area {
        width: 70px;
        height: 90px;
        padding: 2px;
    }

    /* 調整牌堆區域 */
    #deck-area {
        width: 70px;
        height: 90px;
        padding: 2px;
    }

    .deck-stack {
        width: 56px;
        height: 76px;
    }

    /* 調整公開牌區域 */
    #open-cards-area {
        height: 90px;
        padding: 2px;
    }

    .card-stack {
        width: 60px;
        height: 80px;
    }

    /* 調整電腦玩家區域 */
    .computer-hand {
        padding: 2px;
        min-height: 90px;
    }

    .computer-hand .cards-stack {
        height: 80px;
        width: 60px;
    }

    /* 調整玩家區域 */
    #player-area {
        padding: 3px;
        min-height: 100px;
    }

    .player-cards-container {
        height: 80px;
    }

    /* 調整分數區域 */
    #score-area {
        height: 35px;
        padding: 3px;
        font-size: 12px;
    }

    /* 調整返回按鈕 */
    #back-to-menu {
        padding: 5px 10px;
        font-size: 12px;
        height: 25px;
        line-height: 1;
        min-width: 60px;
    }

    .overlapping-cards {
        position: relative;
        width: 56px;
        height: 76px;
        margin: 0 auto;
    }
    .overlapping-cards .card-bottom {
        position: absolute;
        left: 0;
        top: 10px;
        z-index: 2;
    }
    
    .overlapping-cards .card-top {
        position: absolute;
        left: 0;
        top: -10px;
        z-index: 1;
    }

    #scores {
        font-size: 11px;
    }
}

/* 平板版樣式 */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    /* 調整牌的大小 */
    .player-card img,
    .computer-hand img,
    .card-stack img,
    .deck-stack img,
    #played-card-area img,
    #deck-card,
    #deck-card2 {
        width: 100px !important;
        height: 140px !important;
    }


    .computer-hand .cards-stack img {
        transform: translateX(calc(var(--offset-x) * 0.7)) !important;
    }

    /* 調整桌面區域 */
    #table-area {
        min-height: 180px;
    }

    /* 調整出牌區域 */
    #played-card-area {
        width: 120px;
        height: 150px;
    }

    /* 調整牌堆區域 */
    #deck-area {
        width: 120px;
        height: 170px;
    }

    .deck-stack {
        width: 100px;
        height: 140px;
    }

    /* 調整公開牌區域 */
    #open-cards-area {
        height: 150px;
    }

    .card-stack {
        width: 100px;
        height: 140px;
    }

    /* 調整電腦玩家區域 */
    .computer-hand {
        min-height: 160px;
    }

    .computer-hand .cards-stack {
        height: 140px;
        width: 100px;
    }

    /* 調整玩家區域 */
    #player-area {
        min-height: 160px;
    }

    .player-cards-container {
        height: 140px;
    }

    .overlapping-cards {
        position: relative;
        width: 100px;
        height: 140px;
        margin: 0 auto;
    }
    .overlapping-cards .card-bottom {
        position: absolute;
        left: 0;
        top: 30px;
        z-index: 2;
    }
    
    .overlapping-cards .card-top {
        position: absolute;
        left: 0;
        top: -10px;
        z-index: 1;
    }
}

.game-container {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.leaderboard {
    background: rgba(0, 0, 0, 0.8);
    border-radius: 10px;
    padding: 20px;
    color: white;
    min-width: 300px;
}

.leaderboard h2 {
    text-align: center;
    margin-bottom: 20px;
    color: #ffd700;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.rank {
    color: #ffd700;
    font-weight: bold;
    width: 30px;
}

.player-name {
    flex: 1;
    margin: 0 10px;
}

.score {
    color: #00ff00;
    font-weight: bold;
}

