:root {
  --bg-color: #f9f9f9;
  --text-color: #333333;
  --header-bg: #ffffff;
  --content-bg: #ffffff;
  --sidebar-bg: #f9f9f9;
  --link-color: #0066cc;
  --header-buttons: #444444;
  --border-color: #dddddd;
  --button-bg: #555555;
  --button-text: #ffffff;
  --button-hover: #888888;
}

/* 預設 Light Mode */
body {
    margin: 0;
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--bg-color);
    color: var(--text-color);
    transition: background 0.3s, color 0.3s;
}

header {
    padding: 10px;
    text-align: center;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--header-bg);    
    transition: background 0.3s;
}
header h1 {
    margin: 0;
    font-size: 30px;
    cursor: pointer;
    color: var(--text-color);
    transition: color 0.3s;    
}
.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
}
header input[type="text"] {
    width: 60%;
    max-width: 300px;
    padding: 6px;
    margin: 6px 0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
    transition: background 0.3s;
}
header button {
    margin: 4px;
    padding: 6px 12px;
    cursor: pointer;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--button-bg);
    color: var(--button-text);
    transition: background 0.3s;
}
header button:hover {
    background: var(--button-hover);
}

.header-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 6px;
    background: var(--header-buttons);
    flex-wrap: wrap;
}
.header-buttons button {
    padding: 4px 10px;
    background: var(--button-bg);
    color: var(--button-text);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.3s;
}
.header-buttons button:hover {
    background: var(--button-hover);
}

/* 統計儀表板樣式 */
.dashboard {
    background: var(--content-bg);
    padding: 10px;
    margin: 10px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: none;
    transition: background 0.3s, color 0.3s;
}
.dashboard.active {
    display: block;
}
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}
.stat-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}
.stat-number {
    font-size: 2em;
    font-weight: bold;
    margin-bottom: 5px;
}
.stat-label {
    font-size: 0.9em;
    opacity: 0.9;
}

/* 熱力圖樣式 */
.heatmap-container {
    background: var(--content-bg);
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-top: 20px;
    margin-bottom: 20px;
    transition: background 0.3s, color 0.3s;
}
.heatmap {
    display: grid;
    grid-template-columns: repeat(52, 1fr);
    gap: 2px;
    max-width: 800px;
    margin: 0 auto;
}
.heatmap-day {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    cursor: pointer;
    position: relative;
    transition: background 0.3s, transform 0.2s;
}
.heatmap-day:hover {
    transform: scale(1.2);
}

.heatmap-day.level-0 { background: #ebedf0; }
.heatmap-day.level-1 { background: #c6e48b; }
.heatmap-day.level-2 { background: #7bc96f; }
.heatmap-day.level-3 { background: #239a3b; }
.heatmap-day.level-4 { background: #196127; }

.heatmap-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px; 
  font-size: 12px;
  margin: 10px 0;
  padding-right: 10px;
}
.heatmap-legend .heatmap-day {
  cursor: default;
}
.heatmap-legend .heatmap-day:hover {
  transform: none;
}

.menu-toggle {
    display: none;
    background: var(--text-color);
    color: var(--content-bg);
    padding: 6px;
    cursor: pointer;
    text-align: center;
}

.container {
    flex: 1;
    display: flex;
    overflow: hidden;
}

#sidebar {
    background: var(--sidebar-bg);
    color: var(--text-color);
    transition: background 0.3s, color 0.3s, transform 0.3s ease-in-out; 
    display: flex;
    flex-direction: column;
}
.sidebar-content {
  flex-grow: 1;
  overflow-y: auto;
}
.sidebar-footer {
  padding: 10px;
  border-top: 1px solid var(--border-color);
}

.about-button {
  width: 100%;
  padding: 10px;
  background: var(--button-bg);
  color: var(--button-text);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
  font-size: 1rem;
  transition: background 0.3s;
}
.about-button:hover {
  background: var(--button-hover);
}
.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.6);
  align-items: center;
  justify-content: center;
}
.modal.show {
  display: flex; 
}
.modal-content {
  background-color: var(--content-bg);
  color: var(--text-color);
  margin: auto;
  padding: 20px 30px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  width: 80%;
  max-width: 500px;
  position: relative;
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
  animation: modal-pop 0.3s ease-out;
}
.modal-content h3 {
  margin-top: 1.5em;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 5px;
}
.modal-content p {
  line-height: 1.8;
}
.modal a {
    color: var(--link-color);
    text-decoration: none;
}
.close-button {
  color: #aaa;
  position: absolute;
  top: 10px;
  right: 20px;
  font-size: 28px;
  font-weight: bold;
}
.close-button:hover,
.close-button:focus {
  color: var(--text-color);
  text-decoration: none;
  cursor: pointer;
}
@keyframes modal-pop {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

#monthList {
    background: var(--bg-color);
    color: var(--text-color);
    transition: background 0.3s, color 0.3s;
}

#content {
    background: var(--content-bg);
    color: var(--text-color);
    transition: background 0.3s, color 0.3s, opacity 0.2s ease-in-out;
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}
#content.fade-out {
  opacity: 0;
}

nav {
    width: 250px;
    background: var(--bg-color);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    transition: transform 0.3s ease-in-out; 
}
nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
nav li {
    padding: 10px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    user-select: none;
}
nav li:hover {
    background: #e0e0e0;
}

nav li ul {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease-in-out;
}
nav li ul.open {
  max-height: 1000px;
}
nav li ul li {
    padding-left: 20px;
    background: #f1f1f1;
    border-bottom: none;
    font-size: 0.9rem;
}
nav li ul li:hover {
    background: #ddd;
}

.day-item {
    padding: 5px 10px;
    cursor: pointer;
    border-radius: 5px;
    margin: 2px 0;
    transition: background 0.3s, color 0.3s;
}
.day-item:hover {
    background: #e6f0ff; /* 淺藍 */
}
.day-item.selected {
    background: #dbeeff; /* 更明顯藍底 */
}

h2 {
    margin-top: 0.5em;
    margin-bottom: 0.5em;
}
h3 {
    margin-top: 0.5em;
    margin-bottom: 0.5em;
}

.record {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    line-height: 1.6;
}
.record-content {
  flex-grow: 1;
  word-break: break-word;
}
.record strong {
    color: #444;
}
.record a {
    color: var(--link-color);
    text-decoration: none;
}
.record a:hover {
    text-decoration: underline;
}
.record img {
    max-width: 100%;
    height: auto;
    display: block;
    margin-top: 10px;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.external-link-section {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}
.external-link-section a {
  color: var(--link-color);
  text-decoration: none;
}
.external-link-section a:hover {
  text-decoration: underline;
}

mark {
  background-color: #ffdd57;
  color: #111;
  padding: 1px 3px;
  border-radius: 3px;
}

.search-result-item {
   margin-bottom: 8px;
}
.search-result-date {
  display: block;
  font-weight: bold;
  font-size: 1.1em;
  color: var(--link-color);
  margin-bottom: 8px;
  text-decoration: none;
}
.search-result-date:hover {
  text-decoration: underline;
}

footer {
    background: var(--text-color);
    color: var(--content-bg);
    text-align: left;
    padding: 0px 10px;
    font-size: 14px;
}
footer a {
    color: #66ccff;
    text-decoration: none;
}
footer a:hover {
    text-decoration: underline;
}
footer a + a::before {
  content: "|";
  margin: 0 0.5em;
  color: var(--border-color);
}

/* --- 回到頂部按鈕樣式 --- */
#backToTopBtn {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 30px;
  z-index: 1001;
  border: none;
  outline: none;
  background-color: var(--button-bg);
  color: var(--button-text);
  cursor: pointer;
  padding: 10px;
  border-radius: 50%;
  width: 45px;
  height: 45px;
  font-size: 20px;
  opacity: 0.7;
  transition: opacity 0.3s, visibility 0.3s;
}
#backToTopBtn:hover {
  opacity: 1;
}

/* Dark Mode 主題 */
body.dark-mode {
  --bg-color: #1e1e1e;
  --text-color: #e0e0e0;
  --header-bg: #2a2a2a;
  --content-bg: #2c2c2c;
  --sidebar-bg: #2c2c2c;
  --link-color: #66aaff;
  --border-color: #555555;
  --button-bg: #333333;
  --button-text: #e0e0e0;
  --button-hover: #555555;
}
body.dark-mode {
    background: var(--bg-color);
    color: var(--text-color);
}
body.dark-mode header {
    background: var(--header-bg);
}
body.dark-mode h1 {
    color: var(--text-color);
}
body.dark-mode input[type="text"] {
    background: #333;
    color: var(--text-color);
    border: 1px solid var(--border-color);
}
body.dark-mode input[type="text"]:hover,
body.dark-mode input[type="text"]:focus {
    border-color: #888;
}
body.dark-mode .dashboard {
    background: var(--content-bg);
}
body.dark-mode .heatmap-container {
    background: var(--content-bg);
}
body.dark-mode .heatmap-day.level-0 { 
    background: #2d333b; 
}
body.dark-mode .menu-toggle{
    background: var(--button-bg);
    color: var(--text-color);
}
body.dark-mode #sidebar {
    background: var(--sidebar-bg);
    color: #f1f1f1;
}
body.dark-mode #monthList {
    background: #3a3a3a;
    color: #e0e0e0;
}
body.dark-mode .month-item {
    background: #3a3a3a;
    color: #e0e0e0;
    transition: background 0.3s, color 0.3s;
}
body.dark-mode .month-item:hover {
    background: #555555;
    color: #ffffff;
}
body.dark-mode .day-item {
    background: #2e2e2e;
    color: #e0e0e0;
}
body.dark-mode .day-item:hover {
    background: #70708f;
}
body.dark-mode .day-item.selected {
    background: #5a5a7a;
}
body.dark-mode #content {
    background: #2c2c2c;
    color: #e0e0e0;
}
body.dark-mode .record a {
    color: var(--link-color);
}
body.dark-mode .record a:hover {
    color: #99ccff;
}
body.dark-mode .external-link-section a {
  color: var(--link-color);
}
body.dark-mode .external-link-section a:hover {
  color: #99ccff;
}
body.dark-mode mark {
  background-color: #f7d926;
}
body.dark-mode footer {
    background: #222;
    color: #ccc;
}
body.dark-mode footer a {
    color: #80d4ff;
}

/* --- 測驗容器樣式 --- */
.quiz-container {
  display: none;
  padding: 20px;
  background: var(--content-bg);
  color: var(--text-color);
  flex-grow: 1;
  text-align: center;
  overflow-y: auto;
}
.quiz-container.active {
  display: block;
}
.quiz-header {
  display: flex;
  justify-content: space-between;
  font-size: 1.1em;
  margin-bottom: 20px;
  color: var(--text-color);
}
.quiz-question {
  font-size: 1.3em;
  font-weight: bold;
  margin: 20px 0;
  min-height: 80px;
  max-height: 40vh;
  overflow-y: auto;
  line-height: 1.6;
}
.quiz-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 15px;
  margin: 20px 0;
}
.quiz-option-btn {
  padding: 15px;
  font-size: 1em;
  border: 1px solid var(--border-color);
  background: var(--content-bg);
  color: var(--text-color);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
}
.quiz-option-btn:hover:not(:disabled) {
  background: var(--sidebar-bg);
  transform: translateY(-2px);
}
.quiz-option-btn:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}
/* 答對/答錯的樣式 */
.quiz-option-btn.correct {
  background-color: #28a745;
  color: white;
  border-color: #28a745;
}
.quiz-option-btn.incorrect {
  background-color: #dc3545;
  color: white;
  border-color: #dc3545;
}
.quiz-feedback {
  margin-top: 20px;
  font-size: 1.2em;
  font-weight: bold;
  min-height: 30px;
}
.quiz-results {
  padding-top: 10px;
}
.quiz-results h2 {
  font-size: 2em;
  margin: 10px 0;
}
.quiz-results p {
  font-size: 1.5em;
  margin: 10px 0;
}
.quiz-results-buttons button {
  padding: 10px 20px;
  font-size: 1em;
  cursor: pointer;
  margin: 0 10px;
  border-radius: 5px;
  border: 1px solid var(--border-color);
  background: var(--button-bg);
  color: var(--button-text);
}
.quiz-results-buttons button:hover {
    background: var(--button-hover);
}

.cloze-blank {
  font-weight: bold;
  color: var(--link-color);
  border-bottom: 2px solid var(--link-color);
  padding: 0 5px;
}
.game-setup-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 15px;
  margin-top: 15px;
}
.game-option-btn {
  padding: 12px 25px;
  font-size: 1.1em;
  border: 1px solid var(--border-color);
  background: var(--button-bg);
  color: var(--button-text);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
}
.game-option-btn:hover {
  background: var(--button-hover);
  transform: translateY(-2px);
}
.game-review-area {
  margin-top: 25px;
  text-align: left;
  border-top: 1px solid var(--border-color);
  padding-top: 15px;
}
.review-item {
  margin-bottom: 25px;
  padding-bottom: 15px;
  border-bottom: 1px dashed var(--border-color);
}
.review-item:last-child {
  border-bottom: none;
}
.review-question {
  font-weight: bold;
  margin-bottom: 10px;
}
.review-answer {
  padding-left: 15px;
}
.review-answer p {
  margin: 5px 0;
  font-size: 1em;
}
.review-answer .user-answer.correct {
  font-weight: bold;
  color: #28a745;
}
.review-answer .user-answer.incorrect {
  font-weight: bold;
  color: #dc3545;
}

/* 手機版 */
@media (max-width: 768px) {
    header {
        font-size: 0.9rem;
    }
    header h1 {
        font-size: 1.2rem;
    }
    .menu-toggle {
        display: block;
        border: none;
        font-family: inherit;
        font-size: 1rem;
    }
    .container {
        flex-direction: column;
    }
    nav {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        max-width: 240px;
        transform: translateX(-100%);
        z-index: 1000;
        box-shadow: 2px 0 8px rgba(0,0,0,0.2);
    }
    nav.open {
        transform: translateX(0);
    }
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .heatmap {
        grid-template-columns: repeat(26, 1fr);
    }
    .heatmap-day {
        width: 10px;
        height: 10px;
    }
    .content {
        padding: 15px;
    }
}

/* --- 關鍵字詞雲樣式 --- */
.wordcloud-container {
  background: var(--content-bg);
  padding: 10px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  margin-top: 20px;
  transition: background 0.3s, color 0.3s;
}
.wordcloud-canvas {
  width: 100%;
  height: 400px;
  min-height: 300px;
  position: relative;
}
.wordcloud-canvas .loading-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-color);
  opacity: 0.7;
}

/* --- 頁面標題與朗讀按鈕樣式 --- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1em;
  flex-wrap: wrap;
  gap: 10px;
}
.page-header h2 {
  margin: 0;
}
#tts-button {
  padding: 6px 12px;
  font-size: 0.9em;
  background: var(--button-bg);
  color: var(--button-text);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.3s;
  min-width: 90px;
  text-align: center;
}
#tts-button:hover {
  background: var(--button-hover);
}
#tts-button:disabled {
  background: #ccc;
  cursor: not-allowed;
  opacity: 0.6;
}

/* --- 儀表板控制項樣式 --- */
.dashboard-controls {
  margin-bottom: 20px;
  text-align: right;
}
#year-filter {
  padding: 5px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: var(--content-bg);
  color: var(--text-color);
  font-size: 0.9em;
}

/* --- 趨勢圖容器樣式 --- */
.trend-chart-container {
  background: var(--content-bg);
  padding: 10px 20px 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  margin-top: 20px;
  transition: background 0.3s;
  height: 400px;
  display: flex;
  flex-direction: column;
}
.trend-chart-container h3 {
  flex-shrink: 0;
  margin-bottom: 10px;
}
.chart-wrapper {
  flex-grow: 1;
  position: relative;
}

/* --- 收藏功能樣式 --- */
.favorite-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  font-size: 1.3em;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: transform 0.2s ease;
}
.favorite-btn:hover {
  transform: scale(1.2);
}
.favorites-controls {
  margin-bottom: 20px;
  text-align: right;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.sort-button {
  padding: 5px 10px;
  font-size: 0.9em;
  border: 1px solid var(--border-color);
  background: var(--content-bg);
  color: var(--text-color);
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.3s, color 0.3s;
}
.sort-button:hover {
  background: var(--sidebar-bg);
}
.sort-button.active {
  background: var(--link-color);
  color: var(--button-text);
  border-color: var(--link-color);
}
.view-original-link {
  display: block;
  margin-top: 10px;
  font-size: 0.9em;
  text-align: right;
}
.view-original-link a {
  color: var(--link-color);
  opacity: 0.8;
  text-decoration: none;
}
.view-original-link a:hover {
  opacity: 1;
  text-decoration: underline;
}

/* --- 橫向時間軸樣式 --- */
.timeline-view-container {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 10px;
  -webkit-overflow-scrolling: touch;
}
.timeline-track {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  padding-top: 10px;
}
.timeline-year-card {
  flex: 0 0 300px;
  width: 300px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--sidebar-bg);
  padding: 15px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.timeline-year-card h3 {
  margin-top: 0;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border-color);
  text-align: center;
}
.timeline-year-card .record {
  border-bottom: 1px dashed var(--border-color);
  padding-bottom: 15px;
  margin-bottom: 15px;
}
.timeline-year-card .record:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}
