* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

.header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}

/* Selection Screens */
.selection-screen {
    padding: 60px 40px;
    text-align: center;
    display: none;
}

.selection-screen.active {
    display: block;
}

.selection-screen h2 {
    font-size: 2em;
    color: #667eea;
    margin-bottom: 40px;
}

.selection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 30px;
    max-width: 900px;
    margin: 0 auto;
}

.selection-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 40px;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s;
    color: white;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.selection-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 15px 30px rgba(102, 126, 234, 0.5);
}

.selection-card h3 {
    font-size: 2em;
    margin-bottom: 10px;
}

.selection-card p {
    font-size: 1.1em;
    opacity: 0.9;
}

.back-btn {
    display: inline-block;
    background: #6c757d;
    color: white;
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    margin-bottom: 40px;
    transition: all 0.3s;
    font-size: 1em;
}

.back-btn:hover {
    background: #5a6268;
    transform: translateY(-2px);
}


/* Mode Selection */
.mode-selection {
    padding: 40px;
    display: none;
}

.mode-selection.active {
    display: block;
}

.mode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.mode-card {
    background: #f8f9fa;
    padding: 30px;
    border-radius: 15px;
    border: 3px solid #e0e0e0;
    cursor: pointer;
    transition: all 0.3s;
}

.mode-card:hover {
    border-color: #667eea;
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(102, 126, 234, 0.2);
}

.mode-card.selected {
    border-color: #667eea;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.mode-card.selected p {
    color: white !important;
}

.mode-card h3 {
    font-size: 1.5em;
    margin-bottom: 10px;
}

.start-btn {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    padding: 15px 50px;
    border: none;
    border-radius: 10px;
    font-size: 1.2em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: block;
    margin: 30px auto 0;
}

.start-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(40, 167, 69, 0.3);
}

.start-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Timer Bar */
.timer-bar {
    background: #f8f9fa;
    padding: 15px 30px;
    border-bottom: 2px solid #e0e0e0;
    display: none;
    justify-content: space-between;
    align-items: center;
}

.timer-bar.active {
    display: flex;
}

.timer {
    font-size: 1.5em;
    font-weight: bold;
    color: #667eea;
}

/* Content Area */
.content {
    padding: 40px;
    display: none;
}

.content.active {
    display: block;
}

.section {
    margin-bottom: 40px;
}

.part-title {
    font-size: 1.8em;
    color: #667eea;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 3px solid #667eea;
}

.audio-player {
    background: #f0f0f0;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 30px;
    text-align: center;
}

.question {
    background: #f8f9fa;
    padding: 25px;
    margin-bottom: 25px;
    border-radius: 10px;
    border-left: 4px solid #667eea;
}

.question-number {
    font-weight: bold;
    color: #667eea;
    font-size: 1.1em;
    margin-bottom: 15px;
}

.question-text {
    margin-bottom: 15px;
    font-size: 1.05em;
    line-height: 1.6;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.option {
    display: flex;
    align-items: center;
    padding: 15px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

.option:hover {
    border-color: #667eea;
    background: #f0f4ff;
}

.option input[type="radio"] {
    margin-right: 12px;
    min-width: 20px;
    height: 20px;
    cursor: pointer;
}

.image-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.image-option {
    border: 3px solid #e0e0e0;
    border-radius: 10px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.3s;
    background: white;
}

.image-option:hover {
    border-color: #667eea;
    transform: scale(1.02);
}

.image-option.selected {
    border-color: #667eea;
    background: #f0f4ff;
}

.image-option img {
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 5px;
    margin-bottom: 10px;
}

.image-label {
    text-align: center;
    font-weight: 600;
    color: #333;
}

.matching-column h3 {
    color: #667eea;
    margin-bottom: 15px;
    text-align: center;
}

.matching-item select {
    width: 100%;
    padding: 8px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    font-size: 1em;
    margin-top: 10px;
}

.notice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.notice-card {
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9em;
}

.text-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1em;
    margin-top: 10px;
    font-family: inherit;
    text-transform: uppercase;
    transition: all 0.3s;
}

.text-input:focus {
    outline: none;
    border-color: #667eea;
}

/* Completion Modal */
.completion-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.completion-modal.show {
    display: flex;
}

.modal-content {
    background: white;
    padding: 50px;
    border-radius: 20px;
    text-align: center;
    max-width: 500px;
}

.modal-content h2 {
    color: #667eea;
    font-size: 2.5em;
    margin-bottom: 20px;
}

.modal-content p {
    font-size: 1.2em;
    margin-bottom: 10px;
}

.close-modal-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 40px;
    border: none;
    border-radius: 10px;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    margin-top: 20px;
}

/* Custom Added Styles */
#quit-test-btn {
    background-color: #aa8453;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.3s;
}

#quit-test-btn:hover {
    background-color: #8c6c43;
}

.dialogue-container {
    border: 1px solid #ddd;
    padding: 20px;
    border-radius: 8px;
    background-color: #f9f9f9;
}

.dialogue-line {
    margin-bottom: 15px;
    transition: all 0.3s;
}

.dialogue-line select {
    width: 100%;
    padding: 10px;
    margin-top: 5px;
    border-radius: 5px;
    border: 1px solid #ccc;
}

/* Định dạng cho chữ ở Part 6 */
.sentence-building-item p {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.2em;
    color: #333;
    margin-bottom: 10px;
    background-color: #e9ecef;
    padding: 15px;
    border-radius: 5px;
    border-left: 4px solid #6c757d;
}

.sentence-building-item textarea {
    width: 100%;
    padding: 10px;
    font-size: 1em;
    border: 2px solid #ccc;
    border-radius: 5px;
    min-height: 60px;
    transition: border-color 0.3s, background-color 0.3s;
}

.correct {
    background-color: #d4edda !important;
    border-color: #28a745 !important;
}

.incorrect {
    background-color: #f8d7da !important;
    border-color: #dc3545 !important;
}

/* Results Screen */
#results-container {
    margin-top: 60px;
    padding-top: 40px;
    border-top: 3px dashed #667eea;
}

.results-title {
    color: #667eea;
}

.results-summary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 30px;
    text-align: center;
}

.results-summary h3 {
    margin-bottom: 10px;
}

.results-summary p {
    font-size: 1.2em;
}

#results-details-container {
    text-align: left;
    max-width: 800px;
    margin: 0 auto 30px;
}

.result-item {
    background: #f8f9fa;
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 8px;
    border-left: 5px solid #ccc;
}

.result-item.correct {
    border-left-color: #28a745;
}

.result-item.incorrect {
    border-left-color: #dc3545;
}

.result-item p {
    margin: 5px 0;
}

.result-item .user-answer {
    color: #dc3545;
    text-decoration: line-through;
}

.result-item .correct-answer {
    color: #28a745;
    font-weight: bold;
}


@media (max-width: 768px) {
    /* Responsive cho Matching Container sẽ được xử lý tự động bởi Flexbox */
    .notice-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
    .content {
        padding: 20px;
    }
    .selection-grid {
        grid-template-columns: 1fr;
    }
    .timer-bar {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }
}

/* =========================================
   SỬA LỖI LAYOUT 2 CỘT (Part 2 & 4) - Dùng Flexbox
   ========================================= */

.matching-container {
    display: flex;          /* Xếp ngang */
    flex-wrap: wrap;        /* Tự xuống dòng khi hẹp */
    justify-content: space-between;
    gap: 30px;              /* Khoảng cách giữa 2 cột */
    margin-top: 20px;
}

/* Style cho các cột con (Places, Things, Conversation, Responses) */
.matching-container > div {
    flex: 1;                /* Tự chia sẻ không gian */
    min-width: 300px;       /* Chiều rộng tối thiểu trước khi xuống dòng */
}

/* Style lại cho các mục A, B, C... trong cột thứ 2 */
.matching-item {
    border: 1px solid #ddd;
    padding: 10px 15px;
    border-radius: 8px;
    background: #f9f9f9;
    margin-bottom: 8px;
    transition: all 0.3s;
}

/* =========================================
   CSS CHO PART 7 (VIẾT BÀI) VÀ HƯỚNG DẪN
   ========================================= */

/* 1. Style cho khối hướng dẫn chung */
.part-instructions {
  font-size: 1.1em;      /* Cỡ chữ */
  color: #333;           /* Màu chữ */
  line-height: 1.6;      /* Dãn dòng */
  text-align: left;      /* Căn trái */
  margin-bottom: 25px;   /* Khoảng cách dưới */
  font-weight: 700;
}

/* 2. Đảm bảo chữ trong <strong> là in đậm */
.part-instructions strong {
  font-weight: bold;
}

/* 3. Style cho danh sách gạch đầu dòng (<ul>) NẰM NGAY SAU hướng dẫn */
.part-instructions + ul {
  list-style-type: disc !important;  /* BẮT BUỘC hiện dấu chấm */
  padding-left: 40px !important;     /* BẮT BUỘC thụt lề (dùng padding) */
  margin-top: 10px;                  /* Khoảng cách trên */
  margin-bottom: 10px;               /* Khoảng cách dưới */
  font-family: inherit;              /* Giữ font chữ gốc */
  font-size: 1em;                    /* Giữ cỡ chữ gốc */
  line-height: 1.6;                  /* Dãn dòng */
}

/* 4. Style cho từng mục gạch đầu dòng (<li>) */
.part-instructions + ul li {
  margin-bottom: 8px; /* Khoảng cách giữa các mục */
  
}

/* 5. Style cho ô gõ chữ */
.writing-textarea {
  width: 100%;
  min-height: 150px;
  padding: 15px;
  font-size: 1em;
  font-family: inherit;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  line-height: 1.6;
  margin-bottom: 20px;
}
.writing-textarea:focus {
  outline: none;
  border-color: #667eea;
}

/* 6. Style cho nút "Xem bài viết mẫu" */
.sample-answer-toggle summary {
  cursor: pointer;
  font-weight: bold;
  color: #667eea;
  font-size: 1.1em;
  margin-bottom: 10px; /* Khoảng cách dưới */
}

/* 7. Style cho phần bài viết mẫu */
.writing-sample {
  margin-top: 15px;
  padding: 15px;
  background: #f8f9fa;
  border-left: 4px solid #667eea;
  border-radius: 4px;
  line-height: 1.7;
  color: #333;
}

.part-instructions  ul {
    margin-left: 60px;
}