:root {
  --bg: #0a0a23;
  --bg-alt: #12122f;
  --bg-hover: #1a1a3f;
  --text: #e0e0e0;
  --text-dim: #888;
  --cyan: #00d4ff;
  --purple: #a855f7;
  --accent: var(--cyan);
}

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

body {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header & Tabs */
header {
  padding: 1rem;
  border-bottom: 1px solid var(--bg-alt);
  display: flex;
  align-items: center;
  gap: 2rem;
}

header h1 {
  font-size: 1.5rem;
  color: var(--cyan);
  font-weight: 400;
}

#tabs {
  display: flex;
  gap: 0.5rem;
}

.tab {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 0.5rem 1rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--cyan);
  border-bottom-color: var(--cyan);
}

/* Views */
main {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.view {
  display: none;
  height: 100%;
  overflow-y: auto;
}

.view.active {
  display: flex;
  flex-direction: column;
}

/* Episode Info */
#episode-info {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-alt);
  align-items: center;
}

#cover-art {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg);
  display: none;
}

#cover-art[src]:not([src=""]) {
  display: block;
}

#episode-meta {
  flex: 1;
}

#episode-title {
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

#podcast-name {
  font-size: 0.9rem;
  color: var(--text-dim);
}

/* Transcript Status */
#transcript-status {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  display: none;
}

#transcript-status.visible {
  display: block;
}

#transcript-status.loading {
  color: var(--cyan);
}

#transcript-status.error {
  color: #f87171;
}

/* Manuscript View */
kweb-manuscript {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  scroll-behavior: smooth;
}

.manuscript {
  max-width: 800px;
  margin: 0 auto;
  line-height: 2;
  font-size: 1.1rem;
}

.cue {
  padding: 0.5rem 1rem;
  border-radius: 4px;
  transition: all 0.3s;
  cursor: pointer;
}

.cue:hover {
  background: var(--bg-alt);
}

.cue.active {
  background: var(--bg-alt);
  border-left: 3px solid var(--cyan);
  color: var(--cyan);
}

.cue.past {
  color: var(--text-dim);
}

.cue .timestamp {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-right: 1rem;
  opacity: 0;
  transition: opacity 0.2s;
}

.cue:hover .timestamp {
  opacity: 1;
}

/* Word-level karaoke highlighting */
.cue.word-level .text {
  display: inline;
}

.word {
  display: inline;
  transition: all 0.15s ease-out;
  border-radius: 2px;
  padding: 0 2px;
  margin: 0 -2px;
}

.word:hover {
  background: rgba(0, 255, 255, 0.1);
  cursor: pointer;
}

.word.active {
  color: var(--cyan);
  font-weight: 600;
  text-shadow: 0 0 8px rgba(0, 255, 255, 0.5);
  transform: scale(1.05);
  display: inline-block;
}

.word.past {
  color: var(--text-dim);
}

/* Smooth bounce on active word */
@keyframes word-pulse {
  0%, 100% { transform: scale(1.05); }
  50% { transform: scale(1.08); }
}

.word.active {
  animation: word-pulse 0.4s ease-in-out;
}

/* Entity links (Wikipedia-linked words) */
.word.entity {
  color: var(--purple);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
  cursor: pointer;
}

.word.entity:hover {
  color: var(--cyan);
  text-decoration-style: solid;
}

.word.entity.active {
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(168, 85, 247, 0.5);
}

.word.entity.past {
  color: #7c3aed;
  opacity: 0.7;
}

/* Library Grid */
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  padding: 1rem;
}

.podcast-card {
  background: var(--bg-alt);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.podcast-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.podcast-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.podcast-card-info {
  padding: 1rem;
}

.podcast-card-title {
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.podcast-card-count {
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* Episode List */
.episode-list {
  padding: 1rem;
}

.episode-item {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-alt);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: background 0.2s;
}

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

.episode-item-info {
  flex: 1;
}

.episode-item-title {
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
}

.episode-item-date {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.episode-item-duration {
  font-size: 0.8rem;
  color: var(--text-dim);
  align-self: center;
}

/* Add Form */
.add-form {
  max-width: 600px;
  margin: 0 auto;
  padding: 2rem;
}

.add-form h2 {
  margin-bottom: 2rem;
  font-weight: 400;
}

.input-group {
  margin-bottom: 1.5rem;
}

.input-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.input-group input[type="url"],
.input-group input[type="text"] {
  width: 100%;
  background: var(--bg-alt);
  border: 1px solid #333;
  color: var(--text);
  padding: 0.75rem 1rem;
  font-family: inherit;
  font-size: 0.9rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.input-group input:focus {
  outline: none;
  border-color: var(--cyan);
}

.input-group button {
  width: 100%;
}

.drop-zone {
  border: 2px dashed #333;
  border-radius: 8px;
  padding: 3rem;
  text-align: center;
  color: var(--text-dim);
  transition: all 0.2s;
  margin-bottom: 2rem;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--cyan);
  background: rgba(0, 212, 255, 0.05);
}

.drop-zone .hint {
  font-size: 0.8rem;
  margin-top: 0.5rem;
}

.transcription-options {
  background: var(--bg-alt);
  padding: 1rem;
  border-radius: 8px;
}

.transcription-options h3 {
  font-size: 0.9rem;
  font-weight: 400;
  margin-bottom: 1rem;
  color: var(--text-dim);
}

.transcription-options label {
  display: block;
  padding: 0.5rem 0;
  cursor: pointer;
}

.transcription-options input[type="radio"] {
  margin-right: 0.5rem;
}

/* Footer player bar */
footer {
  border-top: 1px solid var(--bg-alt);
  padding: 1rem;
  background: var(--bg);
}

#player-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

#play-pause {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.2rem;
  flex-shrink: 0;
}

#progress-container {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 1rem;
}

#progress-container #seek {
  flex: 1;
}

#time {
  font-size: 0.8rem;
  color: var(--text-dim);
  min-width: 100px;
  text-align: right;
}

#speed-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#speed {
  width: 60px;
}

#speed-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  min-width: 30px;
}

#transcript-btn,
#wikify-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1rem;
  padding: 0;
}

#transcript-btn.active,
#wikify-btn.active {
  background: var(--cyan);
  color: var(--bg);
}

#wikify-btn.done {
  background: var(--purple);
  color: var(--bg);
}

/* Range slider styling */
input[type="range"] {
  -webkit-appearance: none;
  background: var(--bg-alt);
  height: 6px;
  border-radius: 3px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--cyan);
  border-radius: 50%;
  cursor: pointer;
}

button {
  background: var(--bg-alt);
  border: 1px solid #333;
  color: var(--text);
  padding: 0.5rem 1rem;
  font-family: inherit;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
}

button:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim);
  text-align: center;
  gap: 1rem;
  padding: 2rem;
}

.empty-state h2 {
  font-weight: 400;
  color: var(--text);
}

/* Loading state */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--bg-alt);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Responsive */
@media (max-width: 768px) {
  header {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  #tabs {
    justify-content: center;
  }

  #episode-info {
    flex-direction: column;
    text-align: center;
  }

  #player-bar {
    flex-wrap: wrap;
  }

  #progress-container {
    order: 3;
    width: 100%;
  }

  #speed-control {
    display: none;
  }

  kweb-manuscript {
    padding: 1rem;
  }

  .manuscript {
    font-size: 1rem;
  }

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

/* Streaming indicator */
.streaming-indicator {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  color: var(--cyan);
  font-size: 0.9rem;
  margin-top: 1rem;
  border-top: 1px dashed var(--bg-alt);
}

.streaming-indicator .pulse {
  width: 10px;
  height: 10px;
  background: var(--cyan);
  border-radius: 50%;
  animation: pulse-glow 1.5s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% {
    opacity: 1;
    box-shadow: 0 0 4px var(--cyan);
  }
  50% {
    opacity: 0.5;
    box-shadow: 0 0 12px var(--cyan), 0 0 20px var(--cyan);
  }
}
