/**
 * @description 作文专项 - AI互动写作教练 样式文件
 * @design 温暖橙色调，教育类产品，亲切友好
 */

/* ===== CSS Variables ===== */
:root {
  --primary: #FF8C42;
  --primary-light: #FFF0E0;
  --primary-dark: #E67329;
  --secondary: #FFD166;
  --success: #06D6A0;
  --success-light: #E6FAF5;
  --danger: #EF476F;
  --bg: #FFFBF5;
  --bg-white: #FFFFFF;
  --text-main: #3D2C29;
  --text-sub: #6B5E5B;
  --text-light: #9A8C89;
  --border: #F0E6DE;
  --ai-bubble: #FFF5E6;
  --user-bubble: #FF8C42;
  --user-bubble-text: #FFFFFF;
  --shadow-sm: 0 1px 3px rgba(61,44,41,0.06);
  --shadow-md: 0 4px 12px rgba(61,44,41,0.08);
  --shadow-lg: 0 8px 24px rgba(61,44,41,0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

/* ===== Reset & Base ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-main);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ===== Markdown Styles ===== */
.markdown h1 { font-size: 1.4em; margin: 0.8em 0 0.4em; color: var(--primary-dark); }
.markdown h2 { font-size: 1.2em; margin: 0.8em 0 0.4em; color: var(--primary-dark); }
.markdown h3 { font-size: 1.05em; margin: 0.6em 0 0.3em; }
.markdown p { margin: 0.5em 0; }
.markdown ul, .markdown ol { padding-left: 1.5em; margin: 0.5em 0; }
.markdown li { margin: 0.2em 0; }
.markdown strong { color: var(--primary-dark); font-weight: 600; }
.markdown em { color: var(--primary); font-style: normal; background: linear-gradient(transparent 60%, rgba(255,209,102,0.4) 60%); padding: 0 2px; }
.markdown blockquote { border-left: 3px solid var(--primary); padding-left: 12px; margin: 0.5em 0; color: var(--text-sub); background: var(--primary-light); padding: 8px 12px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.markdown code { background: #F5F0EB; padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
.markdown table { width: 100%; border-collapse: collapse; margin: 0.5em 0; font-size: 0.9em; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.markdown th { background: var(--primary-light); font-weight: 600; }
.markdown hr { border: none; border-top: 1px dashed var(--border); margin: 1em 0; }

/* ===== App Layout ===== */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 900px;
  margin: 0 auto;
  background: var(--bg-white);
  position: relative;
}

/* ===== Top Header ===== */
.app-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
  z-index: 10;
}
.app-header .back-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-sub);
  transition: background 0.2s;
  border: none;
  background: transparent;
  font-size: 20px;
}
.app-header .back-btn:hover { background: var(--primary-light); }
.app-header .header-info { flex: 1; min-width: 0; }
.app-header .header-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-header .header-subtitle {
  font-size: 12px;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-header .phase-badge {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 500;
  white-space: nowrap;
}

/* ===== Diagnosis Profile Bar (top, after diagnosis) ===== */
.profile-bar {
  display: none;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--primary-light) 0%, #FFF8F0 100%);
  border-bottom: 1px solid var(--border);
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.profile-bar.visible { display: flex; }
.profile-tag {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 12px;
  background: var(--bg-white);
  color: var(--text-sub);
  border: 1px solid var(--border);
}
.profile-tag.stage { background: var(--primary); color: white; border-color: var(--primary); }
.profile-tag.strength { background: var(--success-light); color: #059669; border-color: #A7F3D0; }
.profile-tag.blockage { background: #FEF2F2; color: #DC2626; border-color: #FECACA; }

/* ===== Chat Area ===== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
.chat-area::-webkit-scrollbar { width: 4px; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Welcome Screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 70%;
  text-align: center;
  padding: 20px;
}
.welcome-icon {
  width: 80px; height: 80px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  border-radius: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-md);
}
.welcome-title {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 8px;
}
.welcome-desc {
  font-size: 14px;
  color: var(--text-sub);
  margin-bottom: 28px;
  max-width: 320px;
}
.grade-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 360px;
  margin-bottom: 24px;
}
.grade-btn {
  padding: 8px 16px;
  border-radius: 20px;
  border: 2px solid var(--border);
  background: var(--bg-white);
  color: var(--text-sub);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}
.grade-btn:hover { border-color: var(--primary); color: var(--primary); }
.grade-btn.selected {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}
.nickname-input {
  width: 240px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 2px solid var(--border);
  font-size: 15px;
  text-align: center;
  margin-bottom: 20px;
  outline: none;
  transition: border-color 0.2s;
}
.nickname-input:focus { border-color: var(--primary); }
.start-btn {
  padding: 12px 40px;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  font-size: 16px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform 0.2s, box-shadow 0.2s;
}
.start-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.start-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Topic Selection Screen */
.topic-screen { padding: 20px; }
.topic-screen h3 {
  font-size: 18px; font-weight: 700; margin-bottom: 8px; text-align: center;
}
.topic-screen .topic-hint {
  font-size: 13px; color: var(--text-sub); text-align: center; margin-bottom: 20px;
}
.topic-list { display: flex; flex-direction: column; gap: 12px; max-width: 400px; margin: 0 auto; }
.topic-card {
  padding: 16px;
  border-radius: var(--radius-md);
  border: 2px solid var(--border);
  background: var(--bg-white);
  cursor: pointer;
  transition: all 0.2s;
}
.topic-card:hover { border-color: var(--primary); background: var(--primary-light); }
.topic-card .topic-title { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.topic-card .topic-meta { font-size: 12px; color: var(--text-light); display: flex; gap: 8px; }
.topic-card .topic-type { background: var(--secondary); color: var(--text-main); padding: 1px 8px; border-radius: 8px; font-weight: 500; }
.topic-custom {
  margin-top: 16px;
  text-align: center;
}
.topic-custom input {
  width: 100%;
  max-width: 400px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 2px solid var(--border);
  font-size: 14px;
  outline: none;
  margin-bottom: 8px;
}
.topic-custom input:focus { border-color: var(--primary); }

/* Chat Messages */
.message {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  animation: messageIn 0.3s ease;
}
@keyframes messageIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.message.user { flex-direction: row-reverse; }
.message-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.message.ai .message-avatar {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
}
.message.user .message-avatar {
  background: var(--primary);
  color: white;
  font-size: 14px;
  font-weight: 600;
}
.message-bubble {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  line-height: 1.7;
  word-wrap: break-word;
}
.message.ai .message-bubble {
  background: var(--ai-bubble);
  color: var(--text-main);
  border-top-left-radius: 4px;
}
.message.user .message-bubble {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-top-right-radius: 4px;
}
.message.user .message-bubble .markdown { color: white; }
.message.user .message-bubble .markdown strong,
.message.user .message-bubble .markdown h1,
.message.user .message-bubble .markdown h2,
.message.user .message-bubble .markdown h3 { color: white; }
.message.user .message-bubble .markdown blockquote {
  background: rgba(255,255,255,0.15);
  border-left-color: rgba(255,255,255,0.4);
  color: rgba(255,255,255,0.9);
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}
.typing-indicator span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--primary);
  opacity: 0.4;
  animation: typingBounce 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Gold Sentence Cards (displayed during coaching) */
.gold-sentence {
  background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
  border-left: 4px solid var(--secondary);
  padding: 8px 12px;
  margin: 8px 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
  color: #92400E;
}

/* Outline/Essay Output Card */
.output-card {
  background: var(--bg-white);
  border: 2px solid var(--primary);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin: 12px 0;
  box-shadow: var(--shadow-md);
}
.output-card .output-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== Plan Page ===== */
.plan-page { display: none; padding: 16px; overflow-y: auto; flex: 1; }
.plan-page.active { display: block; }

.progress-overview {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  border-radius: var(--radius-lg);
  padding: 20px;
  color: white;
  margin-bottom: 20px;
}
.progress-overview .progress-label { font-size: 13px; opacity: 0.9; margin-bottom: 8px; }
.progress-overview .progress-text { font-size: 28px; font-weight: 800; margin-bottom: 12px; }
.progress-bar-bg {
  height: 8px;
  background: rgba(255,255,255,0.3);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: white;
  border-radius: 4px;
  transition: width 0.5s ease;
}

.current-week-card {
  background: var(--bg-white);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.current-week-card .week-label { font-size: 12px; color: var(--primary); font-weight: 600; margin-bottom: 4px; }
.current-week-card .week-topic { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.current-week-card .week-tip { font-size: 13px; color: var(--text-sub); margin-bottom: 12px; }
.current-week-card .week-skill { font-size: 12px; color: var(--text-light); }
.start-writing-btn {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: white;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 12px;
  transition: background 0.2s;
}
.start-writing-btn:hover { background: var(--primary-dark); }

.week-list { margin-top: 16px; }
.week-list-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; }
.week-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  gap: 12px;
}
.week-item.completed { border-color: var(--success); background: var(--success-light); }
.week-item.current { border-color: var(--primary); background: var(--primary-light); }
.week-num {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-sub);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.week-item.completed .week-num { background: var(--success); color: white; }
.week-item.current .week-num { background: var(--primary); color: white; }
.week-info { flex: 1; min-width: 0; }
.week-info .w-topic { font-weight: 600; font-size: 14px; }
.week-info .w-meta { font-size: 12px; color: var(--text-light); margin-top: 2px; }
.week-status {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 10px;
}
.week-status.done { background: var(--success); color: white; }
.week-status.current { background: var(--primary); color: white; }
.week-status.locked { background: var(--border); color: var(--text-light); }

/* ===== Growth / Charts Page ===== */
.growth-page { display: none; padding: 16px; overflow-y: auto; flex: 1; }
.growth-page.active { display: block; }
.growth-page .page-title { font-size: 20px; font-weight: 800; margin-bottom: 16px; text-align: center; }
.chart-card {
  background: var(--bg-white);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.chart-card .chart-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--text-sub); }
.chart-placeholder {
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  color: var(--text-light);
  font-size: 13px;
  background: #FAFAF8;
  border-radius: var(--radius-sm);
}
/* Simple CSS bar chart */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding: 0 4px; }
.bar-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bar-fill {
  width: 100%;
  min-height: 4px;
  background: linear-gradient(to top, var(--primary), var(--secondary));
  border-radius: 4px 4px 0 0;
  transition: height 0.5s ease;
  position: relative;
}
.bar-label { font-size: 10px; color: var(--text-light); }
.bar-value { font-size: 10px; color: var(--text-sub); font-weight: 600; }

/* Radar chart simulation */
.radar-container {
  display: flex;
  justify-content: center;
  padding: 10px 0;
}

/* Gold sentences wall */
.gold-wall {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.gold-wall .gold-chip {
  padding: 6px 12px;
  background: linear-gradient(135deg, #FEF3C7, #FDE68A);
  border-radius: 16px;
  font-size: 13px;
  color: #92400E;
  border: 1px solid #FCD34D;
}

/* ===== Input Area ===== */
.input-area {
  padding: 12px 16px;
  background: var(--bg-white);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.input-area textarea {
  flex: 1;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  min-height: 42px;
  line-height: 1.5;
  transition: border-color 0.2s;
  background: var(--bg);
}
.input-area textarea:focus { border-color: var(--primary); }
.input-area textarea:disabled { opacity: 0.6; }
.voice-btn, .send-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  transition: all 0.2s;
}
.voice-btn {
  background: var(--bg);
  color: var(--text-sub);
  border: 2px solid var(--border);
}
.voice-btn:hover { border-color: var(--primary); color: var(--primary); }
.send-btn {
  background: var(--primary);
  color: white;
}
.send-btn:hover { background: var(--primary-dark); transform: scale(1.05); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ===== Bottom Tab Bar ===== */
.bottom-tabs {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg-white);
  flex-shrink: 0;
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  cursor: pointer;
  color: var(--text-light);
  font-size: 11px;
  gap: 2px;
  transition: color 0.2s;
  border: none;
  background: transparent;
}
.tab-item.active { color: var(--primary); }
.tab-item svg { width: 22px; height: 22px; }
.tab-item.hidden { display: none; }

/* ===== Essay Submit Form ===== */
.essay-form {
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin: 12px 0;
  box-shadow: var(--shadow-md);
}
.essay-form h4 { font-size: 16px; font-weight: 700; margin-bottom: 12px; color: var(--primary-dark); }
.essay-form textarea {
  width: 100%;
  min-height: 200px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  outline: none;
  line-height: 1.8;
}
.essay-form textarea:focus { border-color: var(--primary); }
.essay-form .submit-essay-btn {
  margin-top: 12px;
  padding: 10px 24px;
  border-radius: 20px;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.essay-form .submit-essay-btn:hover { background: var(--primary-dark); }
.essay-form .submit-essay-btn:disabled { opacity: 0.5; }

/* Quick Reply Buttons (for low grades) */
.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 8px 46px;
}
.quick-reply-btn {
  padding: 6px 14px;
  border-radius: 16px;
  border: 1px solid var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.quick-reply-btn:hover { background: var(--primary); color: white; }

/* Demo mode banner */
.demo-banner {
  background: #FEF3C7;
  color: #92400E;
  text-align: center;
  padding: 6px 16px;
  font-size: 12px;
  border-bottom: 1px solid #FDE68A;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .app-header { padding: 10px 12px; }
  .chat-area { padding: 12px; }
  .message-bubble { max-width: 80%; padding: 10px 14px; font-size: 14px; }
  .welcome-title { font-size: 20px; }
  .grade-btn { padding: 6px 12px; font-size: 13px; }
}

@media (min-width: 768px) {
  .app-container { box-shadow: var(--shadow-lg); border-radius: 0; }
  body { background: #F5EFE8; }
}
