/* ════════════════════════════════════════════════════════════
   CurveVocab — 明亮學習風設計系統
   從暗色工程風 → 淺色漸變 + 薄荷綠主色 + 白卡片 + 柔和陰影
   ════════════════════════════════════════════════════════════ */

:root {
  --ink: #17212b;
  --muted: #6b7785;
  --line: #dde5ed;
  --paper: #f7fafc;
  --panel: #ffffff;
  --mint: #1f9d7a;
  --mint-soft: #dff4ed;
  --mint-dark: #14765e;
  --blue: #246bfe;
  --blue-soft: #e8efff;
  --amber: #f6b73c;
  --amber-soft: #fff4d8;
  --amber-dark: #bd7900;
  --red: #e65a53;
  --red-soft: #ffe9e7;
  --shadow-sm: 0 3px 12px rgba(33,47,64,.06);
  --shadow: 0 12px 34px rgba(58,75,94,.09);
  --shadow-lg: 0 18px 50px rgba(38,54,77,.13);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #edf5f2 0%, #f8fbff 42%, #eef2f7 100%);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  user-select: none;
  letter-spacing: 0;
}

/* ══ 啟動覆蓋層 ══ */
.overlay {
  position: fixed; inset: 0;
  background: linear-gradient(180deg, #edf5f2 0%, #f8fbff 42%, #eef2f7 100%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 200; gap: 16px; padding: 40px; text-align: center;
}
.overlay h1 { font-size: 28px; color: var(--ink); font-weight: 850; }
.overlay p { color: var(--muted); font-size: 16px; line-height: 1.6; max-width: 400px; }
.overlay .start-btn {
  margin-top: 12px; padding: 16px 36px; border: none; border-radius: 16px;
  background: var(--mint); color: white;
  font-size: 17px; font-weight: 850; cursor: pointer;
  box-shadow: 0 10px 22px rgba(31,157,122,.24);
  transition: all .2s ease;
}
.overlay .start-btn:active { transform: scale(0.95); }
.overlay .mode-btn-secondary {
  background: var(--panel); color: #344a5f; border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  font-size: 14px !important; padding: 12px 28px !important;
}
.overlay .mode-select { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.overlay .warn { font-size: 13px; color: var(--amber-dark); margin-top: 8px; }
.overlay.hidden { display: none !important; }

/* 安全聲明 */
.safety-overlay { background: linear-gradient(180deg, #fff8ea 0%, #f8fbff 42%, #eef2f7 100%); z-index: 500; }
.safety-box {
  background: var(--panel); border: 1px solid var(--amber); border-radius: 22px;
  padding: 32px 28px; max-width: 380px; text-align: center; box-shadow: 0 0 40px rgba(246,183,60,.15);
}
.safety-icon { font-size: 48px; margin-bottom: 12px; }
.safety-box h2 { font-size: 22px; color: var(--amber-dark); margin-bottom: 16px; font-weight: 850; }
.safety-box p { color: var(--muted); font-size: 15px; line-height: 1.6; margin-bottom: 12px; }
.safety-warn { color: var(--red) !important; font-size: 15px !important; }
.safety-box .start-btn { background: linear-gradient(135deg, var(--amber), var(--amber-dark)); margin-top: 8px; }

/* ══ 主內容 ══ */
#mainContent {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
}

/* 頂部 */
.header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px 10px;
  background: rgba(247,250,252,.92);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.header .title { font-size: 16px; color: var(--muted); font-weight: 700; flex: 1; }
.header .badge { font-size: 12px; color: var(--mint-dark); background: var(--mint-soft); padding: 3px 10px; border-radius: 999px; font-weight: 700; }

.streak-display {
  display: flex; align-items: center; gap: 2px; font-size: 16px;
  background: var(--amber-soft); padding: 4px 12px; border-radius: 999px;
  color: var(--amber-dark); font-weight: 850;
}
.header-btn {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  width: 38px; height: 38px; font-size: 18px; cursor: pointer; color: var(--ink);
  display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
  transition: all .2s ease;
}
.header-btn:active { transform: scale(0.9); }
.lang-toggle {
  background: var(--mint-soft); border: none; border-radius: 999px;
  padding: 6px 14px; font-size: 13px; font-weight: 700; cursor: pointer;
  color: var(--mint-dark);
  transition: all .2s ease;
}
.lang-toggle:active { transform: scale(0.93); }

/* 每日目標進度條 */
.daily-goal-bar-container {
  height: 5px; background: #e6edf3; position: relative; margin: 0;
}
.daily-goal-bar {
  height: 100%; background: linear-gradient(90deg, var(--mint), #45b995);
  width: 0%; transition: width 0.5s ease; border-radius: 0 3px 3px 0;
}
.daily-goal-bar.goal-done { background: linear-gradient(90deg, var(--mint), #45b995); }
.daily-goal-text {
  position: absolute; right: 8px; top: -18px; font-size: 11px; color: var(--muted); font-weight: 650;
}

/* 統計面板 */
.stats-panel {
  display: flex; justify-content: space-around;
  padding: 10px 20px; margin: 8px 16px;
  background: var(--panel); border-radius: 18px; box-shadow: var(--shadow-sm);
  border: 1px solid var(--line);
}
.stat-item { text-align: center; }
.stat-num { font-size: 22px; font-weight: 850; color: var(--mint); display: block; }
.stat-label { font-size: 11px; color: var(--muted); }

/* 內容區 */
.content-scroll {
  flex: 1; overflow-y: auto; padding: 0 0 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.content-scroll::-webkit-scrollbar { display: none; }

/* 單詞顯示 */
.word-display { text-align: center; padding: 20px; }
.word-display .word {
  font-size: clamp(36px, 10vw, 43px); font-weight: 850; letter-spacing: 0;
  color: var(--ink); min-height: 50px; line-height: 1.1;
}
.status-tag {
  display: inline-block; font-size: 11px; font-weight: 750;
  padding: 3px 10px; border-radius: 999px; margin-top: 8px;
}
.status-tag.new { background: var(--blue-soft); color: var(--blue); }
.status-tag.learning { background: var(--amber-soft); color: var(--amber-dark); }
.status-tag.review { background: var(--mint-soft); color: var(--mint-dark); }
.word-meta { margin-top: 8px; }
.word-meta .meta-chip {
  display: inline-block; font-size: 11px; background: #f3f7fa; color: var(--muted);
  padding: 3px 8px; border-radius: 10px; margin: 2px;
}

/* 音標 */
.phonetic-row { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.phonetic-item {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); background: #fbfdff; color: #3d5267;
  border-radius: 999px; padding: 7px 12px; font-size: 14px;
  cursor: pointer; transition: all .2s ease;
}
.phonetic-item:active { transform: scale(0.95); }
.phonetic-item .ph-flag { font-size: 15px; }
.phonetic-item .ph-text { font-size: 14px; }
.phonetic-item .ph-speaker { font-size: 13px; opacity: 0.6; }
.popup-phonetic-row { margin-top: 8px; }

.definition { font-size: 16px; color: var(--muted); margin-top: 8px; }

/* 例句 */
.examples-list { padding: 0 18px 4px; display: flex; flex-direction: column; gap: 10px; }
.def-header { display: flex; align-items: center; gap: 8px; }
.def-num {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--mint); color: white;
  display: grid; place-items: center; font-size: 12px; font-weight: 850; flex-shrink: 0;
}
.def-meaning { font-size: 16px; font-weight: 700; color: var(--ink); }
.example-item {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.example-en { font-size: 15px; color: var(--ink); line-height: 1.5; }
.target-word {
  background: #fff1c9; color: #7c5700; border-radius: 5px; padding: 0 3px; font-weight: 700;
}
.clickable-word { cursor: pointer; }
.clickable-word:active { color: var(--mint); }
.example-zh { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* 相關詞 */
.related-section { padding: 8px 18px 4px; }
.related-header { font-size: 14px; font-weight: 700; color: var(--muted); margin-bottom: 10px; }
.related-list { display: flex; flex-wrap: wrap; gap: 6px; }
.related-chip {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 6px 12px; display: flex; flex-direction: column; gap: 2px;
}
.rel-tag { font-size: 10px; font-weight: 700; }
.rel-synonym { color: var(--mint); }
.rel-antonym { color: var(--red); }
.rel-derivative { color: #8b5cf6; }
.rel-collocation { color: var(--blue); }
.rel-root { color: var(--amber-dark); }
.rel-category { color: var(--muted); }
.rel-word { font-weight: 700; color: var(--ink); cursor: pointer; }
.rel-reason { font-size: 11px; color: var(--muted); }

/* 彈窗 */
.popup-overlay {
  position: fixed; inset: 0; background: rgba(23,33,43,.4); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 300; padding: 20px;
}
.popup {
  background: var(--panel); border-radius: 22px; padding: 28px;
  max-width: 400px; width: 100%; max-height: 80vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.popup-word { font-size: 28px; font-weight: 850; color: var(--ink); margin-bottom: 8px; }
.popup-def { font-size: 16px; color: var(--ink); margin: 12px 0; line-height: 1.5; }
.popup-examples { margin: 12px 0; }
.popup-examples .ex { font-size: 14px; color: var(--ink); margin-bottom: 4px; }
.popup-examples .ex-zh { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.popup-actions { display: flex; gap: 10px; margin-top: 16px; }
.popup-btn {
  flex: 1; padding: 12px; border: 1px solid var(--line); border-radius: 14px;
  font-size: 14px; font-weight: 700; cursor: pointer; background: var(--panel); color: var(--ink);
  transition: all .2s ease;
}
.popup-btn:active { transform: scale(0.96); }
.wordbook-btn { background: var(--mint); color: white; border: none; }
.wordbook-btn.in-list { background: var(--mint-soft); color: var(--mint-dark); }
.close-btn { background: #f3f7fa; }

/* 對話區 */
.chat-area { padding: 0 18px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 85%; padding: 12px 16px; border-radius: 18px; font-size: 15px; line-height: 1.5; animation: fadeIn 0.3s ease; }
.msg.coach {
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  align-self: flex-start; border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-sm);
}
.msg.user {
  background: var(--mint-soft); color: var(--mint-dark); align-self: flex-end; border-bottom-right-radius: 6px;
}
.msg.system { align-self: center; font-size: 13px; color: var(--muted); background: #f3f7fa; padding: 6px 14px; border-radius: 999px; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ══ 答題結果浮層 ══ */
.result-flash {
  position: fixed; inset: 0; z-index: 600;
  display: none; align-items: center; justify-content: center;
  pointer-events: none; opacity: 0;
  transition: opacity .25s ease;
}
.result-flash.show { display: flex; opacity: 1; }
.result-flash::before {
  content: ''; position: absolute; inset: 0;
  backdrop-filter: blur(2px);
}
.result-flash.correct::before { background: rgba(31,157,122,.12); }
.result-flash.wrong::before { background: rgba(230,90,83,.10); }
.result-flash .rf-icon {
  position: relative; z-index: 1;
  width: 80px; height: 80px; border-radius: 50%;
  display: grid; place-items: center;
  animation: rf-pop .35s cubic-bezier(.18,.89,.32,1.28);
}
.result-flash.correct .rf-icon { background: var(--mint); box-shadow: 0 0 40px rgba(31,157,122,.4); }
.result-flash.wrong .rf-icon { background: var(--red); box-shadow: 0 0 40px rgba(230,90,83,.35); }
.rf-icon svg { width: 40px; height: 40px; stroke: #fff; stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; }
@keyframes rf-pop {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

/* ══ 語音狀態卡片(合併狀態欄+音量+對話) ══ */
.voice-panel {
  margin: 0 16px 8px;
  background: linear-gradient(135deg, #f0f7f4, #f8fbfc);
  border: 1px solid #d5e9df; border-radius: 18px;
  padding: 14px;
  box-shadow: var(--shadow-sm);
  transition: all .3s ease;
}
.voice-panel-main {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  gap: 12px; align-items: center;
}
.mic-ring {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--mint); display: grid; place-items: center;
  color: #fff;
  box-shadow: 0 0 0 7px rgba(31,157,122,.13);
  transition: all .3s ease;
}
.mic-ring .vc-icon {
  width: 20px; height: 20px; stroke: currentColor; stroke-width: 2;
  fill: none; stroke-linecap: round; stroke-linejoin: round;
}
/* 狀態變體 */
.voice-panel.state-ai .mic-ring { background: var(--blue); box-shadow: 0 0 0 7px rgba(36,107,254,.13); cursor: default; }
.voice-panel.state-listen .mic-ring { background: var(--mint); animation: pulse-ring 1.5s infinite; }
.voice-panel.state-thinking .mic-ring { background: var(--amber); box-shadow: 0 0 0 7px rgba(246,183,60,.13); cursor: default; }
/* 靜音狀態 */
.mic-ring.muted { background: #94a3b8 !important; animation: none !important; box-shadow: 0 0 0 7px rgba(148,163,184,.13) !important; }
.mic-ring.muted::after {
  content: ''; position: absolute; width: 28px; height: 2px; background: var(--red);
  transform: rotate(-45deg); border-radius: 2px;
}
.mic-ring { position: relative; cursor: pointer; }
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 7px rgba(31,157,122,.2); }
  50% { box-shadow: 0 0 0 14px rgba(31,157,122,.05); }
  100% { box-shadow: 0 0 0 7px rgba(31,157,122,.2); }
}

.voice-content { min-width: 0; }
.voice-status { font-size: 14px; font-weight: 800; color: var(--ink); line-height: 1.3; }
.voice-dialog {
  font-size: 13px; color: var(--muted); line-height: 1.45; margin-top: 3px;
  max-height: 60px; overflow: hidden;
}
.voice-dialog .vd-coach { color: var(--ink); font-weight: 600; }
.voice-dialog .vd-user { color: var(--mint-dark); }

/* 波形(真實音量驅動) */
.wave {
  display: flex; align-items: center; gap: 2px; height: 28px;
  opacity: 0.3; transition: opacity .3s;
}
.voice-panel.state-ai .wave, .voice-panel.state-listen .wave { opacity: 1; }
.wave span {
  width: 3px; min-height: 3px; border-radius: 999px;
  transition: height .08s ease-out; /* JS 控制 height */
}
/* AI 說話時波形藍色,用戶說話時綠色 */
.voice-panel.state-ai .wave span { background: var(--blue); }
.voice-panel.state-listen .wave span { background: var(--mint); }
.voice-panel.state-thinking .wave span { background: var(--amber); }

/* ══ 底部控制(Demo SVG 圖標風格) ══ */
.controls {
  margin-top: auto; padding: 14px 18px 20px;
  background: linear-gradient(180deg, rgba(248,251,252,0), #f8fbfc 18%);
}
.actions {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 10px; margin-bottom: 10px;
}
.action {
  border: 1px solid var(--line); background: #fff; border-radius: 16px;
  min-height: 58px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  color: #334454; font-size: 12px; font-weight: 700;
  cursor: pointer; transition: all .2s ease;
  box-shadow: var(--shadow-sm);
}
.action:active { transform: scale(0.96); }
.action:disabled { opacity: 0.4; }
.action.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.action .act-icon {
  width: 22px; height: 22px; stroke: currentColor; stroke-width: 2;
  fill: none; stroke-linecap: round; stroke-linejoin: round;
}
.safe-note {
  display: flex; align-items: center; justify-content: center;
  gap: 6px; color: #7a8793; font-size: 12px;
}
.safe-note .act-icon { width: 16px; height: 16px; }

/* ══ 單詞本管理 ══ */
.wordbook-list { display:flex; flex-direction:column; gap:8px; margin-bottom:10px; }
.wb-card {
  display:flex; align-items:center; gap:10px; padding:10px 14px;
  background:#fff; border:1px solid var(--line); border-radius:14px;
  cursor:pointer; transition:all .2s; box-shadow:var(--shadow-sm);
}
.wb-card:hover { border-color:var(--mint); }
.wb-card.active { border:2px solid var(--mint); background:var(--mint-soft); }
.wb-card .wb-info { flex:1; }
.wb-card .wb-name { font-size:14px; font-weight:700; color:var(--ink); }
.wb-card .wb-stats { font-size:11px; color:var(--muted); margin-top:2px; }
.wb-card .wb-bar { height:4px; background:#e6edf3; border-radius:2px; margin-top:4px; overflow:hidden; }
.wb-card .wb-bar span { display:block; height:100%; background:var(--mint); border-radius:2px; }
.wb-card .wb-activate {
  font-size:11px; padding:4px 10px; border-radius:8px;
  border:1px solid var(--line); background:#fff; color:var(--muted); cursor:pointer;
}
.wb-card.active .wb-activate { display:none; }
.wordbook-actions { display:flex; gap:8px; }
.wb-btn {
  flex:1; padding:8px; border:1px dashed var(--line); border-radius:10px;
  background:transparent; color:var(--muted); font-size:12px; cursor:pointer; text-align:center;
}
.wb-btn:hover { border-color:var(--mint); color:var(--mint); }
.import-label { display:flex; align-items:center; justify-content:center; }

/* ══ Profile 個人中心 ══ */
.profile-overlay { z-index: 400; background: rgba(23,33,43,.4); backdrop-filter: blur(4px); padding: 0; }
.profile-panel {
  background: var(--paper); width: 100%; max-width: 500px; height: 100vh; height: 100dvh;
  margin: 0 auto; display: flex; flex-direction: column;
}
.profile-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  background: rgba(247,250,252,.92); backdrop-filter: blur(16px);
}
.profile-header h2 { font-size: 18px; font-weight: 850; color: var(--ink); }
.profile-close { background: none; border: none; color: var(--muted); font-size: 22px; cursor: pointer; }
.profile-scroll { overflow-y: auto; padding: 20px; flex: 1; }
.profile-section { margin-bottom: 24px; }
.profile-section h3 {
  font-size: 13px; color: var(--muted); margin-bottom: 12px; font-weight: 850;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.profile-streak-card {
  background: linear-gradient(135deg, var(--amber-soft), rgba(246,183,60,.05));
  border: 1px solid var(--amber); border-radius: 18px; padding: 20px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.streak-fire { font-size: 36px; }
.streak-num-big { font-size: 40px; font-weight: 850; color: var(--amber-dark); }
.streak-label { font-size: 15px; color: var(--muted); }
.profile-form { display: flex; flex-direction: column; gap: 14px; }
.profile-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 650; }
.profile-form input, .profile-form select {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; color: var(--ink); font-size: 15px; font-family: inherit;
}
.profile-form input:focus, .profile-form select:focus { outline: none; border-color: var(--mint); }
.profile-save-btn {
  background: var(--mint); color: white; border: none; border-radius: 16px;
  padding: 14px; font-size: 16px; font-weight: 850; cursor: pointer; margin-top: 4px;
  box-shadow: 0 10px 22px rgba(31,157,122,.24);
  transition: all .2s ease;
}

/* 日曆熱力圖 */
.calendar-heatmap { overflow-x: auto; }
.heatmap-grid { display: flex; gap: 3px; min-width: max-content; }
.heatmap-col { display: flex; flex-direction: column; gap: 3px; }
.heatmap-cell { width: 14px; height: 14px; border-radius: 4px; background: #e6edf3; }
.heatmap-cell.level-1 { background: #9fd9c5; }
.heatmap-cell.level-2 { background: #56ba98; }
.heatmap-cell.level-3 { background: var(--mint); }
.heatmap-cell.level-4 { background: #14765e; }
.heatmap-legend { display: flex; align-items: center; gap: 4px; margin-top: 8px; font-size: 11px; color: var(--muted); }
.heatmap-legend .heatmap-cell { width: 11px; height: 11px; }
.heatmap-empty { color: var(--muted); padding: 20px; text-align: center; }

/* 單詞熟悉度熱力圖 */
.fam-dist-bar { display: flex; height: 24px; border-radius: 8px; overflow: hidden; margin-bottom: 8px; }
.fam-dist-seg { transition: flex-grow 0.3s; }
.fam-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; font-size: 12px; color: var(--muted); }
.fam-legend-item { display: flex; align-items: center; gap: 4px; }
.fam-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.word-heatmap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 4px; }
.word-cell {
  padding: 6px 4px; border-radius: 8px; text-align: center; font-size: 12px;
  cursor: pointer; transition: transform 0.1s; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.word-cell:active { transform: scale(0.95); }
.word-cell.fam-0 { background: #f3f7fa; color: var(--muted); }
.word-cell.fam-1 { background: var(--red-soft); color: var(--red); }
.word-cell.fam-2 { background: var(--amber-soft); color: var(--amber-dark); }
.word-cell.fam-3 { background: var(--mint-soft); color: var(--mint-dark); }
.word-cell.fam-4 { background: var(--mint); color: white; }

/* 數據管理 */
.data-actions { display: flex; gap: 8px; }
.data-btn {
  flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px; color: var(--ink); font-size: 14px; cursor: pointer; text-align: center;
  box-shadow: var(--shadow-sm); transition: all .2s ease;
}
.data-btn:active { transform: scale(0.97); }
