/* ===== Reset & Base ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-hover: #334155;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --transition: 0.2s ease;
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: 1rem;
  line-height: 1.5;
}

#app {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ===== Offline Banner ===== */
.offline-banner {
  background: var(--warning);
  color: #000;
  text-align: center;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  animation: slideDown 0.3s ease;
}

.offline-dot {
  width: 8px;
  height: 8px;
  background: #000;
  border-radius: 50%;
  display: inline-block;
  animation: blink 1.5s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.hidden {
  display: none !important;
}

/* ===== Header ===== */
header {
  text-align: center;
  padding: 1.5rem 0 0.5rem;
}

header h1 {
  font-size: 1.8rem;
  font-weight: 700;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

/* ===== Progress Section ===== */
.progress-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #8b5cf6);
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* ===== Language Selectors ===== */
.lang-selectors {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.lang-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.lang-group label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.lang-group select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
}

.lang-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.swap-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  transition: background var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* ===== Tabs ===== */
.tabs {
  display: flex;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px;
  gap: 4px;
  border: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 0.6rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  font-weight: 500;
}

.tab.active {
  background: var(--primary);
  color: #fff;
}

.tab:hover:not(.active) {
  color: var(--text);
  background: var(--surface-hover);
}

/* ===== Panels ===== */
.panel {
  display: none;
  flex-direction: column;
  gap: 0.75rem;
}

.panel.active {
  display: flex;
}

textarea {
  width: 100%;
  padding: 1rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: var(--font);
  resize: vertical;
  min-height: 120px;
  transition: border-color var(--transition);
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

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

/* ===== Buttons ===== */
.btn-primary {
  width: 100%;
  padding: 0.75rem 1.5rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}

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

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

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

.btn-icon:hover {
  background: var(--surface-hover);
}

/* ===== Audio Controls ===== */
.audio-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem;
}

.btn-record {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  transition: all var(--transition);
  color: var(--text);
  font-size: 0.7rem;
  font-weight: 500;
}

.btn-record:hover {
  border-color: var(--danger);
}

.btn-record.recording {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
  animation: pulse-ring 1.5s infinite;
}

.record-icon {
  width: 24px;
  height: 24px;
  background: var(--danger);
  border-radius: 50%;
  transition: all var(--transition);
}

.btn-record.recording .record-icon {
  border-radius: 4px;
  width: 20px;
  height: 20px;
}

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

.recording-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 500;
}

.pulse {
  width: 10px;
  height: 10px;
  background: var(--danger);
  border-radius: 50%;
  animation: blink 1s infinite;
}

.hint {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
}

.transcription-result,
.ocr-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-size: 0.9rem;
}

.transcription-result strong,
.ocr-result strong {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ===== Image Upload ===== */
.image-upload {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
}

.upload-area:hover {
  border-color: var(--primary);
  color: var(--text);
}

.upload-icon {
  font-size: 2rem;
}

.upload-area input[type="file"] {
  display: none;
}

.image-preview {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius);
  object-fit: contain;
  border: 1px solid var(--border);
}

/* ===== Output Section ===== */
.output-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  animation: slideDown 0.3s ease;
}

.output-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.output-header h2 {
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.output-actions {
  display: flex;
  gap: 0.5rem;
}

.output-text {
  font-size: 1.1rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ===== Status Bar ===== */
.status-bar {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.5rem;
  border-top: 1px solid var(--border);
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  html {
    font-size: 15px;
  }

  #app {
    gap: 0.75rem;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .lang-selectors {
    flex-wrap: wrap;
  }

  .swap-btn {
    order: 3;
    width: 100%;
    height: 36px;
  }

  .lang-group {
    min-width: calc(50% - 0.5rem);
  }

  .tab {
    font-size: 0.8rem;
    padding: 0.5rem;
  }

  .audio-controls {
    padding: 1rem;
  }

  .btn-record {
    width: 70px;
    height: 70px;
  }
}

/* ===== Spinner for loading states ===== */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--text-muted);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 0.5rem;
}

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