/* ===== Base & Variables ===== */
:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #222240;
  --bg-card: #16162d;
  --text-primary: #e8e8f0;
  --text-secondary: #a0a0b8;
  --text-muted: #6a6a82;
  --accent: #3355ff;
  --accent-light: #5577ff;
  --accent-glow: rgba(51, 85, 255, 0.3);
  --host-color: #3b82f6;
  --host-bg: rgba(59, 130, 246, 0.1);
  --guest-color: #22c55e;
  --guest-bg: rgba(34, 197, 94, 0.1);
  --contraction-bg: rgba(234, 179, 8, 0.2);
  --contraction-color: #facc15;
  --border: #2a2a45;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --transition: 0.2s ease;
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* ===== Top Nav ===== */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo { font-size: 24px; }

.site-title {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.episode-select {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}

/* ===== Main Layout ===== */
.main-container {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  gap: 0;
  height: calc(100vh - 56px);
  overflow: hidden;
}

/* ===== Player Panel ===== */
.player-panel {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px;
}

.player-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.player-cover {
  display: flex;
  justify-content: center;
  padding: 20px 0;
}

.cover-art {
  width: 120px;
  height: 120px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  box-shadow: 0 8px 32px var(--accent-glow);
}

.player-info {
  text-align: center;
}

.episode-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.episode-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
}

.player-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
}

.ctrl-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 16px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ctrl-btn:hover { background: var(--accent); transform: scale(1.05); }

.ctrl-play {
  width: 52px;
  height: 52px;
  font-size: 20px;
  background: var(--accent);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.ctrl-play:hover { background: var(--accent-light); }

.progress-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.time-display {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 36px;
  font-variant-numeric: tabular-nums;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  cursor: pointer;
  position: relative;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width 0.1s linear;
}

.progress-thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-light);
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity var(--transition);
  box-shadow: 0 0 8px var(--accent-glow);
}

.progress-bar:hover .progress-thumb { opacity: 1; }

.speed-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  justify-content: center;
}

.speed-btn {
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  transition: var(--transition);
}

.speed-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.speed-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ===== Transcript Panel ===== */
.transcript-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

.transcript-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.transcript-header h2 { font-size: 16px; }

.transcript-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  transition: var(--transition);
}

.action-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.action-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.transcript-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scroll-behavior: smooth;
}

.transcript-body .loading {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
}

/* Segment Styles */
.segment {
  padding: 12px 16px;
  margin-bottom: 8px;
  border-radius: var(--radius-sm);
  border-left: 3px solid transparent;
  transition: var(--transition);
  cursor: default;
  line-height: 1.7;
}

.segment:hover {
  background: var(--bg-card);
}

.segment.host {
  border-left-color: var(--host-color);
  background: var(--host-bg);
}

.segment.guest {
  border-left-color: var(--guest-color);
  background: var(--guest-bg);
}

.segment.active {
  background: var(--bg-tertiary);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.segment .role-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.segment.host .role-badge {
  background: var(--host-color);
  color: #fff;
}

.segment.guest .role-badge {
  background: var(--guest-color);
  color: #000;
}

/* Word Styles */
.word {
  cursor: pointer;
  position: relative;
  display: inline;
  transition: color var(--transition);
  border-bottom: 1px dashed transparent;
}

.word:hover {
  color: var(--accent-light);
  border-bottom-color: var(--accent-light);
}

.word.has-vocab {
  border-bottom: 1px dashed var(--text-muted);
}

.word.has-vocab:hover {
  border-bottom-color: var(--accent-light);
}

.word.contraction {
  background: var(--contraction-bg);
  color: var(--contraction-color);
  border-radius: 3px;
  padding: 0 2px;
  font-weight: 600;
  border-bottom: 1px dashed var(--contraction-color);
}

.word.contraction:hover {
  background: rgba(234, 179, 8, 0.4);
  color: #fde68a;
}

/* ===== Vocab Panel ===== */
.vocab-panel {
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.vocab-header h2 { font-size: 16px; }

.vocab-count {
  font-size: 12px;
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: 10px;
  color: var(--text-secondary);
}

.vocab-search {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

#vocab-search-input {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
}

#vocab-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

#vocab-search-input::placeholder {
  color: var(--text-muted);
}

.vocab-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.vocab-list .loading {
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
}

.vocab-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

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

.vocab-item .en {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.vocab-item .zh {
  color: var(--text-secondary);
  font-size: 12px;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

.vocab-item .tag {
  display: inline-block;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--contraction-bg);
  color: var(--contraction-color);
  margin-left: 4px;
  flex-shrink: 0;
}

.vocab-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 14px;
}

/* ===== Word Tooltip ===== */
.word-tooltip {
  position: fixed;
  z-index: 200;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  max-width: 280px;
  display: none;
  pointer-events: none;
}

.word-tooltip.visible { display: block; }

.word-tooltip .tooltip-word {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.word-tooltip .tooltip-zh {
  font-size: 14px;
  color: var(--accent-light);
  margin-bottom: 2px;
}

.word-tooltip .tooltip-full {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* ===== Grammar Panel ===== */
.grammar-panel {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.grammar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
}

.grammar-header:hover { background: var(--bg-tertiary); }

.grammar-header h2 { font-size: 15px; }

.toggle-icon {
  font-size: 12px;
  transition: transform var(--transition);
  color: var(--text-muted);
}

.grammar-panel.collapsed .toggle-icon { transform: rotate(-90deg); }

.grammar-content {
  padding: 0 24px 16px;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.grammar-panel.collapsed .grammar-content {
  max-height: 0;
  padding-bottom: 0;
}

.grammar-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.grammar-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
}

.grammar-card h3 {
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--accent-light);
}

.contraction-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.contraction-item {
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--contraction-bg);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.ct-short {
  font-weight: 700;
  color: var(--contraction-color);
}

.ct-full {
  color: var(--text-secondary);
  font-size: 12px;
}

.ct-zh {
  color: var(--text-muted);
  font-size: 11px;
  width: 100%;
}

.practice-list {
  padding-left: 20px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text-secondary);
}

.practice-list strong { color: var(--text-primary); }
.practice-list em { color: var(--accent-light); }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Responsive ===== */
@media (max-width: 1200px) {
  .main-container {
    grid-template-columns: 240px 1fr 280px;
  }
}

@media (max-width: 900px) {
  .main-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    height: auto;
  }

  .player-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 16px;
  }

  .player-card {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
  }

  .player-cover { padding: 0; }
  .cover-art { width: 64px; height: 64px; font-size: 28px; }
  .player-info { text-align: left; flex: 1; }
  .player-controls { order: 3; width: 100%; }
  .progress-container { order: 4; width: 100%; }
  .speed-control { order: 5; width: 100%; }

  .vocab-panel {
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 300px;
  }

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

  .transcript-body { padding: 12px; }
}

@media (max-width: 600px) {
  .top-nav { padding: 0 12px; }
  .site-title { font-size: 14px; }
  .grammar-header { padding: 10px 12px; }
  .grammar-content { padding: 0 12px 12px; }
  .contraction-list { grid-template-columns: 1fr; }
  .segment { padding: 8px 12px; }
}

/* ===== Entry Page (Splash) ===== */
.entry-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-primary);
}

.entry-splash {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.splash-logo {
  font-size: 64px;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); opacity: 0.8; }
}

.splash-title {
  font-size: 28px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.splash-loader {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ===== Login Page ===== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-primary);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(51, 85, 255, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(139, 92, 246, 0.06) 0%, transparent 50%);
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 24px;
}

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
}

.login-logo {
  font-size: 48px;
  margin-bottom: 16px;
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: left;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group input::placeholder {
  color: var(--text-muted);
}

.login-error {
  font-size: 13px;
  color: #ef4444;
  min-height: 20px;
  text-align: center;
  opacity: 0;
  transition: opacity var(--transition);
}

.login-error.visible {
  opacity: 1;
}

.login-btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition), transform var(--transition);
  position: relative;
  overflow: hidden;
}

.login-btn:hover {
  background: var(--accent-light);
  transform: translateY(-1px);
}

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

.login-btn .btn-loading {
  display: none;
}

.login-btn.loading {
  pointer-events: none;
  opacity: 0.7;
}

.login-btn.loading .btn-text {
  display: none;
}

.login-btn.loading .btn-loading {
  display: inline;
}

.login-footer {
  margin-top: 24px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Home Page ===== */
.home-page {
  min-height: 100vh;
  background: var(--bg-primary);
}

.nav-back {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color var(--transition), background var(--transition);
}

.nav-back:hover {
  color: var(--accent-light);
  background: var(--bg-tertiary);
}

.user-greeting {
  font-size: 13px;
  color: var(--text-secondary);
  margin-right: 8px;
}

.logout-btn {
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: var(--transition);
}

.logout-btn:hover {
  border-color: #ef4444;
  color: #ef4444;
}

.home-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
}

.home-hero {
  text-align: center;
  margin-bottom: 40px;
  padding-top: 20px;
}

.home-heading {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}

.home-description {
  font-size: 15px;
  color: var(--text-secondary);
}

.episode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
}

.episode-card {
  display: block;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}

.episode-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  border-color: var(--accent);
}

.episode-card-cover {
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.episode-cover-emoji {
  font-size: 56px;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

.episode-day-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
}

.episode-card-body {
  padding: 20px;
}

.episode-card-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.episode-card-subtitle {
  font-size: 13px;
  color: var(--accent-light);
  margin-bottom: 12px;
}

.episode-card-meta {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.episode-card-summary {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-state p {
  font-size: 16px;
}

/* ===== Home Page Responsive ===== */
@media (max-width: 768px) {
  .episode-grid {
    grid-template-columns: 1fr;
  }

  .home-main {
    padding: 16px;
  }

  .home-heading {
    font-size: 22px;
  }

  .login-container {
    padding: 16px;
  }

  .login-card {
    padding: 28px 20px;
  }

  .login-title {
    font-size: 20px;
  }
}