/* VTranslate - Mobile-first styles */

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --bg: #0f0f0f;
  --bg-card: #1a1a1a;
  --bg-elevated: #252525;
  --text: #ffffff;
  --text-muted: #a1a1aa;
  --border: #2a2a2a;
  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;

  --radius: 12px;
  --radius-lg: 16px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

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

.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;
}

.settings-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 0.2s, color 0.2s;
}

.settings-btn:hover {
  background: var(--bg-elevated);
  color: var(--text);
}

/* Language Bar */
.language-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 20px;
  background: var(--bg-card);
}

.lang-select {
  flex: 1;
  min-width: 0;
  padding: 12px 36px 12px 12px;
  font-size: 15px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.swap-btn {
  flex-shrink: 0;
  width: 44px;
  min-width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  transition: transform 0.3s, background 0.2s;
}

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

.swap-btn:active {
  transform: rotate(180deg);
}

/* Main Content */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Input Row */
.input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.input-row .text-box {
  flex: 1;
}

.text-box.editable {
  cursor: text;
  outline: none;
}

.text-box.editable:focus {
  border-color: var(--primary);
}

.text-box.editable:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  font-style: italic;
}

.send-btn {
  width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  border: none;
  border-radius: var(--radius);
  color: white;
  cursor: pointer;
  transition: background 0.2s;
  align-self: flex-end;
}

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

.send-btn:disabled {
  background: var(--border);
  cursor: not-allowed;
}

/* Status */
.status {
  text-align: center;
  padding: 12px;
}

.status-text {
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.status.listening .status-text {
  color: var(--success);
}

.status.processing .status-text {
  color: var(--warning);
}

.status.speaking .status-text {
  color: var(--primary);
}

.status.error .status-text {
  color: var(--error);
}

/* Text Sections */
.text-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.text-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 60px;
  font-size: 16px;
  line-height: 1.5;
}

.text-box .placeholder {
  color: var(--text-muted);
  font-style: italic;
}

.text-box.translation {
  background: var(--bg-elevated);
  border-color: var(--primary);
  font-size: 18px;
  font-weight: 500;
}

.text-box.pronunciation {
  font-size: 16px;
  font-weight: 400;
  color: var(--text);
}

/* Record Button */
.record-container {
  display: flex;
  justify-content: center;
  padding: 24px 20px;
  padding-bottom: calc(24px + var(--safe-bottom));
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}

.record-btn {
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}

.record-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 24px rgba(99, 102, 241, 0.5);
}

.record-btn:active {
  transform: scale(0.95);
}

.record-btn.listening {
  background: var(--error);
  animation: pulse 1.5s infinite;
  box-shadow: 0 4px 20px rgba(239, 68, 68, 0.4);
}

.record-btn.listening .mic-icon {
  display: none;
}

.record-btn.listening .stop-icon {
  display: block;
}

.record-btn.processing {
  background: var(--warning);
  animation: none;
}

.hidden {
  display: none !important;
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5);
  }
  50% {
    box-shadow: 0 0 0 16px rgba(239, 68, 68, 0);
  }
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

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

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

.close-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius);
}

.close-btn:hover {
  background: var(--bg-elevated);
  color: var(--text);
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.input-with-toggle {
  position: relative;
  display: flex;
}

.form-group input {
  flex: 1;
  padding: 14px 16px;
  padding-right: 48px;
  font-size: 16px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
}

.toggle-visibility {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
}

.toggle-visibility:hover {
  color: var(--text);
}

.tone-select {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.tone-select:focus {
  outline: none;
  border-color: var(--primary);
}

.custom-prompt {
  width: 100%;
  padding: 14px 16px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
  min-height: 80px;
}

.custom-prompt:focus {
  outline: none;
  border-color: var(--primary);
}

.custom-prompt::placeholder {
  color: var(--text-muted);
}

.help-link {
  font-size: 13px;
  color: var(--primary);
  text-decoration: none;
}

.help-link:hover {
  text-decoration: underline;
}

.save-btn {
  padding: 16px;
  font-size: 16px;
  font-weight: 600;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s;
}

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

/* Toast */
.toast {
  position: fixed;
  bottom: calc(120px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  z-index: 50;
  animation: slideUp 0.3s ease;
}

.toast.error {
  background: var(--error);
}

.toast.success {
  background: var(--success);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Examples Section */
.examples-section {
  margin-top: 8px;
}

.examples-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.example-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: border-color 0.2s;
}

.example-item:hover {
  border-color: var(--primary);
}

.example-target {
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
  line-height: 1.4;
}

.example-pronunciation {
  font-size: 15px;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 2px;
}

.example-source {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.4;
}

.examples-loading {
  text-align: center;
  padding: 16px;
  color: var(--text-muted);
  font-size: 14px;
}

/* Mode Tabs */
.mode-tabs {
  display: flex;
  gap: 0;
  padding: 0 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.mode-tab {
  flex: 1;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.mode-tab:hover {
  color: var(--text);
}

.mode-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Practice Mode */
.practice-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.topic-select {
  width: 100%;
  padding: 12px 16px;
  font-size: 15px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.topic-select:focus {
  outline: none;
  border-color: var(--primary);
}

/* Chat Thread */
.chat-thread {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 16px;
}

.chat-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-muted);
  text-align: center;
  font-size: 14px;
}

/* Chat Bubbles */
.chat-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius);
  animation: fadeIn 0.3s ease;
}

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

.chat-bubble.ai {
  align-self: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
}

.bubble-target {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 4px;
}

.bubble-pronunciation {
  font-size: 14px;
  line-height: 1.4;
  margin-bottom: 4px;
  opacity: 0.9;
}

.chat-bubble.ai .bubble-pronunciation {
  color: var(--text);
}

.chat-bubble.user .bubble-pronunciation {
  color: rgba(255, 255, 255, 0.9);
}

.bubble-translation {
  font-size: 13px;
  line-height: 1.4;
  opacity: 0.7;
}

.chat-bubble.ai .bubble-translation {
  color: var(--text-muted);
}

.chat-bubble.user .bubble-translation {
  color: rgba(255, 255, 255, 0.7);
}

.chat-bubble.loading {
  color: var(--text-muted);
  font-style: italic;
}

/* New Conversation Button */
.new-conversation-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  font-size: 15px;
  font-weight: 500;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.new-conversation-btn:hover {
  background: var(--bg-elevated);
  border-color: var(--primary);
}

.new-conversation-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Responsive */
@media (min-width: 640px) {
  .main {
    max-width: 600px;
    margin: 0 auto;
  }

  .text-box {
    min-height: 80px;
  }
}
