:root {
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-secondary: #f1f5f9;
  --bg-hover: #e2e8f0;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  
  --accent: #0ea5e9;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;
  
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-secondary: #334155;
  --bg-hover: #475569;
  
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-light: #1e3a8a33;
  
  --border-color: #334155;
  --border-focus: #60a5fa;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  position: relative;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, color 0.3s ease;
  line-height: 1.5;
}

.app-container {
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 1.75rem;
}

.logo-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: inline-block;
  margin-right: 6px;
}

.badge-ai {
  font-size: 0.72rem;
  font-weight: 600;
  background: linear-gradient(135deg, #2563eb, #9333ea);
  color: #fff;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  vertical-align: middle;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.icon-btn:hover {
  background: var(--bg-hover);
  transform: translateY(-1px);
}

/* Language Selection Bar */
.lang-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  box-shadow: var(--shadow-sm);
  gap: 8px;
  width: 100%;
}

.lang-select-wrapper {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-surface-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: var(--transition);
}

.lang-select-wrapper:hover {
  border-color: var(--primary);
}

.lang-select-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.lang-dropdown {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  padding: 10px 28px 10px 12px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: inherit;
}

.lang-dropdown option {
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 1rem;
}

.dropdown-arrow {
  position: absolute;
  right: 10px;
  pointer-events: none;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.swap-btn {
  background: var(--primary);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.25s ease, background-color 0.2s ease;
  box-shadow: var(--shadow-md);
  flex-shrink: 0;
}

.swap-btn:hover {
  background: var(--primary-hover);
  transform: scale(1.06) rotate(180deg);
}

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

@media (max-width: 480px) {
  .app-container {
    padding: 10px;
    gap: 12px;
  }
  .lang-bar {
    padding: 6px 8px;
    gap: 6px;
  }
  .lang-dropdown {
    padding: 8px 24px 8px 8px;
    font-size: 0.88rem;
  }
  .swap-btn {
    width: 36px;
    height: 36px;
  }
  .panel-header {
    padding: 10px 12px;
  }
  .tool-btn {
    padding: 4px 8px;
    font-size: 0.78rem;
  }
}
  cursor: pointer;
  transition: transform 0.25s ease, background-color 0.2s ease;
  box-shadow: var(--shadow-md);
  flex-shrink: 0;
}

.swap-btn:hover {
  background: var(--primary-hover);
  transform: scale(1.08) rotate(180deg);
}

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

/* Tone Bar */
.tone-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.tone-bar::-webkit-scrollbar {
  display: none;
}

.tone-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.tone-chips {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.tone-chip {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

.tone-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tone-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}

/* Translation Grid */
.translation-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  flex: 1;
}

@media (max-width: 768px) {
  .translation-grid {
    grid-template-columns: 1fr;
  }
}

/* Panels */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  overflow: hidden;
}

.panel:focus-within {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-md);
}

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

.panel-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.output-title-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.panel-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-btn {
  background: var(--bg-surface-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: var(--transition);
}

.tool-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.tool-btn:active {
  transform: scale(0.97);
}

/* Textareas & Output */
.textarea-wrapper {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 220px;
}

textarea {
  width: 100%;
  height: 100%;
  min-height: 180px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1.05rem;
  line-height: 1.6;
  resize: vertical;
  outline: none;
}

textarea::placeholder {
  color: var(--text-muted);
}

.output-content {
  width: 100%;
  height: 100%;
  min-height: 180px;
  font-size: 1.05rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-primary);
  user-select: text;
}

.output-content.empty {
  color: var(--text-muted);
  font-style: italic;
}

/* Notes Container */
.notes-container {
  margin: 0 16px 12px 16px;
  padding: 10px 14px;
  background: var(--bg-surface-secondary);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.notes-header {
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}

/* Panel Footers */
.panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface-secondary);
  font-size: 0.85rem;
}

.char-count {
  color: var(--text-muted);
}

.action-buttons {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auto-translate-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.primary-btn:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow-md);
}

.primary-btn:active {
  transform: translateY(1px);
}

.primary-btn.w-full {
  width: 100%;
  justify-content: center;
  padding: 12px;
}

.shortcut-hint {
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: normal;
}

@media (max-width: 600px) {
  .shortcut-hint {
    display: none;
  }
}

.model-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.status-msg {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Loading Spinner */
.loading-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--primary);
  font-weight: 500;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(37, 99, 235, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalEnter 0.2s ease-out;
}

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

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

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.close-modal-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.close-modal-btn:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
}

/* Settings Form */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.form-group label {
  font-size: 0.9rem;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.form-group label small {
  color: var(--text-muted);
  font-weight: normal;
}

.input-with-button {
  display: flex;
  align-items: center;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-surface-secondary);
  overflow: hidden;
}

.input-with-button input {
  flex: 1;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
}

.icon-btn-inline {
  background: transparent;
  border: none;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 1rem;
}

.form-group select {
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-surface-secondary);
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
}

.field-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.field-hint a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.field-hint a:hover {
  text-decoration: underline;
}

/* History List */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: var(--bg-surface-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  cursor: pointer;
  transition: var(--transition);
}

.history-item:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.history-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.history-source {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  font-size: 0.92rem;
  line-height: 1.4;
}

.history-target {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.4;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 30px 10px;
  font-size: 0.95rem;
}

.text-btn {
  background: none;
  border: none;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 600;
}

.text-btn.danger {
  color: var(--danger);
}

.text-btn.danger:hover {
  text-decoration: underline;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: #1e293b;
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  transition: transform 0.2s ease, opacity 0.2s ease;
  pointer-events: none;
}

.toast.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(20px);
}

.hidden {
  display: none !important;
}
