:root {
  color-scheme: dark;
  --bg-main: #0a0d16;
  --bg-card: rgba(18, 25, 41, 0.85);
  --bg-surface: #121929;
  --bg-surface-elevated: #1a233a;
  --bg-hover: #222e4c;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(56, 189, 248, 0.45);
  --accent: #38bdf8;
  --accent-glow: rgba(56, 189, 248, 0.2);
  --text-main: #edf2f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --danger: #f43f5e;
  --danger-hover: #e11d48;
  --success: #10b981;
  font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
}

* { box-sizing: border-box; }
body { margin: 0; padding: 12px 20px 24px; min-height: 100vh; background: radial-gradient(circle at top right, #131c33 0%, #0a0d16 60%); }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
}

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

h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff 40%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.track-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent);
  border: 1px solid var(--border-accent);
}

.actions { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }

button {
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(8px);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

button:hover {
  background: var(--bg-hover);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: 0.5; cursor: wait; transform: none; }

button.btn-playlist.active,
button#openSidebar.active {
  background: rgba(56, 189, 248, 0.18);
  border-color: var(--border-accent);
  color: #38bdf8;
  box-shadow: 0 0 14px var(--accent-glow);
}

.count-badge {
  background: var(--accent);
  color: #000;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  margin-left: 4px;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 22px;
  max-width: 1720px;
  margin: auto;
  align-items: start;
  transition: grid-template-columns 0.25s ease;
}

.layout.playlist-collapsed {
  grid-template-columns: minmax(0, 1fr);
}

.layout.playlist-collapsed .playlist-panel {
  display: none;
}

/* Video Container */
main, .video-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.video-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 8px 14px;
}

#fileName {
  margin: 0;
  font-weight: 600;
  font-size: 14.5px;
  color: #f1f5f9;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 580px;
}

.transport-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.transport-nav button {
  padding: 6px 11px;
  font-size: 12.5px;
}

#autoPlayNextBtn.active {
  background: rgba(16, 185, 129, 0.18);
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
}

video {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100dvh - 300px);
  aspect-ratio: 16/9;
  background: #000;
  border-radius: 12px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.7);
  outline: none;
  margin-bottom: 36px;
}

#status {
  color: #93c5fd;
  min-height: 22px;
  margin: 0;
  font-size: 13.5px;
}

.hint {
  color: var(--text-dim);
  font-size: 12.5px;
  margin: 0;
}

body.dragging {
  outline: 3px dashed var(--accent);
  outline-offset: -8px;
  background: #0d1629;
}

/* Playlist Panel */
.playlist-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 120px);
  min-height: 520px;
  overflow: hidden;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(12px);
}

.playlist-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.02);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.playlist-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.playlist-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
}

.playlist-subcount {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

.playlist-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}

.btn-tool {
  padding: 4px 8px;
  font-size: 11.5px;
  border-radius: 6px;
  white-space: nowrap;
}

.btn-tool.btn-danger {
  color: #fda4af;
}

.btn-tool.btn-danger:hover {
  background: rgba(244, 63, 94, 0.2);
  border-color: var(--danger);
}

.playlist-search-wrap input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  color: #fff;
  outline: none;
  transition: border-color 0.15s ease;
}

.playlist-search-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

/* Playlist Item List */
.playlist-items {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.playlist-items::-webkit-scrollbar {
  width: 6px;
}

.playlist-items::-webkit-scrollbar-track {
  background: transparent;
}

.playlist-items::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 4px;
}

.playlist-items::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

.playlist-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.empty-icon { font-size: 38px; opacity: 0.7; margin-bottom: 4px; }
.playlist-empty p { margin: 0; font-size: 14px; font-weight: 500; }
.playlist-empty .empty-sub { font-size: 12.5px; color: var(--text-dim); max-width: 260px; line-height: 1.4; }

/* Item Card */
.playlist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
  min-height: 58px;
  box-sizing: border-box;
}

.playlist-item:hover {
  background: var(--bg-surface-elevated);
  border-color: rgba(255, 255, 255, 0.14);
  transform: translateX(2px);
}

.playlist-item.active {
  background: linear-gradient(90deg, rgba(56, 189, 248, 0.2) 0%, rgba(18, 25, 41, 0.95) 100%);
  border-color: var(--accent);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.18);
}

.playlist-item.watched:not(.active) {
  opacity: 0.75;
}

.item-index {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  width: 22px;
  text-align: center;
  flex-shrink: 0;
  line-height: 1;
}

.playlist-item.active .item-index {
  color: var(--accent);
  font-size: 13px;
}

.item-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.item-title {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.4;
  color: #f1f5f9;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.playlist-item.active .item-title {
  color: #38bdf8;
}

.item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  line-height: 1.3;
  color: var(--text-dim);
}

.item-badge {
  padding: 1.5px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: #cbd5e1;
  font-size: 10.5px;
  font-weight: 500;
}

.item-progress-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: var(--accent);
  opacity: 0.85;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.playlist-item:hover .item-actions {
  opacity: 1;
}

.btn-item-action {
  padding: 3px 6px;
  font-size: 11px;
  border-radius: 4px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
}

.btn-item-action:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.btn-item-action.delete:hover {
  background: rgba(244, 63, 94, 0.25);
  color: #fda4af;
}

/* Playlist Footer */
.playlist-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.02);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
}

.btn-resync {
  padding: 3px 8px;
  font-size: 11px;
  background: rgba(56, 189, 248, 0.15);
  border-color: var(--border-accent);
  color: var(--accent);
  border-radius: 4px;
}

:root:fullscreen { overflow: auto; }

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .playlist-panel {
    height: 440px;
    min-height: auto;
  }
}

@media (max-width: 600px) {
  body { padding: 12px; }
  video { max-height: 60dvh; }
  header { flex-direction: column; align-items: flex-start; }
}
