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

:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --secondary: #10b981;
  --danger: #ef4444;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1f2937;
  --text-light: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --radius: 12px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--card);
  box-shadow: 0 0 20px rgba(0,0,0,0.05);
}

.header {
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.header h1 {
  font-size: 18px;
  font-weight: 600;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-light);
}

.indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--secondary);
  transition: background 0.3s;
}

.indicator.recording {
  background: var(--danger);
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  70% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.main {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.welcome {
  text-align: center;
  color: var(--text-light);
  margin-top: 40px;
  line-height: 1.8;
}

.message {
  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); }
}

.message.teacher {
  align-self: flex-start;
}

.message.me {
  align-self: flex-end;
  align-items: flex-end;
}

.bubble {
  padding: 12px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: relative;
}

.message.teacher .bubble {
  background: #eff6ff;
  border-bottom-left-radius: 4px;
}

.message.me .bubble {
  background: #ecfdf5;
  border-bottom-right-radius: 4px;
}

.original {
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 6px;
  word-break: break-word;
}

.translation {
  font-size: 14px;
  color: var(--text-light);
  line-height: 1.5;
  padding-top: 6px;
  border-top: 1px dashed rgba(0,0,0,0.08);
}

.translation .lang-tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.1);
  color: var(--primary-dark);
  margin-right: 6px;
  margin-bottom: 4px;
}

.message-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--bg);
  color: var(--text-light);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: var(--border);
  color: var(--text);
}

.meta {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 4px;
}

.controls {
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 12px 16px 16px;
  flex-shrink: 0;
}

.language-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
}

.lang-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.lang-group label {
  font-size: 11px;
  color: var(--text-light);
  text-align: center;
}

.lang-group select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  font-size: 14px;
  min-width: 90px;
}

.lang-arrow {
  font-size: 18px;
  color: var(--text-light);
  padding-bottom: 6px;
}

.action-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.btn {
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn.primary {
  background: var(--primary);
  color: white;
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.secondary:hover {
  background: var(--border);
}

.mic-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35);
  transition: all 0.2s;
}

.mic-btn:hover {
  transform: scale(1.05);
}

.mic-btn.recording {
  background: var(--danger);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.35);
  animation: pulse 1.2s infinite;
}

.mic-icon {
  font-size: 28px;
}

.hint {
  text-align: center;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-light);
}

.summary-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  max-width: 420px;
  height: 100%;
  background: var(--card);
  box-shadow: -4px 0 20px rgba(0,0,0,0.1);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.summary-panel.hidden {
  transform: translateX(100%);
}

.summary-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.summary-header h2 {
  font-size: 18px;
}

.summary-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  line-height: 1.7;
}

.summary-content h3 {
  font-size: 15px;
  margin: 16px 0 8px;
  color: var(--primary-dark);
}

.summary-content h3:first-child {
  margin-top: 0;
}

.summary-content ul {
  padding-left: 18px;
  margin-bottom: 12px;
}

.summary-content li {
  margin-bottom: 6px;
}

.summary-content .term {
  font-weight: 600;
  color: var(--text);
}

.summary-content .meaning {
  color: var(--text-light);
}

.summary-actions {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
}

.summary-actions .btn {
  flex: 1;
}

.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(31, 41, 55, 0.9);
  color: white;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  z-index: 200;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 480px) {
  .header h1 {
    font-size: 16px;
  }

  .message {
    max-width: 92%;
  }

  .bubble {
    padding: 10px 12px;
  }

  .mic-btn {
    width: 58px;
    height: 58px;
  }

  .mic-icon {
    font-size: 24px;
  }

  .btn {
    padding: 9px 14px;
    font-size: 13px;
  }
}

@media (min-width: 721px) {
  .app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
