/* 主要佈局樣式 */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    min-height: 100vh;
    color: #333;
    padding: 6px; /* 減少與螢幕邊界距離 */
}

.container {
    max-width: 560px; /* 擴增內容可用寬度 */
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 100vh; /* 允許內容超出並可捲動 */
}

/* 標題區域 */
header {
    text-align: center;
    margin-bottom: 15px;
    color: white;
    flex-shrink: 0;
}

header h1 {
    font-size: 1.5rem;
    margin-bottom: 5px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

header p {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* 選中牌組區域 */
.selected-cards {
    background: white;
    border-radius: 25px;
    padding: 10px;
    margin-bottom: 10px;
    box-shadow: 0 8px 12px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
}

.selected-cards h2 {
    margin-bottom: 20px;
    color: #2c3e50;
    font-size: 1.5rem;
}

.cards-container.has-cards {
    border: none;
    background: transparent !important;
}

.cards-container:empty::before {
    content: "請使用下方虛擬鍵盤選擇撲克牌（已選的牌可點擊刪除）";
    color: #999;
    font-style: italic;
}

/* 撲克牌樣式 */
.card {
    width: 38px;
    height: 50px;
    border-radius: 6px;
    border: 1px solid #333;
    background: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    flex-shrink: 0;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 3px 10px rgba(0,0,0,0.25);
    border-color: #dc3545;
}

.card:hover::after {
    content: "點擊刪除";
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 0.6rem;
    white-space: nowrap;
    z-index: 10;
}

.card.spades, .card.clubs {
    color: #000;
}

.card.hearts, .card.diamonds {
    color: #dc3545;
}

.card .rank {
    font-size: 0.8rem;
    margin-bottom: 2px;
}

.card .suit {
    font-size: 1.2rem;
}

.card .remove-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 12px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.card:hover .remove-btn {
    display: flex;
}

/* 虛擬鍵盤區域 */
.poker-keyboard {
    background: white;
    border-radius: 12px;
    padding: 10px; /* 減少內距以放大實際內容寬度 */
    margin-bottom: 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.poker-keyboard h2 {
    margin-bottom: 15px;
    color: #2c3e50;
    text-align: center;
    font-size: 1.2rem;
}

/* 花色選擇器 */
.suit-selector {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 15px;
}

.suit-btn {
    padding: 8px 12px;
    border: 2px solid #ddd;
    background: white;
    border-radius: 20px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 45px;
    height: 40px;
}

.suit-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.suit-btn.active {
    background: #007bff;
    color: white;
    border-color: #007bff;
}

.suit-btn[data-suit="S"].active,
.suit-btn[data-suit="C"].active {
    background: #343a40;
    border-color: #343a40;
}

.suit-btn[data-suit="H"].active,
.suit-btn[data-suit="D"].active {
    background: #dc3545;
    border-color: #dc3545;
}

/* 牌面鍵盤 */
.card-keyboard {
    margin-bottom: 15px;
}

.card-row {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 6px;
}

.card-btn {
    width: 45px;
    height: 45px;
    border: 2px solid #ddd;
    background: white;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    background: #f8f9fa;
}

.card-btn.selected {
    background: #28a745;
    color: white;
    border-color: #28a745;
    position: relative;
}

.card-btn.selected:hover {
    background: #dc3545;
    border-color: #dc3545;
    transform: translateY(-1px);
}

.card-btn.selected:hover::after {
    content: "點擊取消";
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 0.6rem;
    white-space: nowrap;
    z-index: 10;
}

.card-btn:disabled {
    background: #e9ecef;
    color: #6c757d;
    cursor: not-allowed;
    opacity: 0.6;
}

.card-btn:disabled:hover {
    transform: none;
    box-shadow: none;
}

/* 快速選擇區已移除 */

/* 選中牌組區域 */
.selected-cards {
    background: white;
    border-radius: 12px;
    padding: 6px; /* 進一步縮小內距，讓牌更貼近外框 */
    margin-bottom: 10px; /* 減少區塊間距 */
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.selected-cards h2 {
    margin-bottom: 4px; /* 減少標題與牌組距離 */
    color: #2c3e50;
    font-size: 1.1rem;
    text-align: center;
}

.cards-container {
    min-height: 0; /* 移除不必要的最小高度，縮減上下留白 */
    max-height: 140px;
    border: none;
    border-radius: 8px;
    padding: 0; /* 讓卡片最貼近容器邊緣 */
    margin-bottom: 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    justify-content: center;
    background: transparent; /* 移除底色避免看起來像分隔線 */
    transition: all 0.3s ease;
    overflow-y: auto;
}

.cards-container.has-cards {
    border: none;
    background: transparent; /* 取消高亮底色，避免底部形成一道線 */
}

.cards-container:empty::before {
    content: "請使用上方虛擬鍵盤選擇撲克牌（已選的牌可點擊刪除）";
    color: #999;
    font-style: italic;
    font-size: 0.8rem;
    text-align: center;
}

.action-buttons {
    display: flex;
    justify-content: center;
    gap: 8px; /* 稍微縮小間距 */
}

/* 按鈕樣式 */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 18px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 0 5px;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0,0,0,0.15);
}

.btn-primary {
    background: #007bff;
    color: white;
}

.btn-primary:hover {
    background: #0056b3;
}

.btn-primary:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.btn-primary:disabled:hover {
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

/* 載入指示器 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    background: white;
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 錯誤訊息 */
.error-message {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
}

.error-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    max-width: 400px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.error-content h3 {
    color: #dc3545;
    margin-bottom: 15px;
    font-size: 1.3rem;
}

.error-content p {
    margin-bottom: 20px;
    color: #666;
    line-height: 1.5;
}

/* 響應式設計 */
@media (max-width: 768px) {
    .container {
    padding: 6px; /* 跟 body 同步縮小 */
    max-width: 520px;
    }
    
    .header h1 {
        font-size: 1.3rem;
    }
    
    .header p {
        font-size: 0.75rem;
    }
    
    .suit-selector {
        gap: 6px;
    }
    
    .suit-btn {
        min-width: 42px;
        height: 38px;
        font-size: 1.1rem;
        padding: 6px 10px;
    }
    
    .card-row {
        gap: 5px;
    }
    
    .card-btn {
        width: 42px;
        height: 42px;
        font-size: 0.95rem;
    }
    
    .card {
        width: 36px;
        height: 48px;
        font-size: 0.65rem;
    }
    
    .card .rank {
        font-size: 0.75rem;
    }
    
    .card .suit {
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 8px;
        max-width: 100%;
    }
    
    .selected-cards, .poker-keyboard, .analysis-results {
        padding: 12px;
        margin-bottom: 10px;
    }
    /* 手機端針對已選區塊再縮小內距，讓卡片更貼框 */
    .selected-cards {
        padding: 6px;
    }
    
    .card-row {
        gap: 3px;
    }
    
    .card-btn {
        width: 38px;
        height: 38px;
        font-size: 0.85rem;
    }
    
    .card {
        width: 32px;
        height: 42px;
        font-size: 0.6rem;
    }
    
    .card .rank {
        font-size: 0.7rem;
    }
    
    .card .suit {
        font-size: 0.75rem;
    }
    
    .suit-btn {
        min-width: 38px;
        height: 35px;
        font-size: 1rem;
    }
}
