:root {
  --bg-main: #0c1017;
  --bg-surface: #141b26;
  --bg-surface-elevated: #1a2332;
  --bg-surface-hover: #222d40;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #00d2ff;
  --text-primary: #f0f4f8;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-cyan: #00d2ff;
  --accent-blue: #3a7bd5;
  --accent-gradient: linear-gradient(135deg, #00d2ff 0%, #3a7bd5 100%);
  --accent-purple: #9d4edd;
  --danger-color: #ff4757;
  --success-color: #2ed573;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --shadow-lg: 0 10px 30px -5px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(0, 210, 255, 0.35);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  background-color: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* App Container */
.app-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 20px 40px;
}

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

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  font-size: 32px;
  line-height: 1;
}

.brand-text h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  font-size: 13px;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-indicator.online {
  background-color: var(--success-color);
  box-shadow: 0 0 8px var(--success-color);
}

.status-text {
  color: var(--text-secondary);
}

/* Search Section */
.search-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-lg);
}

.search-box {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
}

.input-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  font-size: 18px;
  pointer-events: none;
  opacity: 0.7;
}

#url-input {
  width: 100%;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 40px 14px 44px;
  font-size: 15px;
  color: var(--text-primary);
  outline: none;
  transition: all 0.2s ease;
}

#url-input:focus {
  border-color: var(--accent-cyan);
  box-shadow: var(--shadow-glow);
}

.clear-btn {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.clear-btn:hover {
  color: var(--text-primary);
}

.parse-btn {
  background: var(--accent-gradient);
  border: none;
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  padding: 0 28px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.parse-btn:hover {
  opacity: 0.95;
  transform: translateY(-1px);
}

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

.parse-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.quick-samples {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
}

.sample-label {
  color: var(--text-muted);
}

.sample-tag {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sample-tag:hover {
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
  background: var(--bg-surface-hover);
}

/* Main Player Layout */
.main-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  margin-bottom: 30px;
  align-items: start;
}

/* Left Column */
.player-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Player Top Bar */
.player-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--bg-surface);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.current-playing-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 200px;
}

.playing-badge {
  background: rgba(0, 210, 255, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(0, 210, 255, 0.3);
  font-size: 12px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.playing-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 500px;
}

/* Proxy Toggle Switch */
.proxy-switch-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.proxy-label {
  font-size: 13px;
  color: var(--text-secondary);
  cursor: help;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  transition: .3s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-muted);
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

input:checked + .slider:before {
  transform: translateX(20px);
  background-color: #fff;
}

/* Video Player Frame */
.player-wrapper {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* 16:9 ratio */
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
}

.artplayer-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.player-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #10151f 0%, #080a0f 100%);
  z-index: 5;
}

.placeholder-content {
  text-align: center;
  padding: 20px;
  max-width: 450px;
}

.placeholder-icon {
  font-size: 56px;
  margin-bottom: 12px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.placeholder-content h3 {
  font-size: 20px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.placeholder-content p {
  font-size: 14px;
  color: var(--text-muted);
}

/* Source Lines Selector Bar */
.source-lines-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
}

.lines-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.lines-count {
  font-size: 12px;
  color: var(--text-muted);
}

.lines-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.line-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s ease;
}

.line-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
}

.line-btn.active {
  background: rgba(0, 210, 255, 0.15);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
  font-weight: 600;
}

/* Media Details Box */
.media-details {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  gap: 16px;
}

.media-poster-wrapper {
  width: 90px;
  height: 126px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg-surface-elevated);
}

.media-poster-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-info-text {
  flex: 1;
}

.media-meta {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.media-tag {
  background: rgba(157, 78, 221, 0.2);
  color: var(--accent-purple);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

.media-ep-status {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

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

/* Right Column: Playlist / Episodes */
.playlist-column {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  height: 640px;
}

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

.panel-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-title-group h3 {
  font-size: 16px;
  font-weight: 600;
}

.ep-count-badge {
  background: var(--bg-surface-elevated);
  color: var(--text-muted);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.sort-toggle-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.sort-toggle-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.ep-search-bar {
  margin-bottom: 12px;
}

#ep-filter-input {
  width: 100%;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
}

#ep-filter-input:focus {
  border-color: var(--accent-cyan);
}

.episodes-scroll {
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
}

.episodes-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.ep-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.15s ease;
}

.ep-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
}

.ep-btn.active {
  background: var(--accent-gradient);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 210, 255, 0.3);
}

/* History Section */
.history-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 30px;
}

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

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-icon {
  font-size: 18px;
}

.section-title h3 {
  font-size: 16px;
  font-weight: 600;
}

.text-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
}

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

.history-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.history-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  gap: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-card:hover {
  background: var(--bg-surface-hover);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.history-poster {
  width: 50px;
  height: 70px;
  border-radius: 4px;
  object-fit: cover;
  background: #000;
  flex-shrink: 0;
}

.history-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

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

.history-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.history-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 30px;
  color: var(--text-muted);
  font-size: 14px;
}

/* Footer */
.footer {
  text-align: center;
  padding: 20px 0;
  color: var(--text-muted);
  font-size: 13px;
  border-top: 1px solid var(--border-color);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: rgba(20, 27, 38, 0.95);
  border: 1px solid var(--border-color);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(10px);
  z-index: 9999;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.error {
  border-color: var(--danger-color);
  color: #ff6b81;
}

.toast.success {
  border-color: var(--success-color);
  color: #7bed9f;
}

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

  .playlist-column {
    height: 480px;
  }

  .episodes-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 640px) {
  .app-container {
    padding: 12px 14px 30px;
  }

  .search-box {
    flex-direction: column;
  }

  .parse-btn {
    width: 100%;
    justify-content: center;
    padding: 14px;
  }

  .episodes-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .playing-title {
    max-width: 200px;
  }
}

/* Cast Button & Modal Styles */
.player-topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cast-btn {
  background: rgba(0, 210, 255, 0.12);
  border: 1px solid rgba(0, 210, 255, 0.4);
  color: var(--accent-cyan);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.cast-btn:hover {
  background: rgba(0, 210, 255, 0.22);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 12px rgba(0, 210, 255, 0.3);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  padding: 24px;
  animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

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

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-icon {
  font-size: 24px;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}

.modal-close-btn:hover {
  color: var(--text-primary);
}

.modal-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: var(--bg-surface-elevated);
  color: var(--accent-cyan);
}

.cast-step {
  display: flex;
  gap: 14px;
  margin-bottom: 20px;
  align-items: flex-start;
}

.step-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.step-text {
  font-size: 14px;
  color: var(--text-primary);
  flex: 1;
  line-height: 1.6;
}

.tv-url-badge {
  background: #000;
  border: 1px solid var(--border-color);
  color: var(--accent-cyan);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: monospace;
  font-size: 14px;
  margin-top: 8px;
  user-select: all;
}

.code-input-row {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

#cast-room-input {
  flex: 1;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 18px;
  letter-spacing: 4px;
  color: #fff;
  font-weight: 700;
  outline: none;
  text-align: center;
}

#cast-room-input:focus {
  border-color: var(--accent-cyan);
}

.primary-btn {
  background: var(--accent-gradient);
  border: none;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}

.primary-btn:hover {
  opacity: 0.95;
}

/* Remote Controller */
.remote-controller {
  background: var(--bg-surface-elevated);
  border: 1px solid rgba(0, 210, 255, 0.3);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-top: 16px;
  text-align: center;
}

.remote-status {
  font-size: 14px;
  color: #10b981;
  font-weight: 600;
  margin-bottom: 14px;
}

.remote-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.remote-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
}

.remote-btn:hover {
  background: var(--bg-surface-hover);
}

.remote-btn.btn-highlight {
  background: rgba(0, 210, 255, 0.2);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.remote-disconnect-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
}

.remote-disconnect-btn:hover {
  color: var(--danger-color);
}

/* Guide tabs */
.guide-box {
  background: rgba(0, 210, 255, 0.08);
  border-left: 3px solid var(--accent-cyan);
  padding: 12px 14px;
  border-radius: 4px;
  margin-bottom: 16px;
}

.guide-box h4 {
  font-size: 14px;
  color: var(--accent-cyan);
  margin-bottom: 6px;
}

.guide-box p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.guide-action-box {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 14px;
}

.guide-action-box h4 {
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.guide-action-box p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.copy-url-row {
  display: flex;
  gap: 8px;
}

.copy-url-row input {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  outline: none;
}
