/* style.css - Phiên bản cải tiến */

/* --- Imports --- */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&family=Montserrat:wght@400;500;700&display=swap');

/* --- CSS Variables --- */
:root {
  --primary-color: #4A90E2; /* Xanh dương dịu */
  --secondary-color: #50E3C2; /* Xanh lá cây tươi (có thể dùng cho thành công hoặc điểm nhấn khác) */
  --accent-color: #F5A623; /* Vàng cam làm điểm nhấn (ví dụ: nút Reset) */
  --text-color: #333;
  --text-light: #555;
  --placeholder-color: #6c757d;
  --background-light: #f8f9fa;
  --background-white: #ffffff;
  --border-color: #dee2e6;
  --correct-color: #28a745;
  --incorrect-color: #dc3545;
  --hover-primary: #357ABD;
  --hover-correct: #218838;
  --hover-accent: #E09518;
  --used-word-bg: #6c757d;
  --dropzone-bg: #e9ecef;
  --dropzone-bg-hover: #e2e6ea;
  --dropzone-filled-bg: #d1ecf1;
  --dropzone-filled-border: #bee5eb;
  --dropzone-filled-text: #0c5460;
  --table-header-bg: var(--primary-color);
  --table-row-even-bg: #f7f7f7;
  --table-row-hover-bg: #e9f5f0;
  --explanation-bg: #f9fafb;
  --explanation-border: #e5e7eb;
  --box-shadow-light: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* --- Body and General Styles --- */
body {
  font-family: 'Roboto', sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start; /* Align top để dễ scroll */
  min-height: 100vh;
  background-color: var(--background-light);
  color: var(--text-color);
  padding: 20px 0; /* Thêm padding trên dưới cho body */
  line-height: 1.6;
}

/* --- Container --- */
.container {
  max-width: 900px; /* Giảm max-width một chút cho gọn */
  width: 95%; /* Thêm width để đảm bảo padding hoạt động tốt */
  margin: auto;
  background-color: var(--background-white);
  padding: 30px 40px; /* Điều chỉnh padding */
  border-radius: 10px;
  box-shadow: var(--box-shadow-light);
  text-align: center;
  border: 1px solid var(--border-color);
}

/* --- Headings --- */
h1 {
  font-family: 'Montserrat', sans-serif;
  margin-bottom: 30px;
  font-size: 2.2em; /* Tăng nhẹ kích thước */
  color: var(--primary-color);
  font-weight: 700;
}

h2 { /* Áp dụng cho tiêu đề các mục như Lịch sử học tập */
  font-family: 'Montserrat', sans-serif;
  margin-top: 40px;
  margin-bottom: 20px;
  font-size: 1.6em;
  color: var(--text-color);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 10px;
}

/* --- Quote Section --- */
#quote-container {
  position: relative;
  border: 1px solid var(--border-color); /* Viền mảnh hơn */
  padding: 30px 40px; /* Tăng padding ngang */
  margin-bottom: 30px;
  border-radius: 8px;
  background-color: #fdfdfd; /* Nền hơi khác biệt */
}

#quote-container::before,
#quote-container::after {
  font-family: 'Times New Roman', Times, serif; /* Font cổ điển cho dấu ngoặc kép */
  font-size: 4em;
  position: absolute;
  color: var(--border-color); /* Màu nhạt hơn */
  line-height: 1;
}

#quote-container::before {
  content: open-quote;
  top: 10px; /* Điều chỉnh vị trí */
  left: 15px;
}

#quote-container::after {
  content: close-quote;
  bottom: 5px; /* Điều chỉnh vị trí */
  right: 15px;
}

#quote {
  font-size: 1.3em;
  line-height: 1.7;
  color: var(--text-light); /* Màu chữ nhẹ hơn */
  margin-bottom: 15px; /* Khoảng cách với tác giả */
  min-height: 50px; /* Đảm bảo có chiều cao tối thiểu */
}

#author {
  font-style: italic;
  font-weight: bold;
  margin-top: 15px;
  display: block;
  color: var(--text-light);
  font-size: 0.95em;
}

/* --- Word Bank & Words --- */
.word-bank {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 15px; /* Giữ khoảng cách */
  margin-top: 30px;
  margin-bottom: 40px;
}

.word {
  font-family: 'Montserrat', sans-serif;
  padding: 10px 25px; /* Điều chỉnh padding */
  background-color: var(--primary-color);
  color: white;
  border-radius: 25px; /* Bo tròn */
  cursor: pointer; /* Đổi thành pointer */
  transition: transform 0.2s ease, background-color 0.2s ease, opacity 0.3s ease, box-shadow 0.2s ease;
  font-weight: 500;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.word:hover {
  transform: scale(1.05) translateY(-2px); /* Hiệu ứng nhấc lên */
  background-color: var(--hover-primary);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}



/* --- Drop Zones --- */
.drop-zone {
  background-color: var(--dropzone-bg);
  border: 2px dashed var(--border-color);
  border-radius: 6px;
  min-width: 80px;
  padding: 8px 12px;
  display: inline-block;
  vertical-align: bottom;
  margin: 0 4px 4px 4px; /* Thêm margin dưới */
  text-align: center;
  color: var(--placeholder-color);
  transition: background-color 0.3s ease, border-color 0.3s ease;
  height: auto;
  min-height: 1.4em; /* Đảm bảo chiều cao tối thiểu */
  line-height: 1.4;
  box-sizing: border-box;
}

.drop-zone:hover {
  border-color: var(--primary-color);
  background-color: var(--dropzone-bg-hover);
}

/* Kiểu khi từ đã được thả vào (cần JS kiểm tra để thêm class/thuộc tính hoặc dùng :not(:empty) nếu phù hợp) */
.drop-zone.filled { /* Thêm class .filled bằng JS khi thả từ vào */
     background-color: var(--dropzone-filled-bg);
     border-color: var(--dropzone-filled-border);
     color: var(--dropzone-filled-text);
     font-weight: 500;
     border-style: solid; /* Chuyển thành viền liền */
}

.correct {
  /* Bỏ border-color ở đây nếu dùng class .filled */
  color: var(--correct-color);
}

.incorrect {
  /* Bỏ border-color ở đây nếu dùng class .filled */
  color: var(--incorrect-color);
}

/* --- Buttons --- */
.buttons {
  margin-top: 30px;
  margin-bottom: 30px;
}

.buttons button {
  font-family: 'Montserrat', sans-serif;
  padding: 12px 30px;
  color: white;
  border: none;
  border-radius: 6px; /* Đồng bộ bo góc */
  cursor: pointer;
  margin: 5px 10px; /* Điều chỉnh margin */
  font-size: 1em;
  font-weight: 500;
  transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.buttons button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.buttons button:active {
  transform: scale(0.98);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.buttons button#checkButton {
  background-color: var(--correct-color);
}
.buttons button#checkButton:hover {
  background-color: var(--hover-correct);
}

.buttons button#resetButton {
  background-color: var(--accent-color);
}
.buttons button#resetButton:hover {
  background-color: var(--hover-accent);
}

.buttons button#skipButton {
    /* CSS hiện tại đang display: none; */
    background-color: #6c757d; /* Màu xám nếu hiển thị */
}
.buttons button#skipButton:hover {
    background-color: #5a6268;
}

/* --- Result Area --- */
#result {
  margin-top: 30px; /* Tăng khoảng cách */
  font-size: 1.1em;
  color: var(--text-light);
}

#result span {
  font-weight: bold;
}

#correctness.correct {
  color: var(--correct-color);
}

#correctness.incorrect {
  color: var(--incorrect-color);
}

/* --- History & Stats Section --- */
#stats-section {
  margin-top: 40px;
}

.stats-overview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px; /* Giảm gap */
    margin-bottom: 30px;
    font-size: 1.1em;
}

#overallAveragePercentage {
    font-weight: bold;
    color: var(--primary-color); /* Đồng bộ màu */
    background-color: #e7f3ff; /* Nền nhạt */
    padding: 5px 15px;
    border-radius: 15px;
}

#spiderChart {
    max-width: 400px; /* Giảm kích thước tối đa */
    width: 100%;
    height: auto;
    margin: 20px auto; /* Thêm khoảng cách trên dưới */
}

/* --- Tables (History & NewHistory) --- */
#newHistory, #history {
    margin: 30px 0; /* Tăng khoảng cách */
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--box-shadow-light);
    font-family: 'Lato', sans-serif; /* Đồng bộ font */
}

#newHistory table, #history table {
    width: 100%;
    border-collapse: collapse;
    background-color: var(--background-white);
}

#newHistory table thead, #history table thead {
    background-color: var(--table-header-bg);
    color: var(--background-white);
}

#newHistory table th, #history table th {
    padding: 12px 15px; /* Điều chỉnh padding */
    text-align: left;
    font-weight: 700; /* Đậm hơn */
    font-size: 0.95em; /* Điều chỉnh font */
    letter-spacing: 0.5px;
    text-transform: uppercase; /* Viết hoa tiêu đề */
}

#newHistory table tbody tr, #history table tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.3s ease;
}

#newHistory table tbody tr:nth-child(even), #history table tbody tr:nth-child(even) {
    background-color: var(--table-row-even-bg);
}

#newHistory table tbody tr:hover, #history table tbody tr:hover {
    background-color: var(--table-row-hover-bg);
}

#newHistory table tbody td, #history table tbody td {
    padding: 12px 15px;
    font-size: 0.9em;
    color: var(--text-light);
    vertical-align: middle;
}

#newHistory table tbody td:first-child, #history table tbody td:first-child {
    font-weight: 600;
    color: var(--text-color);
}

/* --- Explanation Section --- */
#history .explain-button { /* Nút Giải thích trong bảng History */
    padding: 5px 10px;
    font-size: 0.8em;
    background-color: var(--secondary-color);
    color: var(--text-color);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
#history .explain-button:hover {
    background-color: #45d1b5;
}

.explanation-row td { /* Cell chứa phần giải thích */
    padding: 0 !important; /* Bỏ padding mặc định của td */
    border-top: 1px dashed var(--border-color);
}

.explanation-content {
    padding: 15px; /* Tăng padding */
    text-align: left;
    background-color: var(--explanation-bg);
    border-top: none; /* Bỏ border-top đã có trong row td */
    font-size: 0.95em;
    color: var(--text-light);
}

.explanation-content p {
    margin: 10px 0;
}

.explanation-content strong {
    font-weight: 600;
    color: var(--primary-color); /* Hoặc --text-color */
}

.explanation-content ul,
.explanation-content ol {
    margin: 10px 0 10px 20px; /* Điều chỉnh margin */
    padding-left: 20px;
}

.explanation-content li {
    margin: 6px 0;
}

/* --- Responsive Adjustments --- */
@media screen and (max-width: 768px) {
  body {
    padding: 10px 0;
  }
  .container {
    padding: 20px 15px; /* Giảm padding ngang */
    width: 100%;
    border: none; /* Bỏ border trên mobile */
    box-shadow: none;
  }
  h1 {
    font-size: 1.8em;
  }
  h2 {
    font-size: 1.4em;
  }
  #quote-container {
    padding: 20px 15px;
  }
  #quote {
    font-size: 1.1em;
    line-height: 1.6;
  }
  .word-bank {
    gap: 10px;
    margin-bottom: 30px;
  }
  .word {
    padding: 10px 20px;
    font-size: 0.9em;
  }
  .buttons button {
    padding: 10px 20px;
    font-size: 0.9em;
    margin: 5px;
  }
  .drop-zone {
    min-width: 60px;
    padding: 6px 8px;
    margin: 0 2px 4px 2px;
  }

  /* Responsive cho Bảng (Giữ nguyên phần JS thêm data-label) */
  #newHistory table thead, #history table thead {
      display: none; /* Hide header row on small screens */
  }

  #newHistory table tbody tr, #history table tbody tr {
      display: block;
      margin-bottom: 15px; /* Khoảng cách giữa các hàng */
      border: 1px solid var(--border-color);
      border-radius: 8px;
      overflow: hidden;
      background-color: var(--background-white); /* Nền trắng cho mỗi card */
  }
  #newHistory table tbody tr:nth-child(even), #history table tbody tr:nth-child(even) {
      background-color: var(--background-white); /* Reset màu nền xen kẽ */
  }

  #newHistory table tbody td, #history table tbody td {
      display: flex;
      justify-content: space-between;
      padding: 10px 15px;
      position: relative;
      border-bottom: 1px dotted var(--border-color); /* Ngăn cách các cell */
      text-align: right; /* Căn phải giá trị */
      font-size: 0.9em;
  }
  #newHistory table tbody td:last-child, #history table tbody td:last-child {
      border-bottom: none; /* Bỏ border cho cell cuối */
  }

  #newHistory table tbody td::before, #history table tbody td::before {
      content: attr(data-label); /* JS cần thêm data-label vào td */
      font-weight: bold;
      color: var(--primary-color); /* Màu label */
      flex-basis: 45%; /* Chiếm phần trăm chiều rộng */
      text-align: left; /* Căn trái label */
      margin-right: 10px;
  }
  #history table tbody td:nth-child(3) { /* Căn trái cho cột "Câu bạn sắp xếp" */
        text-align: left;
        justify-content: flex-start; /* Đẩy label về trái */
   }
   #history table tbody td:nth-child(3)::before {
        margin-right: 5px;
   }
    #history .explain-button {
        width: 100%; /* Nút chiếm cả hàng */
        text-align: center;
        padding: 8px;
        margin-top: 5px; /* Khoảng cách với cell trên */
    }
     #history table tbody td:last-child { /* Cell chứa nút */
         padding: 10px;
     }
      #history table tbody td:last-child::before {
          display: none; /* Ẩn label cho cột Hành động */
      }
       .explanation-row {
           display: block !important; /* Hiển thị khối */
       }
        .explanation-row td {
            display: block; /* Cell chiếm toàn bộ */
            border-top: none;
        }
       .explanation-content {
           font-size: 0.9em;
       }
}

@media screen and (max-width: 480px) {
   .container {
        padding: 15px 10px;
   }
   h1 {
     font-size: 1.6em;
   }
   #quote {
     font-size: 1em;
   }
   .word-bank {
     gap: 8px;
     justify-content: space-around;
   }
   .word {
     padding: 8px 15px;
   }
   .buttons {
     display: flex;
     flex-direction: column; /* Nút xếp chồng lên nhau */
     gap: 10px;
     align-items: center; /* Căn giữa nút */
   }
   .buttons button {
       width: 80%; /* Chiều rộng nút */
       margin: 0;
   }
   #result {
        font-size: 1em;
   }
   #newHistory table tbody td, #history table tbody td {
        font-size: 0.85em;
   }
    #newHistory table tbody td::before, #history table tbody td::before {
        flex-basis: 40%; /* Giảm tỉ lệ label */
    }
}
.logo-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding-top: 20px;
}

.logo {
    max-width: 150px; /* Kích thước gốc */
    height: auto;
    display: block;
}