:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --primary: #6366f1;
  --primary-light: #e0e7ff;
  --primary-dark: #4f46e5;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
  --bubble-user: #6366f1;
  --bubble-ai: #ffffff;
  --correction-bg: #fef2f2;
  --correction-old: #ef4444;
  --correction-new: #22c55e;
  --practice-bg: #f0fdf4;
  --practice-border: #bbf7d0;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-rows: 64px 1fr 88px;
  height: 100vh;
}

/* ===== Header ===== */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 10;
}
.header-left { display: flex; align-items: center; gap: 16px; }
.logo {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.scene-select {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}
.scene-select:hover { border-color: var(--primary); }
.scene-select:focus { border-color: var(--primary); }

.speed-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.speed-label { white-space: nowrap; }
.speed-control input[type="range"] {
  width: 80px;
  accent-color: var(--primary);
}
#speedValue { min-width: 36px; font-size: 12px; color: var(--primary); font-weight: 500; }

.btn-secondary {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-muted);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ===== Conversation Area ===== */
.conversation-area {
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

.welcome-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.welcome-icon { font-size: 48px; margin-bottom: 16px; }
.welcome-message h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}
.welcome-message p {
  font-size: 14px;
  margin-bottom: 4px;
}
.welcome-tip {
  color: var(--text-light) !important;
  font-size: 13px !important;
  margin-top: 8px !important;
  max-width: 400px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 800px;
  margin: 0 auto;
}

/* ===== Message Bubbles ===== */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-user { align-self: flex-end; }
.msg-ai { align-self: flex-start; }

.bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.6;
  word-break: break-word;
}
.msg-user .bubble {
  background: var(--bubble-user);
  color: white;
  border-bottom-right-radius: 4px;
}
.msg-ai .bubble {
  background: var(--bubble-ai);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}

.msg-meta {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 4px;
  padding: 0 4px;
}
.msg-user .msg-meta { text-align: right; }

/* AI message sections */
.ai-section {
  margin-bottom: 10px;
}
.ai-section:last-child { margin-bottom: 0; }

.ai-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.english-to-say {
  background: var(--practice-bg);
  border: 1px solid var(--practice-border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 15px;
  color: #166534;
  margin-bottom: 10px;
}

.correction-item {
  background: var(--correction-bg);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 6px;
  font-size: 13px;
}
.correction-original {
  color: var(--correction-old);
  text-decoration: line-through;
  margin-right: 6px;
}
.correction-arrow { color: var(--text-light); margin-right: 6px; }
.correction-corrected {
  color: var(--correction-new);
  font-weight: 500;
}
.correction-explanation {
  display: block;
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 12px;
}

.conversation-reply {
  font-size: 15px;
  color: var(--text);
}
.reply-cn {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Action buttons on AI messages */
.msg-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.action-btn {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 4px;
}
.action-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.action-btn.speaking {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

/* Readalong result */
.readalong-result {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
}
.readalong-good {
  background: var(--practice-bg);
  color: #166534;
}
.readalong-bad {
  background: #fffbeb;
  color: #92400e;
}
.readalong-word {
  display: inline;
}
.readalong-word.wrong {
  color: var(--danger);
  text-decoration: underline wavy var(--danger);
}

/* ===== Bottom Controls ===== */
.controls {
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 0 24px;
}

.language-switch {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.lang-btn {
  padding: 8px 16px;
  border: none;
  background: var(--surface);
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}
.lang-btn.active {
  background: var(--primary);
  color: white;
}

.mic-button {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(99,102,241,0.3);
}
.mic-button:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(99,102,241,0.4);
}
.mic-button.recording {
  background: var(--danger);
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50% { box-shadow: 0 0 0 12px rgba(239,68,68,0); }
}
.mic-label {
  display: none;
}

.status-text {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 80px;
}

/* ===== Loading indicator ===== */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}
.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-light);
  animation: typing 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; }
  30% { opacity: 1; }
}

/* ===== Scrollbar ===== */
.conversation-area::-webkit-scrollbar { width: 6px; }
.conversation-area::-webkit-scrollbar-track { background: transparent; }
.conversation-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.conversation-area::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ===== Overlay ===== */
.overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

/* ===== Side Panel ===== */
.side-panel {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100vw;
  height: 100vh;
  background: var(--surface);
  z-index: 101;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}
.side-panel.show {
  transform: translateX(0);
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  width: 100%;
}
.panel-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.panel-close {
  border: none;
  background: none;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.panel-close:hover { color: var(--text); }
.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  width: 100%;
}

/* Stats panel content */
.stats-today {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}
.stats-today-card {
  flex: 1;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.stats-today-card .label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.stats-today-card .value {
  font-size: 26px;
  font-weight: 700;
  color: var(--primary);
}
.stats-today-card .unit {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.stats-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.stats-streak {
  font-size: 12px;
  color: var(--success);
  font-weight: 500;
}

.stats-week {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
}
.stats-day {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 4px;
  text-align: center;
  background: var(--surface);
  transition: all 0.2s;
}
.stats-day.done {
  background: var(--primary-light);
  border-color: #c7d2fe;
}
.stats-day.today {
  background: var(--primary);
  border-color: var(--primary-dark);
}
.stats-day.today .stats-day-name { color: #e0e7ff; }
.stats-day.today .stats-day-time { color: white; }
.stats-day-name {
  font-size: 10px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 2px;
}
.stats-day-time {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
}
.stats-day-time.muted {
  color: var(--text-light);
  font-weight: 400;
}

.stats-week-summary {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}
.stats-week-card {
  flex: 1;
  background: var(--bg);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}
.stats-week-card .label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.stats-week-card .value {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.stats-history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: #f0fdf4;
  margin-bottom: 6px;
  font-size: 12px;
  color: #166534;
}
.stats-history-item .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

/* ===== Calendar (Stats Panel) ===== */
.cal-section { margin-bottom: 8px; }
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.cal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.cal-nav {
  border: 1px solid var(--border);
  background: var(--surface);
  width: 34px; height: 34px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  color: var(--text-muted);
  transition: all 0.2s;
}
.cal-nav:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  margin-bottom: 6px;
}
.cal-weekdays span {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}
.cal-cell {
  min-height: 92px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.cal-cell.empty {
  border: none;
  background: transparent;
  box-shadow: none;
}
.cal-cell.have-data {
  cursor: pointer;
}
.cal-cell.have-data:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(99,102,241,0.15);
}
.cal-cell.future {
  background: #fafafa;
  color: var(--text-light);
}
.cal-cell.today {
  border: 2px solid var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.cal-day-num {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.cal-day-min {
  font-size: 11px;
  color: var(--text-muted);
}
.cal-day-dlg {
  font-size: 11px;
  color: var(--text-light);
}
.cal-day-min.muted {
  color: var(--text-light);
}
/* Intensity levels with gradient backgrounds */
.cal-cell.lv1 { background: linear-gradient(135deg, #eef2ff, #e0e7ff); border-color: #c7d2fe; }
.cal-cell.lv2 { background: linear-gradient(135deg, #e0e7ff, #c7d2fe); border-color: #a5b4fc; }
.cal-cell.lv3 { background: linear-gradient(135deg, #c7d2fe, #a5b4fc); border-color: #818cf8; }
.cal-cell.lv4 { background: linear-gradient(135deg, #a5b4fc, #818cf8); border-color: #6366f1; }
.cal-cell.lv4 .cal-day-num,
.cal-cell.lv4 .cal-day-min,
.cal-cell.lv4 .cal-day-dlg { color: #312e81; }
/* Weekend day numbers in warm tone */
.cal-cell:nth-child(7n+1) .cal-day-num,
.cal-cell:nth-child(7n) .cal-day-num { color: #f43f5e; }
.cal-cell.lv3 .cal-day-num, .cal-cell.lv4 .cal-day-num { color: inherit; }

/* Stats summary bar */
.stats-summary-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, #f0f4ff, #e0e7ff);
  border-radius: 12px;
  padding: 14px 20px;
  margin-bottom: 20px;
}
.stats-summary-streak {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #166534;
}
.stats-summary-streak .badge {
  background: var(--success);
  color: white;
  font-size: 18px;
  font-weight: 700;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stats-summary-today {
  display: flex;
  gap: 20px;
  font-size: 13px;
  color: var(--text-muted);
}
.stats-summary-today .v {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  margin-right: 3px;
}

/* Day detail block */
.day-detail {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 12px;
}
.day-detail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}
.day-detail-close {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  cursor: pointer;
}
.day-detail-close:hover { color: var(--primary); }
.day-detail-stats {
  display: flex;
  gap: 28px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.day-detail-stats .v {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  margin-right: 3px;
}
.day-detail-title {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.day-detail-fav {
  font-size: 12px;
  background: var(--practice-bg);
  border: 1px solid var(--practice-border);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 6px;
  color: #166534;
}

/* Duration chart */
.stats-chart-wrap {
  margin-top: 8px;
}
.stats-chart-wrap canvas {
  width: 100%;
  height: 220px;
  display: block;
}

/* Favorite button on messages */
.fav-btn {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 4px;
}
.fav-btn:hover {
  border-color: var(--warning);
  color: var(--warning);
}
.fav-btn.favorited {
  border-color: var(--warning);
  color: var(--warning);
  background: #fffbeb;
}

/* Favorite card */
.fav-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  background: var(--surface);
  position: relative;
  overflow: hidden;
}
.fav-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
}
.fav-card.scene-life::before { background: var(--success); }
.fav-card.scene-campus::before { background: var(--warning); }
.fav-card.scene-interview::before { background: var(--danger); }
.fav-card-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.fav-card-english {
  background: var(--practice-bg);
  border: 1px solid var(--practice-border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: #166534;
  margin-bottom: 6px;
}
.fav-card-correction {
  background: var(--correction-bg);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  margin-bottom: 6px;
}
.fav-card-correction .orig { color: var(--correction-old); text-decoration: line-through; }
.fav-card-correction .fix { color: var(--correction-new); font-weight: 500; }
.fav-card-user {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.fav-card-reply {
  font-size: 11px;
  color: var(--text-light);
  margin-bottom: 8px;
}
.fav-card-actions {
  display: flex;
  gap: 8px;
}
.fav-card-actions button {
  font-size: 11px;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
}
.fav-card-actions button:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.fav-card-actions .remove:hover {
  border-color: var(--danger);
  color: var(--danger);
}
.fav-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
  font-size: 14px;
}

/* Favorites grid layout */
#favBody {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  align-content: start;
}
.fav-card {
  margin-bottom: 0;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.fav-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(99,102,241,0.18);
  border-color: var(--primary);
}
.fav-empty {
  grid-column: 1 / -1;
}

/* ===== AI section header with inline speak button ===== */
.ai-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.inline-speak-btn {
  background: rgba(99,102,241,0.08);
  border: 1px solid rgba(99,102,241,0.2);
  color: var(--primary);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  padding: 0;
  flex-shrink: 0;
}
.inline-speak-btn:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.inline-speak-btn.speaking {
  background: var(--primary);
  color: white;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.08); }
}

/* ===== Day Detail Modal ===== */
.day-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}
.day-modal.show {
  display: flex;
  animation: modalFadeIn 0.2s ease;
}
.day-modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
}
.day-modal-content {
  position: relative;
  background: var(--surface);
  border-radius: 16px;
  max-width: 520px;
  width: calc(100vw - 40px);
  max-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  animation: modalSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.day-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  z-index: 1;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.day-modal-close:hover {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}
.day-modal-body {
  padding: 24px 24px 20px;
  overflow-y: auto;
  flex: 1;
}

/* Day modal - header */
.day-modal-header {
  text-align: center;
  margin-bottom: 20px;
}
.day-modal-date {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}
.day-modal-weekday {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Day modal - time rows */
.day-modal-time {
  display: flex;
  gap: 16px;
  margin-bottom: 18px;
}
.day-modal-time-item {
  flex: 1;
  background: var(--bg);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: center;
}
.day-modal-time-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.day-modal-time-val {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

/* Day modal - stats row */
.day-modal-stats {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
}
.day-modal-stat {
  flex: 1;
  text-align: center;
  background: linear-gradient(135deg, #f0f4ff, #e0e7ff);
  border-radius: 10px;
  padding: 12px 8px;
}
.day-modal-stat .v {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
}
.day-modal-stat .l {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Day modal - mood section */
.day-modal-section {
  margin-bottom: 18px;
}
.day-modal-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.day-modal-section-title .icon {
  font-size: 15px;
}

/* Emoji picker */
.emoji-picker {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.emoji-btn {
  width: 44px;
  height: 44px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 22px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.emoji-btn:hover {
  border-color: var(--primary);
  transform: scale(1.1);
}
.emoji-btn.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: scale(1.12);
}

/* Mood text input */
.mood-text-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}
.mood-text-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.mood-text-input::placeholder {
  color: var(--text-light);
}

/* Note textarea */
.note-textarea {
  width: 100%;
  min-height: 80px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  resize: vertical;
  font-family: inherit;
  line-height: 1.6;
  transition: border-color 0.2s;
}
.note-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.note-textarea::placeholder {
  color: var(--text-light);
}

/* Day modal - save button */
.day-modal-save {
  width: 100%;
  padding: 11px 0;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 4px;
}
.day-modal-save:hover {
  background: var(--primary-dark);
}
.day-modal-save:disabled {
  opacity: 0.6;
  cursor: default;
}

/* Day modal - day favorites */
.day-modal-favs {
  margin-top: 4px;
}
.day-modal-fav-title {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.day-modal-fav-item {
  font-size: 12px;
  background: var(--practice-bg);
  border: 1px solid var(--practice-border);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 4px;
  color: #166534;
}

/* Make cal-cell clickable when it has data */
.cal-cell[data-date] {
  cursor: pointer;
}
.cal-cell[data-date]:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(99,102,241,0.18);
}

/* ===== Favorite Detail Modal ===== */
.fav-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}
.fav-modal.show {
  display: flex;
  animation: modalFadeIn 0.2s ease;
}
@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.fav-modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
}
.fav-modal-content {
  position: relative;
  background: var(--surface);
  border-radius: 16px;
  max-width: 640px;
  width: calc(100vw - 40px);
  max-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  animation: modalSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.fav-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  z-index: 1;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fav-modal-close:hover {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}
.fav-modal-body {
  padding: 24px 24px 20px;
  overflow-y: auto;
  flex: 1;
}
.fav-modal-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.fav-modal-user {
  font-size: 13px;
  color: var(--text-muted);
  margin: 12px 0;
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: 8px;
  border-left: 3px solid var(--text-light);
}
.fav-modal-actions {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}
.fav-modal-remove {
  font-size: 12px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}
.fav-modal-remove:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: #fef2f2;
}

/* ===== Floating Learning Control Panel ===== */
.learning-float {
  position: fixed;
  bottom: 116px;
  right: 24px;
  z-index: 90;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1), 0 1px 4px rgba(0,0,0,0.06);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  transition: all 0.3s ease;
}

.lf-state { display: none; align-items: center; gap: 10px; }
.lf-state.show { display: flex; }

/* Idle: "开始学习" button */
.lf-start-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(99,102,241,0.3);
}
.lf-start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(99,102,241,0.4);
}
.lf-start-btn:active {
  transform: translateY(0);
}

/* Timer */
.lf-timer {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  min-width: 54px;
  text-align: center;
}
.lf-timer.paused {
  color: var(--text-muted);
  animation: timerBlink 1.5s ease-in-out infinite;
}
@keyframes timerBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Active/paused buttons */
.lf-active-btns {
  display: flex;
  gap: 6px;
}

.lf-pause-btn, .lf-resume-btn, .lf-end-btn {
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--surface);
  color: var(--text-muted);
  padding: 0;
}
.lf-pause-btn:hover, .lf-resume-btn:hover {
  border-color: var(--warning);
  color: var(--warning);
  background: #fffbeb;
}
.lf-end-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: #fef2f2;
}

/* ===== Session Modal (Start & End) ===== */
.session-modal {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: none;
  align-items: center;
  justify-content: center;
}
.session-modal.show {
  display: flex;
}
.session-modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
}
.session-modal-content {
  position: relative;
  background: var(--surface);
  border-radius: 20px;
  max-width: 480px;
  width: calc(100vw - 40px);
  max-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  animation: modalSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.session-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  z-index: 1;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.session-modal-close:hover {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

/* Start modal */
.start-modal {
  padding: 36px 28px 28px;
  text-align: center;
}
.start-modal-icon {
  font-size: 56px;
  margin-bottom: 16px;
  animation: bounceIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
@keyframes bounceIn {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}
.start-modal-msg {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  line-height: 1.5;
}
.start-modal-quote {
  font-size: 15px;
  color: var(--primary);
  font-style: italic;
  margin-bottom: 4px;
  line-height: 1.6;
}
.start-modal-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 24px;
}
.start-modal-btn {
  width: 100%;
  padding: 12px 0;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(99,102,241,0.3);
}
.start-modal-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99,102,241,0.4);
}

/* End modal */
.end-modal {
  padding: 28px 24px 20px;
  overflow-y: auto;
}
.end-modal-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  margin-bottom: 20px;
}
.end-modal-summary {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}
.end-modal-summary .sm-card {
  flex: 1;
  background: linear-gradient(135deg, #f0f4ff, #e0e7ff);
  border-radius: 12px;
  padding: 14px 10px;
  text-align: center;
}
.end-modal-summary .sm-card .v {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
}
.end-modal-summary .sm-card .l {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.end-modal-section {
  margin-bottom: 18px;
}
.end-modal .day-modal-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.end-modal .day-modal-section-title .icon {
  font-size: 15px;
}

/* ============================================================
   Mobile Responsive — max-width: 768px
   ============================================================ */
@media (max-width: 768px) {

  /* ---- overall layout ---- */
  body {
    height: 100dvh;
  }
  .app {
    grid-template-rows: auto 1fr auto;
  }

  /* ---- header (two rows) ---- */
  .header {
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 6px;
    height: auto;
  }
  .logo {
    font-size: 16px;
    flex-shrink: 0;
  }
  .header-right {
    flex: 1 1 100%;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .speed-control {
    display: none;
  }
  .scene-select {
    padding: 6px 10px;
    font-size: 13px;
    border-radius: 8px;
  }
  .btn-secondary {
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 8px;
  }

  /* ---- conversation area ---- */
  .conversation-area {
    padding: 12px 8px;
  }
  .messages {
    max-width: 100%;
    gap: 14px;
  }
  .welcome-message {
    padding: 30px 16px;
  }
  .welcome-message h2 {
    font-size: 20px;
  }
  .welcome-message p {
    font-size: 14px;
  }
  .msg {
    max-width: 92%;
  }
  .bubble {
    font-size: 14px;
    padding: 10px 14px;
  }
  .english-to-say {
    font-size: 14px;
  }
  .correction-item {
    font-size: 13px;
    padding: 6px 8px;
  }
  .ai-section-header {
    font-size: 12px;
    gap: 6px;
  }
  .inline-speak-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }
  .inline-speak-btn svg {
    width: 16px;
    height: 16px;
  }
  .reply-cn-text {
    font-size: 12px;
  }

  /* ---- bottom controls ---- */
  .controls {
    padding: 0 12px;
    gap: 12px;
  }
  .mic-button {
    width: 64px;
    height: 64px;
  }
  .mic-button svg {
    width: 28px;
    height: 28px;
  }
  .lang-btn {
    padding: 10px 14px;
    font-size: 13px;
    border-radius: 10px;
  }
  .status-text {
    font-size: 12px;
    min-width: 50px;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* ---- floating learning panel ---- */
  .learning-float {
    bottom: 88px;
    right: 12px;
    padding: 6px 10px;
    border-radius: 14px;
  }
  .lf-start-btn {
    padding: 8px 14px;
    font-size: 13px;
    border-radius: 10px;
  }
  .lf-timer {
    font-size: 16px;
    min-width: 44px;
  }
  .lf-pause-btn,
  .lf-resume-btn,
  .lf-end-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  /* ---- side panels ---- */
  .panel-header {
    padding: 12px 16px;
  }
  .panel-body {
    padding: 12px;
  }

  /* ---- stats panel ---- */
  .stats-summary-bar {
    flex-direction: column;
    gap: 10px;
  }
  .stats-summary-today {
    gap: 12px;
  }
  .stats-summary-today .stat-item .label {
    font-size: 12px;
  }
  .stats-summary-today .stat-item .value {
    font-size: 18px;
  }
  /* calendar */
  .cal-weekdays span {
    font-size: 10px;
  }
  .cal-grid {
    gap: 3px;
  }
  .cal-cell {
    min-height: 52px;
    padding: 4px 4px;
    border-radius: 8px;
  }
  .cal-day-num {
    font-size: 12px;
  }
  .cal-day-min,
  .cal-day-dlg {
    display: none;
  }
  .cal-nav {
    width: 40px;
    height: 40px;
    font-size: 13px;
  }
  .cal-nav svg {
    width: 16px;
    height: 16px;
  }
  .cal-header-right {
    font-size: 14px;
  }

  /* chart */
  .stats-chart-wrap canvas {
    height: 200px;
  }

  /* ---- favorites panel ---- */
  #favBody {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .fav-card {
    padding: 12px;
  }
  .fav-card .eng {
    font-size: 14px;
  }
  .fav-card .cn {
    font-size: 13px;
  }
  .fav-card-actions {
    flex-wrap: wrap;
    gap: 6px;
  }
  .fav-card-actions button {
    padding: 6px 12px;
    font-size: 13px;
    border-radius: 8px;
  }

  /* ---- modals — fullscreen on mobile ---- */
  .day-modal-content,
  .fav-modal-content,
  .session-modal-content {
    max-width: 100%;
    width: 100vw;
    border-radius: 0;
    max-height: 100vh;
    height: 100vh;
    overflow-y: auto;
  }
  .day-modal-body {
    padding: 16px;
  }
  .fav-modal-body {
    padding: 16px;
  }
  .end-modal {
    padding: 20px 16px 16px;
  }
  .start-modal {
    padding: 32px 20px;
  }

  /* ---- day modal ---- */
  .day-modal-stats {
    flex-wrap: wrap;
    gap: 10px;
  }
  .day-modal-stat .v {
    font-size: 22px;
  }
  .emoji-picker {
    gap: 8px;
  }
  .emoji-btn {
    width: 44px;
    height: 44px;
    font-size: 22px;
  }
  .mood-text-input {
    font-size: 14px;
    padding: 10px 14px;
  }
  .note-textarea {
    font-size: 14px;
    min-height: 80px;
  }
  .day-modal-save {
    padding: 14px 0;
    font-size: 16px;
  }

  /* ---- start modal ---- */
  .start-modal-icon {
    font-size: 48px;
  }
  .start-modal-msg {
    font-size: 18px;
  }
  .start-modal-quote {
    font-size: 14px;
  }
  .start-modal-sub {
    font-size: 12px;
  }
  .start-modal-btn {
    padding: 12px 32px;
    font-size: 15px;
  }

  /* ---- end modal ---- */
  .end-modal-title {
    font-size: 18px;
  }
  .end-modal-summary {
    gap: 8px;
  }
  .end-modal-summary .sm-card .v {
    font-size: 20px;
  }
  .end-modal-summary .sm-card .l {
    font-size: 11px;
  }
  .end-modal .day-modal-section-title {
    font-size: 12px;
  }

  /* ---- fav modal ---- */
  .fav-modal-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
  .fav-modal-actions button {
    font-size: 13px;
    padding: 6px 12px;
  }
  .fav-modal-corr .correction-item {
    font-size: 13px;
  }

  /* ---- buttons in panels ---- */
  .action-btn,
  .fav-btn {
    padding: 8px 12px;
    font-size: 13px;
  }

  /* ---- misc ---- */
  .panel-close {
    padding: 6px 10px;
    font-size: 13px;
  }
  .day-detail-fav {
    font-size: 13px;
    padding: 8px 10px;
  }

  /* header "new chat" button abbreviation */
  .btn-secondary[title="新对话"] {
    font-size: 12px;
    padding: 6px 8px;
  }
}
