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

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 8px;
    margin: 0;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.1);
    overflow: hidden;
    min-height: calc(100vh - 16px);
}

.header {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    padding: 15px;
    text-align: center;
    color: white;
}

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

.header p {
    font-size: 1.0em;
    opacity: 0.9;
    margin: 0;
}

.game-area {
    padding: 15px;
    display: flex;
    gap: 15px;
    height: calc(100vh - 180px);
    min-height: calc(100vh - 180px);
    align-items: stretch;
}

.questions-section, .answers-section {
    flex: 1;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 10px;
    border: 2px solid #e9ecef;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0; /* 重要：允許flexbox子元素縮小 */
}

.section-title {
    font-size: 1.2em;
    margin-bottom: 10px;
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 10px;
    border-radius: 6px;
    text-align: center;
    font-weight: bold;
    flex: 0 0 auto; /* 不縮放 */
}

/* 智能化網格容器 - 滿格佈局優化 */
#questions-container, #answers-container {
    display: grid;
    gap: 6px;
    flex: 1; /* 填滿剩餘空間 */
    align-content: stretch;
    height: 100%;
    min-height: 0; /* 允許縮小 */
    padding: 5px;
}

/* 智能佈局：基於內容類型和數量 - 完全填滿空間 */
.layout-smart-large {
    grid-template-columns: 1fr;
    gap: 10px;
    grid-template-rows: repeat(auto-fit, minmax(180px, 1fr));
}

.layout-smart-medium {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    grid-template-rows: repeat(auto-fit, minmax(140px, 1fr));
}

.layout-smart-compact {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    grid-template-rows: repeat(auto-fit, minmax(110px, 1fr));
}

.layout-smart-dense {
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    grid-template-rows: repeat(auto-fit, minmax(90px, 1fr));
}

/* 圖片優先佈局 - 完全填滿 */
.layout-image-dominant {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 6px;
    grid-template-rows: repeat(auto-fit, minmax(130px, 1fr));
}

/* 文字優先佈局 - 完全填滿 */
.layout-text-dominant {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 8px;
    grid-template-rows: repeat(auto-fit, minmax(80px, 1fr));
}

/* 混合內容佈局 - 完全填滿 */
.layout-mixed-content {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 6px;
    grid-template-rows: repeat(auto-fit, minmax(120px, 1fr));
}

/* 智能卡片樣式 - 完全填滿容器 */
.card {
    background: white;
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 2px solid transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
    overflow: hidden;
    /* 關鍵：讓卡片填滿格子 */
    height: 100%;
    min-height: 0;
}

/* 動態卡片高度基於佈局類型 - 移除最小高度限制 */
.layout-smart-large .card { 
    min-height: 0;
    padding: 15px;
}
.layout-smart-medium .card { 
    min-height: 0;
    padding: 12px;
}
.layout-smart-compact .card { 
    min-height: 0;
    padding: 10px;
}
.layout-smart-dense .card { 
    min-height: 0;
    padding: 8px;
}
.layout-image-dominant .card { 
    min-height: 0;
    padding: 10px;
}
.layout-text-dominant .card { 
    min-height: 0;
    padding: 12px;
}
.layout-mixed-content .card { 
    min-height: 0;
    padding: 10px;
}

.card:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    border-color: #007bff;
    z-index: 2;
}

.card.selected {
    border-color: #007bff;
    background: #e3f2fd;
    transform: scale(1.03);
    box-shadow: 0 6px 20px rgba(0, 123, 255, 0.3);
}

.card.matched {
    border-color: #28a745;
    background: linear-gradient(135deg, #d4edda, #c3e6cb);
    cursor: default;
    opacity: 0.9;
}

.card.matched:hover {
    transform: none;
}

.card-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    gap: 5px;
}

/* 智能圖片樣式 - 最大化利用空間 */
.card-image {
    object-fit: contain;
    border-radius: 4px;
    transition: all 0.3s ease;
    width: 100%;
    display: block;
    max-width: 100%;
    /* 讓圖片盡可能填滿卡片 */
    flex: 1;
    max-height: 100%;
}

/* 動態圖片大小基於佈局 - 最大化利用空間 */
.layout-smart-large .card-image { 
    max-height: none;
    height: auto;
    flex: 1;
}
.layout-smart-medium .card-image { 
    max-height: none;
    height: auto;
    flex: 1;
}
.layout-smart-compact .card-image { 
    max-height: none;
    height: auto;
    flex: 1;
}
.layout-smart-dense .card-image { 
    max-height: none;
    height: auto;
    flex: 1;
}
.layout-image-dominant .card-image { 
    max-height: none;
    height: auto;
    flex: 1;
}
.layout-text-dominant .card-image { 
    max-height: 50px;
    flex: 0 0 auto;
}
.layout-mixed-content .card-image { 
    max-height: none;
    height: auto;
    flex: 1;
}

/* 圖片錯誤處理樣式 */
.error-container {
    text-align: center;
    padding: 10px;
    background-color: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 4px;
    color: #856404;
}

.error-message {
    font-weight: bold;
    color: #dc3545;
    margin-bottom: 5px;
}

.error-format {
    font-size: 0.8em;
    color: #495057;
    font-weight: bold;
    margin-bottom: 5px;
    background: #e9ecef;
    padding: 2px 6px;
    border-radius: 3px;
    display: inline-block;
}

.error-url {
    font-size: 0.8em;
    color: #666;
    word-break: break-all;
    margin-bottom: 8px;
    background: #f8f9fa;
    padding: 4px;
    border-radius: 3px;
}

.format-suggestion {
    background: #e7f3ff;
    border: 1px solid #bee5eb;
    border-radius: 4px;
    padding: 8px;
    margin: 8px 0;
    color: #0c5460;
    text-align: left;
}

.format-suggestion strong {
    color: #0056b3;
}

.error-suggestion {
    font-size: 0.7em;
    color: #6c757d;
    text-align: left;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #ddd;
}

/* 智能文字樣式 - 自適應填滿 */
.card-text {
    color: #333;
    word-wrap: break-word;
    line-height: 1.3;
    font-weight: 600;
    max-width: 100%;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    hyphens: auto;
    overflow-wrap: break-word;
    /* 讓文字填滿可用空間 */
    flex: 1;
    min-height: 0;
}

/* 動態文字大小基於佈局 - 自適應字體 */
.layout-smart-large .card-text { 
    font-size: clamp(1.2em, 4vw, 2.5em);
    line-height: 1.4;
}
.layout-smart-medium .card-text { 
    font-size: clamp(1em, 3vw, 1.8em);
    line-height: 1.3;
}
.layout-smart-compact .card-text { 
    font-size: clamp(0.9em, 2.5vw, 1.4em);
    line-height: 1.2;
}
.layout-smart-dense .card-text { 
    font-size: clamp(0.8em, 2vw, 1.1em);
    line-height: 1.1;
}
.layout-image-dominant .card-text { 
    font-size: clamp(0.9em, 2.5vw, 1.3em);
    line-height: 1.3;
    flex: 0 0 auto;
    margin-top: 5px;
}
.layout-text-dominant .card-text { 
    font-size: clamp(1.1em, 3vw, 1.6em);
    line-height: 1.4;
    padding: 8px;
}
.layout-mixed-content .card-text { 
    font-size: clamp(0.9em, 2.5vw, 1.3em);
    line-height: 1.3;
    flex: 0 0 auto;
    margin-top: 5px;
}

/* 遊戲控制區優化 */
.game-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-radius: 0 0 8px 8px;
    flex-wrap: wrap;
}

.btn, .reset-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

#reset-button, .reset-btn {
    background: linear-gradient(135deg, #ff6b6b, #ff5252);
    color: white;
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
}

#reset-button:hover, .reset-btn:hover {
    background: linear-gradient(135deg, #ff5252, #f44336);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(255, 107, 107, 0.4);
}

.btn-success {
    background: linear-gradient(135deg, #4caf50, #45a049);
    color: white;
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.btn-success:hover {
    background: linear-gradient(135deg, #45a049, #3d8b40);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(76, 175, 80, 0.4);
}

.btn-warning {
    background: linear-gradient(135deg, #ff9800, #f57c00);
    color: white;
    box-shadow: 0 4px 12px rgba(255, 152, 0, 0.3);
}

.btn-warning:hover {
    background: linear-gradient(135deg, #f57c00, #ef6c00);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(255, 152, 0, 0.4);
}

/* 分數板優化 */
.score-board {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.score-board span {
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 12px;
    border-radius: 20px;
    font-weight: 600;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    flex-wrap: wrap;
    gap: 15px;
}

/* 完成訊息樣式 */
.completion-message {
    text-align: center;
    padding: 20px;
    margin: 20px;
    background: linear-gradient(135deg, #d4edda, #c3e6cb);
    border: 2px solid #28a745;
    border-radius: 8px;
    font-size: 1.2em;
    font-weight: bold;
    color: #155724;
    animation: celebrationPulse 2s ease-in-out infinite;
}

@keyframes celebrationPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

/* 智能化提示系統 */
.layout-hint {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 123, 255, 0.1);
    color: #007bff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.7em;
    font-weight: bold;
    border: 1px solid rgba(0, 123, 255, 0.3);
}

.questions-section, .answers-section {
    position: relative;
}

/* 載入動畫 */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
.cards-container-7 .card-text { font-size: 1.2em; }
.cards-container-8 .card-text { font-size: 1.1em; }
.cards-container-9 .card-text { font-size: 1.0em; }
.cards-container-10 .card-text { font-size: 0.95em; }
.cards-container-12 .card-text { font-size: 0.9em; }

.score-board {
    background: #fff3cd;
    border: 1px solid #ffeeba;
    border-radius: 6px;
    padding: 8px;
    margin: 5px 15px;
    text-align: center;
}

.score-text {
    font-size: 0.9em;
    color: #856404;
    margin-bottom: 3px;
}

.game-controls {
    text-align: center;
    padding: 8px;
}

.btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: 3px solid transparent;
    padding: 15px 35px;
    border-radius: 30px;
    font-size: 1.2em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    position: relative;
    overflow: hidden;
}

.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: left 0.5s;
}

.btn:hover::before {
    left: 100%;
}

.btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6);
    border-color: rgba(255,255,255,0.3);
}

.btn-success {
    background: linear-gradient(135deg, #56ab2f 0%, #a8e6cf 100%);
    box-shadow: 0 4px 15px rgba(86, 171, 47, 0.4);
}

.btn-success:hover {
    box-shadow: 0 8px 25px rgba(86, 171, 47, 0.6);
}

.btn-warning {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    box-shadow: 0 4px 15px rgba(240, 147, 251, 0.4);
}

.btn-warning:hover {
    box-shadow: 0 8px 25px rgba(240, 147, 251, 0.6);
}

.game-list {
    padding: 40px;
}

.game-item {
    background: white;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 15px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
    border-left: 5px solid #007bff;
}

.game-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}

.game-item a {
    text-decoration: none;
    color: #333;
    font-size: 1.3em;
    font-weight: bold;
    display: block;
}

.game-item a:hover {
    color: #007bff;
}

.completion-message {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    padding: 15px;
    text-align: center;
    border-radius: 8px;
    margin: 5px 15px;
    font-size: 1.0em;
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}

.completion-message h2 {
    margin-bottom: 8px;
    font-size: 1.6em;
}

@media (max-width: 768px) {
    .game-area {
        grid-template-columns: 1fr;
        gap: 10px;
        padding: 8px;
    }
    
    .header h1 {
        font-size: 1.6em;
    }
    
    .header p {
        font-size: 0.85em;
    }
    
    .questions-section, .answers-section {
        padding: 8px;
    }
    
    .section-title {
        font-size: 1.0em;
        margin-bottom: 6px;
    }
    
    #questions-container, #answers-container {
        gap: 3px;
    }
    
    /* 手機版佈局調整 */
    .cards-container-1 { grid-template-columns: 1fr; }
    .cards-container-2 { grid-template-columns: 1fr 1fr; }
    .cards-container-3 { grid-template-columns: repeat(2, 1fr); }
    .cards-container-4 { grid-template-columns: repeat(2, 1fr); }
    .cards-container-5 { grid-template-columns: repeat(2, 1fr); }
    .cards-container-6 { grid-template-columns: repeat(2, 1fr); }
    .cards-container-7 { grid-template-columns: repeat(2, 1fr); }
    .cards-container-8 { grid-template-columns: repeat(2, 1fr); }
    .cards-container-9 { grid-template-columns: repeat(3, 1fr); }
    .cards-container-10 { grid-template-columns: repeat(3, 1fr); }
    .cards-container-12 { grid-template-columns: repeat(3, 1fr); }
    
    .card {
        padding: 4px;
    }
    
    /* 手機版卡片高度調整 - 更大 */
    .cards-container-1 .card { min-height: 250px; }
    .cards-container-2 .card { min-height: 200px; }
    .cards-container-3 .card { min-height: 160px; }
    .cards-container-4 .card { min-height: 150px; }
    .cards-container-5 .card { min-height: 140px; }
    .cards-container-6 .card { min-height: 130px; }
    .cards-container-7 .card { min-height: 120px; }
    .cards-container-8 .card { min-height: 110px; }
    .cards-container-9 .card { min-height: 100px; }
    .cards-container-10 .card { min-height: 90px; }
    .cards-container-12 .card { min-height: 80px; }
    
    .card-content {
        gap: 2px;
    }
    
    /* 手機版圖片大小調整 - 佔卡片高度一半 */
    .cards-container-1 .card-image { max-width: 100%; max-height: 110px; }
    .cards-container-2 .card-image { max-width: 100%; max-height: 90px; }
    .cards-container-3 .card-image { max-width: 100%; max-height: 70px; }
    .cards-container-4 .card-image { max-width: 100%; max-height: 65px; }
    .cards-container-5 .card-image { max-width: 100%; max-height: 60px; }
    .cards-container-6 .card-image { max-width: 100%; max-height: 55px; }
    .cards-container-7 .card-image { max-width: 100%; max-height: 50px; }
    .cards-container-8 .card-image { max-width: 100%; max-height: 45px; }
    .cards-container-9 .card-image { max-width: 100%; max-height: 40px; }
    .cards-container-10 .card-image { max-width: 100%; max-height: 35px; }
    .cards-container-12 .card-image { max-width: 100%; max-height: 30px; }
    
    /* 手機版文字大小調整 - 佔卡片高度一半 */
    .cards-container-1 .card-text { font-size: 1.8em; }
    .cards-container-2 .card-text { font-size: 1.5em; }
    .cards-container-3 .card-text { font-size: 1.3em; }
    .cards-container-4 .card-text { font-size: 1.2em; }
    .cards-container-5 .card-text { font-size: 1.1em; }
    .cards-container-6 .card-text { font-size: 1.0em; }
    .cards-container-7 .card-text { font-size: 0.95em; }
    .cards-container-8 .card-text { font-size: 0.9em; }
    .cards-container-9 .card-text { font-size: 0.8em; }
    .cards-container-10 .card-text { font-size: 0.75em; }
    .cards-container-12 .card-text { font-size: 0.7em; }
    
    .score-board {
        margin: 3px 8px;
        padding: 6px;
    }
    
    .score-text {
        font-size: 0.8em;
        margin-bottom: 2px;
    }
    
    .game-controls {
        padding: 6px;
    }
    
    .completion-message {
        margin: 3px 8px;
        padding: 12px;
        font-size: 0.9em;
    }
    
    .completion-message h2 {
        font-size: 1.4em;
        margin-bottom: 6px;
    }
}
