:root {
  color-scheme: dark;
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg-body: #0f1117;
  --bg-surface: #181a24;
  --bg-surface-hover: #1f2233;
  --bg-elevated: #232638;
  --border: #2a2d40;
  --border-focus: #6366f1;
  --text-primary: #e8eaf0;
  --text-secondary: #8b90a8;
  --text-muted: #5c6080;
  --accent: #6366f1;
  --accent-hover: #5457e5;
  --accent-glow: rgba(99, 102, 241, 0.2);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --danger-border: rgba(239, 68, 68, 0.3);
  --success: #22c55e;
  --gemini: #4285f4;
  --openai: #10a37f;
  --grok: #f97316;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --transition: 180ms ease;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-body);
  color: var(--text-primary);
}

/* ── Topbar ─────────────────────────────────────────────── */

.topbar {
  align-items: center;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 24px;
  justify-content: space-between;
  padding: 20px clamp(16px, 4vw, 40px);
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

h1, h2, p { margin: 0; }

h1 {
  font-size: 26px;
  font-weight: 800;
  background: linear-gradient(135deg, #818cf8, #6366f1, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

p {
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ── Layout ─────────────────────────────────────────────── */

.layout {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
  padding: 20px clamp(16px, 4vw, 40px) 40px;
}

.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.list-panel {
  min-height: 640px;
}

.panel-head {
  border-bottom: 1px solid var(--border);
  display: grid;
  gap: 12px;
  padding: 16px;
}

/* ── Form Elements ──────────────────────────────────────── */

input, select, textarea, button {
  border-radius: var(--radius);
  font: inherit;
}

input, select, textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  outline: none;
  padding: 10px 12px;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

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

button {
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  cursor: pointer;
  display: inline-flex;
  font-weight: 600;
  gap: 6px;
  justify-content: center;
  min-height: 40px;
  padding: 9px 14px;
  transition: background var(--transition), border-color var(--transition), transform 80ms ease;
}

button:hover {
  background: var(--bg-surface-hover);
}

button:active {
  transform: scale(0.97);
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.danger:hover {
  background: rgba(239, 68, 68, 0.15);
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition);
}

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

/* ── Subtitle List ──────────────────────────────────────── */

.subtitle-list {
  display: grid;
  gap: 1px;
}

.subtitle-item {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  display: grid;
  gap: 5px;
  justify-items: start;
  min-height: 76px;
  padding: 12px 16px;
  text-align: left;
  width: 100%;
  transition: background var(--transition);
}

.subtitle-item:hover {
  background: var(--bg-elevated);
}

.subtitle-item.active {
  background: rgba(99, 102, 241, 0.08);
  border-left: 3px solid var(--accent);
}

.subtitle-item strong {
  font-size: 15px;
  color: var(--text-primary);
}

.subtitle-item span {
  color: var(--text-secondary);
  font-size: 13px;
  overflow-wrap: anywhere;
}

/* ── Editor ─────────────────────────────────────────────── */

.editor-panel {
  padding: 18px;
}

.form-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label, .content-label {
  color: var(--text-secondary);
  display: grid;
  font-size: 13px;
  font-weight: 600;
  gap: 7px;
}

.editor-toolbar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  margin: 16px 0;
}

.translate-btn {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(139, 92, 246, 0.15));
  border: 1px solid rgba(99, 102, 241, 0.35);
  color: #a5b4fc;
  font-weight: 650;
}

.translate-btn:hover {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.25), rgba(139, 92, 246, 0.25));
  border-color: rgba(99, 102, 241, 0.5);
}

.translate-btn svg {
  flex-shrink: 0;
}

textarea {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 14px;
  line-height: 1.55;
  min-height: 480px;
  resize: vertical;
  white-space: pre;
}

.url-row {
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  gap: 10px;
  margin-top: 12px;
  min-height: 42px;
  padding: 10px 12px;
}

.url-row span {
  color: var(--text-secondary);
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 650;
}

.url-row a {
  color: #818cf8;
  overflow-wrap: anywhere;
  text-decoration: none;
}

.url-row a:hover {
  text-decoration: underline;
}

/* ── Modal System ───────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 200ms ease;
  padding: 20px;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-overlay.visible {
  opacity: 1;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
  width: 100%;
  transform: translateY(12px) scale(0.97);
  transition: transform 200ms ease;
}

.modal-overlay.visible .modal {
  transform: translateY(0) scale(1);
}

.settings-modal {
  max-width: 520px;
}

.translate-modal {
  max-width: 680px;
}

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

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

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

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

.modal-body {
  padding: 20px 24px;
}

.modal-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.5;
}

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

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

/* ── Settings ───────────────────────────────────────────── */

.settings-grid {
  display: grid;
  gap: 16px;
}

.setting-row {
  display: grid;
  gap: 8px;
}

.setting-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.provider-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.provider-badge.gemini {
  background: rgba(66, 133, 244, 0.15);
  color: #93b5f8;
  border: 1px solid rgba(66, 133, 244, 0.3);
}

.provider-badge.openai {
  background: rgba(16, 163, 127, 0.15);
  color: #5dd8b4;
  border: 1px solid rgba(16, 163, 127, 0.3);
}

.provider-badge.grok {
  background: rgba(249, 115, 22, 0.15);
  color: #fba95c;
  border: 1px solid rgba(249, 115, 22, 0.3);
}

.setting-model {
  font-size: 12px;
  color: var(--text-muted);
  font-family: "Cascadia Mono", Consolas, monospace;
}

.setting-status {
  font-size: 12px;
  font-weight: 600;
}

.setting-status.configured {
  color: var(--success);
}

.setting-status.not-configured {
  color: var(--text-muted);
}

/* ── Translate Modal ────────────────────────────────────── */

.translate-config {
  display: grid;
  gap: 18px;
}

.lang-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 14px;
  align-items: end;
}

.lang-arrow {
  font-size: 20px;
  color: var(--text-muted);
  padding-bottom: 12px;
  font-weight: 600;
}

.provider-select {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tone-select {
  max-width: 280px;
}

.provider-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.provider-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  padding: 7px 16px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 600;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  min-height: auto;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pill:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.pill.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: #a5b4fc;
}

.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.pill-dot.gemini { background: var(--gemini); }
.pill-dot.openai { background: var(--openai); }
.pill-dot.grok { background: var(--grok); }

/* ── Progress Bar ───────────────────────────────────────── */

.translate-progress {
  margin-top: 20px;
}

.progress-bar {
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 100px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #a78bfa);
  border-radius: 100px;
  transition: width 400ms ease;
  animation: progress-shimmer 1.5s ease infinite;
}

@keyframes progress-shimmer {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.progress-fill.indeterminate {
  width: 30% !important;
  animation: progress-indeterminate 1.5s ease-in-out infinite;
}

@keyframes progress-indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

.progress-text {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 10px;
  text-align: center;
}

/* ── Preview ────────────────────────────────────────────── */

.preview-stats {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.preview-stats .stat {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 4px 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.preview-stats .stat strong {
  color: var(--text-primary);
  font-weight: 700;
}

.preview-textarea {
  min-height: 280px;
  font-size: 13px;
  background: var(--bg-body);
}

/* ── Toast ──────────────────────────────────────────────── */

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  bottom: 18px;
  box-shadow: var(--shadow-md);
  color: var(--text-primary);
  left: 50%;
  opacity: 0;
  padding: 10px 18px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 10px);
  transition: opacity 160ms ease, transform 160ms ease;
  font-size: 14px;
  font-weight: 500;
  z-index: 2000;
}

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

/* ── Responsive ─────────────────────────────────────────── */

@media (max-width: 860px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-end;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .list-panel {
    min-height: auto;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .editor-toolbar {
    justify-content: stretch;
  }

  .editor-toolbar button {
    flex: 1 1 140px;
  }

  .lang-row {
    grid-template-columns: 1fr;
  }

  .lang-arrow {
    display: none;
  }

  .modal {
    max-height: 95vh;
  }
}
