@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Lora:ital,wght@0,400;0,600;1,400&display=swap');

:root {
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
  --surface-bg: rgba(255, 255, 255, 0.03);
  --surface-border: rgba(255, 255, 255, 0.08);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --warning: #f59e0b;
  --danger: #ef4444;
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

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

body {
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-main);
  padding: 2rem 1rem;
}

.app-wrapper {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.glass-panel {
  background: var(--surface-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--surface-border);
  border-radius: 24px;
  padding: 2rem;
  box-shadow: var(--glass-shadow);
}

.header { text-align: center; margin-bottom: 2rem; }
.header h1 {
  font-size: 2.5rem; font-weight: 700;
  background: linear-gradient(to right, #818cf8, #c084fc);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  display: inline-flex; align-items: center; gap: 0.75rem;
}
.header p { color: var(--text-muted); font-size: 1.1rem; margin-top: 0.5rem; }

/* Upload & Voice */
.top-controls {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 2rem;
}
@media (max-width: 768px) { .top-controls { grid-template-columns: 1fr; } }
.file-upload-wrapper { position: relative; }
.file-upload-label {
  display: flex; align-items: center; justify-content: center; gap: 0.75rem;
  background: rgba(255, 255, 255, 0.05); border: 2px dashed var(--surface-border);
  border-radius: 16px; padding: 1.5rem; cursor: pointer; color: var(--text-muted);
  font-weight: 500; transition: all 0.3s ease; text-align: center;
}
.file-upload-label:hover { border-color: var(--primary); color: var(--text-main); background: rgba(99, 102, 241, 0.1); }
.file-upload-label i { font-size: 1.5rem; color: var(--primary); transition: all 0.3s ease; }

.file-upload-label.is-dragover {
  border-color: #818cf8;
  background: rgba(99, 102, 241, 0.2);
  transform: scale(1.02);
}

.file-upload-label.is-loading {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.12);
  color: var(--text-main);
  animation: pulseBorder 1.5s ease-in-out infinite;
  cursor: wait;
  pointer-events: none;
}
.file-upload-label.is-loading i {
  color: #818cf8;
}

.file-upload-label.is-loaded {
  border-color: rgba(34, 197, 94, 0.4);
  background: rgba(34, 197, 94, 0.08);
  color: var(--text-main);
}
.file-upload-label.is-loaded i {
  color: #22c55e;
}

.file-upload-label.is-error {
  border-color: rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.08);
  color: #fca5a5;
}
.file-upload-label.is-error i {
  color: var(--danger);
}

@keyframes pulseBorder {
  0%, 100% { border-color: rgba(99, 102, 241, 0.4); box-shadow: 0 0 10px rgba(99, 102, 241, 0.15); }
  50% { border-color: #818cf8; box-shadow: 0 0 22px rgba(99, 102, 241, 0.4); }
}

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

.spin, .ph-spin {
  animation: spin 1s linear infinite !important;
  display: inline-block;
}

input[type="file"] { position: absolute; opacity: 0; width: 0; height: 0; }
.select-wrapper { position: relative; display: flex; flex-direction: column; justify-content: center; }
select {
  appearance: none; background: rgba(0, 0, 0, 0.2); border: 1px solid var(--surface-border);
  border-radius: 16px; padding: 1rem 3rem 1rem 1.5rem; color: var(--text-main);
  font-size: 1rem; width: 100%; transition: border-color 0.3s ease; cursor: pointer; font-family: 'Inter', sans-serif;
}
select:focus { outline: none; border-color: var(--primary); }
select:disabled { opacity: 0.5; cursor: not-allowed; }
.select-wrapper i { position: absolute; right: 1.5rem; top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--text-muted); }

/* Chapters */
.chapter-container { display: flex; flex-direction: column; gap: 1.5rem; }
.chapter-nav-group { display: flex; gap: 0.5rem; align-items: center; width: 100%; }
.chapter-nav-group .select-wrapper { flex: 1; }
.btn-icon {
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--surface-border);
  color: var(--text-main); width: 3.2rem; height: 3.2rem; border-radius: 16px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.3s ease; flex-shrink: 0;
}
.btn-icon:hover:not(:disabled) { background: rgba(255, 255, 255, 0.1); transform: translateY(-2px); }
.btn-icon:disabled { opacity: 0.5; cursor: not-allowed; }

/* Settings */
.settings-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem; padding-top: 1rem; border-top: 1px solid var(--surface-border); }
.settings-group { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.toggle-group { display: flex; align-items: center; gap: 0.75rem; color: var(--text-muted); font-size: 0.9rem; cursor: pointer; }
.toggle-group input[type="checkbox"] {
  appearance: none; width: 40px; height: 24px; background: rgba(255,255,255,0.1);
  border-radius: 12px; position: relative; cursor: pointer; border: 1px solid var(--surface-border); transition: all 0.3s;
}
.toggle-group input[type="checkbox"]:checked { background: var(--primary); border-color: var(--primary); }
.toggle-group input[type="checkbox"]::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  background: white; border-radius: 50%; transition: all 0.3s;
}
.toggle-group input[type="checkbox"]:checked::after { left: 18px; }

/* Speed */
.speed-control { display: flex; align-items: center; gap: 1rem; background: rgba(0,0,0,0.2); padding: 0.5rem 1rem; border-radius: 12px; border: 1px solid var(--surface-border); }
.speed-control i { color: var(--text-muted); }
input[type="range"] { appearance: none; width: 100px; height: 6px; background: rgba(255,255,255,0.1); border-radius: 3px; }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 16px; height: 16px; background: var(--primary); border-radius: 50%; cursor: pointer; transition: transform 0.2s; }
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }
#speedValue { font-variant-numeric: tabular-nums; min-width: 3ch; text-align: right; color: var(--text-muted); font-size: 0.9rem; }

/* Playback Controls */
.playback-controls { display: flex; justify-content: center; align-items: center; gap: 1.5rem; padding: 1rem 0; }
.btn-play {
  width: 4.5rem; height: 4.5rem; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: white; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 2rem;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4); transition: all 0.3s ease;
}
.btn-play:hover:not(:disabled) { transform: scale(1.05); box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6); }
.btn-play:disabled { background: rgba(255, 255, 255, 0.1); color: rgba(255, 255, 255, 0.3); box-shadow: none; cursor: not-allowed; }
.btn-action {
  width: 3.5rem; height: 3.5rem; border-radius: 50%; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--surface-border);
  color: var(--text-main); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; transition: all 0.3s ease;
}
.btn-action:hover:not(:disabled) { background: rgba(255, 255, 255, 0.15); transform: translateY(-2px); }
.btn-action:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-stop:hover:not(:disabled) { background: rgba(239, 68, 68, 0.2); color: var(--danger); border-color: rgba(239, 68, 68, 0.5); }
.btn-pause:hover:not(:disabled) { background: rgba(245, 158, 11, 0.2); color: var(--warning); border-color: rgba(245, 158, 11, 0.5); }

/* Status & Layout */
.status-container { margin-top: 1rem; }
#status { font-size: 0.95rem; color: var(--text-muted); margin-bottom: 0.8rem; display: flex; align-items: center; justify-content: center; gap: 0.5rem; }
#status i { font-size: 1.15rem; }
.progress-wrapper { height: 6px; background: rgba(0,0,0,0.3); border-radius: 3px; overflow: hidden; width: 100%; margin-top: 1rem;}
#progressFill { height: 100%; width: 0%; background: linear-gradient(90deg, #818cf8, #c084fc); transition: width 0.3s ease; }

.progress-wrapper.is-loading #progressFill {
  width: 100% !important;
  background: linear-gradient(90deg, #6366f1, #c084fc, #6366f1);
  background-size: 200% 100%;
  animation: loadingGradient 1.5s linear infinite;
}

@keyframes loadingGradient {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Text Display */
#textDisplay {
  display: none; margin-top: 2rem; padding: 2rem; background: rgba(0,0,0,0.2); border-radius: 20px;
  border: 1px solid var(--surface-border); font-family: 'Lora', serif; font-size: 1.35rem; line-height: 1.8;
  max-height: 50vh; overflow-y: auto; color: #e2e8f0;
}
#textDisplay.visible { display: block; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.3); }

/* Word Highlights */
.word { display: inline; padding: 2px 0px; transition: all 0.2s ease; border-radius: 4px; }
.word.current { background-color: var(--primary); color: white; font-weight: 500; }
.word.read { color: var(--text-muted); }

/* Debug */
#debug {
  background: rgba(0,0,0,0.5); border: 1px solid var(--surface-border); border-radius: 12px;
  padding: 1.5rem; font-family: monospace; font-size: 0.85rem; color: #a7f3d0;
  max-height: 15rem; overflow-y: auto; white-space: pre-wrap; margin-top: 0;
}
#textPreview, #chapterProgress { display: none; }
