* {
  box-sizing: border-box;
}

:root {
  --bg: #faf8f5;
  --card: #fff;
  --border: #e8e4df;
  --primary: #c45c3e;
  --primary-soft: #e8a090;
  --text: #2c2825;
  --text-muted: #6b6560;
  --assistant-bg: #f5f1ed;
  --user-bg: #95ec69;
  --user-text: #1a1a1a;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --safe-top: env(safe-area-inset-top, 0);
  --safe-right: env(safe-area-inset-right, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --safe-left: env(safe-area-inset-left, 0);
}

html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  overflow: hidden;
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 24px 16px 0;
  padding-top: calc(24px + var(--safe-top));
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
  overflow: hidden;
}

.header {
  text-align: center;
  margin-bottom: 24px;
}

.header h1 {
  font-size: clamp(1.1rem, 4vw, 1.5rem);
  font-weight: 600;
  color: var(--text);
  margin: 0 0 4px;
  line-height: 1.3;
}

.subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0;
}

.progress-wrap {
  margin: 12px 0 8px;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 4px 0 0;
}

.header-actions {
  margin: 8px 0 0;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85rem;
  color: var(--primary);
  cursor: pointer;
  text-decoration: underline;
}

.link-btn:hover {
  color: #a84d32;
}

.main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0 24px;
}

.msg {
  display: flex;
  margin-bottom: 16px;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user {
  justify-content: flex-end;
}

.msg .bubble {
  max-width: 85%;
  min-width: 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
}

.msg.assistant .bubble {
  background: var(--assistant-bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.msg.assistant .bubble-question {
  font-weight: 700;
  color: var(--text);
  display: block;
  margin-top: 2px;
}

.msg.user .bubble {
  background: var(--user-bg);
  color: var(--user-text);
  border: none;
}

.msg .role {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.msg.user .role { text-align: right; }

.input-wrap {
  flex-shrink: 0;
  padding: 12px 16px 24px;
  padding-bottom: calc(24px + var(--safe-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  resize: none;
  min-height: 48px;
  max-height: 120px;
  background: var(--card);
  color: var(--text);
}

.input:focus {
  outline: none;
  border-color: var(--primary-soft);
  box-shadow: 0 0 0 2px rgba(196, 92, 62, 0.15);
}

.send {
  padding: 12px 20px;
  min-height: 48px;
  min-width: 64px;
  border: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
}

.send:hover {
  background: #a84d32;
}

.send:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
}

.send.secondary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.send.secondary:hover {
  background: rgba(196, 92, 62, 0.08);
}

.correction-notice {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0 0 12px;
  line-height: 1.5;
}

.loading {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 8px 0;
}

.error {
  color: #b33;
  font-size: 0.9rem;
  padding: 8px 0;
}

.correction-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0 0 16px;
  overflow-y: auto;
  overflow-x: hidden;
}

.correction-title {
  font-size: 1rem;
  margin: 0 0 12px;
  color: var(--text);
}

.correction-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 12px;
}

.correction-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.correction-question {
  background: rgba(44, 40, 37, 0.06);
  border-left: 4px solid var(--primary);
  padding: 10px 12px;
  border-radius: 0 8px 8px 0;
}

.correction-question-label {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 4px;
}

.correction-question .issue {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  color: #b33;
  line-height: 1.35;
}

.correction-item input,
.correction-item textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.95rem;
  font-family: inherit;
}

.done-msg {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
}

/* ---------- 响应式：手机与小屏 ---------- */
@media (max-width: 768px) {
  .wrap {
    padding-left: calc(12px + var(--safe-left));
    padding-right: calc(12px + var(--safe-right));
  }

  .header {
    margin-bottom: 16px;
  }

  .header h1 {
    padding: 0 8px;
  }

  .msg .bubble {
    max-width: 88%;
    padding: 10px 14px;
  }

  .input-wrap {
    padding: 10px 12px 20px;
    padding-bottom: calc(20px + var(--safe-bottom));
    gap: 8px;
  }

  .input {
    min-height: 44px;
    padding: 10px 12px;
  }

  .send {
    min-height: 44px;
    padding: 10px 16px;
  }

  .correction-wrap {
    padding: 12px;
    margin: 0 0 12px;
  }
}

@media (max-width: 480px) {
  .wrap {
    padding-top: calc(16px + var(--safe-top));
    padding-left: calc(10px + var(--safe-left));
    padding-right: calc(10px + var(--safe-right));
  }

  .header {
    margin-bottom: 12px;
  }

  .subtitle {
    font-size: 0.85rem;
  }

  .msg {
    margin-bottom: 12px;
  }

  .msg .bubble {
    max-width: 92%;
    padding: 10px 12px;
    border-radius: 10px;
  }

  .msg .role {
    font-size: 0.7rem;
  }

  .input-wrap {
    padding: 8px 10px 16px;
    padding-bottom: calc(16px + var(--safe-bottom));
  }

  .link-btn {
    font-size: 0.8rem;
    padding: 8px 0;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}
