:root {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #f0f2f5;
  color: #1a1a1a;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
/*  background: #f0f2f5; */
  background: linear-gradient(180deg, #0d1b2a 0%, #1b2d45 100%);
}

/* ===== 頁首 ===== */
header {
  text-align: center;
  padding: 1rem 1rem;
  background: linear-gradient(180deg, #2B8BD2 0%, #1D6396 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(29, 99, 150, 0.3);
}
header h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 1px;
}
header p {
  margin: 0.5rem 0 0;
  font-size: 1rem;
  opacity: 0.9;
}

/* ===== 主內容 ===== */
main {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1rem 3rem;
}

/* ===== 卡片 ===== */
.card {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  padding: 1.7rem;
  margin-bottom: 1.7rem;
  border: 1px solid #e8ecf1;
}

h2 {
  margin: 0 0 0.8rem;
  color: #1D6396;
  font-size: 1.6rem;
  font-weight: 600;
}

/* ===== 按鈕 ===== */
button {
  background: #2B8BD2;
  border: none;
  color: white;
  padding: 0.7rem 1.2rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background 0.2s ease, transform 0.1s ease;
}
button:hover {
  background: #1D6396;
}
button:active {
  transform: scale(0.97);
}

.small-btn {
  margin-top: 0.8rem;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
}

/* ===== 答案按鈕 ===== */
.answer-btn {
  background: #f7f9fc;
  color: #1a1a1a;
  border: 1px solid #d0d7e2;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
  padding: 0.85rem 1.1rem;
  font-weight: bold;
  font-family: 'Segoe UI', 'Helvetica Neue', 'Noto Sans', '微軟正黑體', 'Microsoft JhengHei', sans-serif;
  border-radius: 6px;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.answer-btn:hover {
  background: #e8ecf1;
  border-color: #b0b8c4;
}
.answer-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: #e8ecf1;
  border-color: #d0d7e2;
  box-shadow: none;
}

/* ===== 測驗區塊 ===== */
.quiz {
  margin-top: 1rem;
}

.answers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin-top: 1rem;
}

/* ===== 圖片區塊 ===== */
.vocab-image {
  margin-top: 1rem;
  border-radius: 12px;
  overflow: hidden;
  background: #f7f9fc;
  padding: 0.8rem;
  text-align: center;
  border: 1px solid #e8ecf1;
}
.vocab-image img {
  width: 100%;
  max-width: 480px;
  height: auto;
  border-radius: 8px;
  display: block;
  margin: 0 auto;
}
.vocab-image p {
  margin: 0.75rem 0 0;
  color: #333;
  font-weight: 600;
}

/* ===== 例句區塊 ===== */
.vocab-examples {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  background: #fafbfc;
  border: 1px solid #e8ecf1;
  border-radius: 8px;
  text-align: left;
}
.vocab-examples p {
  margin: 0.4rem 0;
  color: #2d3e6b;
  line-height: 1.6;
}

/* ===== 例句容器 ===== */
.example-sentence {
  margin-bottom: 16px;
  line-height: 1.6;
}

/* ===== 發音按鈕 ===== */
.speak-example-btn,
.speak-zh-btn,
.speak-last-word,
.speak-current-word {
  background: #eef2f7;
  border: none;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 2px 10px;
  border-radius: 16px;
  transition: background 0.15s ease;
  margin-right: 6px;
  white-space: nowrap;
  color: #1D6396;
}
.speak-example-btn:hover,
.speak-zh-btn:hover,
.speak-last-word:hover,
.speak-current-word:hover {
  background: #dce4ed;
}

/* ===== 上一個單字連結 ===== */
#last-word-link {
  background-color: #f7f9fc;
  border-radius: 8px;
  padding: 6px 10px;
  margin-top: 12px;
  font-size: 0.9rem;
  border: 1px solid #e8ecf1;
}

/* ===== 題目文字 ===== */
#vocab-question {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 1.6rem;
  font-weight: 500;
  margin-top: 0.8rem;
  margin-bottom: 0.8rem;
  padding: 0.5rem 0;
  color: #1a1a1a;
}
#quiz-status {
  font-size: 1rem;
  font-weight: 500;
  color: #1D6396;
  margin-bottom: 0.25rem;
}

/* ===== 閱讀文章 ===== */
.passage {
  background: #f7f9fc;
  border-radius: 8px;
  padding: 1rem;
  line-height: 1.7;
  border: 1px solid #e8ecf1;
}

/* ★★★ 新增這段：徹底消除 content 容器內部的多餘空隙 ★★★ */
#reading-content {
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
}

/* ===== 結果文字 ===== */
.result {
  margin-top: 1rem;
  font-weight: 600;
}

/* ===== 頁尾 ===== */
footer {
  text-align: center;
  padding: 1rem 0;
  color: #8895aa;
  font-size: 0.9rem;
}

/* ===== 響應式 ===== */
@media (max-width: 640px) {
  main {
    padding: 1rem;
  }
  #vocab-question {
    font-size: 1.2rem;
  }
  .card {
    padding: 1.2rem;
  }
}

/* ===== 折疊動畫 ===== */
.collapsible {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 320ms ease, opacity 260ms ease, transform 260ms ease;
  transform-origin: top;
  transform: translateY(-6px);
}
.collapsible:not(.collapsed) {
  max-height: 800px;
  opacity: 1;
  transform: translateY(0);
}
.review h3,
.history h3 {
  margin-top: 0;
}

/* ===== 標籤與表單 ===== */
.vocab-summary p {
  font-size: 1rem;
  font-weight: 500;
  color: #445566;
}
label {
  font-size: 0.95rem;
  font-weight: 500;
  margin-top: 6px;
  display: inline-block;
  color: #334455;
}
select,
input {
  font-size: 0.95rem;
  padding: 6px 10px;
  border: 1px solid #d0d7e2;
  border-radius: 6px;
  background: white;
  color: #1a1a1a;
}
select:focus,
input:focus {
  outline: none;
  border-color: #2B8BD2;
  box-shadow: 0 0 0 3px rgba(43, 139, 210, 0.15);
}

/* ===== 開關按鈕 ===== */
#toggle-images,
#toggle-examples {
  transform: scale(1.1);
  cursor: pointer;
  margin-right: 6px;
}
label:has(#toggle-images),
label:has(#toggle-examples) {
  cursor: pointer;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ===== 匯入/匯出按鈕 ===== */
#export-wrong-btn,
#import-wrong-btn,
#import-vocab-btn,
#clear-vocab-btn {
  font-size: 0.9rem;
}

/* ===== 粗體單字顏色 ===== */
strong {
  color: #1D6396;
}

/* ★★★ 新增加：遊戲與配對相關樣式 ★★★ */
.game-dir-btn {
  padding: 15px 30px;
  border: none;
  border-radius: 8px;
  background-color: #3498db;
  color: white;
  cursor: pointer;
  font-weight: bold;
  white-space: nowrap;
}
.game-dir-btn:hover { background-color: #2980b9; }

.game-block {
  position: absolute;
  width: 100px;
  height: 60px;
  box-sizing: border-box;
  border-radius: 6px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: bold;
  font-size: 11px;
  text-align: center;
  line-height: 1.2;
  padding: 2px;
  word-break: break-all;
  color: #333;
  box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
  cursor: pointer;
  transition: opacity 0.3s;
  user-select: none;
}
.game-block.en-block { background: #85c1e9; border: 2px solid #2980b9; }
.game-block.zh-block { background: #f9e79f; border: 2px solid #f1c40f; }
.game-block.matched { opacity: 0; pointer-events: none; transition: opacity 0.5s; }
.game-block.selected { border: 4px solid #e74c3c; transform: scale(0.95); }

/* 未配對單字動態網格 */
.unmatched-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  margin-top: 15px;
  padding: 10px;
  background: #fff;
  border-radius: 8px;
  border: 1px solid #eee;
}
.unmatched-item {
  background: #f8f9fa;
  padding: 6px 10px;
  border-radius: 4px;
  border-left: 4px solid #e74c3c;
  font-size: 13px;
  line-height: 1.4;
  text-align: left;
  color: #333;
  word-break: break-word;
}
.unmatched-item strong {
  color: #1D6396;
  margin-right: 4px;
}

#debug-output {
    display: none !important;
}

/* ★★★ 修正排版：還原並優化題目排版 ★★★ */
#vocab-question {
    display: flex;
    align-items: center;
    flex-wrap: wrap;       /* 允許文字自然換行，而不是強制斷行分開 */
    gap: 8px;
    font-size: 1.6rem;
    font-weight: 500;
    margin-top: 0.8rem;
    margin-bottom: 0.8rem;
    padding: 0.5rem 0;
    color: #1a1a1a;
}

/* 優化包含單字和喇叭圖示的那一行 */
#vocab-question span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    line-height: normal;   /* 讓行高回到自然狀態，解決 APP 多空一行的問題 */
}

/* 優化喇叭圖示按鈕 */
#vocab-question span button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 4px;
    font-size: 1.2rem;
    vertical-align: middle;
    line-height: 1;
}

#music-info {
  flex: 1 1 100%;          /* 強制佔滿整行，讓文件名獨自一行 */
  white-space: normal;     /* 允許長文件名換行（防止溢出） */
  word-break: break-all;   /* 防止超長英文單詞不換行 */
  overflow: visible;       /* 不隱藏內容 */
  text-overflow: clip;     /* 不添加省略號 */
  font-size: 0.9rem;
  color: #555;
  margin-left: 8px;
}

/* ★★★ 即時字典彈窗樣式 ★★★ */
.dictionary-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 99999;
    display: none; /* 預設隱藏 */

    /* ★★★ 核心修改區 ★★★ */
    align-items: flex-start; /* 靠頂對齊 */
    justify-content: center;  /* 水平維持置中 */
    padding-top: 0px;        /* 距離頂端 40px，不會黏死邊緣 */
}

/* ★★★ 修正：讓即時字典的遮罩蓋滿整個螢幕 ★★★ */
#dict-overlay {
    position: fixed;       /* 固定定位，無論捲動到哪都在螢幕最上層 */
    top: 0;
    left: 0;
    width: 100vw;          /* 寬度佔滿整個視窗 */
    height: 100vh;         /* 高度佔滿整個視窗 */
    background: rgba(0, 0, 0, 0.5); /* 半透明的黑色背景 */
    display: none;         /* 預設隱藏 */
    justify-content: center;
/*    align-items: center;    /* 拿掉 align-items: center; 後，它就會乖乖聽從上方 class 裡的 flex-start 了 */
    z-index: 9999;         /* 確保在最上層 */
}

/* 字典彈窗本身 */
.dictionary-popup {
    background: #ffffff;
    padding: 16px 20px;         /* ✅ 原本是 24px 28px，改小一點 */
    max-width: 260px;           /* ✅ 原本是 320px，改小一點 */
    max-width: 320px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    width: 90%;
    text-align: center;
    position: relative;
}

@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.dictionary-popup .word {
    font-size: 1.4rem;         /* ✅ 原本是 1.8rem，改小一點 */
    font-weight: 700;
    color: #1D6396;
    margin-bottom: 6px;        /* 距離縮小 */
    display: block;
}

.dictionary-popup .meaning {
    font-size: 1.0rem;         /* ✅ 原本是 1.2rem，改小一點 */
    color: #333;
    margin-bottom: 12px;       /* 距離縮小 */
    display: block;
}

.dictionary-popup .actions {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.dictionary-popup .actions button {
    padding: 8px 16px;
    font-size: 0.9rem;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    background: #eef2f7;
    color: #1D6396;
    transition: 0.2s;
}
.dictionary-popup .actions button:hover {
    background: #dce4ed;
}

.dictionary-popup .actions button.speak-btn {
    background: #2B8BD2;
    color: white;
}
.dictionary-popup .actions button.speak-btn:hover {
    background: #1D6396;
}

/* ★★★ 字典搜尋功能樣式 ★★★ */
#dict-search-results .result-item {
  padding: 8px 4px;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
}
#dict-search-results .result-item:hover {
  background: #f4f6f9;
}
#dict-search-results .result-item .result-word {
  font-weight: bold;
  color: #1D6396;
}
#dict-search-results .result-item .result-meaning {
  color: #333;
  font-size: 0.9rem;
}