/* =============================================
   LectoVoz — Multi-Language Text to Speech
   ============================================= */

:root {
  --primary:        #6c63ff;
  --primary-hover:  #5a52e0;
  --primary-light:  #ede9ff;
  --bg:             #f5f5fb;
  --surface:        #ffffff;
  --surface-2:      #f0f0f8;
  --border:         #e2e2f0;
  --text:           #1a1a2e;
  --text-muted:     #6b6b8a;
  --success:        #22c55e;
  --warning:        #f59e0b;
  --danger:         #ef4444;
  --radius:         16px;
  --radius-sm:      10px;
  --shadow:         0 2px 16px rgba(108, 99, 255, 0.08);
  --shadow-lg:      0 8px 40px rgba(108, 99, 255, 0.14);
  --transition:     0.2s ease;
}

[data-theme="dark"] {
  --primary:        #8b7fff;
  --primary-hover:  #7a6ef0;
  --primary-light:  #2a2550;
  --bg:             #0f0f1a;
  --surface:        #1a1a2e;
  --surface-2:      #222236;
  --border:         #2e2e4a;
  --text:           #e8e8f0;
  --text-muted:     #9090b0;
  --shadow:         0 2px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg:      0 8px 40px rgba(0, 0, 0, 0.5);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse 80% 40% at 50% -5%, rgba(108, 99, 255, 0.07) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

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

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  padding: 0 20px;
}

/* ── Header ─────────────────────────────────── */

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

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.03em;
}

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

.header-bmc {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  text-decoration: none;
  transition: all var(--transition);
  flex-shrink: 0;
}

.header-bmc:hover {
  background: #FFDD00;
  border-color: #f5d000;
  transform: scale(1.08);
  box-shadow: 0 2px 12px rgba(255, 221, 0, 0.4);
}

.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

/* ── Main ────────────────────────────────────── */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 28px;
}

/* ── Cards ───────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  transition: background var(--transition), border-color var(--transition);
}

/* ── Labels ──────────────────────────────────── */

.label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.label-sm {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

/* ── Textarea ─────────────────────────────────── */

.textarea-wrapper { position: relative; }

.textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text);
  resize: vertical;
  min-height: 160px;
  font-family: inherit;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
  outline: none;
}

.textarea:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.12);
}

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

.textarea-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
}

.char-count {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ── Icon Buttons ─────────────────────────────── */

.btn-icon {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}

.btn-icon:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

/* ── Snippets Card ────────────────────────────── */

.snippets-card { padding: 18px 22px; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.count-badge {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  min-width: 22px;
  text-align: center;
}

.snippets-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 2px;
}

.snippet-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition);
}

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

.snippet-body {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.snippet-lang-flag { font-size: 1rem; flex-shrink: 0; }

.snippet-preview {
  font-size: 0.83rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.snippet-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-sm {
  background: var(--primary-light);
  color: var(--primary);
  border: 1.5px solid transparent;
  border-radius: 99px;
  padding: 4px 12px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  white-space: nowrap;
}

.btn-sm:hover {
  background: var(--primary);
  color: #fff;
}

.btn-icon-xs {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}

.btn-icon-xs:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border-color: var(--danger);
}

/* ── Controls Card Sections ───────────────────── */

.controls-section { padding: 4px 0; }
.controls-section:first-child { padding-top: 0; }
.controls-section:last-child  { padding-bottom: 0; }

.controls-divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* ── Language Pills ──────────────────────────── */

.lang-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 2px;
}

.lang-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 13px;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  white-space: nowrap;
  line-height: 1;
}

.lang-pill:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

.lang-pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 10px rgba(108, 99, 255, 0.3);
}

/* ── Voice Hint ───────────────────────────────── */

.voice-hint {
  margin-top: 6px;
  font-size: 0.74rem;
  color: var(--warning);
  min-height: 1em;
}

/* ── Select ──────────────────────────────────── */

.select {
  width: 100%;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 36px 10px 12px;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6b8a' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}

.select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.12);
}

/* ── Sliders Row ──────────────────────────────── */

.sliders-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

@media (max-width: 600px) {
  .sliders-row { grid-template-columns: 1fr; gap: 18px; }
}

/* ── Range Inputs ─────────────────────────────── */

.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 99px;
  background: var(--border);
  outline: none;
  cursor: pointer;
  accent-color: var(--primary);
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2.5px solid var(--surface);
  box-shadow: 0 0 0 2px var(--primary);
  transition: box-shadow var(--transition);
}

.range::-webkit-slider-thumb:hover { box-shadow: 0 0 0 5px rgba(108, 99, 255, 0.2); }

.range::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2.5px solid var(--surface);
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.67rem;
  color: var(--text-muted);
  margin-top: 5px;
}

.value-badge {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
  font-variant-numeric: tabular-nums;
}

/* ── Reading Profiles ─────────────────────────── */

.btn-text {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
  transition: background var(--transition);
  font-family: inherit;
  white-space: nowrap;
}

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

.profile-save-form {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}

.profile-name-input {
  flex: 1;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85rem;
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  min-width: 0;
}

.profile-name-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.12);
}

.profiles-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.empty-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}

.profile-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 6px 14px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.profile-pill:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.profile-pill-name {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-pill-delete {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  flex-shrink: 0;
  transition: all var(--transition);
}

.profile-pill:hover .profile-pill-delete {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

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

.progress-container { padding: 0 2px; }

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 7px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #a78bff);
  border-radius: 99px;
  width: 0%;
  transition: width 0.4s ease;
}

.progress-text {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* ── Playback Controls ────────────────────────── */

.playback-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 13px 26px;
  border-radius: 99px;
  font-size: 0.92rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  white-space: nowrap;
  font-family: inherit;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  min-width: 150px;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(108, 99, 255, 0.35);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 6px 28px rgba(108, 99, 255, 0.48);
  transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 2px 12px rgba(108, 99, 255, 0.3);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-muted);
  border: 1.5px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

/* ── Status Bar ───────────────────────────────── */

.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 2px 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background var(--transition);
  flex-shrink: 0;
}

.status-dot.playing {
  background: var(--success);
  animation: pulse-dot 1.2s ease-in-out infinite;
}

.status-dot.paused { background: var(--warning); }
.status-dot.error  { background: var(--danger); }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.75); }
}

/* ── Footer ──────────────────────────────────── */

.footer {
  border-top: 1px solid var(--border);
  padding: 16px 0 24px;
  text-align: center;
  font-size: 0.76rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.footer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ── Buy Me a Coffee ──────────────────────────── */

.bmc-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: #FFDD00;
  color: #1a1a1a;
  border: none;
  border-radius: 99px;
  padding: 9px 20px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition);
  font-family: inherit;
  box-shadow: 0 2px 12px rgba(255, 221, 0, 0.3);
}

.bmc-btn:hover {
  background: #f5d000;
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(255, 221, 0, 0.45);
}

.bmc-btn:active { transform: translateY(0); }

/* ── Install Button ───────────────────────────── */

.install-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-light);
  color: var(--primary);
  border: 1.5px solid var(--primary);
  border-radius: 99px;
  padding: 8px 18px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.install-btn:hover {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 16px rgba(108, 99, 255, 0.3);
}

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

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 22px;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  z-index: 999;
  white-space: nowrap;
  max-width: calc(100vw - 48px);
  text-overflow: ellipsis;
  overflow: hidden;
  font-family: inherit;
}

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

/* ── Scrollbar ───────────────────────────────── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Focus ───────────────────────────────────── */

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ── Responsive: Tablet ──────────────────────── */

@media (max-width: 800px) { .app { padding: 0 16px; } }

/* ── Responsive: Mobile ──────────────────────── */

@media (max-width: 480px) {
  .app { padding: 0 12px; }
  .card { padding: 18px 16px; }
  .snippets-card { padding: 16px; }
  .header { padding: 16px 0 12px; margin-bottom: 16px; }
  .btn { padding: 12px 20px; font-size: 0.88rem; }
  .btn-primary { min-width: 130px; }
  .lang-pill { font-size: 0.75rem; padding: 5px 10px; }
}
