:root {
  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-dark: #4f46e5;
  --primary-bg: rgba(99, 102, 241, 0.08);
  --accent: #f43f5e;
  --accent-light: #fb7185;
  --success: #10b981;
  --warning: #f59e0b;
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-tertiary: #94a3b8;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-full: 9999px;
  --header-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.app-container {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
}

/* ====== Header ====== */
.app-header {
  background: var(--header-gradient);
  padding: 40px 24px 28px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.app-header::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 60%);
  animation: headerShine 8s linear infinite;
}

@keyframes headerShine {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.app-title {
  font-size: 32px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 4px;
  position: relative;
}

.app-tagline {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.8);
  margin-top: 4px;
  position: relative;
}

/* ====== Main Content ====== */
.main-content {
  padding: 20px 16px 100px;
}

/* ====== Mode Switch ====== */
.mode-switch {
  display: flex;
  background: var(--card);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.mode-btn {
  flex: 1;
  padding: 10px 16px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.mode-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.mode-btn:not(.active):hover {
  color: var(--primary);
  background: var(--primary-bg);
}

/* ====== Cards ====== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s;
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* ====== Textarea ====== */
.textarea-wrapper {
  position: relative;
}

.textarea-wrapper textarea {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 48px 12px 12px;
  font-size: 15px;
  line-height: 1.6;
  resize: vertical;
  font-family: inherit;
  color: var(--text);
  background: #fafbfc;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 100px;
}

.textarea-wrapper textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-bg);
  background: #fff;
}

.textarea-wrapper textarea::placeholder {
  color: var(--text-tertiary);
}

.voice-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--primary-bg);
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.voice-btn:hover {
  background: var(--primary);
  color: #fff;
  transform: scale(1.1);
}

.voice-btn.recording {
  background: var(--accent);
  color: #fff;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(244, 63, 94, 0); }
}

.voice-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--accent);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 1s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ====== Chips ====== */
.chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--border);
  background: #fafbfc;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  white-space: nowrap;
}

.chip:hover {
  border-color: var(--primary-light);
  color: var(--primary);
  background: var(--primary-bg);
}

.chip.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

.chip.custom {
  border-style: dashed;
}

.chip .remove-custom {
  margin-left: 4px;
  font-size: 12px;
  opacity: 0.6;
  cursor: pointer;
}

.chip .remove-custom:hover {
  opacity: 1;
}

/* ====== Text Button ====== */
.text-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.2s;
}

.text-btn:hover {
  background: var(--primary-bg);
}

.text-btn.danger {
  color: var(--accent);
}

.text-btn.danger:hover {
  background: rgba(244, 63, 94, 0.08);
}

/* ====== Action Button ====== */
.action-btn {
  width: 100%;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius);
  background: var(--header-gradient);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  margin: 8px 0 20px;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.35);
  letter-spacing: 1px;
}

.action-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.45);
}

.action-btn:active:not(:disabled) {
  transform: translateY(0);
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ====== Loading ====== */
.loading-area {
  margin: 16px 0;
}

.loading-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.loading-card p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 16px;
}

.typing-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.typing-indicator span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary-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% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-8px); opacity: 1; }
}

/* ====== Results ====== */
.results-area {
  margin-top: 8px;
}

.results-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.result-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  border-left: 3px solid var(--primary);
  animation: fadeInUp 0.4s ease forwards;
  opacity: 0;
}

.result-card:nth-child(2) { animation-delay: 0.1s; }
.result-card:nth-child(3) { animation-delay: 0.2s; }
.result-card:nth-child(4) { animation-delay: 0.3s; }

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-style {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-bg);
  padding: 2px 10px;
  border-radius: var(--radius-full);
  margin-bottom: 10px;
}

.result-text {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 10px;
  word-break: break-word;
}

.result-tip {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 10px;
  padding-left: 8px;
  border-left: 2px solid var(--border);
}

.result-actions {
  display: flex;
  justify-content: flex-end;
}

.copy-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.copy-btn:hover {
  border-color: var(--success);
  color: var(--success);
  background: rgba(16, 185, 129, 0.05);
}

.copy-btn.copied {
  border-color: var(--success);
  color: #fff;
  background: var(--success);
}

/* Analyze results */
.analyze-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  animation: fadeInUp 0.4s ease forwards;
  opacity: 0;
}

.analyze-section {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.analyze-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.analyze-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 6px;
}

.analyze-content {
  font-size: 14px;
  color: var(--text);
  line-height: 1.7;
}

.suggestion-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: #fafbfc;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--text);
}

.suggestion-item:last-child {
  margin-bottom: 0;
}

.suggestion-copy {
  flex-shrink: 0;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.suggestion-copy:hover {
  border-color: var(--success);
  color: var(--success);
}

/* ====== History Toggle ====== */
.history-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--header-gradient);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
  z-index: 100;
}

.history-toggle:hover {
  transform: scale(1.1);
}

/* ====== History Panel ====== */
.history-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
}

.panel-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.panel-content {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 85%;
  max-width: 400px;
  background: var(--bg);
  animation: slideIn 0.3s ease;
  display: flex;
  flex-direction: column;
}

@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.panel-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.close-btn:hover {
  background: var(--border);
  color: var(--text);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-tertiary);
}

.history-item {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.history-item:hover {
  box-shadow: var(--shadow-md);
}

.history-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.history-role {
  font-size: 12px;
  color: var(--primary);
  background: var(--primary-bg);
  padding: 1px 8px;
  border-radius: var(--radius-full);
  font-weight: 500;
}

.history-time {
  font-size: 11px;
  color: var(--text-tertiary);
}

.history-input {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-delete {
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  transition: color 0.2s;
}

.history-delete:hover {
  color: var(--accent);
}

/* ====== Modal ====== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s ease;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-content h3 {
  font-size: 18px;
  margin-bottom: 20px;
  text-align: center;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-bg);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.btn-primary,
.btn-secondary {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--bg);
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

/* ====== Toast ====== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 10px 24px;
  border-radius: var(--radius-full);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 400;
  opacity: 0;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ====== Utilities ====== */
.hidden {
  display: none !important;
}

/* ====== Responsive ====== */
@media (min-width: 481px) {
  body {
    background: #e8eaf0;
  }

  .app-container {
    box-shadow: var(--shadow-lg);
    background: var(--bg);
  }

  .history-toggle {
    right: calc(50% - 240px + 24px);
  }
}

@media (max-width: 360px) {
  .app-header {
    padding: 30px 16px 22px;
  }

  .app-title {
    font-size: 26px;
  }

  .main-content {
    padding: 16px 12px 80px;
  }

  .chip {
    font-size: 12px;
    padding: 5px 10px;
  }
}

/* ====== Scrollbar ====== */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ====== Error Card ====== */
.error-card {
  background: #fef2f2;
  border-radius: var(--radius);
  padding: 16px;
  border-left: 3px solid var(--accent);
  animation: fadeInUp 0.4s ease forwards;
}

.error-card p {
  color: var(--accent);
  font-size: 14px;
}

.error-card .retry-btn {
  margin-top: 10px;
  padding: 6px 16px;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.error-card .retry-btn:hover {
  background: var(--accent);
  color: #fff;
}
