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

:root {
  --primary: #6c63ff;
  --primary-dark: #574fd6;
  --bg: #0f0f13;
  --surface: #1a1a24;
  --surface2: #22222f;
  --border: #2e2e3e;
  --text: #e8e8f0;
  --text-muted: #7878a0;
  --success: #4caf8a;
  --error: #e05c5c;
  --radius: 12px;
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px 48px;
}

.container {
  width: 100%;
  max-width: 680px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Header */
header {
  text-align: center;
  padding-top: 8px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.tagline {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Options */
.options-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.option-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 200px;
}

.option-group label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.toggle-group {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
}

.toggle-btn {
  flex: 1;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.toggle-btn.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.toggle-btn:hover:not(.active) {
  background: var(--border);
  color: var(--text);
}

/* Textarea */
.textarea-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.textarea-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}

.toolbar-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.img-btn-group {
  display: flex;
  gap: 5px;
}

.img-upload-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  white-space: nowrap;
}

.img-upload-btn:hover { border-color: var(--primary); color: var(--primary); }
.img-upload-btn.loading { border-color: var(--primary); color: var(--primary); opacity: 0.7; pointer-events: none; }

/* URL input row */
.url-input-row {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  background: var(--surface2);
  border: 1px solid var(--primary);
  border-top: none;
  border-bottom: none;
  animation: fadeIn 0.15s ease;
}

.url-input-row input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.85rem;
  padding: 6px 10px;
  outline: none;
  border-top: 1px solid var(--border);
  border-radius: 6px;
  min-height: unset;
}

.url-input-row input:focus { border-color: var(--primary); }
.url-input-row input::placeholder { color: var(--text-muted); }

.url-input-row #img-url-go-btn {
  padding: 6px 14px;
  background: var(--primary);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.url-input-row #img-url-go-btn:hover { background: var(--primary-dark); }
.url-input-row #img-url-go-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.url-input-row #img-url-cancel-btn {
  padding: 6px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
}

.url-input-row #img-url-cancel-btn:hover { border-color: var(--error); color: var(--error); }

textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.6;
  padding: 14px 14px 32px;
  resize: vertical;
  min-height: 130px;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

textarea:focus {
  border-color: var(--primary);
}

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

.char-count {
  position: absolute;
  bottom: 10px;
  right: 14px;
  font-size: 0.75rem;
  color: var(--text-muted);
  pointer-events: none;
}

/* Image preview */
#img-preview-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface2);
  max-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#img-preview {
  max-width: 100%;
  max-height: 180px;
  object-fit: contain;
  display: block;
}

#img-clear-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(10,10,15,0.8);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

#img-clear-btn:hover { color: var(--error); border-color: var(--error); }

/* Translate button */
.translate-btn {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: background 0.15s, transform 0.1s;
}

.translate-btn:hover:not(:disabled) { background: var(--primary-dark); }
.translate-btn:active:not(:disabled) { transform: scale(0.99); }
.translate-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.spinner {
  width: 20px;
  height: 20px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Output */
.output-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: fadeIn 0.2s ease;
}

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

.output-meta {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0 2px;
}

.variants-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.variant-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s;
}

.variant-card:hover {
  border-color: var(--primary);
}

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

.variant-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
}

.copy-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
}

.copy-btn:hover { border-color: var(--primary); color: var(--primary); }
.copy-btn.copied { border-color: var(--success); color: var(--success); }

.variant-text {
  padding: 14px;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 60px;
}

/* Loading skeleton for variant cards */
.variant-text.loading {
  background: linear-gradient(90deg, var(--border) 25%, var(--surface) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 6px;
  min-height: 80px;
  color: transparent;
}

@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Error */
.error-box {
  background: rgba(224, 92, 92, 0.1);
  border: 1px solid rgba(224, 92, 92, 0.3);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--error);
  font-size: 0.875rem;
}

/* Footer */
footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* Mobile */
@media (max-width: 560px) {
  .card { padding: 16px; }
  .options-row { flex-direction: column; gap: 14px; }
  .option-group { min-width: unset; }
  .variants-row { grid-template-columns: 1fr; }
}
