:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242736;
  --border: #2e3144;
  --text: #e1e4ed;
  --text-dim: #8b8fa3;
  --accent: #6c8cff;
  --accent-dim: #4a6ae0;
  --green: #4ade80;
  --yellow: #fbbf24;
  --red: #f87171;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "SF Mono", "Fira Code", "Cascadia Code", monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

main {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 1px;
  background: var(--border);
  min-height: calc(100vh - 58px);
}

.panel {
  background: var(--bg);
  padding: 1.5rem 2rem;
  overflow-y: auto;
}

.panel h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Upload form */
.file-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.file-drop:hover, .file-drop.dragover {
  border-color: var(--accent);
  background: rgba(108, 140, 255, 0.05);
}

.drop-icon { font-size: 2rem; }
.drop-text p { margin-top: 0.5rem; color: var(--text-dim); }
.drop-text a { color: var(--accent); text-decoration: none; }
.drop-text a:hover { text-decoration: underline; }
.hint { font-size: 0.8rem; color: var(--text-dim); }

.file-name {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.9rem;
}

.file-name .remove-file {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.1rem;
}

/* Options */
.options-toggle {
  margin-top: 1rem;
}

.options-toggle summary {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 0.9rem;
  user-select: none;
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

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

.form-group label {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.checkbox-group {
  flex-direction: row;
  align-items: center;
  grid-column: span 2;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
}

.context-hint-group {
  margin-top: 0.75rem;
}

.hint-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: normal;
}

textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font);
  resize: vertical;
  width: 100%;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
}

input[type="text"],
input[type="number"],
select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font);
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

button[type="submit"] {
  margin-top: 1.25rem;
  width: 100%;
  padding: 0.75rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

button[type="submit"]:hover:not(:disabled) {
  background: var(--accent-dim);
}

button[type="submit"]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Progress */
#progress-area {
  margin-top: 1.5rem;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--yellow);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.complete { background: var(--green); animation: none; }
.status-dot.error { background: var(--red); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.segment-count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-dim);
}

.upload-progress {
  margin-top: 0.5rem;
}

.progress-bar {
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s;
}

#live-summary {
  margin-top: 1rem;
}

#live-summary h3 {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
}

/* Results */
#result-area {
  margin-top: 1.5rem;
}

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 0.6rem 1.25rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.9rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { display: none; padding: 1rem 0; }
.tab-content.active { display: block; }

/* Markdown rendering */
.markdown-body {
  font-size: 0.9rem;
  line-height: 1.7;
  max-height: 70vh;
  overflow-y: auto;
  padding: 0.5rem;
}

.markdown-body h1, .markdown-body h2 {
  font-size: 1.1rem;
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}

.markdown-body h3 { font-size: 1rem; margin: 1rem 0 0.4rem; }
.markdown-body p { margin: 0.5rem 0; }

.markdown-body ul, .markdown-body ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.markdown-body li { margin: 0.25rem 0; }

.markdown-body code {
  background: var(--surface2);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.85em;
}

.markdown-body pre {
  background: var(--surface);
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 0.75rem 0;
}

.markdown-body pre code {
  background: none;
  padding: 0;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

.markdown-body strong { color: #fff; }

/* History panel */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.history-date {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 0.75rem;
  margin-bottom: 0.25rem;
  font-family: var(--mono);
}

.history-date:first-child { margin-top: 0; }

.history-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  background: var(--surface);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 0.9rem;
}

.history-item:hover { background: var(--surface2); }

.history-item .badges {
  margin-left: auto;
  display: flex;
  gap: 0.3rem;
}

.badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  background: var(--surface2);
  color: var(--text-dim);
}

.badge-audio {
  color: var(--accent);
}

.delete-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.15rem;
  opacity: 0;
  transition: color 0.15s, opacity 0.15s;
}

.history-item:hover .delete-btn { opacity: 1; }
.delete-btn:hover { color: var(--red); }

/* Audio player */
#audio-player-area {
  margin-bottom: 0.5rem;
}

#audio-player {
  width: 100%;
  accent-color: var(--accent);
}

/* Now-playing karaoke display */
#now-playing {
  background: var(--surface);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  min-height: 3.5rem;
  display: flex;
  align-items: center;
}

#now-playing-text {
  font-size: 1.35rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text);
  transition: opacity 0.1s;
}

#now-playing-text.fading { opacity: 0; }

/* Read-along highlight */
.transcript-seg { transition: background 0.2s, border-left 0.2s; }

.seg-active {
  background: rgba(108, 140, 255, 0.12);
  border-left: 3px solid var(--accent);
  padding-left: 6px;
  border-radius: 2px;
}

/* Responsive */
@media (max-width: 800px) {
  main {
    grid-template-columns: 1fr;
  }
  .options-grid {
    grid-template-columns: 1fr;
  }
}
